-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadminFormManager.aspx.cs
232 lines (193 loc) · 7.93 KB
/
adminFormManager.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
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;
using System.Security.Cryptography;
using System.Drawing;
namespace indioSupermercado
{
public partial class adminFormManager : System.Web.UI.Page
{
private string stringConnection = usefull.strCon;
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSourceManager.ConnectionString = usefull.strCon;
loadSucursal();
loadEmpleado();
}
public void loadSucursal()
{
try
{
var nombreSucursal = new ArrayList();
var idSucursal = new ArrayList();
SqlConnection con = new SqlConnection(stringConnection);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("spGetSucursales", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
nombreSucursal.Add(reader[1].ToString());
idSucursal.Add(reader[0].ToString());
}
con.Close();
if (!IsPostBack)
{
for (int i = 0; i < nombreSucursal.Count; i++)
sucursalDropList.Items.Insert(0, new ListItem(nombreSucursal[i].ToString(), idSucursal[i].ToString()));
sucursalDropList.DataBind();
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script.");
}
}
public void loadEmpleado()
{
try
{
var nombreEmpleado = new ArrayList();
var idEmpleado = new ArrayList();
SqlConnection con = new SqlConnection(stringConnection);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("spGetEmpleado", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
nombreEmpleado.Add(reader[1].ToString());
idEmpleado.Add(reader[0].ToString());
}
con.Close();
if (!IsPostBack)
{
for (int i = 0; i < nombreEmpleado.Count; i++)
employeeDropList.Items.Insert(0, new ListItem(nombreEmpleado[i].ToString(), idEmpleado[i].ToString()));
employeeDropList.DataBind();
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script.");
}
}
protected void ButtonAgregarManager_Click(object sender, EventArgs e)
{
string idManager = TextBoxMB.Text;
string idSucursal = sucursalDropList.SelectedValue;
string idEmpleado = employeeDropList.SelectedValue;
int valueResult = 0;
string msgResult = "";
if (idSucursal != "" && idEmpleado != "")
{
try
{
SqlConnection connection = new SqlConnection(stringConnection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand cmd = new SqlCommand("crudSucursalManager 1, null, " +idSucursal+ ", "+idEmpleado, connection);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
valueResult = Convert.ToInt32(reader[0].ToString());
msgResult = (reader[1].ToString());
connection.Close();
reader.Close();
if (valueResult == 0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Perfect','" + msgResult + "','success')", true);
GridViewManager.DataBind();
UpdatePanelManager.Update();
}
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 ButtonActualizarManager_Click(object sender, EventArgs e)
{
string idManager = TextBoxMB.Text;
string idSucursal = sucursalDropList.SelectedValue;
string idEmpleado = employeeDropList.SelectedValue;
int valueResult = 0;
string msgResult = "";
if (idManager != "")
{
try
{
SqlConnection connection = new SqlConnection(stringConnection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
SqlCommand cmd = new SqlCommand("crudSucursalManager", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@opcion", 2);
cmd.Parameters.AddWithValue("@idSucursalManger", SqlDbType.Int).Value = Convert.ToInt32(idManager);
cmd.Parameters.AddWithValue("@idSucursal", SqlDbType.Int).Value = Convert.ToInt32(idSucursal);
cmd.Parameters.AddWithValue("@idEmpleado", SqlDbType.Int).Value = Convert.ToInt32(idEmpleado);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
valueResult = Convert.ToInt32(reader[0].ToString());
msgResult = reader[1].ToString();
}
connection.Close();
reader.Close();
if (valueResult == 0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
"Swal.fire('Perfect','" + msgResult + "','success')", true);
GridViewManager.DataBind();
UpdatePanelManager.Update();
}
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);
}
}
protected void ButtonBorrarManager_Click(object sender, EventArgs e)
{
}
}
}