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

dim action,Markid
Markid=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("MarkTop")) 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("MarkNum")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌排序必须是数字！');history.go(-1);</script>"
response.End
end if
if request.form("MarkName") ="" 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 TimesMark",conn,1,3
rs.AddNew
rs("MarkName")=trim(request.form("MarkName"))
rs("MarkNum")=int(request.form("MarkNum"))
rs("MarkTop")=int(request.form("MarkTop"))
rs.Update
rs.Close
set rs=nothing
conn.close
set conn = nothing
response.Redirect "addMark.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("MarkTop")) 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("MarkNum")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('品牌排序必须是数字！');history.go(-1);</script>"
response.End
end if
if request.form("MarkName") ="" 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 TimesMark where Markid="&Markid,conn,1,3
rs("MarkName")=trim(request.form("MarkName"))
rs("MarkNum")=int(request.form("MarkNum"))
rs("MarkTop")=int(request.form("MarkTop"))
rs.Update
rs.Close
set rs=nothing
conn.close
set conn = nothing
response.Redirect "AddMark.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 TimesMark where MarkID="&Markid)
conn.close
set conn = nothing
response.Redirect "AddMark.asp"
end select
%>
<title>管理商品品牌</title>
<script language = "JavaScript">
<!--
function CheckAdd()
{
    if(checkspace(document.AddForm.MarkNmae.value)) {
	document.AddForm.MarkNmae.focus();
    alert("请输入商品品牌名称！");
	return false;
  }

     if(checkspace(document.AddForm.MiniPost.value)) {
	document.AddForm.MiniPost.focus();
    alert("请输入等级积分！");
	return false;
  }
     if(checkspace(document.AddForm.startMark.value)) {
	document.AddForm.startMark.focus();
    alert("请输入等级排序！");
	return false;
  }
      if(checkspace(document.AddForm.Stars.value)) {
	document.AddForm.Stars.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="#227776">
  <tr> 
    <td height="20" bgcolor="#227776" align="center"><font color="#FFFFFF">商品品牌管理</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF"> <br>
      <table width="80%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
        <tr align="center" bgcolor="#FFFFFF" height="25"> 
          <td width="28%">品牌名称</td>
          <td width="18%"> 品牌排序</td>
          <td width="18%">品牌推荐</td>
          <td width="18%">操作</td>
        </tr>
        <%set rs=server.CreateObject("adodb.recordset")
		  rs.Open "select * from TimesMark order by MarkNum",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="addMark.asp?action=edit&id=<%=int(rs("Markid"))%>">
          <tr bgcolor="#FFFFFF" align="center"> 
            <td><input name="MarkName" type="text" id="category" value="<%=trim(rs("MarkName"))%>" size="20" maxlength="15"></td>
            <td><input name="MarkNum" type="text" id="MarkNum" value="<%=int(rs("MarkNum"))%>" size="4" maxlength="4"></td>
            <td><select name="MarkTop" id="MarkTop">
			    <option value="0" <% if rs("MarkTop")=0 Then Response.write("Selected") %>>普通品牌</option>
                <option value="1" <% if rs("MarkTop")=1 Then Response.write("Selected") %>>推荐品牌</option>
              </select></td>
            <td><input type="submit" name="Submit" value="修 改"> &nbsp; <a href="addMark.asp?id=<%=int(rs("Markid"))%>&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="#227776">
  <tr> 
    <td height="20" bgcolor="#227776" align="center"><font color="#FFFFFF">添加商品品牌</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF"> <br>
      <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="addMark.asp?action=add">
          <tr align="center" bgcolor="#FFFFFF"> 
            <td><input name="MarkName" type="text" id="MarkName" size="20"></td>
            <td><input name="MarkNum" type="text" id="MarkNum" size="4" value="<%=follows+1%>"></td>
            <td><select name="MarkTop" id="MarkTop">
                <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>
      <br>
    </td>
  </tr>
</table>
<!--#include file="footer.asp"-->