-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadminFormImpuesto.aspx.cs
271 lines (222 loc) · 9.6 KB
/
adminFormImpuesto.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace indioSupermercado
{
public partial class adminFormImpuesto : System.Web.UI.Page
{
private string stringConnection = usefull.strCon;
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSourceImpuesto.ConnectionString = usefull.strCon;
loadCountry();
}
public void clearForm()
{
IDTaxTxt.Text = "";
nameTaxtxt.Text = "";
taxPorcentagetxt.Text = "";
}
public void loadCountry()
{
try
{
var nombrePais = new ArrayList();
var idPais = new ArrayList();
SqlConnection con = new SqlConnection(stringConnection);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("spGetCountries", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
nombrePais.Add(reader[1].ToString());
idPais.Add(reader[0].ToString());
}
con.Close();
if (!IsPostBack)
{
for (int i = 0; i < nombrePais.Count; i++)
paisDropList.Items.Insert(0, new ListItem(nombrePais[i].ToString(), idPais[i].ToString()));
paisDropList.DataBind();
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script.");
}
}
protected void ButtonAgregarImpuesto_Click(object sender, EventArgs e)
{
string idTax = IDTaxTxt.Text;
string nameTax = nameTaxtxt.Text;
string porcentage = taxPorcentagetxt.Text;
string idCountry = paisDropList.SelectedValue;
string status = DropDownListEstado.SelectedValue;
int valueResult = 0;
string msgResult = "";
if (nameTax != "" && porcentage != "" && idCountry != "" && float.Parse(porcentage) < 1)
{
try
{
SqlConnection connection = new SqlConnection(stringConnection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand cmd = new SqlCommand("spCrudImpuesto", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@nombre", SqlDbType.Int).Value = nameTax;
cmd.Parameters.AddWithValue("@porcentaje", SqlDbType.Float).Value = porcentage;
cmd.Parameters.AddWithValue("@idPais", SqlDbType.Int).Value = Convert.ToInt32(idCountry);
cmd.Parameters.AddWithValue("@operationFlag", 0);
SqlDataReader reader = cmd.ExecuteReader();
connection.Close();
reader.Close();
if (valueResult == 0)
{
clearForm();
GridViewImpuesto.DataBind();
UpdatePanelImpuesto.Update();
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Perfect','" + msgResult + "','success')", true);
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','" + msgResult + "','error')", true);
}
//Response.Write(alert);
}
catch (Exception ex)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','" + ex.Message + "','error')", true);
}
/// Titulo, mensaje, tipo
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','Some files are empty','error')", true);
}
}
protected void ButtonActualizarImpuesto_Click(object sender, EventArgs e)
{
string idTax = IDTaxTxt.Text;
string nameTax = nameTaxtxt.Text;
string porcentage = taxPorcentagetxt.Text;
string idCountry = paisDropList.SelectedValue;
string status = DropDownListEstado.SelectedValue;
int valueResult = 0;
string msgResult = "";
if(idTax != "" && float.Parse(porcentage) < 1)
{
try
{
SqlConnection connection = new SqlConnection(stringConnection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand cmd = new SqlCommand("spCrudImpuesto", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@idImpuesto", SqlDbType.Int).Value = Convert.ToInt32(idTax);
cmd.Parameters.AddWithValue("@nombre", SqlDbType.Int).Value = nameTax;
cmd.Parameters.AddWithValue("@porcentaje", SqlDbType.Float).Value = porcentage;
cmd.Parameters.AddWithValue("@idPais", SqlDbType.Int).Value = Convert.ToInt32(idCountry);
cmd.Parameters.AddWithValue("@operationFlag", 1);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
valueResult = Convert.ToInt32(reader[0].ToString());
msgResult = reader[1].ToString();
}
connection.Close();
reader.Close();
if (valueResult == 0)
{
clearForm();
GridViewImpuesto.DataBind();
UpdatePanelImpuesto.Update();
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Perfect','" + msgResult + "','success')", true);
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','" + msgResult + "','error')", true);
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','Datos invalidos','error')", true);
}
}
protected void ButtonBorrarImpuesto_Click(object sender, EventArgs e)
{
string idImpuesto = IDTaxTxt.Text;
int valueResult = 0;
string msgResult = "";
if (idImpuesto != "")
{
try
{
SqlConnection connection = new SqlConnection(stringConnection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand cmd = new SqlCommand("spCrudImpuesto", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@operationFlag", 4);
cmd.Parameters.AddWithValue("@idImpuesto", SqlDbType.Int).Value = Convert.ToInt32(idImpuesto);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
valueResult = Convert.ToInt32(reader[0].ToString());
msgResult = reader[1].ToString();
}
connection.Close();
reader.Close();
if (valueResult == 0)
{
clearForm();
GridViewImpuesto.DataBind();
UpdatePanelImpuesto.Update();
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Perfect','" + msgResult + "','success')", true);
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','" + msgResult + "','error')", true);
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Error','ID impuesto can not be null','error')", true);
}
}
}
}