-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageClass.aspx.cs
274 lines (251 loc) · 9.65 KB
/
ManageClass.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
272
273
274
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace ClassManageApp
{
public partial class WebForm8 : System.Web.UI.Page
{
string constr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//string constr = "Data Source=DESKTOP-F0U0098;Initial Catalog=ClassManageApp;Integrated Security=True";
StandGridGet();
SectionGridGet();
BatchGridGet();
Clear();
}
}
void Clear()
{
Standard.Text = "";
StdDesc.Text = "";
Section.Text = "";
SecDesc.Text = "";
}
private void StandGridGet()
{
using (SqlConnection con = new SqlConnection(constr))
{
string query = "select * from Standard";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
StandGrid.DataSource = cmd.ExecuteReader();
StandGrid.DataBind();
con.Close();
}
}
private void SectionGridGet()
{
using (SqlConnection con = new SqlConnection(constr))
{
string query = "select * from Section";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SectionGrid.DataSource = cmd.ExecuteReader();
SectionGrid.DataBind();
con.Close();
}
}
private void BatchGridGet()
{
using (SqlConnection con = new SqlConnection(constr))
{
string query = "select * from Batch";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
BatchGrid.DataSource = cmd.ExecuteReader();
BatchGrid.DataBind();
con.Close();
}
}
protected void AddStandard_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
string spname = "uspManageStandard";
con.Open();
SqlCommand cmd = new SqlCommand(spname, con)
{
CommandType = System.Data.CommandType.StoredProcedure
};
cmd.Parameters.AddWithValue("@ACTION", "CREATE");
cmd.Parameters.AddWithValue("@StandardName", Standard.Text);
cmd.Parameters.AddWithValue("@Description", StdDesc.Text);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write("<script>alert('One more standard added!') </script>");
StandGridGet();
Clear();
}
else
{
Response.Write("<script>alert('Sorry! Something went wrong...') </script>");
}
con.Close();
}
protected void StandGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(StandGrid.DataKeys[e.RowIndex].Value);
using (SqlConnection con = new SqlConnection(constr))
{
string query = "Delete from Standard Where StandardID=" + id;
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int row = cmd.ExecuteNonQuery();
con.Close();
if (row == 1)
{
Response.Write("<script>alert('Are you sure you want to delete this item?') </script>");
StandGridGet();
}
else
{
Response.Write("<script>alert('Somethiong went wrong!') </script>");
}
}
}
protected void StandGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection(constr))
{
int id = Convert.ToInt32(StandGrid.DataKeys[e.RowIndex].Value);
TextBox StandardName = (TextBox)StandGrid.Rows[e.RowIndex].FindControl("StandardName");
TextBox Description = (TextBox)StandGrid.Rows[e.RowIndex].FindControl("Description");
string spname = "uspManageStandard";
SqlCommand cmd = new SqlCommand(spname, con)
{
CommandType = System.Data.CommandType.StoredProcedure
};
cmd.Parameters.AddWithValue("@ACTION", "UPDATE");
cmd.Parameters.AddWithValue("@StandardName", Convert.ToString(Standard.Text.Trim()));
cmd.Parameters.AddWithValue("@Description", Convert.ToString(StdDesc.Text.Trim()));
int row = cmd.ExecuteNonQuery();
if (row == 1)
{
Response.Write("<script>alert('Data is edited') </script>");
StandGrid.EditIndex = -1;
StandGridGet();
}
else
{
Response.Write("<script>alert('Somethiong went wrong!') </script>");
}
}
}
catch (Exception ex)
{
Response.Write("<script>alert('Somethiong went wrong! Please check your input data') </script>");
}
}
//here this is Section code
protected void AddSection_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
string spname = "uspManageSection";
con.Open();
SqlCommand cmd = new SqlCommand(spname, con)
{
CommandType = System.Data.CommandType.StoredProcedure
};
cmd.Parameters.AddWithValue("@ACTION", "CREATE");
cmd.Parameters.AddWithValue("@sectionName", Section.Text);
cmd.Parameters.AddWithValue("@Description", SecDesc.Text);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write("<script>alert('One more section added!') </script>");
SectionGridGet();
Clear();
}
else
{
Response.Write("<script>alert('Sorry! Something went wrong...') </script>");
}
con.Close();
}
protected void SectionGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(SectionGrid.DataKeys[e.RowIndex].Value);
using (SqlConnection con = new SqlConnection(constr))
{
string query = "Delete from Section Where SectionID=" + id;
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int row = cmd.ExecuteNonQuery();
con.Close();
if (row == 1)
{
Response.Write("<script>alert('Are you sure you want to delete this item?') </script>");
SectionGridGet();
}
else
{
Response.Write("<script>alert('Somethiong went wrong!') </script>");
}
}
}
//here is the batch code
protected void AddBatch_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(constr);
string spname = "uspManageBatch";
con.Open();
SqlCommand cmd = new SqlCommand(spname, con)
{
CommandType = System.Data.CommandType.StoredProcedure
};
cmd.Parameters.AddWithValue("@ACTION", "CREATE");
cmd.Parameters.AddWithValue("@BatchName", Batch.Text);
cmd.Parameters.AddWithValue("@Description", BatchDesc.Text);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write("<script>alert('One more batch added!') </script>");
BatchGridGet();
Clear();
}
else
{
Response.Write("<script>alert('Sorry! Something went wrong...') </script>");
}
con.Close();
}
catch
{
Response.Write("<script>alert('Sorry! Something went wrong from catch...') </script>");
}
}
protected void BatchGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(BatchGrid.DataKeys[e.RowIndex].Value);
using (SqlConnection con = new SqlConnection(constr))
{
string query = "Delete from Batch Where BatchID=" + id;
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int row = cmd.ExecuteNonQuery();
con.Close();
if (row == 1)
{
Response.Write("<script>alert('Are you sure you want to delete this item?') </script>");
BatchGridGet();
}
else
{
Response.Write("<script>alert('Somethiong went wrong!') </script>");
}
}
}
}
}