试卷考试
試卷頁面 1 <body>
2 <form id="form1" runat="server">
3 <div class="container">
4 <div class="content">
5 <%
6 if (Request.QueryString["paperID"] == null)
7 Response.Redirect("~/index/paperList.aspx");
8 else
9 {
10 string choice = "";
11 string[] array;
12 int arrayCount = 0;
13 DB db = new DB();
14 string paperID = Request.QueryString["paperID"];
15 //string paperID = "試卷20150310153259";
16 test test = new test();
17 string qusList = test.getQusList(paperID);
18 List<all_question> questionList = test.getQuestion(qusList);
19 %>
20 <div class="divPaperTitle"><%=paperID %></div>
21 <div class="divBtn">
22 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/index/images/btnPaper1.png" OnClick="ImageButton1_Click"/>
23 </div>
24 <div style="clear: left">
25 <div class="divID">學號:<asp:Label ID="labID" runat="server" Text="xxx" Width="150px"></asp:Label></div>
26 <div class="divName">姓名:<asp:Label ID="labName" runat="server" Text="xxx" ></asp:Label></div>
27 <div class="divTime">考試時長:45分鐘</div>
28 <div class="divTestTime">
29 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
30 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
31 <Triggers>
32 <asp:AsyncPostBackTrigger ControlID="Timer1" />
33 </Triggers>
34 <ContentTemplate>
35 已用時間:<asp:Label ID="LabelTime" runat="server" ForeColor="Red"></asp:Label>
36 </ContentTemplate>
37 </asp:UpdatePanel>
38 <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
39 </div>
40 </div>
41
42 <div class="Paper">
43 <div class="divtype">一、判斷題(共20小題,每小題 1 分)</div>
44 <%
45 for (int i = 0; i < 20; i++)
46 {
47 all_question all_question = (all_question)questionList[i];
48 %>
49 <div class="divquestion">
50 <%=i+1 %>.<%=all_question.Question%>
51 </div>
52 <div class="divchoice">
53 <input id="Radio1" type="radio" name="<%=i+1 %>" value="A" /><label for="Radio1"> A:正確</label>
54 <input id="Radio2" type="radio" name="<%=i+1 %>" value="B" /><label for="Radio2"> B:錯誤</label>
55 </div>
56 <%}%>
57 <div class="divtype">二、單選題(共20小題,每小題 2 分)</div>
58 <%
59 for (int j = 20; j < 40; j++)
60 {
61 all_question all_question = (all_question)questionList[j];
62 choice = all_question.Choice;
63 array = choice.Split(new string[] { "A:", "B:", "C:", "D:", "A:", "B:", "C:", "D:" }, StringSplitOptions.RemoveEmptyEntries);
64 arrayCount = array.Length;
65 %>
66 <div class="divquestion"><%=j+1 %>.<%=all_question.Question %></div>
67 <div class="divchoice">
68 <input id="Radio3" type="radio" name="<%=j+1 %>" value="A" /><label for="Radio3"> A:<%=array[0] %></label>
69 <br />
70 <input id="Radio4" type="radio" name="<%=j+1 %>" value="B" /><label for="Radio4"> B:<%=array[1] %></label>
71 <%
72 if (arrayCount == 3)
73 {
74 %>
75 <br />
76 <input id="Radio5" type="radio" name="<%=j+1 %>" value="C" /><label for="Radio5"> C:<%=array[2] %></label>
77 <%
78 }
79 if (arrayCount == 4)
80 { %>
81 <br />
82 <input id="Radio6" type="radio" name="<%=j+1 %>" value="C" /><label for="Radio6"> C:<%=array[2] %></label>
83 <br />
84 <input id="Radio7" type="radio" name="<%=j+1 %>" value="D" /><label for="Radio7"> D:<%=array[3] %></label>
85 <%
86 }
87 %>
88 </div>
89 <%
90 }
91 %>
92 <div class="divtype">三、多選題(共10小題,每小題 4 分)</div>
93 <%
94 for (int m = 40; m < 50; m++)
95 {
96 all_question all_question = (all_question)questionList[m];
97 choice = all_question.Choice;
98 array = choice.Split(new string[] { "A:", "B:", "C:", "D:", "A:", "B:", "C:", "D:" }, StringSplitOptions.RemoveEmptyEntries);
99 %>
100 <div class="divquestion"><%=m+1 %>.<%=all_question.Question %></div>
101 <div class="divchoice">
102 <input id="Checkbox1" type="checkbox" name="<%=m+1 %>" value="A" /><label for="Checkbox1"> A:<%=array[0] %></label>
103 <br />
104 <input id="Checkbox2" type="checkbox" name="<%=m+1 %>" value="B" /><label for="Checkbox2"> B:<%=array[1] %></label>
105 <br />
106 <input id="Checkbox3" type="checkbox" name="<%=m+1 %>" value="C" /><label for="Checkbox3"> C:<%=array[2] %></label>
107 <br />
108 <input id="Checkbox4" type="checkbox" name="<%=m+1 %>" value="D" /><label for="Checkbox4"> D:<%=array[3] %></label>
109 </div>
110 <%
111 }%>
112 </div>
113 <% }%>
114 </div>
115 </div>
116 </form>
117 </body> View Code
?
提交試卷并計算成績 1 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) 2 { 3 string paperID = Request.QueryString["paperID"]; 4 //string paperID = "試卷20150310153259"; 5 test test = new test(); 6 string qusList = test.getQusList(paperID); 7 List<all_question> questionList = test.getQuestion(qusList); 8 int totalScore = 0; 9 for (int i = 1; i < 51; i++) 10 { 11 if (!string.IsNullOrEmpty(Request.Form[i.ToString()])) 12 { 13 string selectvalue = Request.Form[i.ToString()]; 14 all_question all_question = (all_question)questionList[i - 1]; 15 if (selectvalue == all_question.Answer) 16 { 17 if (i < 21) 18 totalScore += 1; 19 else if (i < 41) 20 totalScore += 2; 21 else 22 totalScore += 4; 23 24 } 25 //chklist.Add(selectvalue); 26 } 27 } 28 string stuID = labID.Text; 29 string testLength = string.Format("{0:00}:{1:00}", intTmpMin, intTmpSco); 30 string sql = "insert into score(stuID,paperID,score,testLength) values('" + stuID + "','" + paperID + "','" + totalScore + "','" + testLength + "')"; 31 db.sqlEx(sql); 32 Response.Redirect("afterTest.aspx?score=" + totalScore + ""); 33 } View Code?
超時自動提交 1 protected void Timer1_Tick(object sender, EventArgs e) 2 { 3 4 timesecond = timesecond+1; 5 6 intTmpMin = timesecond / 60; 7 intTmpSco = timesecond % 60; 8 9 LabelTime.Text =intTmpMin.ToString() + "分" + intTmpSco.ToString() + "秒"; 10 if (timesecond>=2700) 11 { 12 Timer1.Enabled = false; 13 ImageButton1_Click(null,null); 14 } 15 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/slyvia230/p/4414425.html
總結(jié)
- 上一篇: http://blog.csdn.net
- 下一篇: 不对吧~