数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx

上传人:b****5 文档编号:28200397 上传时间:2023-07-09 格式:DOCX 页数:17 大小:211.65KB
下载 相关 举报
数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx_第1页
第1页 / 共17页
数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx_第2页
第2页 / 共17页
数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx_第3页
第3页 / 共17页
数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx_第4页
第4页 / 共17页
数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx

《数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx》由会员分享,可在线阅读,更多相关《数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx(17页珍藏版)》请在冰豆网上搜索。

数学12129web实验7应用AJAX设计限时在线考试系统石祖极.docx

数学12129web实验7应用AJAX设计限时在线考试系统石祖极

实验7应用AJAX设计限时在线考试系统

成绩

专业班级数学121学号201212010129姓名石祖极报告日期2014.11.25

实验类型:

○验证性实验○综合性实验●设计性实验

实验目的:

1)掌握基本ASP.NETAJAX基本控件的属性设置及使用方法;进一步理解页面局部更新的重要性;了解ASP.NETAJAX扩展控件的使用方法。

2)掌握Timer控件的主要属性、方法和事件,能设计出具有定时功能的应用程序。

实验要求:

设计一个能限制时间的在线考试系统,系统具有如下功能:

1)系统支持最多100道的单选题(4选1)。

2)考试题目存贮在单独的文本文件内(App_Data/test.txt)。

如图7-1所示,每题以题目内容、正确答案、4个选项为顺序逐行书写。

3)自动生成如图7-2所示的考试成绩,存放在App_Data/result.txt文件中

图7-1试题内容

图7-2自动生成的考试成绩表

4)考生访问网站时,首先看到的是如图7-3所示的登录界面,在输入姓名、准考证号后单击开始考试按钮,系统对用户输入的姓名、准考证号的合法性进行检测,要求“姓名”、准考证号不得为空;准考证号必须由六位数字组成,且考生不是重复考试(成绩表中没有准考证号的记录)。

未通过检测将显示相应的出错提示信息。

通过检测后进入进入如图7-4的答题界面。

在答题界面的右上角始终显示一个倒计时的“剩余时间”指示。

5)考生答题结束后,单击答题页面下方的“提交试卷”,屏幕显示如图7-5所示的本次考试成绩,并将该成绩保存到App_Data/result.txt文件中

实验步骤提示

1.设计登陆页面(设计步骤见实验指导书第82页)

2.设计答题界面(设计步骤见实验指导书第83页)

3.设计显示成绩页面

图7-3登录系统界面

图7-5显示考试成绩

图7-4答题界面

实验报告:

根据实验情况和结果(网站页面运行调试情况、通过超链接实现页面跳转情况、最终各个页面运行效果情况)撰写并递交实验报告。

实验总结:

学会了...;掌握了...;训练了...;发现了...;实验中...有待提高。

电子报告word文件命名规则:

专业班级-学号后两位-实验X-姓名.doc,如信息123班学号为201212030315的郭海涛同学实验7报告word文件命名则应是:

信息123-15-实验7-郭海涛.doc,其中.doc是Word文件扩展名。

参考程序

 

程序代码:

Default.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>

DOCTYPEhtml>

//www.w3.org/1999/xhtml">

.auto-style1{

width:

100%;

}

.auto-style2{

text-align:

center;

}

.auto-style3{

height:

24px;

}

.auto-style4{

width:

275px;

}

.auto-style5{

height:

24px;

width:

275px;

}

在线模拟考试系统

center">姓名:

TextBoxID="TextName"runat="server"Width="272px">

TextBox>

 

center">准考证号:

TextBoxID="TextNo"runat="server"Width="271px">

TextBox>

RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlToValidate="TextNo"ErrorMessage="必须是6位数字!

"ValidationExpression="\d{6}">

RegularExpressionValidator>

ButtonID="ButtonStart"runat="server"Text="开始考试"OnClick="ButtonStart_Click"/>

Default.aspx.cs

usingSystem.IO;

usingSystem.Text;

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

publicpartialclass_Default:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

this.Title="在线模拟考试系统";

TextName.Focus();

}

protectedvoidButtonStart_Click(objectsender,EventArgse)

{

//如果未输入姓名或准考证号,弹出出错信息提示信息框,并结束运行

if(TextName.Text==""||TextNo.Text=="")

{

Response.Write("alert('请填写完整的考生信息!

');");

return;

}

stringFilePaht=Server.MapPath("app_Data/result.txt");

StreamReadersr=newStreamReader(FilePaht,Encoding.GetEncoding("gb2312"));

while(!

sr.EndOfStream)//循环读取文件的每一行,直到文件结束

{

//从文本文件中读取1行,取出前6个字符(准考证号数据)

stringStuNo=sr.ReadLine().Substring(0,6);

//如果成绩表中存在考试号,显示出错信息框,并结束运行

if(StuNo.Trim()==TextNo.Text.Trim())

{

Response.Write("alert('不能重复参加考试!

');");

return;

}

}

sr.Close();

Session["name"]=TextName.Text;

Session["no"]=TextNo.Text;

Response.Redirect("Exam.aspx");

}

}

Exam.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Exam.aspx.cs"Inherits="Exam"%>

DOCTYPEhtml>

//www.w3.org/1999/xhtml">

.auto-style1{

width:

100%;

}

.auto-style2{

height:

24px;

}

center">限时在线考试

LabelID="LabelName"runat="server"Text="Label">

Label>

LabelID="LabelNo"runat="server"Text="Label">

Label>

UpdatePanelID="UpdatePanel1"runat="server">

LabelID="LabelTime"runat="server"Text="Label">

Label>

TimerID="Timer1"runat="server"Interval="1000"OnTick="Timer1_Tick">

Timer>

UpdatePanel>

PanelID="Panel1"runat="server">

Panel>

 

ButtonID="ButtonOK"runat="server"OnClick="ButtonOK_Click"Text="提交试卷"/>

 

Exam.aspx.cs

usingSystem.IO;

usingSystem.Text;

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

publicpartialclassExam:

System.Web.UI.Page

{

TimeSpant1=newTimeSpan(0,0,1);

staticstring[]Answer=newstring[100];

staticRadioButtonList[]rbtnList=newRadioButtonList[100];

protectedvoidPage_Load(objectsender,EventArgse)

{

if(Session["name"]==null||Session["no"]==null)

{

Response.Redirect("Default.aspx");

}

if(!

IsPostBack)

{

LabelName.Text="考生姓名:

"+Session["name"].ToString();

LabelNo.Text="准考证号:

"+Session["no"].ToString();

TimeSpant=newTimeSpan(0,3,0);

Session["time"]=t;

LabelTime.Text="剩余时间:

"+string.Format("{0:

hh:

mm:

ss}",t)+"";

}

stringFilePaht=Server.MapPath("App_Data/test.txt");

StreamReadersr=newStreamReader(FilePaht,Encoding.GetEncoding("gb2312"));

intnum=1;

while(!

sr.EndOfStream)

{

Labellbl=newLabel();

RadioButtonListrbtn=newRadioButtonList();

rbtnList[num]=rbtn;

lbl.Text=""+num.ToString()+"."+Server.HtmlEncode(sr.ReadLine())+"";

Answer[num]=sr.ReadLine();

num=num+1;

for(intj=1;j<=4;j++)

{

rbtn.Items.Add(sr.ReadLine());

}

Panel1.Controls.Add(lbl);

Panel1.Controls.Add(rbtn);

}

sr.Close();

}

protectedvoidTimer1_Tick(objectsender,EventArgse)

{

TimeSpant=(TimeSpan)Session["time"];

t=t-t1;

LabelTime.Text=string.Format("{0:

hh:

mm:

ss}",t);

Session["time"]=t;

LabelTime.Text="剩余时间:

"+string.Format("{0:

hh:

mm:

ss}",t)+"";

if(t.Ticks==0)

{

intresult=0;

for(inti=1;i<100;i++)

{

if(Answer[i]!

=null)

{

if(Answer[i]==Convert.ToString((char)(rbtnList[i].SelectedIndex+65)))

{

result=result=1;

}

}

}

Response.Redirect("ShowReult.aspx?

r="+result);

}

}

protectedvoidButtonOK_Click(objectsender,EventArgse)

{

intresult=0;

for(inti=1;i<100;i++)

{

if(Answer[i]!

=null)

{

if(Answer[i]==Convert.ToString((char)(rbtnList[i].SelectedIndex+65)))

{

result=result=1;

}

}

}

Response.Redirect("ShowReult.aspx?

r="+result);

}

protectedvoidButtonStart_Click(objectsender,EventArgse)

{

}

}

ShowResult.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="ShowResult.aspx.cs"Inherits="Default2"%>

DOCTYPEhtml>

//www.w3.org/1999/xhtml">

ShowResult.aspx.cs

usingSystem.IO;

usingSystem.Text;

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

publicpartialclassDefault2:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

Response.Write("你本次考试得分:

"+Request.QueryString["r"]);

stringinfo=Session["no"].ToString()+""+Session["name"].ToString()+""+Request.QueryString["r"]+""+DateTime.Now.ToString();

stringFilePath=Server.MapPath("App_Data/result.txt");

stringappendText=info+Environment.NewLine;

File.AppendAllText(FilePath,appendText);

Session["name"]=null;

Session["no"]=null;

Session["time"]=null;

}

}

调式界面:

1.Default.aspx

2.Exam.aspx

3.运行界面

实验总结:

通过本次试验我掌握基本ASP.NETAJAX基本控件的属性设置及使用方法;进一步理解页面局部更新的重要性;了解ASP.NETAJAX扩展控件的使用方法。

掌握Timer控件的主要属性、方法和事件,能设计出具有定时功能的应用程序。

在调试的过程中,总是不能出现理想的界面。

反复思考揣摩,发现有些控件没有关联上,还有些代码的大小写不正确。

经过调试。

最终出现了预想的结果。

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 农学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1