<!--#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

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

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")=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("price3")=trim(rs("price3")) 
rs("vipprice")=trim(request.form("vipprice"))  
rs("other")=trim(request.form("other")) 
rs("pic")=trim(request.form("pic")) 
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("description")=trim(request.form("description")) 
rs("categoryid")=int(request.form("categoryid"))
rs("sortsid")=int(request.form("sortsid")) 
rs("rebrand")=trim(request.form("rebrand")) 
rs("productdate")=productdate 
rs("discount")=discount 
rs("score")=request.form("score") 
rs("stock")=request.form("stock")+1 
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(rs("prename")) 
rs("name")=trim(request.form("name")) 
rs("company")=trim(rs("company")) 
rs("brand")=trim(request.form("brand")) 
rs("intro")=trim(rs("intro")) 
rs("introduce")=trim(request.form("introduce")) 
rs("predate")=trim(rs("predate")) 
rs("price")=trim(rs("price")) 
rs("price1")=trim(request.form("price1"))  
rs("price2")=trim(request.form("price2")) 
rs("price3")=trim(rs("price3"))
rs("vipprice")=trim(rs("vipprice"))  
rs("other")=trim(rs("other")) 
rs("pic")=trim(rs("pic")) 
rs("graph")=trim(rs("graph")) 
rs("graph2")=trim(rs("graph2")) 
rs("photo")=trim(rs("photo")) 
rs("addlink")=trim(rs("addlink")) 
rs("link")=trim(rs("link")) 
rs("description")=trim(rs("description")) 
rs("categoryid")=int(rs("categoryid"))
rs("sortsid")=int(rs("sortsid")) 
rs("rebrand")=trim(rs("rebrand")) 
rs("productdate")= trim(rs("productdate"))
rs("discount")=discount
rs("score")=trim(rs("score")) 
rs("amount")=trim(rs("amount")) 
rs("stock")=request.form("stock")+1 
rs("grade")=trim(request.form("grade")) 
rs("prestock")=trim(rs("prestock"))
rs("pretype")=trim(rs("pretype"))
rs("type")=trim(rs("type"))
rs("recommend")=trim(request.form("recommend"))
rs("detail")=trim(rs("detail"))
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
%>

