📄 subjectmanage.asp
字号:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/StudentConn.asp" -->
<!--#include file="CheckLogin.asp"-->
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL"))
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "") Then
strSubject=Request("Subject") & ""
if Instr(strSubject,"!")>0 or Instr(strSubject,"@")>0 or Instr(strSubject,"#")>0 or Instr(strSubject,"$")>0 or Instr(strSubject,"%")>0 or Instr(strSubject,"^")>0 or Instr(strSubject,"&")>0 or Instr(strSubject,"*")>0 or Instr(strSubject,"(")>0 or Instr(strSubject,")")>0 or Instr(strSubject,"-")>0 or Instr(strSubject,"=")>0 or Instr(strSubject,"\")>0 or Instr(strSubject,",")>0 or Instr(strSubject,".")>0 or Instr(strSubject,"/")>0 or Instr(strSubject,"?")>0 or Instr(strSubject,"<")>0 or Instr(strSubject,">")>0 or Instr(strSubject,"[")>0 or Instr(strSubject,"]")>0 or Instr(strSubject,"{")>0 or Instr(strSubject,"}")>0 or Instr(strSubject,"|")>0 or Instr(strSubject,"+")>0 or Instr(strSubject,"~")>0 or Lcase(strSubject)="as" then
Response.Redirect "SubjectManage.asp?Err=Char"
end if
MM_dupKeyRedirect="SubjectManage.asp"
MM_rsKeyConnection=MM_StudentConn_STRING
MM_dupKeyUsernameValue = CStr(Request.Form("Subject"))
MM_dupKeySQL="SELECT SubjectName FROM Subject WHERE SubjectName='" & MM_dupKeyUsernameValue & "'"
MM_adodbRecordset="ADODB.Recordset"
set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
MM_rsKey.ActiveConnection=MM_rsKeyConnection
MM_rsKey.Source=MM_dupKeySQL
MM_rsKey.CursorType=0
MM_rsKey.CursorLocation=2
MM_rsKey.LockType=3
MM_rsKey.Open
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "Err=Exist"
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_StudentConn_STRING
MM_editTable = "Subject"
MM_editRedirectUrl = "SubjectManage.asp"
MM_fieldsStr = "Subject|value"
MM_columnsStr = "SubjectName|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
Dim rsTarget
Dim rsTarget_numRows
Set rsTarget = Server.CreateObject("ADODB.Recordset")
rsTarget.ActiveConnection = MM_StudentConn_STRING
rsTarget.Source = "SELECT * FROM TargetScore"
rsTarget.CursorType = 0
rsTarget.CursorLocation = 2
rsTarget.LockType = 1
rsTarget.Open()
rsTarget_numRows = 0
InsertFlag=True
for k=0 to rsTarget.fields.count-1
if rsTarget.fields.item(k).name=CStr(Request.Form("Subject")) then InsertFlag=False
next
rsTarget.Close()
if InsertFlag=True then
' *** 向TargetScore表中添加字段
strSubject = CStr(Request.Form("Subject")) & " SINGLE"
MM_AppendFieldConnection = MM_StudentConn_STRING
MM_AppendFieldQuery = "ALTER TABLE TargetScore ADD COLUMN " & strSubject
Set MM_AppendFieldCmd = Server.CreateObject("ADODB.Command")
MM_AppendFieldCmd.ActiveConnection = MM_AppendFieldConnection
MM_AppendFieldCmd.CommandText = MM_AppendFieldQuery
MM_AppendFieldCmd.Execute
MM_AppendFieldCmd.ActiveConnection.Close
end if
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Delete Record: declare variables
if (CStr(Request("MM_delete")) = "form2") Then
MM_editConnection = MM_StudentConn_STRING
MM_editTable = "Subject"
MM_editColumn = "ID"
MM_recordId = "" + Request.Form("Subject") + ""
MM_editRedirectUrl = "SubjectManage.asp"
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
If (CStr(Request("MM_insert")) = "form1") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
' *** Delete Record: construct a sql delete statement and execute it
If (CStr(Request("MM_delete")) <> "") Then
' create the sql delete statement
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_StudentConn_STRING
Recordset1.Source = "SELECT * FROM Subject ORDER BY ID ASC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
Dim Repeat2__numRows
Dim Repeat2__index
Repeat2__numRows = -1
Repeat2__index = 0
Recordset2_numRows = Recordset2_numRows + Repeat2__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>考试科目管理</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2600.0" Name=GENERATOR>
<link href="home.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function checktest(){
var strSubjectName=document.form1.Subject.value;
if(strSubjectName=="")
{
alert("考试科目名不能为空!");
document.form1.Subject.focus();
return false;
}
}
</script>
</HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0>
<% if Request("Err")="Char" Then %>
<script language="JavaScript" type="text/JavaScript">
alert("科目名称中含有“!@#$%^&*()-+=,./?<>[]{}\|~“等非法字符,操作被取消!");
</script>
<%
end if
if Request("Err")="Exist" Then
%>
<script language="JavaScript" type="text/JavaScript">
alert("数据库中已存在此科目名称,操作被取消!");
</script>
<% End If %>
<!--#include file="TestManage_Top.asp"-->
<TABLE width="760" border=0 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD width=1 background="images/dotLine_h.gif"><IMG src="images/shim(1).gif" width=1></TD>
<TD Width="100" align="center" bgcolor="#EEEEEE"> </TD>
<td width="10" bgcolor="#F2FBF2"></td>
<TD bgcolor="#F2FBF2"><img src="images/ScoreQurey_Title.GIF" width="500" height="60"><br>
<br> <form Name="form1" onsubmit="return checktest()" method="POST" action="<%=MM_editAction%>">
<b>添加新考试科目:</b><font color="#FF0000"><b>
<input name="Subject" type="text" size="10">
<input type="submit" name="Submit" value="添加">
<input type="hidden" name="MM_insert" value="form1">
</b></font>
</form>
<strong>已有的考试科目:</strong><br>
<% If Not Recordset1.EOF Or Not Recordset1.BOF Then %>
<% response.Write "<table border='1' cellspacing='2' cellpadding='2'><tr>"
i = 1
Recordset1.MoveFirst
While (Not Recordset1.EOF)
Response.write "<td Width='50' Align='Center'>" & Recordset1.Fields.Item("SubjectName").Value & "</td>"
if (i)>0 and (i mod 8 =0) then response.write "</tr><tr>"
Recordset1.MoveNext
i=i+1
Wend
If (Recordset1.CursorType > 0) Then
Recordset1.MoveFirst
Else
Recordset1.Requery
End If
response.Write "</tr></table>"
%>
<form name="form2" method="POST" action="<%=MM_editAction%>">
<b>删除已有的考试科目:</b>
<select name="Subject">
<%
intTemp = 0
While (NOT Recordset1.EOF)
intTemp=intTemp+1
%>
<option value="<%=(Recordset1.Fields.Item("ID").Value)%>" selected><%=(Recordset1.Fields.Item("SubjectName").Value)%></option>
<%
Recordset1.MoveNext()
Wend
If (Recordset1.CursorType > 0) Then
Recordset1.MoveFirst
Else
Recordset1.Requery
End If
%>
</select>
<% if intTemp>0 then %>
<input name="Submit" type="submit" value="删除">
<input type="hidden" name="MM_delete" value="form2">
<% end if %>
</form>
<br>
<% End If ' end Not Recordset1.EOF Or NOT Recordset1.BOF %>
<% If Recordset1.EOF And Recordset1.BOF Then %>
<p align="center">找不到任何考试科目,请添加考试科目!<br>
<br>
</p>
<% End If ' end Recordset1.EOF And Recordset1.BOF %>
</td>
<TD width=1 background="images/dotLine_h.gif"><IMG src="images/shim(1).gif" width=1></TD>
</TR>
<tr>
<TD height="1" colspan="7" background="images/dotLine_w.gif"><IMG height=1 src="images/shim(1).gif" width=100></TD>
</tr>
</TBODY>
</TABLE>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <Iframe src="http://cqzx.sdedu.net/sdms/CopyRight.asp" width="760" height="200" marginheight="0" marginwidth="0" scrolling="NO" frameborder="0" name="CopyRight"></iframe> </td> </tr></table></BODY>
</HTML>
<%
Recordset1.Close()
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -