📄 testmodify.asp
字号:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="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>月库管理>>月库信息修改</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=#f7f7ff leftMargin=0 topMargin=0>
<!--#include file="TestManage_Top.asp"-->
<TABLE width="760" border=0 align="center" cellPadding=0 cellSpacing=0>
<TR>
<TD align="center" bgcolor="#F7f7ff">
<% 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">
<span class="title">修改月库</span>
<table width="300" border="1"align="center" cellpadding="2" cellspacing="0" bordercolor="#CCCCFF" style="border-collapse:collapse">
<tr>
<td height="25" align="right" class="littletitle">月库名称: </td>
<td height="25">
<input Name="TestName" type="text" value="<%=(Recordset1.Fields.Item("TestName").Value)%>" size="25">
</td>
</tr>
<tr>
<td height="25" align="right" class="littletitle">数据库表名:</td>
<td height="25" align="left"> <%=(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="center"><a href="TestManage.asp">【返回月库管理主界面】</a></p>
<br>
</td>
</TR>
</TABLE>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<Iframe src="CopyRight.asp" width="760" height="100" 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 + -