<%

Class UserCart
     '建立购物车
     Sub CreateCart()
         Dim CFlag
         dim mCart(6,0)
         CFlag=CheckCart()
         if CFlag=false then
             For iCount =LBound(mCart,2) to UBound(mCart,2)
                 mCart(0,iCount)=""
             next 
             Session("UserCart")=mCart
         end if 
     End Sub
     '检查购物车
     Public Function CheckCart()
         IF IsArray(Session("UserCart")) THEN
             CheckCart = true
             ELSE 
             CheckCart = false 
         END IF 
     End Function
     '检查购物车是否为空 
     Function CheckEmtpy()
         dim mCart
         mCart=Session("UserCart")
         For i =LBound(mCart,2) to UBound(mCart,2)
             if mCart(0,i)<>"" then
                 CheckEmtpy=false
                 Exit Function
             end if
         next
         CheckEmtpy=True 
     End Function
     '添加商品
     Function AddItem(aID,aName,aPrice1,aPrice2,aPrice3,aCount,aImage)
         dim mCart
         AddItem=false
         if CheckItem(aID)=false then
             '无此商品
             mCart=Session("UserCart")
             For i =LBound(mCart,2) to UBound(mCart,2)
                 if mCart(0,i)="" then
                     mCart(0,i)=aID
                     mCart(1,i)=aName
                     mCart(2,i)=aPrice1
                     mCart(3,i)=aPrice2
                     mCart(4,i)=aPrice3
                     mCart(5,i)=aCount
                     mCart(6,i)=aImage
                     session("UserCart")=mCart
                     AddItem=true
                     exit Function
                 end if
             next 
             i=i+1
             Redim preserve mCart(6,i)
             mCart(0,i)=aID
             mCart(1,i)=aName
             mCart(2,i)=aPrice1
             mCart(3,i)=aPrice2
             mCart(4,i)=aPrice3
             mCart(5,i)=aCount
             mCart(6,i)=aImage
             session("UserCart")=mCart
             AddItem=True
         Else
             '有此商品,则商品数量+1
             ModifItem aID,aCount,0
             AddItem=True
         End if
     End Function
     '修改商品数量
     Sub ModifItem(mID,mCount,mFlag)
         'mFlag－标志 0－添加 1－删除,2-修改 3-清空
         'mID-商品ID
         'mCount－修改商品的数量
         dim mCart
         mCart = Session("UserCart")
         For i =LBound(mCart,2) to UBound(mCart,2)
             if mCart(0,i)=mID then
                 select case mFlag
                 case 1
                     mCart(5,i)= mCart(5,i)-mCount
                 case 0
                     mCart(5,i)= mCart(5,i)+mCount
                 case 2
                     if mCount=0 then
                         mCart(5,i)=0
                         mCart(0,i)=""
                     else
                         mCart(5,i)=mCount
                     end if
                 case 3
                     mCart(5,i)=0
                     mCart(0,i)=""
                 end select
                 session("UserCart")=mCart
                 exit Sub
             end if
         next 
     End Sub
     '查看推车
     Function ViewCart()
         dim mCart
         mCart=session("UserCart")
         ViewCart=mCart
     End Function
     '检查商品
     Function CheckItem(cID)
         dim mCart
         mCart =Session("UserCart")
         For i =LBound(mCart,2) to UBound(mCart,2)
             if mCart(0,i)=cID then
                 CheckItem=True
                 exit Function
             end if
         next 
         CheckItem=false
     End Function
     '清空购物车
     Sub RemoveAll()
         dim mCart
         mCart = Session("UserCart")
         For i =LBound(mCart,2) to UBound(mCart,2)
             mCart(0,i)=""
         next 
         Session("UserCart")=mCart
     End Sub 
     '商品总价值
     Function TPrice()
         dim mCart,i
         dim OutPrice(3)
         mCart=session("UserCart")
         for i=LBound(mCart,2) to UBound(mCart,2)
             if mCart(0,i)<>"" then 
                 Outprice(0) = Outprice(0) + mCart(2,i)*mCart(5,i)
                 Outprice(1) = Outprice(1) + mCart(3,i)*mCart(5,i)
                 Outprice(2) = Outprice(2) + mCart(4,i)*mCart(5,i)
                 Outprice(3) = OutPrice(3) + mCart(5,i)
             end if
         next
         TPrice=OutPrice
     End Function
End Class
'=================================================
'建立购物车对象,该对象用于直接在程序中调用
'来自QQ:1017921826
'=================================================
dim uCart
set uCart= new UserCart
uCart.CreateCart
%>
