-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageQuestion.cs
418 lines (393 loc) · 17.5 KB
/
ManageQuestion.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
namespace QuestionPaper_Genration
{
public partial class ManageQuestion : Form
{
public ManageQuestion()
{
InitializeComponent();
}
public static int Currentrow = 0;
public static string FId;
public static string SubId;
public DataTable DtShowData = new DataTable();
private void BtnAdd_Click(object sender, EventArgs e)
{
try
{
if (lblQid.Text == "")
{
if (DtConnection.Type == "Faculty")
{
if (cmbLevel.Text == "--Select Level--")
{
MessageBox.Show("Select Level.");
return;
}
else if (cmbmarks.Text == "")
{
MessageBox.Show("Select Mark.");
return;
}
else if (txtquestion.Text == "")
{
MessageBox.Show("Enter Question.");
return;
}
else
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("insert into QuestionBank values(@QuestionName, @LId, @SubId, @FId, @QsId)", DtConnection.Con);
DtConnection.Con.Open();
cmd.Parameters.AddWithValue("@FId", DtConnection.FId);
cmd.Parameters.AddWithValue("@LId", cmbLevel.SelectedValue);
cmd.Parameters.AddWithValue("@SubId", DtConnection.SubId);
cmd.Parameters.AddWithValue("@QsId", cmbmarks.SelectedValue);
cmd.Parameters.AddWithValue("@QuestionName", txtquestion.Text.ToString().Trim());
cmd.ExecuteNonQuery();
txtquestion.Text = "";
DtConnection.Con.Close();
MessageBox.Show("Question Added Successfully.");
}
}
else
if (DtConnection.Type == "Admin")
{
if (cmbfaculty.Text == "--Select Faculty--")
{
MessageBox.Show("Select Faculty.");
return;
}
else if (cmbsubject.Text == "--Select Subject--")
{
MessageBox.Show("Select Subject.");
return;
}
else if (cmbLevel.Text == "--Select Level--")
{
MessageBox.Show("Select Level.");
return;
}
else if (cmbmarks.Text == "")
{
MessageBox.Show("Select Mark.");
return;
}
else if (txtquestion.Text == "")
{
MessageBox.Show("Enter Question.");
return;
}
else
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("insert into QuestionBank values(@QuestionName, @LId, @SubId, @FId, @QsId)", DtConnection.Con);
DtConnection.Con.Open();
cmd.Parameters.AddWithValue("@FId", cmbfaculty.SelectedValue);
cmd.Parameters.AddWithValue("@LId", cmbLevel.SelectedValue);
cmd.Parameters.AddWithValue("@SubId", cmbsubject.SelectedValue);
cmd.Parameters.AddWithValue("@QsId", cmbmarks.SelectedValue);
cmd.Parameters.AddWithValue("@QuestionName", txtquestion.Text.ToString().Trim());
cmd.ExecuteNonQuery();
txtquestion.Text = "";
DtConnection.Con.Close();
MessageBox.Show("Question Added Successfully.");
}
}
}
else
{
if (DtConnection.Type == "Admin")
{
DtConnection.Con.Open();
SqlCommand cmd = new SqlCommand("update QuestionBank set QuestionName='" + txtquestion.Text.ToString() + "', LId='" + cmbLevel.SelectedValue + "', SubId='" + cmbsubject.SelectedValue + "', FId='" + cmbfaculty.SelectedValue + "', QsId='" + cmbmarks.SelectedValue + "' where QId='" + lblQid.Text + "'", DtConnection.Con);
// SqlCommand cmd = new SqlCommand("update QuestionBank set QuestionName=@QuestionName, LId=@LId, SubId=@SubId, FId=@FId, QsId=@QsId where QId=@QId", DtConnection.Con);
//cmd.Parameters.AddWithValue("@FId", cmbfaculty.SelectedValue.ToString());
//cmd.Parameters.AddWithValue("@LId", cmbLevel.SelectedValue.ToString());
//cmd.Parameters.AddWithValue("@SubId", cmbsubject.SelectedValue.ToString());
//cmd.Parameters.AddWithValue("@QsId", cmbmarks.SelectedValue.ToString());
//cmd.Parameters.AddWithValue("@QuestionName", txtquestion.Text.ToString().Trim());
//cmd.Parameters.AddWithValue("@QId", lblQid);
cmd.ExecuteNonQuery();
DtConnection.Con.Close();
}
else
if (DtConnection.Type == "Faculty")
{
DtConnection.Con.Open();
SqlCommand cmd = new SqlCommand("update QuestionBank set QuestionName='" + txtquestion.Text.ToString() + "', LId='" + cmbLevel.SelectedValue + "', SubId='" + DtConnection.SubId + "', FId='" + DtConnection.FId + "', QsId='" + cmbmarks.SelectedValue + "' where QId='" + lblQid.Text + "'", DtConnection.Con);
//cmd.Parameters.AddWithValue("@FId", DtConnection.FId);
//cmd.Parameters.AddWithValue("@LId", cmbLevel.SelectedValue);
//cmd.Parameters.AddWithValue("@SubId", DtConnection.SubId);
//cmd.Parameters.AddWithValue("@QsId", cmbmarks.SelectedValue);
//cmd.Parameters.AddWithValue("@QuestionName", txtquestion.Text.ToString().Trim());
//cmd.Parameters.AddWithValue("@QId", lblQid);
cmd.ExecuteNonQuery();
DtConnection.Con.Close();
}
}
}
catch (Exception)
{
throw;
}
}
private void ManageQuestion_Load(object sender, EventArgs e)
{
if (DtConnection.Type == "Admin")
{
cmbfaculty.Enabled = true;
cmbsubject.Enabled = true;
// button2.Visible = false;
//button1.Visible = false;
groupBox1.Visible = false;
}
else if (DtConnection.Type == "Faculty")
{
cmbfaculty.Enabled = false;
cmbsubject.Enabled = false;
// button2.Visible = true;
// button1.Visible = true;
groupBox1.Visible = true;
}
try
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("select distinct * from Faculty_Master", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
DataRow row = dt.NewRow();
row["FId"] = 0;
row["FacultyName"] = "--Select Faculty--";
dt.Rows.InsertAt(row, 0);
cmbfaculty.DataSource = dt;
cmbfaculty.DisplayMember = "FacultyName";
cmbfaculty.ValueMember = "FId";
DtConnection.Con.Close();
DtConnection.Con.Close();
SqlCommand cmd1 = new SqlCommand("select * from Level_Master", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
DataRow row1 = dt1.NewRow();
row1["LId"] = 0;
row1["LevelName"] = "--Select Level--";
dt1.Rows.InsertAt(row1, 0);
cmbLevel.DataSource = dt1;
cmbLevel.DisplayMember = "LevelName";
cmbLevel.ValueMember = "LId";
DtConnection.Con.Close();
DtConnection.Con.Close();
SqlCommand cmd3 = new SqlCommand("select * from QuestionSection", DtConnection.Con);
DtConnection.Con.Open();
SqlDataAdapter adp3 = new SqlDataAdapter(cmd3);
DataTable dt3 = new DataTable();
adp3.Fill(dt3);
cmbmarks.DataSource = dt3;
cmbmarks.DisplayMember = "Marks";
cmbmarks.ValueMember = "QsId";
DtConnection.Con.Close();
BtnFirst.Visible = false;
BtnLast.Visible = false;
BtnOneBack.Visible = false;
BtnOneNext.Visible = false;
}
catch (Exception)
{
throw;
}
}
protected void ShowData()
{
if (DtConnection.Type == "Faculty")
{
try
{
lblQid.Text = DtShowData.Rows[Currentrow]["QId"].ToString();
txtquestion.Text = DtShowData.Rows[Currentrow]["QuestionName"].ToString();
DtConnection.FId = DtShowData.Rows[Currentrow]["FId"].ToString();
cmbLevel.SelectedValue = DtShowData.Rows[Currentrow]["LId"].ToString();
cmbmarks.SelectedValue = DtShowData.Rows[Currentrow]["QsId"].ToString();
DtConnection.SubId = DtShowData.Rows[Currentrow]["SubId"].ToString();
}
catch (Exception)
{
throw;
}
}
else if (DtConnection.Type == "Admin")
{
lblQid.Text = DtShowData.Rows[Currentrow]["QId"].ToString();
txtquestion.Text = DtShowData.Rows[Currentrow]["QuestionName"].ToString();
cmbfaculty.SelectedValue = DtShowData.Rows[Currentrow]["FId"].ToString();
cmbLevel.SelectedValue = DtShowData.Rows[Currentrow]["LId"].ToString();
cmbmarks.SelectedValue = DtShowData.Rows[Currentrow]["QsId"].ToString();
cmbsubject.SelectedValue = DtShowData.Rows[Currentrow]["SubId"].ToString();
}
}
private void BtnOneBack_Click(object sender, EventArgs e)
{
if (Currentrow == 0)
{
Currentrow = 0;
ShowData();
}
else
{
Currentrow = Currentrow - 1;
ShowData();
}
}
private void BtnFirst_Click(object sender, EventArgs e)
{
Currentrow = 0;
ShowData();
}
private void BtnOneNext_Click(object sender, EventArgs e)
{
if (Currentrow == DtShowData.Rows.Count - 1)
{
Currentrow = DtShowData.Rows.Count - 1;
ShowData();
}
else
{
Currentrow = Currentrow + 1;
ShowData();
}
}
private void BtnLast_Click(object sender, EventArgs e)
{
Currentrow = DtShowData.Rows.Count - 1;
ShowData();
}
private void BtnSearch_Click(object sender, EventArgs e)
{
cmbfaculty.Enabled = false;
cmbsubject.Enabled = false;
DtShowData.Clear();
if (DtConnection.Type == "Admin")
{
DtConnection.Con.Close();
SqlDataAdapter adp = new SqlDataAdapter("select * from QuestionBank where SubId='" + cmbsubject .SelectedValue+ "' order by QId",
DtConnection.Con);
adp.Fill(DtShowData);
if (DtShowData.Rows.Count > 0)
{
BtnDelete.Enabled = true;
BtnFirst.Visible = true;
BtnLast.Visible = true;
BtnOneBack.Visible = true;
BtnOneNext.Visible = true;
ShowData();
}
else
{
BtnDelete.Enabled = false;
BtnFirst.Visible = false;
BtnLast.Visible = false;
BtnOneBack.Visible = false;
BtnOneNext.Visible = false;
}
}
else if (DtConnection.Type == "Faculty")
{
DtConnection.Con.Close();
SqlDataAdapter adp = new SqlDataAdapter("select * from QuestionBank where FId='" + DtConnection.FId + "' and SubId='" + DtConnection.SubId + "' order by QId", DtConnection.Con);
adp.Fill(DtShowData);
if (DtShowData.Rows.Count > 0)
{
BtnDelete.Enabled = true;
BtnFirst.Visible = true;
BtnLast.Visible = true;
BtnOneBack.Visible = true;
BtnOneNext.Visible = true;
ShowData();
}
else
{
BtnDelete.Enabled = false;
BtnFirst.Visible = false;
BtnLast.Visible = false;
BtnOneBack.Visible = false;
BtnOneNext.Visible = false;
}
}
}
private void BtnDelete_Click(object sender, EventArgs e)
{
try
{
DtConnection.Con.Close();
SqlCommand cmd = new SqlCommand("Delete from QuestionBank where QId=@QId", DtConnection.Con);
DtConnection.Con.Open();
cmd.Parameters.AddWithValue("@QId", lblQid.Text);
cmd.ExecuteNonQuery();
DtConnection.Con.Close();
MessageBox.Show("Record Deleted!");
}
catch (Exception)
{
throw;
}
}
private void Btnclear_Click(object sender, EventArgs e)
{
cmbfaculty.Enabled = true;
cmbsubject.Enabled = true;
txtquestion.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
ViewQuestions q = new ViewQuestions();
q.Show();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
GenrateQuestionPaper GQP = new GenrateQuestionPaper();
GQP.Show();
}
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
BtnLogin L = new BtnLogin();
L.Show();
}
private void cmbfaculty_SelectedIndexChanged(object sender, EventArgs e)
{
DtConnection.Con.Close();
SqlCommand cmd2 = new SqlCommand("select * from dbo.Subject_Master where subid in(select SubId from dbo.Faculty_Master where FacultyName=@FacultyName)", DtConnection.Con);
cmd2.Parameters.AddWithValue("@FacultyName", cmbfaculty.Text);
DtConnection.Con.Open();
SqlDataAdapter adp2 = new SqlDataAdapter(cmd2);
DataTable dt2 = new DataTable();
adp2.Fill(dt2);
DataRow row2 = dt2.NewRow();
row2["SubId"] = 0;
row2["SubName"] = "--Select Subject--";
dt2.Rows.InsertAt(row2, 0);
cmbsubject.DataSource = dt2;
cmbsubject.DisplayMember = "SubName";
cmbsubject.ValueMember = "SubId";
DtConnection.Con.Close();
}
}
}