<script language="JavaScript">
<!--
function  check1() {
  if (form1.new_type_name.value=="") {
		alert("请填写类别名称！");
		form1.new_type_name.focus();		
		    return (false);
  }
 else
	document.form1.submit();
}
function  check2() {
  if (form2.new_type_son_name.value=="") {
		alert("请填写二级类别名称！");
		form2.new_type_son_name.focus();		
		    return (false);
  }
  if (form2.new_type_id.value=="") {
		alert("请选择所属类别！");
		form2.new_type_id.focus();		
		    return (false);
  }
 else
	document.form2.submit();
}
function  check3() {
  if (form3.new_brand_name.value=="") {
		alert("请填写类型名称！");
		form3.new_brand_name.focus();		
		    return (false);
  }
  if (form3.new_type_id.value=="") {
		alert("请选择所属类别！");
		form3.new_type_id.focus();		
		    return (false);
  }
  if (form3.new_type_son_id.value=="") {
		alert("请选择所属二级类别！");
		form3.new_type_son_id.focus();		
		    return (false);
  }
 else
	document.form3.submit();
}
// -->
</script>
<!-- #include file="conn.asp" -->
<!-- #include file="cookies.asp" -->
<%
'-----------------------------------------------------------------
dim action
action=request.form("action")
select case action
case "add_type"
call add_type
case "add_type_son"
call add_type_son
case "add_brand"
call add_brand
end select
'----------------------------------------------------------------
'增加一个分类
sub add_type()
new_type_name=Trim(Request.Form("new_type_name"))
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from type where type_name='"&new_type_name&"'"
rs.open sql,conn,1,3
if not rs.eof then
response.write"<SCRIPT language=JavaScript>alert('类别名重复，请重新填写！');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
else
rs.addnew
rs("type_name")=new_type_name
rs.update
end if
rs.close
set rs=nothing
response.redirect "addok.asp"
response.end
end sub
'----------------------------------------------------------------
'增加一个二级分类
sub add_type_son()
new_type_son_name=Trim(Request.Form("new_type_son_name"))
new_type_id=Trim(Request.Form("new_type_id"))
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from type_son where type_son_name='"&type_son_name&"' and type_id=" & new_type_id
rs.open sql,conn,1,3
if not rs.eof then
response.write"<SCRIPT language=JavaScript>alert('该类别下已存在这个二级类别，请重新填写！');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
else
rs.addnew
rs("type_son_name")=new_type_son_name
rs("type_id")=new_type_id
rs.update
end if
rs.close
set rs=nothing
response.redirect "addok.asp"
response.end
end sub
'----------------------------------------------------------------
'增加一个类型
sub add_brand()
new_brand_name=Trim(Request.Form("new_brand_name"))
new_type_son_id=Trim(Request.Form("new_type_son_id"))
new_type_id=Trim(Request.Form("new_type_id"))
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from brand where brand_name='"&new_brand_name&"' and type_son_id=" & new_type_son_id
rs.open sql,conn,1,3
if not rs.eof then
response.write"<SCRIPT language=JavaScript>alert('该类别下已存在这个二级类别，请重新填写！');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
else
rs.addnew
rs("brand_name")=new_brand_name
rs("type_son_id")=new_type_son_id
rs("type_id")=new_type_id
rs.update
end if
rs.close
set rs=nothing
response.redirect "addok.asp"
response.end
end sub
'----------------------------------------------------------------


Dim rst
			set rst=server.createobject("adodb.recordset")
		    sqlt="select * from type"
			rst.open sqlt,conn,1,1

Dim rsts
			set rsts=server.createobject("adodb.recordset")
		    sqlts="select * from type_son inner join type on type_son.type_id=type.type_id  ORDER BY type_son_id"
			rsts.open sqlts,conn,1,1

dim mm_jsmenu
dim i 
i = -1
mm_jsmenu = "<script language="&chr(34)&"javascript"&chr(34)&">"&chr(13)
mm_jsmenu = mm_jsmenu&"<!--"&chr(13)
mm_jsmenu = mm_jsmenu&"var subcat = new Array();"&chr(13)
do while not rsts.eof
i = i + 1
mm_jsmenu = mm_jsmenu&"subcat["&i&"] = new Array('"&(rsts.Fields.Item("type_id").Value)&"','"&(rsts.Fields.Item("type_son_name").Value)&"','"&(rsts.Fields.Item("type_son_id").Value)&"')"&chr(13)
rsts.movenext
loop
mm_jsmenu = mm_jsmenu&chr(13)&"function changeselect1(locationid)"&chr(13)
mm_jsmenu = mm_jsmenu&"{"&chr(13)
mm_jsmenu = mm_jsmenu&"document.form3.new_type_son_id.length = 0; "&chr(13)
mm_jsmenu = mm_jsmenu&"document.form3.new_type_son_id.options[0] = new Option('请选择','');"&chr(13) 
mm_jsmenu = mm_jsmenu&"for (i=0; i<subcat.length; i++) "&chr(13)
mm_jsmenu = mm_jsmenu&"{"&chr(13)
mm_jsmenu = mm_jsmenu&"if (subcat[i][0] == locationid) "&chr(13)
mm_jsmenu = mm_jsmenu&"{document.form3.new_type_son_id.options[document.form3.new_type_son_id.length] = new Option(subcat[i][1], subcat[i][2]);} "&chr(13) 
mm_jsmenu = mm_jsmenu&"}"&chr(13)
mm_jsmenu = mm_jsmenu&"}"&chr(13)
mm_jsmenu = mm_jsmenu&"//-->"&chr(13)&"</script>"&chr(13)
response.Write mm_jsmenu
%>
<html>
<head>
<title>管理分类</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#000000" background="blue.gif">
<div align="center">
  <table width="96%"  border="0" cellpadding="10" cellspacing="1" bgcolor="#000066">
    <form name="form1" method="post" action=""><tr bgcolor="#FFCC33">
      <td>&nbsp;&nbsp;添加一个新的<strong>分类</strong></td>
    </tr>
    <tr bgcolor="#FDFEF5">
      <td bgcolor="#FDFEF5">
        <input name="new_type_name" type="text" value="<%=request.form("new_type_name")%>">
        <input type="button" name="Submit" onClick="check1()" value="添加">
		<input type="hidden" name="action" value="add_type">
      </td>
    </tr></form>
  </table>
  <p>&nbsp;</p>
  <table width="96%"  border="0" cellpadding="10" cellspacing="1" bgcolor="#000066">
    <form name="form2" method="post" action="">
      <tr bgcolor="#FFCC33">
        <td>&nbsp;&nbsp;添加一个新的<strong>二级分类</strong></td>
      </tr>
      <tr bgcolor="#FDFEF5">
        <td bgcolor="#FDFEF5">
          <input type="text" name="new_type_son_name"> 
          <select name="new_type_id">
	  <option value="" selected >请选择</option>
          <%
set rs=server.createobject("adodb.recordset")
sql="select * from type"
rs.open sql,conn,1,1 
While (NOT rs.EOF)
%>
          <option value="<%=(rs.Fields.Item("type_id").Value)%>"><%=(rs.Fields.Item("type_name").Value)%></option>
          <%
rs.MoveNext()
Wend
rs.close
set rs=nothing
%>
        </select>
          <input type="button" name="Submit2" onClick="check2()" value="添加">
		<input type="hidden" name="action" value="add_type_son">
        </td>
      </tr>
    </form>
  </table>
  <p>&nbsp;</p>
  <table width="96%"  border="0" cellpadding="10" cellspacing="1" bgcolor="#000066">
    <form name="form3" method="post" action="">
      <tr bgcolor="#FFCC33">
        <td>&nbsp;&nbsp;添加一个新的<strong>类型</strong></td>
      </tr>
      <tr bgcolor="#FDFEF5">
        <td bgcolor="#FDFEF5">
          <input type="text" name="new_brand_name"> 
          <select name="new_type_id" style="font-family: 宋体; font-size: 9pt" onChange="changeselect1(this.value)">
	  <option value="" selected >请选择</option>
          <%
While (NOT rst.EOF)
%>
          <option value="<%=(rst.Fields.Item("type_id").Value)%>"><%=(rst.Fields.Item("type_name").Value)%></option>
          <%
  rst.MoveNext()
Wend
If (rst.CursorType > 0) Then
  rst.MoveFirst
Else
  rst.Requery
End If
%>
        </select> 
        <select name="new_type_son_id" class="px12" id="new_type_son_id">
		<option selected>请选择</option>
        </select> 
          <input type="button" name="Submit3" onClick="check3()" value="添加">
		<input type="hidden" name="action" value="add_brand">
        </td>
      </tr>
    </form>
  </table>
</div>
</body>
</html>
<%
rst.Close()
Set rst = Nothing
rss.Close()
Set rss = Nothing
rsts.Close()
Set rsts = Nothing
rsb.Close()
Set rsb = Nothing
%>