?? function.asp
字號:
<%
'公用常量定義
CONST CONST_PURVIEW_ADMIN = 0 '超級管理員權(quán)限值
CONST CONST_PURVIEW_SUBJECT = 1 '維護(hù)試題檔案權(quán)限值
CONST CONST_PURVIEW_STUDENT = 2 '維護(hù)考生檔案權(quán)限值
CONST CONST_PURVIEW_PROJECT = 4 '維護(hù)考試計劃權(quán)限值
CONST CONST_PURVIEW_COURSE = 8 '維護(hù)課程檔案權(quán)限值
'檢測管理員登錄是否有效
function checkAdminLogin()
dim rsCheckLogin,strSqlCheckLogin
checkAdminLogin = true
set rsCheckLogin = server.createobject("ADODB.Recordset")
strSqlCheckLogin = "select * from admin where adminname='" & request.cookies("aoyi")("adminname") & "'"
rsCheckLogin.open strSqlCheckLogin,G_CONN,1,1
if rsCheckLogin.bof and rsCheckLogin.eof then
checkAdminLogin = false
end if
rsCheckLogin.close
set rsCheckLogin = nothing
end function
'檢測當(dāng)前管理員權(quán)限是否符合指定要求
function checkPurview(intPurview)
dim rsCheckPurview,strSqlCheckPurview
checkPurview = false
set rsCheckPurview = server.createobject("ADODB.Recordset")
strSqlCheckPurview = "select * from admin where adminname='" & request.cookies("aoyi")("adminname") & "'"
rsCheckPurview.open strSqlCheckPurview,G_CONN,1,1
if not rsCheckPurview.bof and not rsCheckPurview.eof then
if rsCheckPurview("adminpurview") and intPurview <> 0 or rsCheckPurview("adminname") = "admin" then '把數(shù)據(jù)庫中權(quán)限值與指定權(quán)限值做與運(yùn)算檢測是否包含指定權(quán)限
checkPurview = true
end if
end if
rsCheckPurview.close
set rsCheckPurview = nothing
end function
'檢測當(dāng)前考生登錄是否有效
function checkStudentLogin()
dim rsCheckLogin,strSqlCheckLogin
checkStudentLogin = true
set rsCheckLogin = server.createobject("ADODB.Recordset")
strSqlCheckLogin = "select studentid from student where studenttype=1 and username='" & request.cookies("aoyi")("username") & "'"
rsCheckLogin.open strSqlCheckLogin,G_CONN,1,1
if rsCheckLogin.bof and rsCheckLogin.eof then
checkStudentLogin = false
end if
rsCheckLogin.close
set rsCheckLogin = nothing
end function
'顯示課程選擇列表
sub showCourseList(SelectedID)
dim rsCourse,strSqlCourse
set rsCourse = server.createobject("ADODB.Recordset")
strSqlCourse = "select * from course"
rsCourse.open strSqlCourse,G_CONN,1,1
response.write "<select name='courseid' style='width:130px;'>" & vbcrlf
response.write "<option value='0'>---所有課程---</option>"
while not rsCourse.eof
response.write "<option "
if rsCourse("courseid") = SelectedID then
response.write "selected"
end if
response.write " value='" & rsCourse("courseid") & "'>" & rsCourse("coursename") & "</option>" & vbcrlf
rsCourse.movenext
wend
response.write "</select>"
rsCourse.close
set rsCourse = nothing
end sub
'顯示錯誤信息
sub showErrMsg(strErrMsg)
%>
<table align="center" width="500" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF" class="tborder">
<tr class="tdtbg">
<td align="center">
<font color="#FFFFFF"> 操 作 失 敗 </font>
</td>
</tr>
<tr class="tdbg">
<td align="center">
操作沒有成功,可能由于以下原因:<br>
<%=strErrMsg%>
</td>
</tr>
<tr class="tdbg">
<td height="30" align="center">
<input type="button" onClick="history.go(-1);" value=" 返回上一頁 ">
</td>
</tr>
</table>
<%
end sub
'顯示頁面控制
sub showPageCtrl(intMaxPage,intCurPage,strUrl)
dim I
if intCurPage > 1 then
response.write "<a href='" & strUrl & "1'>首頁</a> <a href='" & strUrl & intCurPage - 1 & "'>上一頁</a> "
else
response.write "首頁 上一頁 "
end if
response.write "第 <font color='red'>" & intCurPage & "</font>/" & intMaxPage & " 頁 "
if intCurPage < intMaxPage then
response.write "<a href='" & strUrl & intCurPage + 1 & "'>下一頁</a> <a href='" & strUrl & intMaxPage & "'>尾頁</a> "
else
response.write "下一頁 尾頁 "
end if
response.write "跳轉(zhuǎn)到:<select onChange=""window.open('" & strUrl & "' + this.value,'_self');"">"
for I = 1 to intMaxPage
response.write "<option value='" & I & "'>第 " & I & " 頁</option>"
next
response.write "</select>"
end sub
'生成試卷
function makePaper(intPrjID,intStudentID)
dim rsPaper,strSqlPaper,rsNew,strSqlNew,intCourseID,intCount,arrTemp,intSSCount,arrSS,intMSCount,arrMS,intBCount,intZGCount,arrB,intCurType,I,J,intPos,blnPass
G_CONN.execute "delete from prj_process where prjid=" & intPrjID & " and studentid=" & intStudentID
set rsPaper = server.createobject("ADODB.Recordset")
strSqlPaper = "select courseid,ss_count,ms_count,b_count,zg_count from project where prjid=" & intPrjID
rsPaper.open strSqlPaper,G_CONN,1,1
if not rsPaper.bof and not rsPaper.eof then
intCourseID = rsPaper("courseid")
intSSCount = rsPaper("ss_count")
intMSCount = rsPaper("ms_count")
intBCount = rsPaper("b_count")
intZGCount= rsPaper("zg_count")
else
rsPaper.close
set rsPaper = nothing
makePaper = false
exit function
end if
rsPaper.close
for intCurType = 1 to 4
select case intCurType
case 1
intCount = intSSCount
case 2
intCount = intMSCount
case 3
intCount = intBCount
case 4
intCount = intZGCount
end select
if intCount > 0 then
redim arrTemp(intCount)
strSqlPaper = "select id from subject where type=" & intCurType & " and courseid=" & intCourseID
rsPaper.open strSqlPaper,G_CONN,1,1
if rsPaper.recordcount < intCount then '判斷當(dāng)前題庫內(nèi)試題是否足夠
rsPaper.close
set rsPaper = nothing
makePaper = false
exit function
end if
randomize timer
intPos = int(rnd() * rsPaper.recordcount)
arrTemp(1) = intPos
for I = 2 to intCount
intPos = int(rnd() * rsPaper.recordcount)
blnPass = false
while blnPass = false
for J = 1 to I - 1
if intPos = arrTemp(J) then
exit for
end if
next
if J = I then
blnPass = true
else
'使用線性探測解決沖突問題
intPos = intPos + 1
if intPos = rsPaper.recordcount then
intPos = 0
end if
end if
wend
arrTemp(I) = intPos
next
strSqlNew = "select * from prj_process"
set rsNew = server.createobject("ADODB.Recordset")
rsNew.open strSqlNew,G_CONN,1,3
dim intOrderid
intOrderid = 1
for I = 1 to intCount
rsPaper.move arrTemp(I),1
rsNew.addnew
rsNew("prjid") = intPrjID
rsNew("subid") = rsPaper("id")
rsNew("studentid") = intStudentID
rsNew("orderid") = intOrderid
rsNew.update
intOrderid = intOrderid + 1
next
rsNew.close
rsPaper.close
end if
next
G_CONN.execute "update prj_student set state=2 where StudentID =" &intStudentID
G_CONN.execute "update prj_student set starttime=now() where StudentID =" &intStudentID
set rsPaper = nothing
makePaper = true
end function
function score(intPrjID,intStudentID)
dim dtmStartTime,dtmEndTime,intMark,intLimitTime
'首先判斷此試卷能否進(jìn)行打分處理
if G_CONN.execute("select count(*) as reccount from prj_student where state<>1 and "_
& "prjid=" & intPrjID & " and studentid=" & intStudentID)("reccount") = 0 then
score = false
else
'取得此考試的限制時間及進(jìn)行考試的開始時間并計算出考試的結(jié)束時間
intLimitTime = G_CONN.execute("select limittime from project where prjid=" _
& intPrjID)("limittime")
dtmStartTime = G_CONN.execute("select starttime from prj_student where prjid=" _
& intPrjID & " and studentid=" & intStudentID)("starttime")
if DateDiff("n",dtmStartTime,Now()) > intLimitTime then
dtmEndTime = FormatDatetime(dtmStartTime,2) & " " _
& FormatDatetime(TimeSerial(Hour(dtmStartTime),Minute(dtmStartTime) _
+ intLimitTime,Second(dtmStartTime)),3)
else
dtmEndTime = Now()
end if
'計算出考試試卷的得分
intMark = G_CONN.execute("select count(*) as recmark from prj_process P_P,subject "_
& "S where P_P.answer=S.answer and P_P.prjid=" & intPrjID & " and P_P.studentid=" _
& intStudentID & " and P_P.subid=S.id and (S.type=1 or S.type=3)")("recmark")
intMark = intMark + G_CONN.execute("select count(*)*2 as recmark from prj_process"_
& " P_P,subject S where P_P.answer=S.answer and P_P.prjid=" & intPrjID _
& " and P_P.studentid=" & intStudentID & " and P_P.subid=S.id and S.type=2")("recmark")
'將得分填入考試計劃考生表(prj_student)并修改考試狀態(tài)為已考
'G_CONN.execute "update prj_student set state=1,endtime=#" & dtmEndTime _
'& "#,mark=" & intMark & " where prjid=" & intPrjID & " and studentid=" & intStudentID
G_CONN.execute "update prj_student set state=1,endtime=#" & dtmEndTime _
& "#,mark=" & intMark & " where studentid=" & intStudentID '2008年11月15日晚改,基于同一學(xué)生不能同時參加兩次考試考慮。
score = true
end if
end function
'計算出考試試卷單選題的得分
function score1(intPrjID,intStudentID)
score1 = G_CONN.execute("select count(*)*1 as recmark from prj_process P_P,subject S "_
& " where P_P.answer=S.answer and P_P.prjid=" & intPrjID & " and P_P.studentid=" _
& intStudentID & " and P_P.subid=S.id and S.type=1")("recmark")
end function
'計算出考試試卷多選題的得分
function score2(intPrjID,intStudentID)
score2 = G_CONN.execute("select count(*)*2 as recmark from prj_process P_P,subject S "_
& " where P_P.answer=S.answer and P_P.prjid=" & intPrjID & " and P_P.studentid=" _
& intStudentID & " and P_P.subid=S.id and S.type=2")("recmark")
end function
'計算出考試試卷是非題的得分
function score3(intPrjID,intStudentID)
score3 =G_CONN.execute("select count(*)*1 as recmark from prj_process P_P,subject S"_
& " where P_P.answer=S.answer and P_P.prjid=" & intPrjID & " and P_P.studentid=" _
& intStudentID & " and P_P.subid=S.id and S.type=3")("recmark")
end function
function setscore(intPrjID,intStudentID)
dim strSqlNew, rsNew, intDanX_score, intDuoX_score, intSF_score
intDanX_score = score1(intPrjID,intStudentID)
intDuoX_score = score2(intPrjID,intStudentID)
intSF_score = score3(intPrjID,intStudentID)
strSqlNew = "select * from student_score"
set rsNew = server.createobject("ADODB.Recordset")
rsNew.open strSqlNew,G_CONN,1,3
rsNew.addnew
rsNew("studentid") = intStudentID
rsNew("prjid") = intPrjID
rsNew("DanX_score") = intDanX_score
rsNew("DuoX_score") = intDuoX_score
rsNew("SF_score") = intSF_score
'rsNew("ZG_score") = intZG_score
rsNew.update
rsNew.close
end function
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -