if obj="1" then obj為1說明由菜單欄點擊進入的 if not isobject(Session("Bag")) then 如果Session("Bag")不是對象,說明購物車為空 response.write "<script language=""javascript"">" response.write"alert(""購物車為空!"");" & chr(13) response.write "window.location='index.asp'" response.write "</script>" response.end else set obj_bag=Session("Bag") 若購物車不為空,將它賦給對象obj_bag end if else if isobject(Session("Bag")) then 若不是菜單欄點擊進入的,則將購物車信息賦給對象obj_bag
set obj_bag=Session("Bag") else 若購物車為空,說明購物車內沒有商品,則返回首頁 response.write "<script language=""Javascript"">" response.write"alert(""T購物車為空!"");" & chr(13) response.write "window.location='index.asp'" response.write "</script>" response.end end if end if 'response.write "<script>alert("""& isobject(obj_bag) &""")</script>"
select case request("action") 取得按鈕信息 如果選擇刷新則重新計算商品的價值及總價 將當前信息計算寫入購物車并顯示購物車 case "refresh" 若為刷新 for each cart in obj_bag.items p_name=cart(0) 將購物車中的信息數據集合分別賦值給變量 p_manu=cart(1) p_type=cart(2) p_size=cart(3) p_color=cart(4) p_price=cart(5) p_num=cart(6) p_id=cart(7)
if request("checkBox_" & p_id)<>"" then 取得取消單選框的值,如果不為空,即打鉤 if obj_bag.Exists(p_name) then 如果商品已存在刪除該商品 obj_bag.remove(p_name) end if else p_num=trim(request("quantity"&p_name)) 若沒有該操作,寫入購物車 if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then p_num=1 end if bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id) 'response.write "p_num=" & p_num & "<br>" end if next set Session("Bag")=obj_bag 將obj_bag對象里的信息,寫入Session("Bag")
如果選擇去收銀臺則準備開始接收付款 將當前信息寫入購物車并轉向收銀程序 case "check" 按鈕為購買的時候 for each cart in obj_bag.items 循環cart將其所有信息都賦給變量 p_name=cart(0) p_manu=cart(1) p_type=cart(2) p_size=cart(3) p_color=cart(4) p_price=cart(5) p_num=cart(6) p_id=cart(7)
if request("checkBox_" & p_id)="" then 如果取消單選框為空,取id1的值 id1=p_id & "," & id1 將他們有逗號形式連接 end if next id1=left(id1,len(id1)-1) shopping_id=request("id") set obj_bag=session("bag") set session("obj_bag")=obj_bag call insertDB(id1) 調用函數 end select %> '輸出HTML 。。。。。。。。。(略)