<%@ Language=VBScript %>
<% option explicit %>
<!--#include file="conn.asp"-->
<!--#include file="Checkadmin.asp"-->
<% 
dim isedit '是否在编辑状态
dim id,subjectname'定义变量，科目的id
dim sql,rs,rsc
isedit=false
if request("action")="edit" then
    isedit=true
end if
if request("action")="modify" then   '修改考试科目
 if not IsNumeric(request("testtime")) or not IsNumeric(request("multinumber")) or not IsNumeric(request("multiper")) or not IsNumeric(request("singlenumber"))or not IsNumeric(request("singleper")) then
	    response.write "错误!输入项不能为空，且必须为数字! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
        response.end
    end if
    set rs=server.createobject("ADODB.recordset")
	subjectname=request("subjectname")
         rs.open "select * from subject where subjectname='"&subjectname&"'",conn,1,3
             rs("testtime")=clng(request("testtime"))
             rs("singlenumber")=clng(request("singlenumber"))
             rs("singleper")=clng(request("singleper"))
             rs("multinumber")=clng(request("multinumber"))
             rs("multiper")=clng(request("multiper"))
			 rs.update
			 rs.close
			 set rs=nothing
end if
%>
<%
if request("action")="add" then   '添加考试科目
    if trim(request("subjectname"))="" or not IsNumeric(request("testtime")) or not IsNumeric(request("multinumber")) or not IsNumeric(request("multiper")) or not IsNumeric(request("singlenumber"))or not IsNumeric(request("singleper")) then
	    response.write "错误!科目名以及其余各项不能为空，除科目名以外的项必须为数字! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
        response.end
    end if
	set rs=server.createobject("adodb.recordset")   '检查科目名是否重名
    rs.open "select * from subject where subjectname='" & cstr(trim(request("subjectname"))) & "'",conn,1,1
    if err.number <> 0 then
	          response.write "数据库出错"
    else  if not rs.bof and not rs.eof then
	          response.write "错误!该科目已经存在! <a href=# onclick='javascript:window.history.go(-1)'>返回</a>"
              response.end
          end if
    end if
	rs.close
	set rs=nothing
	sql="insert into subject(subjectname,testtime,singlenumber,singleper,multinumber,multiper) values('" & cstr(trim(request("subjectname"))) & "','" & cstr(trim(request("testtime"))) & "','" & cstr(trim(request("singlenumber"))) & "','" & cstr(trim(request("singleper"))) & "','" & cstr(trim(request("multinumber"))) & "','" & cstr(trim(request("multiper"))) & "')"
	conn.execute sql
	if err.number <> 0 then
	    response.write "数据库操作出错:" + err.description
	else %>
	    <script language=vbscript>
			msgbox "操作成功!新科目<%=trim(request("subjectname"))%>的信息添加成功!"
		</script>
  <%end if
end if
if request("action")="del" then   '删除科目
	sql="delete from subject where id=" &request("id")
	conn.execute sql
	if err.number <> 0 then
		response.write "数据库操作错误：" + err.description
		err.clear
	else %>
        <script language=vbscript>
		msgbox "操作成功!科目号为<%=trim(request("id"))%>的信息已删除!"
		</script>
<%  end if
end if
%>
<html>
<head>
<title>管理科目</title>
<script language="JavaScript">
function SureDel(id)
{
    if ( confirm("您确定要删除该科目吗？"))
        {
            window.location.href = "mgsubject.asp?action=del&id=" +id
        }
}
</script>
</head>
<body background=../images/backimage.gif > 
<table width="80%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor=blue>
  <tr> 
    <td width="20%"> 
      <div align="center">科目名称</div>
    </td>
    <td width="15%"> 
      <div align="center">考试时间(分钟)</div>
    </td>
    <td width="10%"> 
      <div align="center">单选题量</div>
    </td>
    <td width="10%"> 
      <div align="center">单选分值</div>
    </td>
    <td width="10%"> 
      <div align="center">多选题量</div>
    </td>
    <td width="10%"> 
      <div align="center">多选分值</div>
    </td>
    <td width="25%"> 
      <div align="center">操作</div>
    </td>
  </tr>
  <%
  set rs=server.createobject("adodb.recordset")
  rs.open "select * from subject ",conn,1,1
  if err.number <> 0 then
	           response.write "数据库出错"
           else
	           if rs.bof and rs.eof then
		           rs.close
		           response.write "目前没有科目"
	           else
			       do while not rs.eof %>
  <tr> 
    <td width="20%" height="21" > 
      <div align="center"><a href="mgquestion.asp?subjectname=<%=rs("subjectname")%>" onMouseOver="window.status='<%=rs("subjectname") %>';return true;" onMouseOut="window.status='';return true;"><%=rs("subjectname")%></a></div>
    </td>
    <td width="15%" height="21" > 
      <div align="center"><%=rs("testtime")%></div>
    </td>
    <td width="10%" height="21" > 
      <div align="center"><%=rs("singlenumber")%></div>
    </td>
    <td width="10%" height="21" > 
      <div align="center"><%=rs("singleper")%></div>
    </td>
    <td width="10%" height="21" > 
      <div align="center"><%=rs("multinumber")%></div>
    </td>
    <td width="10%" height="21" > 
      <div align="center"><%=rs("multiper")%></div>
    </td>
    <td width="25%" height="21" >
      <div align="center"><a href='mgsubject.asp?subjectname=<%=trim(rs("subjectname"))%>&action=edit'>编辑</a>&nbsp&nbsp<a href='javascript:SureDel(<%=rs("id") %>)'>删除</a>&nbsp&nbsp<a href="mgquestion.asp?subjectname=<%=rs("subjectname")%>" onMouseOver="window.status='<%=rs("subjectname") %>';return true;" onMouseOut="window.status='';return true;">考题管理</a></div></td>
  </tr>
  <% rs.movenext				   
	loop			   
	end if	       
       end if
 %>
</table>
<%  if isedit then
	   set rs=server.createobject("adodb.recordset")
	   subjectname=request("subjectname")
	   rs.open "select * from subject where subjectname='"&subjectname&"'",conn,1,1
	   response.write "<p align='center'><font size=3>编 辑 考 试 科 目</font></p>"
   else
	   response.write "<p align='center'><font size=3>添 加 考 试 科 目</font></p>"
   end if %>
 <p align="center">  
    <form action="mgsubject.asp" method="post">
	    <input type="Hidden" name="action" value='<% If isedit then%>modify<% Else  %>add<% End If %>'>
		<%If isedit then%>
              <input type="Hidden" name="subjectname" value='<%=subjectname%>'>
        <%End If%>
        科目名称:
<% if isedit then
response.write request("subjectname")
else
%>
<input type="text" name="subjectname" class=input maxlength=14 size="16">
		<%end if%>
		<br>
	    考试时间:<input type="text" name="testtime"  class=input maxlength=14 size="16" value='<% if isedit then
                 response.write trim(rs("testtime")) 
                 end if %>'><br>
	    单选题量:<input type="text" name="singlenumber"  class=input maxlength=14 size="16" value='<% if isedit then
                 response.write trim(rs("singlenumber")) 
                 end if %>'><br>
	    单选分值:<input type="text" name="singleper"  class=input maxlength=14 size="16" value='<% if isedit then
                 response.write trim(rs("singleper")) 
                 end if %>'><br>
	    多选题量:<input type="text" name="multinumber"  class=input maxlength=14 size="16" value='<% if isedit then
                 response.write trim(rs("multinumber")) 
                 end if %>'><br>
	    多选分值:<input type="text" name="multiper"  class=input maxlength=14 size="16" value='<% if isedit then
                 response.write trim(rs("multiper")) 
                 end if %>'><br>
	            <input type=submit value="确 定" class=button>
     </form>
     <p align=center><a href="primarypage.asp"><font color=red size=+0 face=楷体>返回管理界面</font></a></p>
<%
rs.close
set rs=nothing 
%>
</body>
</html>