
<!-- #include file="conn.asp" -->
<!--#include file="check2.asp"-->
<%
id = request.Form("id")
zuhepkid=request.form("zuhepkid")
model=trim(request.form("model"))
zuhename=trim(request.form("zuhename"))
zuheprice2=trim(request.form("price2"))

if zuhepkid<>"" then
	zuhepkid=replace(zuhepkid," ","")
	zuhepkid=replace(zuhepkid,"，",",")
	zuhepkid=replace(zuhepkid,",,",",")
	zuhepkid=replace(zuhepkid,",,",",")
	if left(zuhepkid,1)="," then zuhepkid = mid(zuhepkid,2)
	if right(zuhepkid,1)="," then zuhepkid = mid(zuhepkid,1,len(zuhepkid)-1)
end if

if instr(zuhepkid,",")>0 then
else
	response.write "<br><br>&nbsp;您可能只是选择了一个商品。商品组合要选择两个或以上的商品。 <a href=javascript:history.back()><font color='#0000FF'>返回</font></a>"
	conn.close
	response.end
end if

if zuhepkid<>"" then
  arr=split(zuhepkid,",")
  for i=0 to Ubound(arr)
    if arr(i)="" or not isnumeric(arr(i)) then
		wrong=1
	else
		myorder = myorder & ",iif(pkid="&arr(i)&","&i&",99)"
	end if
  next
end if
if left(myorder,1)="," then 
	myorder = mid(myorder,2)
end if
if myorder<>"" then
	myorder = " order by "&myorder
end if

allproduct=""
sumprice=0
allpkid =""

sql="select * from e_product where pkid in ("&zuhepkid&") "&myorder
'response.write sql
'response.end
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if rs.bof or rs.eof then
else
	i=1
	do while not rs.eof 
		pkid=rs("pkid")
		productname=rs("productname")
		price2=rs("price2")
		smallpicpath=rs("smallpicpath")
		if i=1 then
			zuhepic=smallpicpath
		end if 
		
		allpkid = allpkid &","& cstr(pkid)
		allproduct = allproduct &"＋"& productname
		sumprice = sumprice + cdbl(price2)
	rs.movenext
	i=i+1
	loop
	allpkid = mid(allpkid,2)
	allproduct = mid(allproduct,2)
end if
rs.close
set rs=nothing


if id = "0" then
	
	
	oneweight=conn.execute("select sum(oneweight) from e_product where pkid in("&allpkid&")")(0)
	if NOT isnumeric(oneweight) then oneweight=0
	
	sql="select * from e_product"
	set rs=server.CreateObject("adodb.recordset")
	rs.open sql,conn,1,3
		rs.addnew
		rs("zuhepkid")=allpkid
		rs("model")=model
		rs("zuhename")=zuhename
		rs("oneweight")=oneweight
		rs("price2")=zuheprice2
		rs("price3")=zuheprice2
		rs("price4")=zuheprice2
		rs("price5")=zuheprice2
		rs("price6")=zuheprice2
		rs("price1")=sumprice
		rs("productname")=allproduct
		rs("zuheflag") = "1"
		rs("smallpicpath")=zuhepic
		rs.update
		pkid=rs("pkid")
		
		'新增规格
		sql="insert into e_guige(pkid,guige,price2,price3,price4,price5,price6) values('"&pkid&"','{单一规格}','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"')"
		conn.execute(sql)
	rs.close
	SET rs=nothing
else

	oneweight=conn.execute("select sum(oneweight) from e_product where pkid in("&allpkid&")")(0)
	if NOT isnumeric(oneweight) then oneweight=0
	
	sql="select * from e_product where pkid="&id
	set rs=server.CreateObject("adodb.recordset")
	rs.open sql,conn,1,3
	if rs.bof or rs.eof then
	else
		rs("zuhepkid")=allpkid
		rs("model")=model
		rs("zuhename")=zuhename
		rs("oneweight")=oneweight
		rs("price2")=zuheprice2
		rs("price3")=zuheprice2
		rs("price4")=zuheprice2
		rs("price5")=zuheprice2
		rs("price6")=zuheprice2
		rs("price1")=sumprice
		rs("productname")=allproduct
		rs("zuheflag") = "1"
		rs("smallpicpath")=zuhepic
		rs.update
		
		sql2="select * from e_guige where pkid="&id
		set rs2=server.CreateObject("adodb.recordset")
		rs2.open sql2,conn,1,1
		if rs2.bof or rs2.eof then
			'新增规格
			sql="insert into e_guige(pkid,guige,price2,price3,price4,price5,price6) values('"&id&"','{单一规格}','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"','"&zuheprice2&"')"
			conn.execute(sql)
		else
			'更新规格
			sql="update e_guige set price2='"&zuheprice2&"',price3='"&zuheprice2&"',price4='"&zuheprice2&"',price5='"&zuheprice2&"',price6='"&zuheprice2&"' where pkid="&id
			conn.execute(sql)
		end if
		rs2.close
		set rs2=nothing
		
	end if
	rs.close
	SET rs=nothing
end if



conn.close
response.redirect("productzuhe.asp")
%>






