select case action

'添加记录
'从产品展示页面“购买”链接过来的
case "add"
productID=HTMLEncode(request.querystring("id"))
set rs=conn.execute("select * from product where )
response.end
end if

'截取
theid=split(request.cookies("myCartInfo")("proID"),"|")
thenum=split(request.cookies("myCartInfo")("num"),"|")
theprice=split(request.cookies("myCartInfo")("price"),"|")


'清空
response.cookies("myCartInfo")=""


'判断
select case ubound(theid)
 case "-1"
   response.cookies("myCartInfo")("proID")=productID   '产品ID
   response.cookies("myCartInfo")("num")=1   '订购数量
   response.cookies("myCartInfo")("price")=rs("price2")   '单价
   response.cookies("myCartInfo").Expires=Date+7
 case "0"
   if theid(0)=productID then
   response.cookies("myCartInfo")("proID")=theid(0)
   response.cookies("myCartInfo")("num")=thenum(0)+1
   response.cookies("myCartInfo")("price")=theprice(0)
   response.cookies("myCartInfo").Expires=Date+7
   else
   response.cookies("myCartInfo")("proID")=theid(0)&"|"&productID   '产品ID
   response.cookies("myCartInfo")("num")=thenum(0)&"|"&"1"   '订购数量
   response.cookies("myCartInfo")("price")=theprice(0)&"|"&rs("price2")   '单价
   response.cookies("myCartInfo").Expires=Date+7
   end if
 case else
   for mm=1 to ubound(theid)+1
    if theid(mm-1)=productID then '此产品ID己存在
      if request.cookies("myCartInfo")("proID")="" then
        response.cookies("myCartInfo")("proID")=theid(mm-1)
        response.cookies("myCartInfo")("num")=thenum(mm-1)+1
        response.cookies("myCartInfo")("price")=theprice(mm-1)
      else
        response.cookies("myCartInfo")("proID")=request.cookies("myCartInfo")("proID")&"|"&theid(mm-1)
        response.cookies("myCartInfo")("num")=request.cookies("myCartInfo")("num")&"|"&thenum(mm-1)+1
        response.cookies("myCartInfo")("price")=request.cookies("myCartInfo")("price")&"|"&theprice(mm-1)
      end if
      response.cookies("myCartInfo")(""&productID&"hasadd")=1
      response.cookies("myCartInfo").Expires=Date+7
    else
      if request.cookies("myCartInfo")("proID")="" then
        response.cookies("myCartInfo")("proID")=theid(mm-1)
        response.cookies("myCartInfo")("num")=thenum(mm-1)
        response.cookies("myCartInfo")("price")=theprice(mm-1)
        response.cookies("myCartInfo").Expires=Date+7
      else
        response.cookies("myCartInfo")("proID")=request.cookies("myCartInfo")("proID")&"|"&theid(mm-1)   '产品ID
        response.cookies("myCartInfo")("num")=request.cookies("myCartInfo")("num")&"|"&thenum(mm-1)  '订购数量
        response.cookies("myCartInfo")("price")=request.cookies("myCartInfo")("price")&"|"&theprice(mm-1)   '单价
        response.cookies("myCartInfo").Expires=Date+7
      end if
    end if
   next
  
        if request.cookies("myCartInfo")(""&productID&"hasadd")<>"1" then
        response.cookies("myCartInfo")("proID")=request.cookies("myCartInfo")("proID")&"|"&productID   '产品ID
        response.cookies("myCartInfo")("num")=request.cookies("myCartInfo")("num")&"|"&"1"  '订购数量
        response.cookies("myCartInfo")("price")=request.cookies("myCartInfo")("price")&"|"&rs("price2")   '单价
        response.cookies("myCartInfo").Expires=Date+7
        end if
       
end select
set rs=nothing
response.redirect("mycart.asp")


'移除某一商品
case "remove"
theid=split(request.cookies("myCartInfo")("proID"),"|")
thenum=split(request.cookies("myCartInfo")("num"),"|")
theprice=split(request.cookies("myCartInfo")("price"),"|")

response.cookies("myCartInfo")("proID")=""
response.cookies("myCartInfo")("num")=""
response.cookies("myCartInfo")("price")=""

for kk=1 to ubound(theid)+1
if theid(kk-1)=theid(request.querystring("location")) then
else
  if kk=1 then
    response.cookies("myCartInfo")("proID")=theid(kk-1)
    response.cookies("myCartInfo")("num")=thenum(kk-1)
    response.cookies("myCartInfo")("price")=theprice(kk-1)
  else
    if request.cookies("myCartInfo")("proID")="" then
    response.cookies("myCartInfo")("proID")=theid(kk-1)
    response.cookies("myCartInfo")("num")=thenum(kk-1)
    response.cookies("myCartInfo")("price")=theprice(kk-1)
    else
    response.cookies("myCartInfo")("proID")=request.cookies("myCartInfo")("proID")&"|"&theid(kk-1)
    response.cookies("myCartInfo")("num")=request.cookies("myCartInfo")("num")&"|"&thenum(kk-1)
    response.cookies("myCartInfo")("price")=request.cookies("myCartInfo")("price")&"|"&theprice(kk-1)
    end if
  end if
end if
next
response.redirect("mycart.asp")


case "更新数量"
response.cookies("myCartInfo")("num")=""
newNum=HTMLEncode(request.form("num"))

thenum=split(newNum,",")
if ubound(thenum)=0 then
  response.cookies("myCartInfo")("num")=thenum(0)
else
  for p=1 to ubound(thenum)+1
   if p=1 then
   response.cookies("myCartInfo")("num")=thenum(p-1)
   else
   response.cookies("myCartInfo")("num")=request.cookies("myCartInfo")("num")&"|"&trim(thenum(p-1))
   end if
  next
end if
response.redirect("mycart.asp")

case "去结帐"
'转到要求顾客填写收货信息的页面
'在continueBuy.asp页面要调用订购信息的话,可直接向cookies中调用。调用方法与本页方法类似。
response.redirect("continueBuy.asp?action="&server.urlencode("去结帐"))
response.end

case "清空购物车"
response.cookies("myCartInfo")=""

case "继续购物"
response.Redirect("product.asp")

end select
%>

相关文章: