Function CheckCart() IF IsArray(Session("Cart")) THEN CheckCart=True ELSE CheckCart=False END IF End Function
CheckItem设计: 请看代码:
Function CheckItem(ID) IF CheckCart=True THEN varMudCart = Session("Cart") FOR i = LBound(varMudCart)TO UBound(varMudCart) IF varMudCart(i,0) = ID THEN CheckItem=TRUE Exit Function ELSEIF varMudCart(i,0) <> ID THEN CheckItem=FALSE END IF NEXT END IF End Function
Function AddItem(ID, Qty) Set CartObj = New CartKit varCartStatus = CartObj.CheckCart IF varCartStatus=false THEN CartObj.CreateCart mudCart=Session("Cart") mudCart(0,0)=ID mudCart(0,1)=Qty Session("Cart")=mudCart Exit Function ELSEIF varCartStatus=true THEN IF CartObj.CheckItem(ID) = true THEN CartObj.UpdateItem ID,Qty ELSEIF cartObj.CheckItem(ID) = false THEN mudCart = Session("Cart") FOR i = LBound(mudCart) TO UBound(mudCart) IF mudCart(i,0) = "" THEN mudCart(i,0) = ID mudCart(i,1) = Qty Session("Cart") = mudCart Exit Function END IF NEXT END IF END IF End Function UpdateItem设计: Function UpdateItem(ID, Qty) mudCart = Session("Cart")
FOR i = LBound(mudCart) TO UBound(mudCart) IF mudCart(i,0) = ID THEN mudCart(i,1) = Qty Session("cart")=mudCart Exit Function END IF NEXT End Function ViewItem设计: Function ViewItem() mudCart=Session("Cart") IF isArray(mudCart) THEN %> Item Name Item Quantity <% Response.Write "Item ID: " & mudCart(i,0) & "<--" Response.Write " " Response.Write "Item Qty: " & mudCart(i,1) & "<--"