<%@language=vbscript codepage=936 %>
<!--#include file="Conn.asp"-->
<!--#include file ="Check_Manager.asp"-->
<!--#include file="Product_Sub.asp"-->
<script language="JavaScript" type="text/JavaScript">
function checkBig()
{
  if (document.form1.BigClassName.value=="")
  {
    alert("大类名称不能为空！");
    document.form1.BigClassName.focus();
    return false;
  }
}
</script>
<script language="JavaScript" type="text/JavaScript">
function checkSmall()
{
  if (document.form1.SmallClassName.value=="")
  {
    alert("小类名称不能为空！");
    document.form1.SmallClassName.focus();
    return false;
  }
}
</script>
<html>
<head>
<titel></titel>
<LINK href="admin/admin.css" type=text/css rel=stylesheet>
</head>
<body>
<%
If Request.QueryString("add")="bigclass" Then
Call AddBigClass
  If Request.Form("Add")=" 添 加 " Then
  BigClassName=Trim(Request("BigClassName"))
   If BigClassName="" Then
   FoundErr=True
        Response.write "<script language='javascript'>" & chr(13)
		Response.write "alert('产品大类名不能为空!');" & Chr(13)
		Response.write "window.document.location.href='Product_ClassManage.asp';"&Chr(13)
		Response.write "</script>" & Chr(13)
        Response.End 
   End if
     If FoundErr<>True then
     Set rs=Server.CreateObject("Adodb.RecordSet")
     rs.Open "Select * From [BigClassProduct] Where Product_BigClass='" & BigClassName & "'",Conn,1,3
        If not (rs.bof and rs.EOF) then
	FoundErr=True
	Response.Write  "<br><li>产品大类“" & BigClassName & "”已经存在！</li>"
        Else
    	rs.addnew
     	rs("Product_BigClass")=BigClassName
    	rs.Update
     	rs.Close
	set rs=Nothing
        JaSys("管理员" & session("ManagerUser") & "<font color=red>添加产品大类["&BigClassName&"]</font>成功")
    	Response.Redirect "Product_ClassManage.asp"  
	End if
     End if
  End if
End if

If Request.QueryString("add")="smallclass" Then
Call AddSmallClass
   If Request.Form("AddS")=" 添 加 " Then
   SmallClassName=Trim(Request("SmallClassName"))
   BigClass=Trim(Request("selectd"))
   If SmallClassName="" or BigClass="0" Then
   FoundErrS=True
        Response.write "<script language='javascript'>" & chr(13)
		Response.write "alert('产品小类名不能为空!');" & Chr(13)
		Response.write "window.document.location.href='Product_ClassManage.asp';"&Chr(13)
		Response.write "</script>" & Chr(13)
        Response.End 
   End if
     If FoundErrS<>True then
     Set rss=Server.CreateObject("Adodb.RecordSet")
     rss.Open "Select * From [SmallClassProduct] Where Product_BigClassName='" & SmallClassName & "'",Conn,1,3
        If not (rss.bof and rss.EOF) then
	FoundErrS=True
	Response.Write  "<center><br><li>文章小类“" & SmallClassName & "”已经存在！</li></center>"
        Else
    	rss.addnew
        rss("Product_BigClassName")=BigClass
     	rss("Product_SmallClassName")=SmallClassName
    	rss.Update
     	rss.Close
	set rss=Nothing
        JaSys("管理员" & session("ManagerUser") & "<font color=red>添加产品小类["&SmallClassName&"]</font>成功")
    	Response.Redirect "Product_ClassManage.asp"  
	End if
     End if
  End if   
End if

If Request.QueryString("action")="upbig" Then
Call EditBigClass
  If Request.Form("UpdateB")=" 修 改 " Then
  BigClassName=Trim(Request("BigClassName"))
   If BigClassName="" Then
   FoundErr=True
   Response.Write "<br><li>产品大类名不能为空！</li>"
   End if
     If FoundErr<>True then
     Set rs=Server.CreateObject("Adodb.RecordSet")
     rs.Open "Select * From [BigClassProduct] Where Product_BigClass='" & BigClassName & "'",Conn,1,1
        If not (rs.bof and rs.EOF) then
	FoundErr=True
	Response.Write  "<br><li>产品大类“" & BigClassName & "”已经存在！</li>"
        Else
        Set bb = Conn.Execute("Select * From [BigClassProduct] Where Product_ID= " &Cint(Request("bigid")))
        big = bb("Product_BigClass")
        Sql = "Update [SmallClassProduct] Set Product_BigClassName='"&BigClassName&"' Where Product_BigClassName='"&big&"'"
        Conn.Execute (Sql)
        Sql1 = "Update [Product] Set BigClassP='"&BigClassName&"' Where BigClassP='"&big&"'"
        Conn.Execute (Sql1)
        Sql2 = "Update [BigClassProduct] Set Product_BigClass='"&BigClassName&"' Where Product_ID="&Cint(Request("bigid"))
        Conn.Execute (Sql2)
        JaSys("管理员" & session("ManagerUser") & "<font color=red>修改产品大类["&BigClassName&"]</font>成功")
    	Response.Redirect "Product_ClassManage.asp"  
	End if
     End if
  End if
End if

If Request.QueryString("action")="upsmall" Then
Call EditSmallClass
  If Request.Form("Update")=" 修 改 " Then
  SmallClassName=Trim(Request("SmallClassName"))
   If SmallClassName="" Then
   FoundErr=True
   Response.Write "<br><li>产品小类名不能为空！</li>"
   End if
     If FoundErr<>True then
     Set rs=Server.CreateObject("Adodb.RecordSet")
     rs.Open "Select * From [SmallClassProduct] Where Product_SmallClassName='" & SmallClassName & "'",Conn,1,1
        If not (rs.bof and rs.EOF) then
	FoundErr=True
	Response.Write  "<br><li>产品小类“" & SmallClassName & "”已经存在！</li>"
        Else
        Set ss = Conn.Execute("Select * From [SmallClassProduct] Where Product_SmallID=" &Cint(Request("smallid")))
        small = ss("Product_SmallClassName")
        Sql = "Update [Product] Set SmallClassP='"&SmallClassName&"' Where SmallClassP='"&small&"'"
        Conn.Execute (Sql)
        Sql1 = "Update [SmallClassProduct] Set Product_SmallClassName='"&SmallClassName&"' Where Product_SmallID="&Cint(Request("smallid"))
        Conn.Execute (Sql1)
        JaSys("管理员" & session("ManagerUser") & "<font color=red>修改产品小类["&SmallClassName&"]</font>成功")
    	Response.Redirect "Product_ClassManage.asp"  
	End if
     End if
  End if
End if

If Request.QueryString("action")="delbig" Then
Set sss = Conn.Execute("Select * From [BigClassProduct] Where Product_ID="&Cint(Request("bigid")))
bbb = sss("Product_BigClass")
Set bs = Conn.Execute("Delete * From [SmallClassProduct] Where Product_BigClassName='"&bbb&"'")
Set nn = Conn.Execute("Delete * From [Product] Where BigClassP='"&bbb&"'")
Set bg = Conn.Execute("Delete * From [BigClassProduct] Where Product_ID="&Cint(Request("bigid")))
JaSys("管理员" & session("ManagerUser") & "<font color=red>删除产品大类["&bbb&"]</font>成功")
Response.Redirect "Product_ClassManage.asp"
End if
If Request.QueryString("action")="delsmall" Then
Set sss = Conn.Execute("Select * From [SmallClassProduct] Where Product_SmallID="&Cint(Request("smallid")))
bbb = sss("Product_SmallClassName")
Set nn = Conn.Execute("Delete * From [Product] Where SmallClassP='"&bbb&"'")
Set bs = Conn.Execute("Delete * From [SmallClassProduct] Where Product_SmallID="&Cint(Request("smallid")))
JaSys("管理员" & session("ManagerUser") & "<font color=red>删除产品小类["&bbb&"]</font>成功")
Response.Redirect "Product_ClassManage.asp"  
End if
%>
</body>
</html>