?? admin_course.asp
字號:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
option explicit
Response.expires=-1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","no-store"
%>
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/function.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>課程管理</title>
<link href="admin.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="90%" align="center" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF" class="tborder">
<tr class="tdtbg">
<td align="center">
課 程 管 理
</td>
</tr>
<tr class="tdbg">
<td>
<a href="admin_course.asp">課程管理首頁</a>
</td>
</tr>
</table>
<br>
<%
dim strAction
if checkAdminLogin() = false then '進行管理員登錄驗證
response.redirect "admin_login.asp"
end if
if checkPurview(CONST_PURVIEW_COURSE) = false then
response.write "<center><font size=4>你沒有進行此操作的權限,請與系統管理員聯系!</font></center>"
response.write "</body></html>"
response.end
end if
strAction = trim(request.form("action"))
if strAction = "" then
strAction = trim(request.querystring("action"))
end if
select case strAction
case "saveupdate"
call saveUpdate()
case "del"
call delCourse()
case else
call main()
end select
call closeConn()
%>
</body>
</html>
<%
sub main() '主界面
dim rsCourse,strSqlCourse
%>
<table width="90%" align="center" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF" class="tborder">
<tr class="tdtbg">
<td align="center">
添 加 / 修 改 課 程 檔 案
</td>
</tr>
<tr class="tdbg">
<td>
如果要添加課程檔案,請把課程ID刪除。<br>
<a name="form">
<form name="frmUpdate" action="admin_course.asp" method="post">
<input name="action" type="hidden" value="saveupdate">
課程ID:<input name="courseid" class="text" type="text" size="10" value="">
課程名稱:<input name="coursename" class="text" type="text" size="40" maxlength="128" value="">
<input type="submit" value=" 更 新 ">
</form>
</td>
</tr>
</table>
<br>
<table width="90%" align="center" cellspacing="1" cellpadding="0" bgcolor="#FFFFFF" class="tborder">
<tr class="tdtbg">
<td width="70" align="center"> 課 程 ID</td>
<td align="center"> 課 程 名 稱 </td>
<td width="150" align="center"> 操 作 </td>
</tr>
<%
set rsCourse = server.createobject("ADODB.Recordset")
strSqlCourse = "select * from course order by courseid desc"
rsCourse.open strSqlCourse,G_CONN,1,1
if rsCourse.bof and rsCourse.eof then
response.write "<tr class='tdbg'><td colspan='3' align='center'>沒有課程檔案</td></tr>"
end if
while not rsCourse.eof
response.write "<tr class='tdbg'>"
response.write "<td align='center'>" & rsCourse("courseid") & "</td>"
response.write "<td>" & rsCourse("coursename") & "</td>"
response.write "<td align='center'><a href='#' onClick=""if(confirm('即將刪除此課程和此課程的所有考題,確認刪除嗎?') == true) window.open('admin_course.asp?action=del&courseid=" & rsCourse("courseid") & "','_self')"">刪除</a> | "
response.write "<a href='#form' onClick=""document.all.frmUpdate.courseid.value=" & rsCourse("courseid") & ";document.all.frmUpdate.coursename.value='" & rsCourse("coursename") & "';"">修改</a>"
response.write "</td></tr>"
rsCourse.movenext
wend
rsCourse.close
set rsCourse = nothing
%>
</table>
<%
end sub
'修改或添加課程檔案
sub saveUpdate()
dim rsCourse,strSqlCourse,intCourseID,strCourseName,strErr
strCourseName = trim(request.form("coursename"))
if strCourseName = "" then
strErr = "<li>課程名為空!</li>"
end if
if trim(request.form("courseid")) <> "" then '驗證是否傳遞了ID號。
intCourseID = Abs(CLng(trim(request.form("courseid"))))
else
intCourseID = -1
end if
if strErr <> "" then
showErrMsg(strErr)
exit sub
end if
set rsCourse = server.createobject("ADODB.Recordset")
strSqlCourse = "select * from course where courseid=" & intCourseID
rsCourse.open strSqlCourse,G_CONN,1,3
if rsCourse.bof and rsCourse.eof and intCourseID = -1 then '當沒有ID存在時添加課程
rsCourse.addnew
rsCourse("coursename") = strCourseName
rsCourse.update
elseif not rsCourse.bof and not rsCourse.eof then '有ID存在并且ID存在于數據庫時就修改課程
rsCourse("coursename") = strCourseName
rsCourse.update
end if
rsCourse.close
set rsCourse = nothing
call closeConn()
response.redirect "admin_course.asp"
end sub
'刪除課程檔案 注意:只有沒有被其他表使用的課程才可以刪除
sub delCourse()
dim intCourseID,strErr
strErr = ""
intCourseID = CLng(trim(request.querystring("courseid")))
if G_CONN.execute("select count(*) as reccount from project where courseid=" & intCourseID)("reccount") > 0 then
strErr = "<li>此課程已經被考試計劃使用,不能刪除!</li>"
end if
if strErr = "" then
G_CONN.begintrans '開始事務
G_CONN.execute "delete from subject where courseid=" & intCourseID
G_CONN.execute "delete from course where courseid=" & intCourseID
G_CONN.committrans '結束事務
call closeConn()
response.redirect "admin_course.asp"
else
showErrMsg(strErr)
end if
end sub
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -