当前位置 > 文字教程 > asp教程

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

文章类别:asp | 发表日期:2008-10-5 20:40:14

<!--checkbag.asp-->

<!--shoppingcart page-->

<%  
    response.expires = 0
    response.expiresabsolute = Now() - 1
    response.addHeader "pragma","no-cache"
    response.addHeader "cache-control","private"
    Response.CacheControl = "no-cache"
%>

<!--#include file= "conn.asp"-->
<!--#include file= "char.inc"-->

<%
    'id_type=request("id_type")
    obj=request("obj")       '用做检测是否是正常购买后的进入购物车取obj参数
    rid=session("id")         '取出会员id
    dim x,i
    dim obj_bag,bag_item,cart
           'obj_bag          ----购物车
           'bag_item        ----商品的信息数据集合
           'cart                ----一件商品的信息数据集合
    dim p_id,p_name,p_price,p_manu,p_type,p_size,p_color,p_num,p_total,sum
            'p_id               ----商品id号
            'p_name         ----商品名称
            'p_price          ----价格
            'p_manu         ----制造商
        'p_type           ----商品式样
            'p_size           ----尺寸
        'p_color          ----颜色
            'p_num           ----数量
            'p_total           ----小计
            'sum              ----合计金额

    dim id1

    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
。。。。。。。。。(略)