-
Notifications
You must be signed in to change notification settings - Fork 0
/
PracticeTest.aspx.cs
283 lines (271 loc) · 9.76 KB
/
PracticeTest.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
275
276
277
278
279
280
281
282
283
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.Data;
using System.Drawing;
public partial class PracticeTest : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
private static int counter = 0;
DataTable dt = new DataTable();
private int id;
private String ans;
int right_ans = 0;
private static int count = 0;
private static int confirmCount = 0;
String sub;
protected void Page_Load(object sender, EventArgs e)
{
sub = Session["Subject"].ToString();
Label2.Text = sub;
}
protected void Button7_Click(object sender, EventArgs e)
{
Button7.Enabled = false;
Button6.Enabled = true;
counter++;
if (counter > 20)
{
con.Open();
//SqlCommand cmd2 = new SqlCommand("DELETE FROM Que_temp", con);
//cmd2.ExecuteNonQuery();
SqlDataAdapter da1 = new SqlDataAdapter("SELECT Opt_Selected,Ans FROM Answer", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
int i = 0;
foreach (DataRow dr in dt1.Rows)
{
if (dt1.Rows[i]["Opt_Selected"].ToString() == dt1.Rows[i]["Ans"].ToString())
{
right_ans++;
}
i++;
}
Session["Right_Answer"] = right_ans;
counter = 0;
right_ans = 0;
//SqlCommand cmd3 = new SqlCommand("DELETE FROM Answer", con);
//cmd3.ExecuteNonQuery();
con.Close();
Session["Subject"] = sub;
Response.Redirect("PracticeResult.aspx");
}
RadioButtonList1.Items.Clear();
SqlDataAdapter da = new SqlDataAdapter("SELECT TOP 20 * FROM " + sub + " WHERE Id NOT IN(SELECT que_id FROM Que_temp) ORDER BY newid()", con);
da.Fill(dt);
Label1.Text = dt.Rows[0]["Question"].ToString();
this.id = Convert.ToInt32(dt.Rows[0]["Id"]);
this.ans = dt.Rows[0]["Answer"].ToString();
RadioButtonList1.Items.Add(new ListItem(dt.Rows[0]["Option1"].ToString(), dt.Rows[0]["Option1"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt.Rows[0]["Option2"].ToString(), dt.Rows[0]["Option2"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt.Rows[0]["Option3"].ToString(), dt.Rows[0]["Option3"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt.Rows[0]["Option4"].ToString(), dt.Rows[0]["Option4"].ToString()));
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Que_temp VALUES(" + this.id + ")", con);
cmd.ExecuteNonQuery();
SqlCommand cmd1 = new SqlCommand("INSERT INTO ANSWER(Que_Id,Que,Opt_Selected,Ans) VALUES(" + this.id + ",'" + Label1.Text + "','0','" + this.ans + "')", con);
cmd1.ExecuteNonQuery();
con.Close();
}
protected void Button6_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex <= -1)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Select an Option!!!')", true);
}
else
{
if (confirmCount == 0)
{
Button6.Enabled = false;
SqlCommand cmd = new SqlCommand("UPDATE Answer SET Opt_Selected=" + (RadioButtonList1.SelectedIndex + 1) + " WHERE Que='" + Label1.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Button7.Enabled = true;
count++;
switch (count)
{
case 1: Button1.BackColor = Color.Green;
break;
case 2: Button2.BackColor = Color.Green;
break;
case 3: Button3.BackColor = Color.Green;
break;
case 4: Button4.BackColor = Color.Green;
break;
case 5: Button5.BackColor = Color.Green;
break;
case 6: Button8.BackColor = Color.Green;
break;
case 7: Button9.BackColor = Color.Green;
break;
case 8: Button10.BackColor = Color.Green;
break;
case 9: Button11.BackColor = Color.Green;
break;
case 10: Button12.BackColor = Color.Green;
break;
case 11: Button13.BackColor = Color.Green;
break;
case 12: Button14.BackColor = Color.Green;
break;
case 13: Button15.BackColor = Color.Green;
break;
case 14: Button16.BackColor = Color.Green;
break;
case 15: Button17.BackColor = Color.Green;
break;
case 16: Button18.BackColor = Color.Green;
break;
case 17: Button19.BackColor = Color.Green;
break;
case 18: Button20.BackColor = Color.Green;
break;
case 19: Button21.BackColor = Color.Green;
break;
case 20: Button22.BackColor = Color.Green;
count = 0;
break;
default:
break;
}
}
else
{
Button6.Enabled = false;
SqlCommand cmd = new SqlCommand("UPDATE Answer SET Opt_Selected=" + (RadioButtonList1.SelectedIndex + 1) + " WHERE Que='" + Label1.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Button7.Enabled = true;
confirmCount = 0;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(1);
}
protected void Button2_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(2);
}
protected void Button3_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(3);
}
protected void Button4_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(4);
}
protected void Button5_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(5);
}
protected void Button8_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(6);
}
protected void Button9_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(7);
}
protected void Button10_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(8);
}
protected void Button11_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(9);
}
protected void Button12_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(10);
}
protected void Button13_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(11);
}
protected void Button14_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(12);
}
protected void Button15_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(13);
}
protected void Button16_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(14);
}
protected void Button17_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(15);
}
protected void Button18_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(16);
}
protected void Button19_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(17);
}
protected void Button20_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(18);
}
protected void Button21_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(19);
}
protected void Button22_Click(object sender, EventArgs e)
{
confirmCount = 1;
display(20);
}
public void display(int id)
{
Button6.Enabled = true;
SqlDataAdapter da = new SqlDataAdapter("SELECT TOP 1 * FROM (SELECT TOP " + id + " * FROM Answer ORDER BY Id ASC) T ORDER BY Id DESC", con);
DataTable dt1 = new DataTable();
da.Fill(dt1);
int que_id = Convert.ToInt32(dt1.Rows[0]["Que_Id"].ToString());
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM " + sub + " WHERE Id=" + que_id, con);
DataTable dt2 = new DataTable();
da1.Fill(dt2);
RadioButtonList1.Items.Clear();
Label1.Text = dt2.Rows[0]["Question"].ToString();
RadioButtonList1.Items.Add(new ListItem(dt2.Rows[0]["Option1"].ToString(), dt2.Rows[0]["Option1"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt2.Rows[0]["Option2"].ToString(), dt2.Rows[0]["Option2"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt2.Rows[0]["Option3"].ToString(), dt2.Rows[0]["Option3"].ToString()));
RadioButtonList1.Items.Add(new ListItem(dt2.Rows[0]["Option4"].ToString(), dt2.Rows[0]["Option4"].ToString()));
if (dt1.Rows[0]["Ans"].ToString() != "0")
{
RadioButtonList1.SelectedIndex = Convert.ToInt32(dt1.Rows[0]["Opt_Selected"].ToString()) - 1;
}
}
}