<!--#include file="../admin/conn.asp" -->
<html>
<head>
<title>收藏箱-<%=sitename%>-<%=siteurl%></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Robots" content="index,follow">
<link rel="stylesheet" href="../shop.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" onload="self.focus();">

<%
'如果未登陆提示出错
if session("user_id")="" then 
response.redirect "../error.asp?error=009"
response.end
end if

'从数据库中读取会员的收藏商品
sqlc="select * from user1 where User_Id='"&session("user_id")&"'"
Set rsc = conn.Execute(sqlc) 
fav=rsc("fav")
if isnull(fav)=true then fav=""
rsc.close
set rsc=nothing

'移入购物车时，先从收藏箱中删除此商品
moveprodid=request("moveid")
moveid=replace(moveprodid," ","")
moveid=replace(moveid,"'","")
moveid="'"&moveid&"'"
fav=replace(fav,", "&moveid,"")   '此商品在收藏列表第二位及以后的情况
fav=replace(fav,moveid&", ","")   '此商品在收藏列表第一位的情况
fav=replace(fav,moveid,"")        '收藏列表只有此商品的情况

'接着将moveprodid编号的商品放入购物车
if moveprodid<>"" then 
ProductList = Session("ProductList")
Products = moveprodid
   If Len(ProductList) = 0 Then
      ProductList = "'" & Products & "'"
   ElseIf InStr( ProductList, Products ) <= 0 Then
      ProductList = ProductList & ", '" & Products & "'"
   End If
Session("ProductList") = ProductList
end if

'更新收藏箱时先清空收藏
if request("ok")="ok" then fav=""

'根据表单中传回的prodid重写收藏列表
Products = Split(request("prodid"), ", ")
For I=0 To UBound(Products)
if fav="" then
fav = "'"&Products(I)&"'"
ElseIf InStr(fav, products(i)) <= 0 Then
fav = fav & ", '" & Products(i) &"'"
End If
Next

'收藏箱满（即收藏列表长度超过100字节时，若允许会员收藏更多商品，修改此处的100即可）
if len(fav)>=100 then
response.redirect "../error.asp?error=012"
response.end
end if

'将收藏的商品写入数据库
Set rsc=Server.CreateObject("ADODB.RecordSet") 
sqlc="select * from userMain where UserId='"&session("estore_userid")&"'"
application.lock
rsc.open sqlc,conn,3,3
rsc("fav")=fav
rsc.update
application.unlock
rsc.close
set rsc=nothing

'收藏箱为空时，提示出错
if fav="" then
response.redirect "../error.asp?error=010"
response.end
end if

'根据收藏箱中商品编号从数据库读取商品名称
sqlc="select * from ProdMain where ProdId in ("&fav&") order by ProdId"
Set rsc = conn.Execute(sqlc) 
%>

<table width="630" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr><td height="50"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF3333"><b>您选择的商品已经放入收藏箱，收藏箱中的商品将永久保存，除非您主动删除。</b></font><br></td></tr>
  <tr><td>
      <table border="0" cellspacing="1" cellpadding="4" align="center" width="567" bgcolor="#CCCCCC">

        <form action="fav.asp" method="POST" name="check">
          <tr bgcolor="#FFFFFF"> 
            <td width="60" height="25"> 
              <div align="center"><font color="B0266D">选择</font></div>
            </td>
            <td width="120"> 
              <div align="center"><font color="B0266D">商 品 编 号</font></div>
            </td>
            <td width="340"> 
              <div align="center"><font color="B0266D">商 品 名 称</font></div>
            </td>
            <td width="170"> 
              <div align="center"><font color="B0266D">购 买</font></div>
            </td>
          </tr>

<%
'无指定商品时，提示出错
if rsc.eof and rsc.bof then
response.redirect "../error.asp?error=011"
response.end
else
do While Not rsc.eof
%> 
          <tr bgcolor="#FFFFFF"> 
            <td height="20" align="center"> 
              <input type="CheckBox" name="ProdId" value="<%=rsc("ProdId")%>" Checked>
            </td>
            <td align="center"> 
              <%=rsc("ProdId")%>
            </td>
            <td>&nbsp;&nbsp;<font color="B0266D"><%=rsc("ProdName")%></font></td>
	    <td align=center><a href='fav.asp?moveId=<%=rsc("ProdId")%>'>放入购物车</a></td>
          </tr>
<%
rsc.MoveNext
loop
end if
rsc.close
set rsc=nothing
%> 
	<tr><td colspan="4" bgcolor="#ffffff" height=40>
		<font color=red>注意：若要删除收藏箱中的商品，请去掉商品前的小勾，再单击“更新收藏”。</font>
	</td></tr>
          <tr bgcolor="#FFFFFF"> 
            <td colspan="4" height="40" align="center" valign="middle">             
                <input type="submit" name="fav" value="更新收藏箱"> &nbsp;&nbsp;&nbsp;
                <input type="button" name="pay" value="查看购物车" onClick="javascript:location.href='check.asp';"> &nbsp;&nbsp;&nbsp; 
                <input type="button" name="button" value=" 继续购物 " language=javascript onClick="javascript:window.close()">
                <input type="hidden" name="OK" value="ok">
                </td>
        </tr>
        </form>

      </table>       
 </td></tr></table>
</body>
</html>
<%
set conn=nothing
%> 
