1、数学12129web实验7应用AJAX设计限时在线考试系统石祖极实验7 应用AJAX设计限时在线考试系统成绩专业班级 数学121 学号 201212010129姓名 石祖极 报告日期 2014.11.25 实验类型:验证性实验 综合性实验 设计性实验实验目的:1) 掌握基本ASP.NET AJAX基本控件的属性设置及使用方法;进一步理解页面局部更新的重要性;了解ASP.NET AJAX扩展控件的使用方法。2) 掌握Timer控件的主要属性、方法和事件,能设计出具有定时功能的应用程序。实验要求:设计一个能限制时间的在线考试系统,系统具有如下功能: 1) 系统支持最多100道的单选题(4选1)。2
2、) 考试题目存贮在单独的文本文件内(App_Data/test.txt)。如图7-1所示,每题以题目内容、正确答案、4个选项为顺序逐行书写。3) 自动生成如图7-2所示的考试成绩,存放在App_Data/result.txt 文件中 图7-1 试题内容 图7-2 自动生成的考试成绩表4) 考生访问网站时, 首先看到的是如图7-3所示的登录界面,在输入姓名、准考证号后单击开始考试按钮,系统对用户输入的姓名、准考证号的合法性进行检测,要求“姓名”、准考证号不得为空;准考证号必须由六位数字组成,且考生不是重复考试(成绩表中没有准考证号的记录)。未通过检测将显示相应的出错提示信息。通过检测后进入进入如
3、图7-4的答题界面。在答题界面的右上角始终显示一个倒计时的“剩余时间”指示。5) 考生答题结束后,单击答题页面下方的“提交试卷”,屏幕显示如图7-5所示的本次考试成绩,并将该成绩保存到App_Data/result.txt文件中实验步骤提示1. 设计登陆页面(设计步骤见实验指导书第82页)2. 设计答题界面(设计步骤见实验指导书第83页)3. 设计显示成绩页面图7-3 登录系统界面 图7-5 显示考试成绩 图7-4 答题界面 实验报告:根据实验情况和结果(网站页面运行调试情况、通过超链接实现页面跳转情况、最终各个页面运行效果情况)撰写并递交实验报告。实验总结:学会了.; 掌握了.; 训练了.;
4、 发现了.; 实验中.有待提高。电子报告word文件命名规则:专业班级学号后两位实验X姓名.doc, 如信息123班学号为201212030315的郭海涛同学实验7报告word文件命名则应是:信息123-15-实验7-郭海涛.doc, 其中 .doc是Word文件扩展名。参考程序程序代码:Default.aspx .auto-style1 width: 100%; .auto-style2 text-align: center; .auto-style3 height: 24px; .auto-style4 width: 275px; .auto-style5 height: 24px; wi
5、dth: 275px; 在线模拟考试系统 姓名: 准考证号: Default.aspx.csusing System.IO;using System.Text;using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page protected void Page_Load(obje
6、ct sender, EventArgs e) this.Title = 在线模拟考试系统; TextName.Focus(); protected void ButtonStart_Click(object sender, EventArgs e) /如果未输入姓名或准考证号,弹出出错信息提示信息框,并结束运行 if (TextName.Text = | TextNo.Text = ) Response.Write(alert(请填写完整的考生信息!);); return; string FilePaht = Server.MapPath(app_Data/result.txt); Stre
7、amReader sr = new StreamReader(FilePaht,Encoding.GetEncoding(gb2312); while(!sr.EndOfStream) /循环读取文件的每一行,直到文件结束 /从文本文件中读取1行,取出前6个字符(准考证号数据) string StuNo=sr.ReadLine().Substring(0,6); /如果成绩表中存在考试号,显示出错信息框,并结束运行 if(StuNo.Trim()=TextNo.Text.Trim() Response.Write(alert(不能重复参加考试!);); return; sr.Close();
8、Sessionname=TextName.Text; Sessionno=TextNo.Text; Response.Redirect(Exam.aspx); Exam.aspx .auto-style1 width: 100%; .auto-style2 height: 24px; 限时在线考试 Exam.aspx.csusing System.IO;using System.Text;using System;using System.Collections.Generic;using System.Linq;using System.Web;using Sys
9、tem.Web.UI;using System.Web.UI.WebControls;public partial class Exam : System.Web.UI.Page TimeSpan t1=new TimeSpan(0,0,1); static stringAnswer=new string100; static RadioButtonListrbtnList=new RadioButtonList100; protected void Page_Load(object sender, EventArgs e) if(Sessionname=null|Sessionno=null
10、) Response.Redirect(Default.aspx); if(!IsPostBack) LabelName.Text=考生姓名:+Sessionname.ToString(); LabelNo.Text=准考证号:+Sessionno.ToString(); TimeSpan t=new TimeSpan(0,3,0); Sessiontime=t; LabelTime.Text=剩余时间:+string.Format(0:hh:mm:ss,t)+; string FilePaht=Server.MapPath(App_Data/test.txt); StreamReader s
11、r=new StreamReader(FilePaht,Encoding.GetEncoding(gb2312); int num=1; while(!sr.EndOfStream) Label lbl=new Label(); RadioButtonList rbtn=new RadioButtonList(); rbtnListnum=rbtn; lbl.Text=+num.ToString()+.+Server.HtmlEncode(sr.ReadLine()+; Answernum=sr.ReadLine(); num=num+1; for(int j=1;j=4;j+) rbtn.I
12、tems.Add(sr.ReadLine(); Panel1.Controls.Add(lbl); Panel1.Controls.Add(rbtn); sr.Close(); protected void Timer1_Tick(object sender, EventArgs e) TimeSpan t=(TimeSpan)Sessiontime; t=t-t1; LabelTime.Text=string.Format(0:hh:mm:ss,t); Sessiontime=t; LabelTime.Text=剩余时间:+string.Format(0:hh:mm:ss,t)+; if(t
13、.Ticks=0) int result=0; for(int i=1;i100;i+) if(Answeri!=null) if(Answeri=Convert.ToString(char)(rbtnListi.SelectedIndex+65) result=result=1; Response.Redirect(ShowReult.aspx?r=+result); protected void ButtonOK_Click(object sender, EventArgs e) int result=0; for(int i=1;i100;i+) if(Answeri!=null) if
14、(Answeri=Convert.ToString(char)(rbtnListi.SelectedIndex+65) result=result=1; Response.Redirect(ShowReult.aspx?r=+result);protected void ButtonStart_Click(object sender, EventArgs e)ShowResult.aspx ShowResult.aspx.csusing System.IO;using System.Text;using System;using System.Collections.Generic;using
15、 System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) Response.Write(你本次考试得分: + Request.QueryStringr); string info=Sessionno.ToString()+ +Sessionname.ToString()+ +Reque
16、st.QueryStringr+ +DateTime.Now.ToString(); string FilePath=Server.MapPath(App_Data/result.txt); string appendText=info+Environment.NewLine; File.AppendAllText(FilePath,appendText); Sessionname=null; Sessionno=null; Sessiontime=null; 调式界面:1.Default.aspx2.Exam.aspx3.运行界面实验总结:通过本次试验我掌握基本ASP.NET AJAX基本控件的属性设置及使用方法;进一步理解页面局部更新的重要性;了解ASP.NET AJAX扩展控件的使用方法。掌握Timer控件的主要属性、方法和事件,能设计出具有定时功能的应用程序。在调试的过程中,总是不能出现理想的界面。反复思考揣摩,发现有些控件没有关联上,还有些代码的大小写不正确。经过调试。最终出现了预想的结果。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1