⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmodify.asp

📁 学籍管理系统
💻 ASP
字号:
<%@LANGUAGE="VBSCRIPT"%> 
<!--#include file="Connections/StudentConn.asp" -->
<!--#include file="CheckLogin.asp"-->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>

<%
' *** 向表中添加字段
If (CStr(Request("AppendField")) <> "" And CStr(Request("Subject")) <> "" And CStr(Request("SheetName")) <> "") Then
	strSheetName = CStr(Request("SheetName"))
	strSubject = Cstr(Request("Subject")) & " SINGLE"

	MM_AppendFieldConnection = MM_StudentConn_STRING
	MM_AppendFieldQuery = "ALTER TABLE " & strSheetName & " 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
	
    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editAction)
    End If

end if
%>

<%
' *** 从表中删除字段
If (CStr(Request("DeleteField")) <> "" And CStr(Request("Subject")) <> "" And CStr(Request("SheetName")) <> "") Then
	strSheetName = CStr(Request("SheetName"))
	strSubject = Cstr(Request("Subject"))

	MM_DeleteFieldConnection = MM_StudentConn_STRING
	MM_DeleteFieldQuery = "ALTER TABLE " & strSheetName & " DROP COLUMN " & strSubject
	Set MM_DeleteFieldCmd = Server.CreateObject("ADODB.Command")
	MM_DeleteFieldCmd.ActiveConnection = MM_DeleteFieldConnection
    MM_DeleteFieldCmd.CommandText = MM_DeleteFieldQuery
	MM_DeleteFieldCmd.Execute
    MM_DeleteFieldCmd.ActiveConnection.Close
	
    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editAction)
    End If

end if
%>


<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  MM_editConnection = MM_StudentConn_STRING
  MM_editTable = "TestName"
  MM_editColumn = "id"
  MM_recordId = "" + Request.Form("MM_recordId") + ""
  MM_editRedirectUrl = "TestManage.asp"
  MM_fieldsStr  = "TestName|value"
  MM_columnsStr = "TestName|',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

  ' 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
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  ' create the sql update statement
  MM_editQuery = "update " & MM_editTable & " set "
  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_editQuery = MM_editQuery & ","
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
  Next
  MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the update
    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
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"

set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_StudentConn_STRING
if (Request.QueryString("id") <> "") then
  Recordset1__MMColParam = Request.QueryString("id")
  Recordset1.Source = "SELECT * FROM TestName WHERE ID = " + Replace(Recordset1__MMColParam, "'", "''") + ""
elseif (Request.QueryString("SheetName") <> "") then
  strSheetName = Request.QueryString("SheetName")
  Recordset1__MMColParam = Request.QueryString("SheetName")
  Recordset1.Source = "SELECT * FROM TestName WHERE SheetName = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
end if

Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
set Recordset2 = Server.CreateObject("ADODB.Recordset")
Recordset2.ActiveConnection = MM_StudentConn_STRING
Recordset2.Source = "SELECT * FROM Subject"
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 3
Recordset2.Open()
Recordset2_numRows = 0
%>
<%
Dim rsSubject
Dim rsSubject_numRows

Set rsSubject = Server.CreateObject("ADODB.Recordset")
rsSubject.ActiveConnection = MM_StudentConn_STRING
rsSubject.Source = "SELECT * FROM " & Recordset1.Fields.Item("SheetName").Value
rsSubject.CursorType = 0
rsSubject.CursorLocation = 2
rsSubject.LockType = 1
rsSubject.Open()

rsSubject_numRows = 0
strSubject=""
For i = 5 to rsSubject.Fields.Count - 1 
	strSubject=strSubject & rsSubject.Fields(i).Name & ","
next
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>考试管理&gt;&gt;考试信息修改</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(){
if(document.form1.TestName.value=="")
  {
   alert("考试名称不能为空!");
   document.form1.TestName.focus();
   return false;
   }

}
function ConfirmDel()
{
   if(confirm("确定要删除考试科目吗?一旦考试科目被删除,其中的成绩也将同时被删除!"))
     return true;
   else
     return false;
}
</script>
</HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0>
<!--#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">&nbsp;</TD>
      <td width="10" bgcolor="#F2FBF2"></td>
      <TD bgcolor="#F2FBF2"><a href="TestManage.asp"><img src="images/TestManage_Title.GIF" width="500" height="60" border="0"></a><br>
        <% If Not Recordset1.EOF Or Not Recordset1.BOF Then %>
        <% if Request.QueryString("SheetName")<>"" then response.write "<br><br>错误!已经存在此考试!请在此修改考试信息!<br><br>" end if %>
        <form onsubmit="return checktest()" ACTION="<%=MM_editAction%>" METHOD="POST" Name="form1">
          <font color="#FF0000"><b>修改考试名称:</b></font> 
          <table width="300" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td height="25" align="right">考试名称: </td>
              <td height="25"> <input Name="TestName" type="text" value="<%=(Recordset1.Fields.Item("TestName").Value)%>" size="30"> 
              </td>
            </tr>
            <tr> 
              <td height="25" align="right">数据库对应的表名:</td>
              <td height="25"> <%=(Recordset1.Fields.Item("SheetName").Value)%></td>
            </tr>
            <tr align="center"> 
              <td height="25" colspan="2"> <input type="hidden" name="MM_update" value="true"> 
                <input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("id").Value %>"> 
                <input type="submit" Name="Submit" value="保存修改结果"> </td>
            </tr>
          </table>
        </form>
        ============================================================== 
        <form name="form2" method="post" action="<%=MM_editAction%>">
          <font color="#FF0000"><b>添加考试科目:</b></font> 
          <select name="Subject">
            <%
i=0
While (NOT Recordset2.EOF)
	strTemp=Recordset2.Fields.Item("SubjectName").Value
	if instr(strSubject,strTemp)<=0 then
%>
            <option value="<%=(Recordset2.Fields.Item("SubjectName").Value)%>" ><%=(Recordset2.Fields.Item("SubjectName").Value)%></option>
            <%
		i=i+1
	end if
  	Recordset2.MoveNext()
Wend
If (Recordset2.CursorType > 0) Then
  Recordset2.MoveFirst
Else
  Recordset2.Requery
End If
if i=0 then
	response.write "<option value=''>全部科目都已添加到考试中</option>"
end if
%>
          </select>
          <% if i>0 then
			response.write "<input type='submit' name='Submit2' value='添加'>"
		end if
		%>
          <input type='hidden' name='AppendField' value='true'>
          <input name="SheetName" type="hidden" id="SheetName2" value="<%=(Recordset1.Fields.Item("SheetName").Value)%>">
        </form>
        ============================================================= 
        <form name="form3" onSubmit="return ConfirmDel()" method="post" action="<%=MM_editAction%>">
          <b><font color="#FF0000">删除已有的考试科目:</font></b> 
          <select name="Subject">
            <%
For i = 5 to rsSubject.Fields.Count - 1 
	Response.write  "<option value=" & rsSubject.Fields(i).Name & "' selected>" & rsSubject.Fields(i).Name & "</option>"
next
%>
          </select>
          <% if i>5 then
			response.write "<input type='submit' name='Submit3' value='删除'>"
		end if
		%>
          <input type='hidden' name='DeleteField' value='true'>
          <input name="SheetName" type="hidden" id="SheetName2" value="<%=(Recordset1.Fields.Item("SheetName").Value)%>">
        </form>
        <% End If ' end Not Recordset1.EOF Or NOT Recordset1.BOF %>
        <% If Recordset1.EOF And Recordset1.BOF Then %>
        <p align="center"><br>
          <br>
          找不到任何考试,请添加考试!<br>
          <br>
        </p>
        <% End If ' end Recordset1.EOF And Recordset1.BOF %>
        <p align="right"><a href="TestManage.asp">【返回考试管理主界面】</a></p><br>
          </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()
%>
<%
Recordset2.Close()
%>
<%
rsSubject.Close()
Set rsSubject = Nothing
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -