/
UserTest.aspx.cs
481 lines (461 loc) · 18.1 KB
/
UserTest.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
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using StuExam;
using System.IO;
using System.Text;
using System.Data.OleDb;
public partial class Web_UserTest : System.Web.UI.Page
{
private StudentExam stuInfo = new StudentExam();
protected void Page_Load(object sender, EventArgs e)
{
timebox.Text = Request.Cookies["time"].Value;
Label9.Text = "你好," + Request.Cookies["UserID"].Value + "号" + Request.Cookies["UserName"].Value + "同学,现在开始做题,";
if (!IsPostBack)
{
InitData();
}
}
protected void InitData()
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
conn.Open();
SqlCommand objcmd = new SqlCommand(" select PapID from Examination where ExaNow='1'", conn);
int m = Convert.ToInt32(objcmd.ExecuteScalar());
conn.Close();
SqlConnection objconn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
objconn.Open();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand("select * from QesPapConn,Question where QesPapConn.PapID = '" + m + "' and QesPapConn.QesID = Question.QesID and QesType='选择题'order by newid()", objconn);
DataSet ds = new DataSet();
adp.Fill(ds); //填充DataSet内存数扰库
objconn.Close();
Response.Write(ds.Tables[0].DefaultView.Count); //显增当前查询结果的总行数
this.GridView1.DataSource = ds.Tables[0]; //绑定到gridview数据源
this.GridView1.DataBind();
SqlConnection objconn2 = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
objconn2.Open();
SqlDataAdapter adp2 = new SqlDataAdapter();
adp2.SelectCommand = new SqlCommand("select * from QesPapConn,MultiSelectQuestion where QesPapConn.PapID = '" + m + "' and QesPapConn.QesID = MultiSelectQuestion.QesID and QesType='多选题'order by newid()", objconn2);
DataSet ds2 = new DataSet();
adp2.Fill(ds2); //填充DataSet内存数扰库
objconn2.Close();
Response.Write(ds2.Tables[0].DefaultView.Count); //显增当前查询结果的总行数
this.GridView2.DataSource = ds2.Tables[0]; //绑定到gridview数据源
this.GridView2.DataBind();
SqlConnection objconn1 = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
objconn1.Open();
SqlDataAdapter adp1 = new SqlDataAdapter();
adp1.SelectCommand = new SqlCommand("select * from QesPapConn,JudgeQuestion where QesPapConn.PapID = '" + m + "' and QesPapConn.QesID = JudgeQuestion.JudgeID and QesType='判断题' order by newid()", objconn1);
DataSet ds1 = new DataSet();
adp1.Fill(ds1); //填充DataSet内存数扰库
Response.Write(ds1.Tables[0].DefaultView.Count); //显增当前查询结果的总行数
this.GridView3.DataSource = ds1.Tables[0]; //绑定到gridview数据源
this.GridView3.DataBind();
objconn1.Close();
SqlConnection objconn3 = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
objconn3.Open();
SqlDataAdapter adp3 = new SqlDataAdapter();
adp3.SelectCommand = new SqlCommand("select * from QesPapConn,FillBlankQuestion where QesPapConn.PapID = '" + m + "' and QesPapConn.QesID = FillBlankQuestion.FillBlankQuestionID and QesType='填空题'order by newid()", objconn3);
DataSet ds3 = new DataSet();
adp3.Fill(ds3); //填充DataSet内存数扰库
objconn3.Close();
Response.Write(ds3.Tables[0].DefaultView.Count); //显增当前查询结果的总行数
this.GridView4.DataSource = ds3.Tables[0]; //绑定到gridview数据源
this.GridView4.DataBind();
}
protected void InitData1()
{
string kk = GetIDSequence();
string kk1 = GetKeySequence();
stuInfo.alertIDSequence(kk, Request.Cookies["UserID"].Value);
stuInfo.alertKeySequence(kk1, Request.Cookies["UserID"].Value);
}
protected string GetIDSequence()
{
string mm = "";
if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView1.Rows)
{
mm += ((Label)dr.FindControl("Label50")).Text.Trim() + " ";
}
}
if (GridView2.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView2.Rows)
{
mm += ((Label)dr.FindControl("Label51")).Text.Trim() + " ";
}
}
if (GridView3.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView3.Rows)
{
mm += ((Label)dr.FindControl("Label52")).Text.Trim() + " ";
}
}
if (GridView4.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView4.Rows)
{
mm += ((Label)dr.FindControl("Label53")).Text.Trim() + " ";
}
}
return mm;
}
protected string GetKeySequence()
{
string mm = "";
if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView1.Rows)
{
mm += ((Label)dr.FindControl("Label3")).Text.Trim() + " ";
}
}
if (GridView2.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView2.Rows)
{
mm += ((Label)dr.FindControl("Label7")).Text.Trim() + " ";
}
}
if (GridView3.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView3.Rows)
{
mm += ((Label)dr.FindControl("Label11")).Text.Trim() + " ";
}
}
if (GridView4.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView4.Rows)
{
mm += ((Label)dr.FindControl("Label16")).Text.Trim() + " ";
}
}
return mm;
}
protected string GetUserSequence()
{
string mm = "";
if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView1.Rows)
{
if (((RadioButton)dr.FindControl("RadioButton1")).Checked == true)
{
mm += "A ";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked == true)
{
mm += "B ";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked == true)
{
mm += "C ";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked == true)
{
mm += "D ";
}
else
{
mm += "* ";
}
}
}
if (GridView2.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView2.Rows)
{
if (((CheckBox)dr.FindControl("CheckBox1")).Checked == true)
{
mm += "A ";
}
else if (((CheckBox)dr.FindControl("CheckBox2")).Checked == true)
{
mm += "B ";
}
else if (((CheckBox)dr.FindControl("CheckBox3")).Checked == true)
{
mm += "C ";
}
else if (((CheckBox)dr.FindControl("CheckBox4")).Checked == true)
{
mm += "D ";
}
else
{
mm += "* ";
}
}
}
if (GridView3.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView3.Rows)
{
if (((CheckBox)dr.FindControl("CheckBox5")).Checked == true)
{
mm += "True ";
}
else mm += "False ";
}
}
if (GridView4.Rows.Count > 0)
{
foreach (GridViewRow dr in GridView4.Rows)
{
string str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
if (str!="")
{
mm += str+" ";
}
else mm += "* ";
}
}
return mm;
}
//提交试卷,生成成绩
protected void imgBtnSubmit_Click(object sender, ImageClickEventArgs e)
{
int score = 0;
if (GridView1.Rows.Count > 0)
{
int singlemark = int.Parse(((Label)GridView1.Rows[0].FindControl("Label4")).Text);//取出单选题的每题分值
foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
{
string str = "";
if (((RadioButton)dr.FindControl("RadioButton1")).Checked == true)
{
str = "A";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked == true)
{
str = "B";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked == true)
{
str = "C";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked == true)
{
str = "D";
}
if (((Label)dr.FindControl("Label3")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + singlemark;
}
}
}
if (GridView2.Rows.Count > 0)
{
int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label8")).Text);//取出多选题每题分值
foreach (GridViewRow dr in GridView2.Rows)//对多选题每题进行判断用户选择答案
{
string str = "";
if (((CheckBox)dr.FindControl("CheckBox1")).Checked)
{
str += "A";
}
if (((CheckBox)dr.FindControl("CheckBox2")).Checked)
{
str += "B";
}
if (((CheckBox)dr.FindControl("CheckBox3")).Checked)
{
str += "C";
}
if (((CheckBox)dr.FindControl("CheckBox4")).Checked)
{
str += "D";
}
if (((Label)dr.FindControl("Label7")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + multimark;
}
}
}
if (GridView3.Rows.Count > 0)
{
int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label12")).Text);//取出判断题每题分值
foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
{
bool j = false;
if (((CheckBox)dr.FindControl("CheckBox5")).Checked == true)
{
j = true;
}
if (j == bool.Parse(((Label)dr.FindControl("Label11")).Text.Trim()))
{
score = score + judgemark;
}
}
}
if (GridView4.Rows.Count > 0)
{
int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label17")).Text);//取出填空题每题分值
foreach (GridViewRow dr in GridView4.Rows)
{
string str = "";
str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
if (str == ((Label)dr.FindControl("Label16")).Text.Trim())
{
score = score + fillmark;
}
}
}
String h_UserID = Request.Cookies["UserID"].Value;
StudentExam myStudentExam = new StudentExam();
InitData1();
string strError = myStudentExam.setSingleScore(h_UserID, score);
if (strError == "1")
{
string userSequence = GetUserSequence();
stuInfo.alertData(userSequence, Request.Cookies["UserID"].Value);
stuInfo.finshed(Request.Cookies["UserID"].Value);
ScriptManager.RegisterStartupScript(this, this.GetType(), "updateScript", "var flag= window.confirm('确认交卷?点击确认后就不能继续答题,请慎重选择!');if(flag||!flag)location.href = 'sendBlank.aspx';", true);
}
else Response.Write("<script language=javascript>alert('自动评分失败,请等待老师公布成绩!')</script>");
}
//抢卷
protected void imgBtnSubmit1_Click(object sender, ImageClickEventArgs e)
{
int score = 0;
if (GridView1.Rows.Count > 0)
{
int singlemark = int.Parse(((Label)GridView1.Rows[0].FindControl("Label4")).Text);//取出单选题的每题分值
foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
{
string str = "";
if (((RadioButton)dr.FindControl("RadioButton1")).Checked == true)
{
str = "A";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked == true)
{
str = "B";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked == true)
{
str = "C";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked == true)
{
str = "D";
}
if (((Label)dr.FindControl("Label3")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + singlemark;
}
}
}
if (GridView2.Rows.Count > 0)
{
int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label8")).Text);//取出多选题每题分值
foreach (GridViewRow dr in GridView2.Rows)//对多选题每题进行判断用户选择答案
{
string str = "";
if (((CheckBox)dr.FindControl("CheckBox1")).Checked)
{
str += "A";
}
if (((CheckBox)dr.FindControl("CheckBox2")).Checked)
{
str += "B";
}
if (((CheckBox)dr.FindControl("CheckBox3")).Checked)
{
str += "C";
}
if (((CheckBox)dr.FindControl("CheckBox4")).Checked)
{
str += "D";
}
if (((Label)dr.FindControl("Label7")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + multimark;
}
}
}
if (GridView3.Rows.Count > 0)
{
int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label12")).Text);//取出判断题每题分值
foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
{
bool j = false;
if (((CheckBox)dr.FindControl("CheckBox5")).Checked == true)
{
j = true;
}
if (j == bool.Parse(((Label)dr.FindControl("Label11")).Text.Trim()))
{
score = score + judgemark;
}
}
}
if (GridView4.Rows.Count > 0)
{
int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label17")).Text);//取出填空题每题分值
foreach (GridViewRow dr in GridView4.Rows)
{
string str = "";
str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
if (str == ((Label)dr.FindControl("Label16")).Text.Trim())
{
score = score + fillmark;
}
}
}
String h_UserID = Request.Cookies["UserID"].Value;
StudentExam myStudentExam = new StudentExam();
InitData1();
string strError = myStudentExam.setSingleScore(h_UserID, score);
if (strError == "1")
{
string userSequence = GetUserSequence();
stuInfo.alertData(userSequence, Request.Cookies["UserID"].Value);
stuInfo.finshed(Request.Cookies["UserID"].Value);
Response.Redirect("sendBlank.aspx");
}
else Response.Write("<script language=javascript>alert('自动评分失败,请等待老师公布成绩!')</script>");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
}
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
}
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
}
}
protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");//点击行变色
}
}
}