NEWSZW_HZH_BEGIN-->
global.asa
< script LANGUAGE=VBScript RUNAT=Server >
Sub Application_OnStart
dbPath = "DBQ=" & Server.Mappath("onlinetest.mdb")
dbConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; " & dbPath
Set Application("Conn") = Server.CreateObject ("ADODB.Connection")
Application("Conn").Open dbConnectionString
End Sub
Sub Application_OnEnd
Application("Conn").Close
Set Application("Conn") = Nothing
End Sub
Sub Session_OnStart
End Sub
Sub Session_OnEnd
End Sub
< /script >
----------------------------------------------------------------------------------------------------------------
注册页面 index.asp 。其中有两个输入域:用户名和口令,这两个输入域需要客户机端的 javascript 确认,以便不把它们作为空白域来传递。非考生要想参加考试必须先注册。这个页面还要显示一些错误信息,如“用户名或口令错误”、“请重新选择一个用户名”等。注册表单中还应包含考生一些个人的信息,如 Emai 、年龄、教育程度等。登录后,考生就可以参答考试站点的其它试卷了。
index.asp
<title> 撼雪喷云之网上考试设计思路 </title>
if (theForm.username.value == "")
{
alert(" 考生姓名 \"User Name\"");
theForm.username.focus();
return (false);
}
if (theForm.password.value == "")
{
alert(" 考生口令 \"Password\"");
theForm.password.focus();
return (false);
}
< table border="0" cellpadding="0" >
< tr >
< td width="50%" >
< font face="Verdana" size="2" > 姓名 :< /font >
< /td >
< td width="50%" >
< font face="Verdana" size="2" >< input type=text name=username size=20 maxlength=50 >< /font >
< /td >
< /tr >
< tr >
< td width="50%" >
< font face="Verdana" size="2" > 口令 :< /font >
< /td >
< td width="50%" >
< font face="Vedana" size=2 >< input type=password name=password size=20 maxlength= 50 >< /font >
< /td >
< /tr >
< tr >
< td width="100%" colspan="2" align="center" >
< font face="Verdana" size="2" >< br > < input type="submit" value=" 提交 " name="B3" >
< input type="reset" value=" 重写 " name="B4" >
< /font >
< /td >
< /tr >
< /table >
----------------------------------------------------------------------------------------------------------------
登录文件 register.asp ,当考生登录或新注册后,就显示这一页。我们可以利用它来询问考生的个人信息。该表单被提交后,转到 sendregister.asp 页面。
----------------------------------------------------------------------------------------------------------------
验证和发送文件 sendregister.asp 。该页面从 register.asp 中取得表单域的内容,查询数据库验证输入的用户名是否已经存在,如果存在,则将考生重新引回 register.asp 页面,并被提示要求重新选择用户名;如果用户名通过,则输入的内容就被传递并插入到数据库中。
sendregister.asp
sql_findmember = "select count(*) from loginuser where username = '" & username &"'"
Set RS_findmember = Application("Conn").Execute(sql_findmember)
If RS_findmember(0) < > 0 Then
Session("message") = " 噢 , 您输入的名字已经存在 , 请重新选择一个名字 !"
response.redirect "register.asp"
' 如果 RS_findmember(0) 返回的值大于 0, 用户就被引导回注册主页 , 并被要求填写一个新的用户名 .
End If
If RS_findmember(0) = 0 Then
sql_insert = "insert into loginuser (username,useremail,password) _
values('" & username & "','" & useremail & "', '" & pwd &"') "
Set RS_insert = Application("Conn").Execute(sql_insert)
Session("message") = "THE ENtrY HAS BEEN INSERTED .. Thank You"
response.redirect "index.asp"
' 如果 RS_findmember(0) 返回的值是 0, 就表示用户名在数据库中不存在 , 名字就被存入 . 这意味着 , 考生可以参答站点其它的试卷了 .
End If
username = replace(request.form("txt_name"),"'","''")
' 防止非法进入数据库哦 . 替换函数 , 当访问者键入了 "'" 单撇号 , 就用 "''" 代替 .
----------------------------------------------------------------------------------------------------------------
checkuser.asp
' 考生登录验证文件 .
sql_check = "select count(*) from loginuser where username ='" & _
username &"' and password = '" & useremail &"'"
' 验证用户名和口令是否存在于数据库中 .
Set RS_check = Application("Conn").Execute(sql_check)
If RS_check(0) < > 0 Then
Session("username") = request.form("username")
response.redirect "default.asp"
' 如果已注册 , 引导到 default.asp 页 .
End If
If RS_check(0) = 0 Then
Session("error") = " 对不起 , 您的姓名或口令无效 , 请重新输入 !"
response.redirect "index.asp"
' 检查用户是否已经注册 , 如果返回值为 0, 表明用户名或口令无效 , 回注册页
End If
username = replace(request.form("username"),"'","''")
useremail = replace(request.form("password"),"'","''")
' 替换函数 .
----------------------------------------------------------------------------------------------------------------
选择试卷页面 default.asp 。登录成功后,进入该页面。在这儿,考生可以选择的考试科目列表。在本设计中,用了 001html 和 002html 两个,在实际应用中,可以增加表格以增加考试科目数。 default.asp 要求表格安装一个下拉菜单,其中包含科目的列表,然后查询数据库,从试卷的表格中搜集两个域。
default.asp
sql_papers = "select *id, topic from paper sort order by topic asc"
SET RS_papers = Application("Conn").Execute(sql_papers)
' 以下代码是为了在下拉菜单中显示结果 .
select size=1 name=select1 onchange="msec(document.form1._
select1.options[document.form1.select1.selectedIndex].value);" >
< option value="0" > 选择科目考试
< %Do while not RS_papers.EOF% >
< option value="< %=RS_papers("id")% >" >< %=lcase(RS_papers("topic"))% >< /OPTION >
< %
RS_papers.MoveNext
Loop
% >
function msec(x)
' msec 函数在 X 值的基础上调用 redirect.asp, 把查询字符串 : ?x 的值作为下拉菜单中被选择的项的值 .
{if (x==0)
{ alert(" 欢迎参加撼雪喷云之精英考试 , 请选择一个考试科目 !")
}
else
{ location.href="redirect.asp?section=" + x
}
}
----------------------------------------------------------------------------------------------------------------
终于可以参加精英赛了!我们进入了试题页面 redirect.asp 。它将考生送到实际生成试题的 ASP 页面,如果数据库中没有所选择的科目的任何题目,就会显示错误信息和返回链接。如果数据库有题,则这一页就被重新引导到 exam.asp 页面,考生就可以进行在线考试了。
redirect.asp
id = Request.QueryString ("section")
' 先 调用查询字符串部分 , 将值存入变量 id 中 .
SQL = "select tbl_name from paper where id="&id
Set RS = Application("Conn").Execute(SQL)
subject= RS(0)
' 再使用 SQL 声明传递试卷表格中的域名 table_name, 结果存储在 subject 中 .
MyString = Split(subject,"tbl",-1,1)
' 分离变量 subject, 将其存储在 MyString 中 . 注意 , 此处用 Split 函数在客户端显示测验名是为了更好地显示 .
IF RS_subject.BOF AND RS_subject.EOF Then
Response.Write Online " & MyString(1) & 题库正在创建中 , 请稍后再来 ! < a href=default.asp > 返回 < /a >"
Else
Response.Redirect ("exam.asp?section="&id )
End If
----------------------------------------------------------------------------------------------------------------
e xam.asp 是标准试卷页面,代码共分两大部分:计时器函数和本页查询选取试题。显示试题,并以单选按钮方式供考生答题。从数据库中选择的试题,本设计采用了随机函数,这也是目前题库生成试卷的通用方式。题目的个数设定为 10 个,考生每次回答 5 个。时间限定为 20 秒,剩余的时间在屏幕底部的状态窗口中显示。所有的试题都一起显示出来,然后开始计时。时间和试题个数都可以改变。
exam.asp
' 以下是计时器函数 .
< script language="javascript" >
var ck=0;
var tf=0;
var timeUp=0;
var timeLeft=0;
var tcount=0;
TimerFunc();
function TimerFunc() {
tf=window.setTimeout("TimerFunc();",1000);
tcount++;
timeLeft=20 - tcount;
window.status = " 嘻嘻 , 做得的好快哦 , 还剩 " +timeLeft + " 秒 ";
}
< /script >
id = Request.QueryString ("section")
session("id") = id
' 查询字符串存储在一个 session("id") 中 , 按顺序启动查询 .
sql_tblname = "select tbl_name from paper where id="&id
' SQL 声明的目的是从试卷表格中找到表格名 , 如果找到了表格名就开始向指定表格的查询 .
Set RS_tblname = Application("Conn").Execute(sql_tblname)
subject= RS_tblname(0)
MyString = Split(subject,"tbl",-1,1)
' split 函数从结果中去掉 tbl, 本设计使用了表格名前加 tbl 前缀的命名惯例 .
sql_details = "select a.id, a.question, a.choice1, a.choice2,a.choice3, " &_
" a.choice4 from " & subject & " a where a.id="&MyArray(Counter)
' 用随机函数生成从 1-10 之间的任意数字 , MyArray(Counter) 是已经生成的随机数字 , 用来从指定的科目表格中选取 id.id,question,choice1,choice2,choice3,choice4 都是科目表格域名 .
----------------------------------------------------------------------------------------------------------------
考试成绩单 result.asp ,显示结果,并将这些结果增加到数据库细节表格中,以供查询:
result.asp
for each item in Request.Form
sql_check = "select Count(*) from "&subject&" where answer ='" & Request.Form(item) & "'"
Set RS_check = Application("Conn").Execute(sql_check)
if RS_check(0) > 0 then
result = result + 1
end if
next
' 变量 result 存储结果 .
percent = round(( 100 * result )/count)
' 百分数换算 .
sql_id = "select id from loginuser where username='" & Session("username") &"'"
Set RS_id = Application("Conn").Execute(sql_id)
id= RS_id(0)
SQL_insert = "insert into details (ref_id,subject,score) values('" & id & "','" _
& subject & "', '" & percent &"') "
' 执行查询 , 将结果存储在数据库中 .
----------------------------------------------------------------------------------------------------------------
view.asp 文件查询是否在此参加过考试。
view.asp
sql_id= "select id from loginuser where username='" & Session("username") &"'"
Set RS_id = Application("Conn").Execute(sql_id)
id= RS_id(0)
sql_count = "Select count(*) from details where ref_id = '" & id &"'"
Set RS_count = Application("Conn").Execute(sql_count)
If RS_count(0) < > 0 Then
response.redirect "viewrecord.asp"
' 如果已参加过考试 , 则转到 viewrecord.asp 页面 .
End If
If RS_count(0) = 0 Then
Session("noview") = " 噢 , 您还没在我们这儿考过试呢 !"
response.redirect "default.asp"
End If
----------------------------------------------------------------------------------------------------------------
viewrecord.asp 文件以表格形式显示注册用户的信息。
viewrecord.asp
sql_details = "Select *subject, score from details where ref_id = '" & id &"'"
Set RS_details = Application("Conn").Execute(sql_details)
----------------------------------------------------------------------------------------------------------------
[1]
NEWSZW_HZH_END-->查看更多关于网上考试设计思路是怎样的?_编程10000问_的详细内容...