<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/function.asp"-->
<%
Response.Buffer = True 
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(13)
dim act
opendb
act=Trim(Request.QueryString("act"))
if act="add" then
  call add()
elseif act="modify" then
  call modify()
elseif act="beforedel" then
  call beforedel()
elseif act="del" then
  call del()
else
  call main()
end if
closedb

sub del()
dim rs,num
num=Trim(Request.Form("grade"))
if num<>"" then
set rs=conn.execute("delete from "&predb&"score where grade in("&num&")")
set rs=nothing
end if
Response.Write("<script>history.go(-2)</script>")
end sub

sub modify()
  dim rs,sql
  On Error Resume Next
  set rs= Server.CreateObject("adodb.recordset")
  sql="select * from "&predb&"score"
  rs.open sql,conn,1,3
  do while not rs.eof
     rs("fscore")=Trim(Request.Form("fscore"&rs("grade")))
	 rs("tscore")=Trim(Request.Form("tscore"&rs("grade")))
	 rs("grade")=Trim(Request.Form("grade"&rs("grade")))
  rs.update
    if err then
	   Call SendMsg("请检查你添加的内容：不可空值、不可与其他重复！")
	   Response.End()
       exit do
    end if
  rs.movenext
  loop
  rs.close
  set rs=nothing
  Response.Write("<script>history.go(-1)</script>")
end sub

sub add()
  dim rs
  On Error Resume Next
  set rs=conn.execute("insert into "&predb&"score(fscore,tscore,grade) values("&Trim(Request.Form("fscore"))&","&Trim(Request.Form("tscore"))&","&Trim(Request.Form("grade"))&")")
  set rs=nothing
  if err then
  Call SendMsg("请检查你添加的内容：不可空值、不可与其他重复！")
  Response.End()
  else
   Call SendMsg("添加等级成功，请设置对应权限和方案")
   Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
  end if
end sub

sub beforedel()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
<tr>
		<th height="25" align="left">删除确认</th>
	</tr>
  <form action="?act=del" method="post">
  <tr>
    <td class="TableRow2">需删除的对应等级：
    <input name="grade" type="text" id="grade" value="<%=Trim(Request.Form("select"))%>" size="38"></td>
  </tr>
  <tr>
    <td class=tablerow1><font color="red">注意：删除后将无法恢复，请确定无误后再进行删除操作，强烈建议操作前请备份数据库。</font></td>
  </tr>
  <tr>
    <td align="center" class=tablerow1><input type="button" name="button4" id="button4" onClick="history.go(-1)" value="返回上一页">
      &nbsp;&nbsp; 
      <input type="submit" name="button5" id="button5" value="批量删除"></td>
  </tr>
  </form>
</table>
<%
end sub

sub main()
 %>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
<tr>
		<th height="25" colspan="3" align="left">等级分值设置</th>
	</tr>
  <tr>
    <td align="center" class="TableRow1"><strong>起始分值</strong></td>
    <td align="center" class="TableRow1"><strong>结束分值</strong></td>
    <td align="center" class="TableRow1"><strong>对应等级</strong></td>
  </tr>
  <form action="?act=modify" method="post">
<%
dim rs,sql,i,n
set rs= Server.CreateObject("adodb.recordset")
sql="select * from "&predb&"Score order by grade asc"
rs.open sql,conn,1,1
do while not rs.eof
i=i+1
if i mod 2=0 then 
   n=1
else
   n=2
end if
%>
  <tr>
    <td align="center" class="TableRow<%= n %>"><input name="select" type="checkbox" id="select" value="<%=rs("grade")%>">
      <input name="fscore<%= rs("grade") %>" type="text" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<%= rs("fscore") %>" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
    <td align="center" class="TableRow<%= n %>"><input name="tscore<%= rs("grade") %>" type="text" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<%= rs("tscore") %>" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
    <td align="center" class="TableRow<%= n %>"><input name="Grade<%= rs("grade") %>" type="text" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<%= rs("Grade") %>" onafterpaste="this.value=this.value.replace(/\D/g,'')" readonly></td>
  </tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
  <tr>
    <td colspan="3" align="center" class="TableRow1"><input type="submit" name="button" id="button" value=" 修 改 ">
     &nbsp; &nbsp; <input type="submit" name="button3" id="button3" value="删除所选" onClick="this.form.action='?act=beforedel'"></td>
  </tr>
</form>
  <tr>
    <td colspan="3" class="TableRow2"><font color="#008800">添加等级&nbsp; </font></td>
  </tr>
  <form action="?act=add" method="post">
  <tr>
    <td align="center" class="TableRow1">
      <input name="fscore" type="text" id="fscore" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
    </td>
    <td align="center" class="TableRow1">
      <input name="tscore" type="text" id="tscore" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
    </td>
    <%
	dim maxgrade
	set rs= conn.execute("select max(grade) from "&predb&"score")
	maxgrade=rs(0)+1
	set rs=nothing
	if IsNumeric(maxgrade)=false then maxgrade=1
	%>
    <td align="center" class="TableRow1">
      <input name="Grade" type="text" id="Grade" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<%= maxgrade %>" onafterpaste="this.value=this.value.replace(/\D/g,'')">
    </td>
  </tr>
  <tr>
    <td colspan="3" align="center" class="TableRow2"><input type="submit" name="button2" id="button2" value=" 添 加  "></td>
  </tr>
  </form>
</table>
<% end sub %>
<br>
</body>
</html>
