购物车范例(处理页面)

1@ Language=VBScript 
 1   
 2'id_type=request("id_type")   
 3  
 4on error resume next   
 5Response.Buffer = true   
 6Response.Expires = 0   
 7dim obj_bag,bag_item,cart   
 8'obj_bag ----购物车   
 9'bag_item ----商品的信息数据集合   
10'cart ----一件商品的信息数据集合   
11dim p_id,p_name,p_price,p_manu,p_type,p_size,p_color,p_num,p_temp   
12'p_id ----商品id号   
13'p_name ----商品名称   
14'p_price ----原价单价   
15'p_manu ----商品制造商   
16'p_type ----商品式样   
17'p_size ----商品尺寸   
18'p_color ----商品颜色   
19'p_num ----商品数量   
20'p_temp ----临时存放p_num   
21  
22  
23if session("login")="" then   
24response.write"

<script javascript""="" langue="">" & chr(13)
response.write"alert(""请先登录"");" & chr(13)
response.write"history.go(-1);" & chr(13)
response.write"</script>

 1" & chr(13)   
 2else   
 3'初始化购物车内变量   
 4p_id=trim(request("id"))   
 5P_manu=trim(request("manu"))   
 6p_type=trim(request("type"))   
 7p_name=replace(trim(request("name1"))," ","")   
 8p_price=trim(request("price"))   
 9p_size=trim(request("size"))   
10p_color=trim(request("color"))   
11p_num=trim(request("num"))   
12  
13if ((not IsNumeric(p_num)) or (p_num<="0") or (instr(1,p_num,".")<>0)) then   
14p_num=1 ‘如果商品数量小于0或者有小数点,取1   
15end if   
16  
17if p_name <>"" then   
18'如果有购物信息传入则准备装如购物车   
19'如果还没有购物车则新建dictionary对象   
20  
21if isobject(Session("Bag")) then '如果有购物车则更新   
22'response.write "isobject(Session(""Bag""))=" & isobject(Session("Bag")) & "

<br/>

 1"   
 2set obj_bag=Session("Bag")   
 3if obj_bag.exists(p_name) then ''如果当前购物车中已有该商品   
 4if err then   
 5response.write err.description   
 6err.clear   
 7end if   
 8  
 9'response.write isobject(obj_Bag)   
10  
11p_temp=obj_bag.item(p_name)(6) '将p_num的值存放于p_temp中   
12response.write "p_num=" & p_num & "

<br/>

 1"   
 2p_num=cint(p_num)+cint(p_temp) '购买的商品数量累加   
 3  
 4bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)   
 5obj_bag.item(p_name)=bag_item   
 6else   
 7bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)   
 8obj_bag.Add p_name,bag_item   
 9end if   
10  
11else '没有购物车生成新的   
12set obj_bag=server.CreateObject ("Scripting.Dictionary")   
13bag_item=array(p_name,p_manu,p_type,p_size,p_color,p_price,p_num,p_id)   
14response.write bag_item(0)   
15obj_bag.Add p_name,bag_item   
16end if   
17set Session("Bag") = obj_Bag '更新购物车   
18end if   
19  
20Response.Redirect ("checkbag.asp?obj="& request("obj") &"") '转向显示购物车页面   
21end if   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus