<!--#include file="conn.asp"-->
<%
if session("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');location.href='index.asp' ;</script>"
response.End
else
if request.cookies("sundxshop")("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');location.href='index.asp' ;</script>"
response.End
end if
end if

dim action,brandid
brandid=SafeRequest("id",1)
action=FormatSQL(SafeRequest("action",0))
select case action

case "add" 
if session("rank")>1 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权添加商品品牌！');history.go(-1);</script>"
response.End
end if
if Not isNumeric(request.form("brandTop")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌推荐必须是数字！');history.go(-1);</script>"
response.End
end if
if Not isNumeric(request.form("brandNum")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌排序必须是数字！');history.go(-1);</script>"
response.End
end if
if request.form("brandName") ="" then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('请填写品牌名称！');history.go(-1);</script>"
response.End
end if
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from sundxbrand",conn,1,3
rs.AddNew
rs("brandName")=trim(request.form("brandName"))
rs("brandNum")=int(request.form("brandNum"))
rs("brandTop")=int(request.form("brandTop"))
rs.Update
rs.Close
set rs=nothing
conn.close
set conn = nothing
response.Redirect "addbrand.asp"

case "edit"
if session("rank")>1 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权编辑商品品牌！');history.go(-1);</script>"
response.End
end if

if Not isNumeric(request.form("brandTop")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌推荐必须是数字！');history.go(-1);</script>"
response.End
end if
if Not isNumeric(request.form("brandNum")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌排序必须是数字！');history.go(-1);</script>"
response.End
end if
if request.form("brandName") ="" then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('请填写品牌名称！');history.go(-1);</script>"
response.End
end if
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from sundxbrand where brandid="&brandid,conn,1,3
rs("brandName")=trim(request.form("brandName"))
rs("brandNum")=int(request.form("brandNum"))
rs("brandTop")=int(request.form("brandTop"))
rs.Update
rs.Close
set rs=nothing
conn.close
set conn = nothing
response.Redirect "Addbrand.asp"

case "del"
if session("rank")>1 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权删除商品品牌！');history.go(-1);</script>"
response.End
end if
conn.execute ("delete from sundxbrand where brandID="&brandid)
conn.close
set conn = nothing
response.Redirect "Addbrand.asp"
end select
%>
<title>管理商品品牌</title>
<script language = "JavaScript">
<!--
function CheckAdd()
{
    if(checkspace(document.AddForm.brandNmae.value)) {
	document.AddForm.brandNmae.focus();
    alert("请输入商品品牌名称！");
	return false;
  }

 
}
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
	function regInput(obj, reg, inputStr)
	{
		var docSel	= document.selection.createRange()
		if (docSel.parentElement().tagName != "INPUT")	return false
		oSel = docSel.duplicate()
		oSel.text = ""
		var srcRange	= obj.createTextRange()
		oSel.setEndPoint("StartToStart", srcRange)
		var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
		return reg.test(str)
	}
//-->
</script>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" BGCOLOR="#39867B">
  <tr> 
    <td height="20" BGCOLOR="#39867B" align="center"><font color="#FFFFFF">商品品牌管理</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF">
	<table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        <tr align="center" bgcolor="#FFFFFF" height="25"> 
         <td width="28%">名称</td>
           <td width="10%"> 介绍</td>
          <td width="12%"> 排序</td>
          <td width="14%">推荐</td>
          <td width="18%">操作</td>
        </tr>
        <%set rs=server.CreateObject("adodb.recordset")
		  rs.Open "select * from sundxbrand order by brandNum",conn,1,1
		  dim follows
		  if rs.EOF and rs.BOF then
		  response.Write "<div align=center><font color=red>还没有商品品牌</font></center>"
		  follows=0
		  else
		  do while not rs.EOF
		  %>
        <form name="form1" method="post" action="addbrand.asp?action=edit&id=<%=int(rs("brandid"))%>">
          <tr bgcolor="#FFFFFF" align="center"> 
            <td><input name="brandName" type="text" id="category" value="<%=trim(rs("brandName"))%>" size="20" maxlength="15"></td>
             <td><a href=branddetial.asp?id=<%=rs("brandid")%>>介绍</a></td>
            <td><input name="brandNum" type="text" id="brandNum" value="<%=int(rs("brandNum"))%>" size="4" maxlength="4"></td>
            <td><select name="brandTop" id="brandTop">
			    <option value="0" <% if rs("brandTop")=0 Then Response.write("Selected") %>>普通品牌</option>
                <option value="1" <% if rs("brandTop")=1 Then Response.write("Selected") %>>推荐品牌</option>
              </select></td>
            <td><input type="submit" name="Submit" value="修 改"> &nbsp; <a href="addbrand.asp?id=<%=int(rs("brandid"))%>&action=del" onClick="return confirm('您确定进行删除操作吗？')"><font color=red>删除</font></a> 
            </td>
          </tr>
        </form>
        <%rs.MoveNext
          loop
          follows=rs.RecordCount
          end if%>
      </table>
      <br></td>
  </tr>
</table>
<br>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" BGCOLOR="#39867B">
  <tr> 
    <td height="20" BGCOLOR="#39867B" align="center"><font color="#FFFFFF">添加商品品牌</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF">
	<table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
          <td width="28%"> 品牌名称</td>
          <td width="18%">品牌排序</td>
          <td width="18%">品牌推荐</td>
          <td width="18%">操作</td>
        </tr>
        <form name="AddForm" method="post" action="addbrand.asp?action=add">
          <tr align="center" bgcolor="#FFFFFF"> 
            <td><input name="brandName" type="text" id="brandName" size="20"></td>
            <td><input name="brandNum" type="text" id="brandNum" size="4" value="<%=follows+1%>"></td>
            <td><select name="brandTop" id="brandTop">
                <option value="0" selected>普通品牌</option>
                <option value="1">推荐品牌</option>
              </select> </td>
            <td><input type="submit" name="Submit3" value="添 加" onClick="return CheckAdd();"></td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
<!--#include file="footer.asp"-->