<!--#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
if session("rank")>2 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权添加修改商品信息！');history.go(-1);</script>"
response.End
end if

if request.form("name")="" 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("vipprice")) 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("price1")) 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("price2")) 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("stock")) 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("stock")) then
conn.close
set conn = nothing
response.Write "<script language=javascript>alert('商品的库存必须是数字！');history.go(-1);</script>"
response.End
end if



  
function array_no(cxstr1,cxstr2,cxstr3)
  

  
if len(cxstr3) > 0 then
  
if not IsNumeric(cxstr3) then
  
array_no = ""
  
Exit Function
  
end if
  
else
  
array_no = ""
  
Exit Function
  
end if
  

  
if isarray(cxstr1) then
  
array_no = ""
  
Exit Function
  
end if
  

  
if cxstr1 = "" or isempty(cxstr1) then
  
array_no = ""
  
Exit Function
  
end if
  

  
ss = split(cxstr1,cxstr2)
  
cxs=cxstr2&ss(0)&cxstr2
  
sss=cxs
  
for m = 0 to ubound(ss)
  
cc = cxstr2&ss(m)&cxstr2
  
if instr(sss,cc)=0 then
  
sss = sss&ss(m)&cxstr2
  
end if
  
next
  
array_no = right(sss,len(sss)-len(cxstr2))
  
array_no = left(array_no,len(array_no)-len(cxstr2))
  
if cxstr3 <> 0 then
  
cx_sp = split(array_no,cxstr2)
  
if cxstr3 > ubound(cx_sp) then
  
array_no = cx_sp(ubound(cx_sp))
  
else
  
array_no = cx_sp(cxstr3)
  
end if
  
end if
 end function 



dim productdate,discount
if request.form("price1")<>0 or request.form("price1")<>"" then 
discount=round(request.form("price2")/request.form("price1"),2)
else
discount=1
end if

srtsortsid=request.form("sortsid")
allsortsid=array_no(srtsortsid,",",0)

set rss=server.createobject("adodb.recordset")
rss.open "select * from sorts where sortsid in ("&allsortsid&")  order by sortsorder ",conn,1,1
  if rss.eof and rss.bof then
allcategoryid=""
else
strcategoryid=""
j=0
all1=int(rss.recordcount)
   do while not rss.eof 
if j=0  then
strcategoryid=Trim(rss("categoryid"))
else
strcategoryid=strcategoryid&","&Trim(rss("categoryid"))
end if

j=j+1
 rss.movenext
        loop
end if
        rss.close
set rss = nothing


allcategoryid=array_no(strcategoryid,",",0)

productdate=trim(request.form("productdateyear"))&"年"&trim(request.form("productdatemonth"))&"月"&trim(request.form("productdateday"))&"日"
dim action,id,temp,strContent,i,strDetail
id=SafeRequest("id",1)



action=FormatSQL(SafeRequest("action",0))
select case action
case "add"
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from product",conn,1,3
rs.AddNew
rs("prename")=trim(request.form("prename")) 
rs("name")=trim(request.form("name")) 
rs("company")=trim(request.form("company")) 
rs("brand")=trim(request.form("brand")) 
rs("intro")=trim(request.form("intro")) 
rs("introduce")=trim(request.form("introduce")) 
rs("predate")=trim(request.form("predate")) 
rs("price")=trim(request.form("price")) 
rs("price1")=trim(request.form("price1"))  
rs("price2")=trim(request.form("price2"))  
rs("vipprice")=trim(request.form("vipprice"))  
rs("other")=trim(request.form("other")) 
rs("pic")=trim(request.form("pic")) 
rs("pic1")=trim(request.form("pic1")) 
rs("pic2")=trim(request.form("pic2"))  
rs("graph")=trim(request.form("graph")) 
rs("graph2")=trim(request.form("graph2")) 
rs("photo")=trim(request.form("photo")) 
rs("addlink")=trim(request.form("addlink")) 
rs("link")=trim(request.form("link")) 
rs("weblink")=trim(request.form("weblink"))
rs("downloadlink")=trim(request.form("downloadlink")) 
rs("description")=trim(request.form("description")) 
rs("categoryid")="0|"&pclass(allcategoryid)&"|0"
rs("sortsid")="0|"&pclass(allsortsid)&"|0"
rs("brand")=trim(request.form("brand"))
rs("rebrand")=trim(request.form("rebrand")) 
rs("productdate")=productdate 
rs("discount")=discount 
rs("score")=request.form("score") 
rs("amount")=request.form("amount") 
rs("stock")=request.form("stock")
rs("grade")=trim(request.form("grade")) 
rs("prestock")=trim(request.form("prestock"))
rs("pretype")=trim(request.form("pretype"))
rs("type")=trim(request.form("type"))
rs("recommend")=trim(request.form("recommend"))
rs("adddate")=Now() 
rs("solded")=0 
rs("viewnum")=0 
rs("rank")=0  
rs("ranknum")=0
For i = 1 To Request.Form("detail").Count 
strDetail = strDetail & Request.Form("detail")(i) 
Next 
rs("detail")=strDetail
rs.Update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.Write "<script language=javascript>alert('添加成功！');history.go(-1);</script>"
response.End

case "edit"
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from product where id="&id,conn,1,3
rs("prename")=trim(request.form("prename")) 
rs("name")=trim(request.form("name")) 
rs("company")=trim(request.form("company")) 
rs("brand")=trim(request.form("brand")) 
rs("intro")=trim(request.form("intro")) 
rs("introduce")=trim(request.form("introduce")) 
rs("predate")=trim(request.form("predate")) 
rs("price")=trim(request.form("price")) 
rs("price1")=trim(request.form("price1"))  
rs("price2")=trim(request.form("price2"))  
rs("vipprice")=trim(request.form("vipprice"))  
rs("other")=trim(request.form("other")) 
rs("pic")=trim(request.form("pic"))
rs("pic1")=trim(request.form("pic1")) 
rs("pic2")=trim(request.form("pic2"))   
rs("graph")=trim(request.form("graph")) 
rs("graph2")=trim(request.form("graph2")) 
rs("photo")=trim(request.form("photo")) 
rs("addlink")=trim(request.form("addlink")) 
rs("link")=trim(request.form("link"))
rs("weblink")=trim(request.form("weblink"))
rs("downloadlink")=trim(request.form("downloadlink")) 
rs("description")=trim(request.form("description")) 
rs("categoryid")="0|"&pclass(allcategoryid)&"|0"
rs("sortsid")="0|"&pclass(allsortsid)&"|0"
rs("brand")=trim(request.form("brand"))
rs("rebrand")=trim(request.form("rebrand")) 
rs("productdate")=productdate 
rs("discount")=discount
rs("score")=request.form("score") 
rs("amount")=request.form("amount") 
rs("stock")=request.form("stock") 
rs("grade")=trim(request.form("grade")) 
rs("prestock")=trim(request.form("prestock"))
rs("pretype")=trim(request.form("pretype"))
rs("type")=trim(request.form("type"))
rs("recommend")=trim(request.form("recommend"))
For i = 1 To Request.Form("detail").Count 
strDetail = strDetail & Request.Form("detail")(i) 
Next 
rs("detail")=strDetail
rs.Update
rs.Close
set rs=nothing
conn.close
set conn=nothing
response.Write "<script language=javascript>alert('修改成功！');history.go(-1);</script>"
response.End
end select
%>

