用ASP開(kāi)發(fā)試題庫(kù)與在線(xiàn)考試系統(tǒng)(八)
...
七、附錄:源程序列表
由于源代碼繁多,限于篇幅,無(wú)法一一列舉,現(xiàn)只公布部分代碼,具體以系統(tǒng)實(shí)物為準(zhǔn)。下面是錄入試題.asp文件:
<script language="VBScript">
<!-- Written by HeKai 2001
Function datacheck()確保前臺(tái)輸入數(shù)據(jù)合法
dim errflag, msg
errflag = True
if Len(Trim(luru.xzsj.value)) = 0 Then
focusto(1); errflag = false; msg="請(qǐng)輸入 選自書(shū)籍名稱(chēng)"
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="請(qǐng)還原成默認(rèn)值"
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)將鼠標(biāo)定位在出錯(cuò)處
document.luru.elements(x).focus()
End Sub
--></script>
以下是錄入試題.inc文件:
<script Language="VBScript" RunAt="Server">
Function check_Pass()檢查庫(kù)中是否已有此數(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()開(kāi)始插入數(shù)據(jù)并顯示出來(lái)
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 & " 試題編號(hào):" & stbh
Response.Write "試題內(nèi)容:" & stnr & "<br>"
Response.Write "答案_A:" & A & "<br>"
┋ ┋ ┋
adocon.Close
End Sub
Sub Register()
If check_Pass() Then 如果庫(kù)中已有的話(huà),則給出提示信息
Show_Warning()
Else 否則添加進(jìn)去
Add_Comment()
End If
End Sub
Sub Show_Warning()給出提示信息的函數(shù)
Response.Write("<p>")
Response.Write("<center>很抱歉<p>")
Response.Write("庫(kù)中已有此試題編號(hào)或試題內(nèi)容,請(qǐng)返回前頁(yè)修改!")
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)換查詢(xún)字符串中的特殊字符至SQL指令
Dim final_str, i WRITE BY HEKAI2001
adj_str = Trim(adj_str)
final_str = "" 每次從傳進(jìn)來(lái)的字符串中取出一個(gè)字符,并判斷是否為下述三個(gè)字符之一: DOS的Filter符號(hào)"|"、左中括號(hào)"["以及單引號(hào)""
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 "沒(méi)有找到試題,"
esponse.Write "請(qǐng)重試一次!</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>題 題編號(hào):<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>
<% "檢索試卷"的查詢(xún)方式源代碼
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í)間自動(dòng)控制程序(便于演示只設(shè)了60秒鐘,實(shí)際應(yīng)用應(yīng)以系統(tǒng)調(diào)出試卷的考試時(shí)間為準(zhǔn)?。?
<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(考試時(shí)間只剩下最后20秒!)}}
if (lasttime == 0){
for(i=1;i<=5;i++){
alert(時(shí)間完畢!請(qǐng)迅速交卷??!)}}
if (lasttime == -10){
for(i=1;i<=10;i++){
alert(考試時(shí)間超過(guò)10秒,關(guān)閉此窗口!)}}
}//-->
</SCRIPT>
八、后記
此系統(tǒng)從研究設(shè)計(jì)到投入實(shí)際應(yīng)用歷時(shí)4個(gè)月之余,通過(guò)多次細(xì)致的測(cè)試及鑒定,證明系統(tǒng)完全具有可行性與可擴(kuò)充性,就最近傳來(lái)的消息,該系統(tǒng)獲得了湖南省科技廳的普遍好評(píng)。另外,系統(tǒng)還有待于進(jìn)一步升級(jí),并將實(shí)現(xiàn)試卷的主觀題部分和多媒體試卷。因此,仍有大量的工作需要開(kāi)展。若有不詳或不妥之處,請(qǐng)您以應(yīng)用程序?yàn)闇?zhǔn)以及提出良好的意見(jiàn)與建議。
上一條:用ASP開(kāi)發(fā)試題庫(kù)與在線(xiàn)考試系統(tǒng)(七)
下一條:ASP字符串函數(shù)大全