购物车范例(购物车页面 )

1   
2response.expires = 0   
3response.expiresabsolute = Now() - 1   
4response.addHeader "pragma","no-cache"   
5response.addHeader "cache-control","private"   
6Response.CacheControl = "no-cache"   
 1   
 2'id_type=request("id_type")   
 3obj=request("obj") '用做检测是否是正常购买后的进入购物车取obj参数   
 4rid=session("id") '取出会员id   
 5dim x,i   
 6dim obj_bag,bag_item,cart   
 7'obj_bag ----购物车   
 8'bag_item ----商品的信息数据集合   
 9'cart ----一件商品的信息数据集合   
10dim p_id,p_name,p_price,p_manu,p_type,p_size,p_color,p_num,p_total,sum   
11'p_id ----商品id号   
12'p_name ----商品名称   
13'p_price ----价格   
14'p_manu ----制造商   
15'p_type ----商品式样   
16'p_size ----尺寸   
17'p_color ----颜色   
18'p_num ----数量   
19'p_total ----小计   
20'sum ----合计金额   
21  
22dim id1   
23  
24if obj="1" then obj为1说明由菜单栏点击进入的   
25if not isobject(Session("Bag")) then 如果Session("Bag")不是对象,说明购物车为空   
26response.write "

<script javascript""="" language="">"
response.write"alert(""购物车为空!"");" & chr(13)
response.write "window.location='index.asp'"
response.write "</script>

 1"   
 2response.end   
 3else   
 4set obj_bag=Session("Bag") 若购物车不为空,将它赋给对象obj_bag   
 5end if   
 6else   
 7if isobject(Session("Bag")) then 若不是菜单栏点击进入的,则将购物车信息赋给对象obj_bag   
 8  
 9set obj_bag=Session("Bag")   
10else 若购物车为空,说明购物车内没有商品,则返回首页   
11response.write "

<script javascript""="" language="">"
response.write"alert(""T购物车为空!"");" & chr(13)
response.write "window.location='index.asp'"
response.write "</script>

1"   
2response.end   
3end if   
4end if   
5'response.write "

<script>alert("""& isobject(obj_bag) &""")</script>

 1"   
 2  
 3''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   
 4'判断单击的是购物车页面下方的哪一个按钮   
 5''''''''''''''''''''''''''''''''''''''''   
 6  
 7select case request("action") 取得按钮信息   
 8如果选择刷新则重新计算商品的价值及总价   
 9将当前信息计算写入购物车并显示购物车   
10case "refresh" 若为刷新   
11for each cart in obj_bag.items   
12p_name=cart(0) 将购物车中的信息数据集合分别赋值给变量   
13p_manu=cart(1)   
14p_type=cart(2)   
15p_size=cart(3)   
16p_color=cart(4)   
17p_price=cart(5)   
18p_num=cart(6)   
19p_id=cart(7)   
20  
21if request("checkBox_" & p_id)<>"" then 取得取消单选框的值,如果不为空,即打钩   
22if obj_bag.Exists(p_name) then 如果商品已存在删除该商品   
23obj_bag.remove(p_name)   
24end if   
25else   
26p_num=trim(request("quantity"&p_name)) 若没有该操作,写入购物车   
27if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then   
28p_num=1   
29end if   
30bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)   
31'response.write "p_num=" & p_num & "

<br/>

 1"   
 2end if   
 3next   
 4set Session("Bag")=obj_bag 将obj_bag对象里的信息,写入Session("Bag")   
 5  
 6如果选择去收银台则准备开始接收付款   
 7将当前信息写入购物车并转向收银程序   
 8case "check" 按钮为购买的时候   
 9for each cart in obj_bag.items 循环cart将其所有信息都赋给变量   
10p_name=cart(0)   
11p_manu=cart(1)   
12p_type=cart(2)   
13p_size=cart(3)   
14p_color=cart(4)   
15p_price=cart(5)   
16p_num=cart(6)   
17p_id=cart(7)   
18  
19if request("checkBox_" & p_id)="" then 如果取消单选框为空,取id1的值   
20id1=p_id & "," & id1 将他们有逗号形式连接   
21end if   
22next   
23id1=left(id1,len(id1)-1)   
24shopping_id=request("id")   
25set obj_bag=session("bag")   
26set session("obj_bag")=obj_bag   
27call insertDB(id1) 调用函数   
28end select   

'输出HTML
。。。。。。。。。(略)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus