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確認,以便不把它們作為空白域來傳遞。非考生要想?yún)⒓涌荚嚤仨毾茸?。這個頁面還要顯示一些錯誤信息,如“用戶名或口令錯誤”、“請重新選擇一個用戶名”等。注冊表單中還應(yīng)包含考生一些個人的信息,如Emai、年齡、教育程度等。登錄后,考生就可以參答考試站點的其它試卷了。
index.asp
title>撼雪噴云之網(wǎng)上考試設(shè)計思路/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,當考生登錄或新注冊后,就顯示這一頁。我們可以利用它來詢問考生的個人信息。該表單被提交后,轉(zhuǎn)到sendregister.asp頁面。
----------------------------------------------------------------------------------------------------------------
驗證和發(fā)送文件sendregister.asp。該頁面從register.asp 中取得表單域的內(nèi)容,查詢數(shù)據(jù)庫驗證輸入的用戶名是否已經(jīng)存在,如果存在,則將考生重新引回register.asp頁面,并被提示要求重新選擇用戶名;如果用戶名通過,則輸入的內(nèi)容就被傳遞并插入到數(shù)據(jù)庫中。
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") = "噢,您輸入的名字已經(jīng)存在,請重新選擇一個名字!"
response.redirect "register.asp"
' 如果RS_findmember(0) 返回的值大于0,用戶就被引導(dǎo)回注冊主頁,并被要求填寫一個新的用戶名.
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,就表示用戶名在數(shù)據(jù)庫中不存在,名字就被存入.這意味著,考生可以參答站點其它的試卷了.
End If
username = replace(request.form("txt_name"),"'","''")
' 防止非法進入數(shù)據(jù)庫哦.替換函數(shù),當訪問者鍵入了"'"單撇號,就用"''"代替.
----------------------------------------------------------------------------------------------------------------
checkuser.asp
' 考生登錄驗證文件.
sql_check = "select count(*) from loginuser where username ='" _
username "' and password = '" useremail "'"
' 驗證用戶名和口令是否存在于數(shù)據(jù)庫中.
Set RS_check = Application("Conn").Execute(sql_check)
If RS_check(0) > 0 Then
Session("username") = request.form("username")
response.redirect "default.asp"
' 如果已注冊,引導(dǎo)到default.asp頁.
End If
If RS_check(0) = 0 Then
Session("error") = "對不起,您的姓名或口令無效,請重新輸入!"
response.redirect "index.asp"
' 檢查用戶是否已經(jīng)注冊,如果返回值為0,表明用戶名或口令無效,回注冊頁
End If
username = replace(request.form("username"),"'","''")
useremail = replace(request.form("password"),"'","''")
' 替換函數(shù).
----------------------------------------------------------------------------------------------------------------
選擇試卷頁面default.asp。登錄成功后,進入該頁面。在這兒,考生可以選擇的考試科目列表。在本設(shè)計中,用了001html 和002html兩個,在實際應(yīng)用中,可以增加表格以增加考試科目數(shù)。default.asp 要求表格安裝一個下拉菜單,其中包含科目的列表,然后查詢數(shù)據(jù)庫,從試卷的表格中搜集兩個域。
default.asp
sql_papers = "select *id, topic from paper sort order by topic asc"
SET RS_papers = Application("Conn").Execute(sql_papers)
' 以下代碼是為了在下拉菜單中顯示結(jié)果.
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函數(shù)在X值的基礎(chǔ)上調(diào)用 redirect.asp,把查詢字符串: ?x的值作為下拉菜單中被選擇的項的值.
{if (x==0)
{ alert("歡迎參加撼雪噴云之精英考試,請選擇一個考試科目!")
}
else
{ location.href="redirect.asp?section=" + x
}
}
----------------------------------------------------------------------------------------------------------------
終于可以參加精英賽了!我們進入了試題頁面redirect.asp。它將考生送到實際生成試題的ASP頁面,如果數(shù)據(jù)庫中沒有所選擇的科目的任何題目,就會顯示錯誤信息和返回鏈接。如果數(shù)據(jù)庫有題,則這一頁就被重新引導(dǎo)到exam.asp頁面,考生就可以進行在線考試了。
redirect.asp
id = Request.QueryString ("section")
' 先調(diào)用查詢字符串部分,將值存入變量 id中.
SQL = "select tbl_name from paper where id="id
Set RS = Application("Conn").Execute(SQL)
subject= RS(0)
' 再使用SQL聲明傳遞試卷表格中的域名table_name,結(jié)果存儲在subject中.
MyString = Split(subject,"tbl",-1,1)
' 分離變量subject,將其存儲在MyString中.注意,此處用Split 函數(shù)在客戶端顯示測驗名是為了更好地顯示.
IF RS_subject.BOF AND RS_subject.EOF Then
Response.Write Online " MyString(1) 題庫正在創(chuàng)建中,請稍后再來! a href=default.asp >返回 /a >"
Else
Response.Redirect ("exam.asp?section="id )
End If
----------------------------------------------------------------------------------------------------------------
exam.asp是標準試卷頁面,代碼共分兩大部分:計時器函數(shù)和本頁查詢選取試題。顯示試題,并以單選按鈕方式供考生答題。從數(shù)據(jù)庫中選擇的試題,本設(shè)計采用了隨機函數(shù),這也是目前題庫生成試卷的通用方式。題目的個數(shù)設(shè)定為10個,考生每次回答5個。時間限定為20秒,剩余的時間在屏幕底部的狀態(tài)窗口中顯示。所有的試題都一起顯示出來,然后開始計時。時間和試題個數(shù)都可以改變。
exam.asp
' 以下是計時器函數(shù).
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函數(shù)從結(jié)果中去掉tbl, 本設(shè)計使用了表格名前加tbl前綴的命名慣例.
sql_details = "select a.id, a.question, a.choice1, a.choice2,a.choice3, " _
" a.choice4 from " subject " a where a.id="MyArray(Counter)
' 用隨機函數(shù)生成從1-10之間的任意數(shù)字, MyArray(Counter)是已經(jīng)生成的隨機數(shù)字,用來從指定的科目表格中選取id.id,question,choice1,choice2,choice3,choice4都是科目表格域名.
----------------------------------------------------------------------------------------------------------------
考試成績單result.asp,顯示結(jié)果,并將這些結(jié)果增加到數(shù)據(jù)庫細節(jié)表格中,以供查詢:
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存儲結(jié)果.
percent = round(( 100 * result )/count)
' 百分數(shù)換算.
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 "') "
' 執(zhí)行查詢,將結(jié)果存儲在數(shù)據(jù)庫中.
----------------------------------------------------------------------------------------------------------------
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"
' 如果已參加過考試,則轉(zhuǎn)到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]
您可能感興趣的文章:- php網(wǎng)上商城購物車設(shè)計代碼分享
- php 網(wǎng)上商城促銷設(shè)計實例代碼
- 我的php學(xué)習(xí)筆記(畢業(yè)設(shè)計)
- ASP.NET網(wǎng)站聊天室的設(shè)計與實現(xiàn)(第3節(jié))
- 管理員登錄設(shè)計(第7節(jié))
- JavaWeb搭建網(wǎng)上圖書商城畢業(yè)設(shè)計
- C#影院售票系統(tǒng)畢業(yè)設(shè)計(1)
- C#影院售票系統(tǒng)畢業(yè)設(shè)計(2)
- C#影院售票系統(tǒng)畢業(yè)設(shè)計(3)
- C#影院售票系統(tǒng)畢業(yè)設(shè)計(4)