ASP.NET调试在线考试系统的实现|上机实验实习报告|计算机上机实习报告|习题10-6需求一和需求二任选一
一 实验目的:
。
二、实验要求:
1:自学第十章
2:调试在线考试系统的实现
3:改进该系统,既习题10-6需求一和需求二任选一,画流程图、编程、调试、运行结果截图
三、实验步骤:
程序设计:
流程图:
<Script runat="server">
void Page_Load(Object Src, EventArgs E) {
string No = "";
string Name = "";
string Lesson = "";
string Msg = "";
if (IsPostBack) {//页面被提交的时候执行
No = Request["txtNo"];
Name = Request["txtName"];
Lesson = Request["Lesson"];
string SQL = "Select * From 成绩单 ";
SQL = SQL + "Where 学号=" + "'" + No + "'" + " And 姓名='" + Name + "'";
"Data Source="+Server.MapPath("test.mdb"));
Conn.Open();
//Response.Write(SQL);
OleDbCommand Comm=new OleDbCommand(SQL,
OleDbDataReader dr=Comm.ExecuteReader();
if (dr.Read()) {
if (dr[Lesson].ToString() != "-1") {
Msg = "你已经考过本科目了!";
}
else{
Conn.Close();
Response.Redirect("TEST.ASPX?Lesson="+Lesson+"&Name="+Name+"&No="+No);
}
}
else{
Msg = "你不是合法考生!";
}
Message.Text = Msg;
Conn.Close();
}
}
</Script>
<HTML>
<BODY BGCOLOR=BEIGE>
<H1 ALIGN="CENTER">在线考试系统</H1>
<HR>
<FORM METHOD="POST" RUNAT="SERVER">
<asp:DropDownList ID="Lesson" RUNAT="server">
<asp:ListItem value="ASP" selected="true">ASP</asp:ListItem>
<asp:ListItem value="XML">XML</asp:ListItem>
</asp:DropDownList>
<P>姓名:<asp:textbox id="txtName" runat="server" /></P>
<P>学号:<asp:textbox id="txtNo" runat="server" /></P>
<P><asp:button text="开始考试" runat="server" /></P>
</FORM> <HR>
<asp:label id="Message" runat="server" />
</BODY>
</HTML>
<% @ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<Script runat="server">
string Lesson;
string No;
string Name;
OleDbDataReader dr;
void Page_Load(Object Src, EventArgs E) {
Lesson = Request["Lesson"];
No = Request["No"];
Name = Request["Name"];
string SQL = "Select * From " + Lesson + " Order By 题号";
"Data Source="+Server.MapPath("test.mdb"));
Conn.Open();
//Response.Write(SQL);
OleDbCommand Comm = new OleDbCommand(SQL,
dr = Comm.ExecuteReader();
}
</Script>
<HTML>
<BODY BGCOLOR=BEIGE>
<CENTER>
<H1><FONT COLOR=#6699DD>在线考试系统</FONT></H1>
</CENTER>
<H2>考试科目 -- <%=Lesson%><HR></H2>
<FORM Action="Score.aspx" Method="GET">
<INPUT Type="Hidden" Name="Lesson" Value=<%=Lesson%>>
<INPUT Type="Hidden" Name="No" Value=<%=No%>>
<INPUT Type="Hidden" Name="Name" Value=<%=Name%>>
<%
string TestType = "";
while (dr.Read()){
Response.Write("<B>" + dr["题号"].ToString() + "."
+ Server.HtmlEncode(dr["题目"].ToString())
+ dr["类型"].ToString() + ":" + dr["分数"].ToString() + "分)</B>");
Response.Write("<div>");
for (int i=1; i<5; i++) {
if (dr["类型"].ToString() == "单选") {
TestType = "Radio";
}
else {
TestType = "CheckBox";
}
Response.Write("<INPUT Type=" + TestType
+ " Name=No" + dr["题号"].ToString()
+ " Value=" + i +">"
+ Server.HtmlEncode(dr["选项" + i].ToString()) + "<BR>");
}
Response.Write("</div>");
}
%>
<INPUT Type=Submit Value=" 交 卷 ">
</FORM><HR></BODY>
</HTML>
<% @ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<Script runat="server">
string Lesson;
string No;
string Name;
OleDbDataReader dr;
string SQL;
OleDbCommand Comm;
void Page_Load(Object Src, EventArgs E) {
Lesson = Request["Lesson"];
No = Request["No"];
Name = Request["Name"];
"Data Source="+Server.MapPath("test.mdb"));
Conn.Open();
SQL = "Select * from " + Lesson;
//Response.Write(SQL);
Comm = new OleDbCommand(SQL,
dr = Comm.ExecuteReader();
}
//如果<60分,显示为红色
string TestResult(string inputScore){
int Score = Convert.ToInt32(inputScore);
if (-1 == Score) {
return "你还没有考试";
}
else if(Score < 60) {
return "<FONT Color=Red>" + Score + "</FONT>";
}
else {
return Score.ToString();
}
}
</Script>
<HTML>
<BODY BGCOLOR="BEIGE">
<H2>成绩单<HR></H2>
<%
int Score = 0;
while (dr.Read()) {
if (Request["No" + dr["题号"].ToString()] != null) {
string Sel = Request["No" + dr["题号"].ToString()];
string Ans = dr["解答"].ToString();
//Response.Write(Sel + Ans + "<br>");
if (Ans == Sel)
{
Score = Score + Convert.ToInt32(dr["分数"].ToString());
//Response.Write( "OK" + Score);
}
}
}
//重新建立DataReader对象,需要重新打开Connection对象
Conn.Close();
Conn.Open();
SQL = "Select * From 成绩单 ";
SQL = SQL + "Where 学号=" + "'" + No + "'" + " And 姓名='" + Name + "'";
Comm = new OleDbCommand(SQL,
OleDbDataReader drScore = Comm.ExecuteReader();
if(drScore.Read()){
if (drScore[Lesson].ToString() == "-1") {
SQL = "update 成绩单 set " + Lesson + " = " + Score.ToString()
+ " where 学号=" + "'" + No + "'"
+ " And 姓名='" + Name + "'";
Conn.Close();
Conn.Open();
Comm = new OleDbCommand(SQL,
Comm.ExecuteNonQuery();
}
else {
Response.Write ("<script>{alert('你已经考过了')}</script>");
}
}
%>
<%=Name%>同志你好,你的考试成绩统计为:<BR>
<CENTER>
<TABLE BORDER=2 BGCOLOR="#F
<TR BGCOLOR="#DDDDDD"><TD>你参加的科目</TD><TD>你的分数</TD></TR>
<%//重新读取成绩
Conn.Close();
Conn.Open();
SQL = "Select * From 成绩单 ";
SQL = SQL + "Where 学号=" + "'" + No + "'" + " And 姓名='" + Name + "'";
Comm = new OleDbCommand(SQL,
drScore = Comm.ExecuteReader();
if(drScore.Read()){
%>
<TR><TD>ASP</TD><TD Align=Right><%=TestResult(drScore["ASP"].ToString())%></TD></TR>
<TR><TD>XML</TD><TD Align=Right><%=TestResult(drScore["XML"].ToString())%></TD></TR>
<% } %>
</TABLE></center>
<HR>
<A HREF="login.aspx?txtNo=<%=No%>&txtName=<%=Name%>">参加其他科目考试</A>
</BODY>
</HTML>
四、试验运行结果:
若图片无法显示请联系站长QQ752018766