<!--#include file="../Inc/Conn.asp"-->
<%
If Request.Cookies("UserName")="" Then
	Response.Write("<script language='javascript'>this.parent.location='login.asp';self.close();</script>")
End If
'二次验证与权限判断
Set rs=Conn.Execute("Select * From [AdminUser] Where [UserName]='"&Request.Cookies("UserName")&"'")
If rs.eof And rs.bof Then
    Response.Write("<script language='javascript'>this.parent.location='login.asp';self.close();</script>")
End If
If rs("Support")=False Then
    Response.Write("对不起，您无权限管理该区域！")
    Response.End()
End If
rs.Close
Set rs=Nothing
'变量赋值
ClassId=ReStr(Request.QueryString("ClassId"))
Action=Request.QueryString("Action")
'新增分类
If Request.Form("B1")<>"" Then
    If Request.Form("ClassName")="" Then
        Msg "分类名称不能为空！","?Action=AddNew"
    End If
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support-Class]"
    rs.Open Sql,Conn,1,3
    rs.AddNew
    rs("ClassName")=Request.Form("ClassName")
    rs("ClassSort")=Request.Form("ClassSort")
    rs.Update
        Msg "恭喜，新增分类成功！","?"
End If
'修改分类
If Request.Form("B2")<>"" Then
    If Request.Form("ClassName")="" Then
        Msg "分类名称不能为空！","?Action=AddNew"
    End If
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support-Class] Where [ClassId]="&ClassId
    rs.Open Sql,Conn,1,3
    rs("ClassName")=Request.Form("ClassName")
    rs("ClassSort")=Request.Form("ClassSort")
    rs.Update
        Msg "恭喜，更新成功！","?"
End If
'删除分类
If Action="Del" Then
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select Count (*) As num From [Support-Class]"
    rs.Open Sql,Conn,1,1
    If rs("num")=1 Then
        Msg "无法删除，原因：至少保留一个分类！","?"
    End If
    Conn.Execute("Delete From [Support-Class] Where [ClassId]="&ClassId)
        Msg "恭喜，删除成功！","?"
End If
If Request.QueryString("Action")="Close" Then
    Conn.Execute("Delete From [Support] Where [ClassId]="&ClassId&"")
    Msg "操作成功，本分类下的工单已经被清空！","?"
End If 
%>
<!Doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="Content-Language" content="zh-CN" />
    <meta name="author" content="神仙醋°" />
    <meta name="copyright" content="新空网络工作室" />
    <link rel="stylesheet" type="text/css" href="Images/Style.css" />
    <title>Page</title>
</head>

<body>
<%
Select Case Action
    Case "AddNew"
'-----新建分类-----
%>
<div class="Title">
    <a href="?">工单类型</a><span>新建类型</span>
</div>
<div class="TableInput">
    <form method="post" action="">
    <table>
        <tr>
            <td style="width:80px;text-align:right;">分类名称：</td>
            <td><input style="width:200px;" class="Input" type="text" name="ClassName" /></td>
        </tr>
        <tr>
            <td style="text-align:right;">分类排序：</td>
            <td><input style="width:80px;" class="Input" type="text" name="ClassSort" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input class="btn" type="submit" name="B1" value="保存" /></td>
        </tr>
    </table>
    </form>
</div>
<%
    Case "Edit"
'-----修改分类-----
%>
<div class="Title">
    <a href="?">工单类型</a><a href="?Action=AddNew">新建类型</a><span>修改类型</span>
</div>
<div class="TableInput">
    <%
    Set rs=Conn.Execute("Select * From [Support-Class] Where [ClassId]="&ClassId)
    %>
    <form method="post" action="">
    <table>
        <tr>
            <td style="width:80px;text-align:right;">分类名称：</td>
            <td><input style="width:200px;" class="Input" type="text" name="ClassName" value="<%=rs("ClassName")%>" /></td>
        </tr>
        <tr>
            <td style="text-align:right;">分类排序：</td>
            <td><input style="width:200px;" class="Input" type="text" name="ClassSort" value="<%=rs("ClassSort")%>" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input class="btn" type="submit" name="B2" value="更新" /></td>
        </tr>
    </table>
    </form>
</div>
<%
    Case Else
'-----显示列表-----
%>
<div class="Title">
    <span>工单类型</span><a href="?Action=AddNew">新建类型</a>
</div>
<div class="Table">
    <%
    Set rs=Conn.Execute("Select * From [Support-Class] Order by [ClassSort] Asc")
    %>
    <table>
        <tr>
            <th>排 序</th>
            <th>名 称</th>
            <th>工单数</th>
            <th style="width:20%;"></th>
        </tr>
    <%
    Do While Not rs.eof
    %>
        <tr style="text-align:center;">
            <td><%=rs("ClassSort")%></td>
            <td><a href="Support.asp?ClassId=<%=rs("ClassId")%>"><%=rs("ClassName")%></a></td>
            <td>
                <%
                Set N=Conn.Execute("Select Count (*) As num From [Support] Where [ClassId]="&rs("ClassId")&"")
                Response.Write(""&N("num")&"")
                N.Close
                Set N=Nothing
                %>
            </td>
            <td class="link"><a href="?Action=Edit&ClassId=<%=rs("ClassId")%>">修改</a> <a href="?Action=Del&ClassId=<%=rs("ClassId")%>" onclick="return confirm('确定删除这个分类吗？');">删除</a> <a href="?Action=Close&ClassId=<%=rs("ClassId")%>" onclick="return confirm('注意，此操作会清空本分类下的全部工单！');">清空</a></td>
        </tr>
    <%
    rs.MoveNext
    Loop
    rs.Close
    Set rs=Nothing
    %>
    </table>
</div>
<%
End Select
%>
</body>
</html>
