用ASP開發(fā)試題庫與在線考試系統(tǒng)(八)
...
七、附錄:源程序列表
由于源代碼繁多,限于篇幅,無法一一列舉,現(xiàn)只公布部分代碼,具體以系統(tǒng)實物為準。下面是錄入試題.asp文件:
<script language="VBScript">
<!-- Written by HeKai 2001
Function datacheck()確保前臺輸入數(shù)據(jù)合法
dim errflag, msg
errflag = True
if Len(Trim(luru.xzsj.value)) = 0 Then
focusto(1); errflag = false; msg="請輸入 選自書籍名稱"
ElseIf Len(Trim(luru.stnr.value)) = 0 Then
focusto(9); errflag = false; msg=" 試題內(nèi)容 呢"
ElseIf Len(Trim(luru.A.value)) = 0 Then
focusto(10); errflag = false; msg=" 答案_A 呢"
┋ ┋ ┋
ElseIf Len(Trim(luru.F.value)) = 0 Then
focusto(15); errflag = false; msg="請還原成默認值"
End if
If (errflag = false) then
msg = msg & vbCRLF
MsgBox msg, 64, "提示"
Exit Function
End if
datacheck = errflag; luru.Submit
End Function
Sub focusto(x)將鼠標定位在出錯處
document.luru.elements(x).focus()
End Sub
--></script>
以下是錄入試題.inc文件:
<script Language="VBScript" RunAt="Server">
Function check_Pass()檢查庫中是否已有此數(shù)據(jù)
kmxxmc = Request.Form("kmxxmc")
stbh = Request.Form("stbh") stnr = Request.Form("stnr")
SQLstr = "select * from " & kmxxmc & " where stbh=" & "" & stbh & ""
SQLstr = SQLstr & " or tmnr=" & "" & stnr & ""
set adocon=Server.CreateObject("ADODB.Connection")
adocon.Open "zxtest"
set sa1=adocon.Execute(SQLstr)
If sa1.EOF Then
check_Pass = False
Else
check_Pass = True
End If
sa1.Close adocon.Close
End Function
Sub Add_Comment()開始插入數(shù)據(jù)并顯示出來
Dim kmxxmc,xzsj,tmlx,nycd,jxyq,stbh,stnr
Dim A,B,C,D,E,F,bzda,lrz,Picstr,SQLstr,lr_date,zhang,jie
kmxxmc = Request.Form("kmxxmc") xzsj = Request.Form("xzsj")
┋ ┋ ┋
bzda = Request.Form("bzda") zhang = Request.form("zhang")
set adocon=Server.CreateObject("ADODB.Connection")
adocon.Open "zxtest"
SQLstr = "insert into " & kmxxmc & " (xzsj,tmlx,tmnd,jxyq,stbh,tmnr, bxda_a,"
SQLstr = SQLstr & ",jie,lrz) values (" & "" & xzsj & "," & "" & tmlx & ","
┋ ┋ ┋
SQLstr = SQLstr & "," & "" & date & "," & "" & zhang & "," & "" & jie & "," SQLstr = SQLstr & "" & lrz & ")"
set sa1 = adocon.Execute(SQLstr)
Picstr="<img src=/images/hekai.jpg>"
Response.Write "恭喜!此為<i> " & lrz & "</i> 剛才錄入的試題"
Response.Write Picstr & " 試題編號:" & stbh
Response.Write "試題內(nèi)容:" & stnr & "<br>"
Response.Write "答案_A:" & A & "<br>"
┋ ┋ ┋
adocon.Close
End Sub
Sub Register()
If check_Pass() Then 如果庫中已有的話,則給出提示信息
Show_Warning()
Else 否則添加進去
Add_Comment()
End If
End Sub
Sub Show_Warning()給出提示信息的函數(shù)
Response.Write("<p>")
Response.Write("<center>很抱歉<p>")
Response.Write("庫中已有此試題編號或試題內(nèi)容,請返回前頁修改!")
Response.Write("</center>")
Response.Write("Made by hekai himself in 2001")
End Sub
</script>
此為"檢索試題"的程序代碼:
<script Language="VBScript" RunAt="Server">
Function adjust_sql(adj_str)
目的---轉(zhuǎn)換查詢字符串中的特殊字符至SQL指令
Dim final_str, i WRITE BY HEKAI2001
adj_str = Trim(adj_str)
final_str = "" 每次從傳進來的字符串中取出一個字符,并判斷是否為下述三個字符之一: DOS的Filter符號"|"、左中括號"["以及單引號""
If Len(adj_str) > 0 Then
For i = 1 To Len(adj_str)
Select Case Mid(adj_str, i, 1)
Case "[": final_str = final_str & "[[]"
Case "|": final_str = final_str & "[{-}]"
Case "": final_str = final_str & "[&-()"
Case Else: 以上皆非則什么事都不做!
final_str = final_str & Mid(adj_str, i, 1)
End Select
Next
End If
adjust_sql = final_str
End Function
Sub Output_shiti()
Dim kmxxmc,xzsj,stbh,zhang,jie,tmlx,nycd,jxyq,lrz,stnr,cond_count, Picstr
Dim SQLstr,mf,zhangfw,jiefw,stbhfw,nycdfw,lr_datefw,lr_date
記錄指定條件的欄位總數(shù)
cond_count = 10; mf = "%"
Picstr="<img src=/images/hk.gif>"
取得表單欄位內(nèi)容
kmxxmc = Request.Form("kmxxmc")
stbh = Request.Form("stbh")
┋ ┋ ┋
stnr = Request.Form("stnr")
調(diào)整SQL指令中的特定字元
kmxxmc = adjust_sql(kmxxmc)
stbh = adjust_sql(stbh)
┋ ┋ ┋
stnr = adjust_sql(stnr)
If Len(xzsj) = 0 Then cond_count = cond_count - 1
If Len(stbh) = 0 Then cond_count = cond_count - 1
┋ ┋ ┋
If Len(stnr) = 0 Then cond_count = cond_count - 1
SQLstr = "select * from " & kmxxmc & " where "
If Len(stbh) > 0 Then
SQLstr = SQLstr & " stbh " & stbhfw & "" & stbh & ""
If cond_count > 1 Then
SQLstr = SQLstr & " and "
cond_count = cond_count - 1
End If
End If
┋ ┋ ┋
If Len(stnr) > 0 Then
SQLstr = SQLstr & " tmnr like " & "" & mf & stnr & mf & ""
If cond_count > 1 Then
SQLstr = SQLstr & " and "
cond_count = cond_count - 1
End If
End If
SQLstr = SQLstr & " order by lr_date DESC "
set adocon=Server.CreateObject("ADODB.Connection")
adocon.Open "zxtest"
set sa1 = adocon.Execute(SQLstr)
If sa1.EOF Then
Response.Write "<br><center><h1>"
Response.Write "Sorry!<p>"
Response.Write "沒有找到試題,"
esponse.Write "請重試一次?。?center><p>"
Response.Write "<hr></h1>"
Else
i = 0
Response.Write "<h2>"
Response.Write "符合條件的試題相關(guān)內(nèi)容如下:"
Response.Write "</h2>"
While Not sa1.EOF
i = i + 1
Response.Write "第 <i>" & i & "</i>題 題編號:<i>" & sa1("stbh") & "</i><br>"
Response.Write "試題內(nèi)容:" & sa1("tmnr") & "<br>"
┋ ┋ ┋
Response.Write "答案A:" & sa1("bxda_a") & "<br>"
sa1.MoveNext
WEnd
adocon.Close
End If
End Sub
</script>
<% "檢索試卷"的查詢方式源代碼
mf="%"
select case request("findfs")
case "sjbh"
sqlstr="SELECT * FROM tbsjxx WHERE " & " sjbh LIKE"
sqlstr=sqlstr & "" & mf & request("findfsz") & mf & "order by ksrq DESC"
┋ ┋ ┋
case "lr_date"
sqlstr="SELECT * FROM tbsjxx WHERE " & " lr_date LIKE"
sqlstr=sqlstr & "" & mf & request("findfsz") & mf & "order by ksrq DESC"
case else
sqlstr="SELECT * FROM tbsjxx order by ksrq DESC"
end select %>
下面是考試的時間自動控制程序(便于演示只設(shè)了60秒鐘,實際應用應以系統(tǒng)調(diào)出試卷的考試時間為準!):
<SCRIPT language=JavaScript>
<!-- Write by HEKAI for TestTimeContorl
var timerID = null;var timerRunning = false
var stardate = new Date();var startime = gettotalsecond(stardate)
var totaltime = 60; var lasttime;var facetime
function Stepclock(){
// hk made by himself
if(timerRunning)
clearTimeout(timerID)
timerRunning = false }
function startclock(){
Stepclock();showtime() }
function gettotalsecond(getdate){
var hours = getdate.getHours()
var minutes = getdate.getMinutes();var seconds = getdate.getSeconds()
var gettotalsecond = seconds + minutes * 60 + hours * 3600
return(gettotalsecond) }
function showtime(){
var now = new Date();var timeValue = gettotalsecond(now)
document.clock.face.value = timeValue - startime
facetime = document.clock.face.value;lasttime = totaltime - facetime
document.clock.sytime.value = lasttime
timerID = setTimeout("showtime()",1000)
timerRunning = true
if (lasttime == 20){
for(i=1;i<=3;i++){
alert(考試時間只剩下最后20秒!)}}
if (lasttime == 0){
for(i=1;i<=5;i++){
alert(時間完畢!請迅速交卷?。?#146;)}}
if (lasttime == -10){
for(i=1;i<=10;i++){
alert(考試時間超過10秒,關(guān)閉此窗口!)}}
}//-->
</SCRIPT>
八、后記
此系統(tǒng)從研究設(shè)計到投入實際應用歷時4個月之余,通過多次細致的測試及鑒定,證明系統(tǒng)完全具有可行性與可擴充性,就最近傳來的消息,該系統(tǒng)獲得了湖南省科技廳的普遍好評。另外,系統(tǒng)還有待于進一步升級,并將實現(xiàn)試卷的主觀題部分和多媒體試卷。因此,仍有大量的工作需要開展。若有不詳或不妥之處,請您以應用程序為準以及提出良好的意見與建議。
上一條:用ASP開發(fā)試題庫與在線考試系統(tǒng)(七)
下一條:ASP字符串函數(shù)大全