最近接了个业务,由于牵涉到在线购物,于是找了以前的文档,发现以前做过类似的东西,就是关于购物车的东东,呵呵,放这里共享一下,或许对很多人都有用
'购物车类
'使用时 定义 : Set gwc = New ZLBuy
'作者:coos (qq:52590565,有兴趣可以交流,转载请注明出处)
'完成时间:2008-04-11
Class ZLBuy
Private TempCount '定义清单个数
Private TempUser '定义用户ID
Private i '定义计数器
Private Sub Class_Initialize()
Response.Cookies("SSN").Expires=Date + 1
UserID=Session("username")
end Sub
Private Sub Class_Terminate()
end Sub
'*******设置/获取用户ID********
Public Property Get UserID
UserID=TempUser
End Property
Public Property Let UserID(Byval Value)
Dim uid
If Len(Value)=0 Then
Randomize
uid=Fix((9999-1000)*Rnd())+1
uid=Cstr(Hour(Time)) & Cstr(Minute(Time)) & Cstr(Second(Time)) & uid
TempUser=uid
else
TempUser=Value
end if
Response.Cookies("SSN")("User")=TempUser
End Property
'**********************************
'*****操作cookie*****
'********获取物品种类数量*********
Public Function GetCount()
if Len(Request.Cookies("SSN")("Count"))=0 then
GetCount=0
else
GetCount=Cint(Request.Cookies("SSN")("Count"))
end if
End Function
'*************货品购物车显示***************
'*********获取货品信息********
Public Function Items(ID,Col)
If ID>=0 Then
Select Case Col
Case "id"
Items=ProductID(ID)
Case "num"
Items=Count(ID)
End Select
End If
End Function
'*********获取货品ID********
Private Function ProductID(ID)
Dim myArry
myArry=Split(Request.Cookies("SSN")("ProductsID") & ",",",")
ProductID=myArry(ID)
End Function
'*********获取货品数量********
Private Function Count(ID)
Dim myArry
myArry=Split(Request.Cookies("SSN")("ProductsNum") & ",",",")
count=myArry(ID)
End Function
'******************************************
'**********增加货品*********
Public Sub Add(Pid)
Dim Parry,PnumArry
Parry=Split(Request.Cookies("SSN")("ProductsID") & "," ,",")
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
For i=0 To Ubound(Parry)-1
if Parry(i)=Pid then
PnumArry(i)=Cint(PnumArry(i)) + 1
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
Exit Sub
End if
Next
Response.Cookies("SSN")("ProductsID")=Request.Cookies("SSN")("ProductsID") & "," & Pid
Response.Cookies("SSN")("ProductsNum")=Request.Cookies("SSN")("ProductsNum") & ",1"
Response.Cookies("SSN")("Count")=Cint(Request.Cookies("SSN")("Count"))+1
End Sub
'**********购买*********
'购物车类
'使用时 定义 : Set gwc = New ZLBuy
'作者:coos (qq:52590565,有兴趣可以交流,转载请注明出处)
'完成时间:2008-04-11
Class ZLBuy
Private TempCount '定义清单个数
Private TempUser '定义用户ID
Private i '定义计数器
Private Sub Class_Initialize()
Response.Cookies("SSN").Expires=Date + 1
UserID=Session("username")
end Sub
Private Sub Class_Terminate()
end Sub
'*******设置/获取用户ID********
Public Property Get UserID
UserID=TempUser
End Property
Public Property Let UserID(Byval Value)
Dim uid
If Len(Value)=0 Then
Randomize
uid=Fix((9999-1000)*Rnd())+1
uid=Cstr(Hour(Time)) & Cstr(Minute(Time)) & Cstr(Second(Time)) & uid
TempUser=uid
else
TempUser=Value
end if
Response.Cookies("SSN")("User")=TempUser
End Property
'**********************************
'*****操作cookie*****
'********获取物品种类数量*********
Public Function GetCount()
if Len(Request.Cookies("SSN")("Count"))=0 then
GetCount=0
else
GetCount=Cint(Request.Cookies("SSN")("Count"))
end if
End Function
'*************货品购物车显示***************
'*********获取货品信息********
Public Function Items(ID,Col)
If ID>=0 Then
Select Case Col
Case "id"
Items=ProductID(ID)
Case "num"
Items=Count(ID)
End Select
End If
End Function
'*********获取货品ID********
Private Function ProductID(ID)
Dim myArry
myArry=Split(Request.Cookies("SSN")("ProductsID") & ",",",")
ProductID=myArry(ID)
End Function
'*********获取货品数量********
Private Function Count(ID)
Dim myArry
myArry=Split(Request.Cookies("SSN")("ProductsNum") & ",",",")
count=myArry(ID)
End Function
'******************************************
'**********增加货品*********
Public Sub Add(Pid)
Dim Parry,PnumArry
Parry=Split(Request.Cookies("SSN")("ProductsID") & "," ,",")
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
For i=0 To Ubound(Parry)-1
if Parry(i)=Pid then
PnumArry(i)=Cint(PnumArry(i)) + 1
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
Exit Sub
End if
Next
Response.Cookies("SSN")("ProductsID")=Request.Cookies("SSN")("ProductsID") & "," & Pid
Response.Cookies("SSN")("ProductsNum")=Request.Cookies("SSN")("ProductsNum") & ",1"
Response.Cookies("SSN")("Count")=Cint(Request.Cookies("SSN")("Count"))+1
End Sub
'**********购买*********
'这里我调用了数据库的操作,其实也就是一条插入语句,读者可以自己更改一下
Public Sub Buy()
For i=0 To Count -1
DB.Buy Seesion("uid"),Request.Cookies("Pid")(Cstr(i)),Request.Cookies("Pcount")(Cstr(i))
Next
End Sub
'***********删除某物品*********
Public Sub Del(ID)
Dim Parry,PnumArry
Parry=Split(Request.Cookies("SSN")("ProductsID") & "," ,",")
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),Parry(ID),",")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),",,,",",")
Pnumarry(ID)=","
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
Response.Cookies("SSN")("ProductsNum")=Replace(Request.Cookies("SSN")("ProductsNum"),",,,",",")
Response.Cookies("SSN")("Count")=GetCount -1
If Instr(Request.Cookies("SSN")("ProductsID"),",,")<>0 then
Response.Cookies("SSN")("ProductsNum")=Replace(Request.Cookies("SSN")("ProductsNum"),",,","")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),",,","")
End If
End Sub
'***********修改物品数量*********
Public Sub Modi(ID,Num)
Dim Pnumarry
If Num>999 Or Num<=0 Then '这里的数字可以根据实际情况修改
Response.Write("<Script>return false</Script>")
Exit Sub
End If
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
Pnumarry(ID)=Num
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
End Sub
'*********清空购物车*********
Public Sub Drop()
Response.Cookies("SSN")=""
End Sub
End Class
Public Sub Buy()
For i=0 To Count -1
DB.Buy Seesion("uid"),Request.Cookies("Pid")(Cstr(i)),Request.Cookies("Pcount")(Cstr(i))
Next
End Sub
'***********删除某物品*********
Public Sub Del(ID)
Dim Parry,PnumArry
Parry=Split(Request.Cookies("SSN")("ProductsID") & "," ,",")
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),Parry(ID),",")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),",,,",",")
Pnumarry(ID)=","
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
Response.Cookies("SSN")("ProductsNum")=Replace(Request.Cookies("SSN")("ProductsNum"),",,,",",")
Response.Cookies("SSN")("Count")=GetCount -1
If Instr(Request.Cookies("SSN")("ProductsID"),",,")<>0 then
Response.Cookies("SSN")("ProductsNum")=Replace(Request.Cookies("SSN")("ProductsNum"),",,","")
Response.Cookies("SSN")("ProductsID")=Replace(Request.Cookies("SSN")("ProductsID"),",,","")
End If
End Sub
'***********修改物品数量*********
Public Sub Modi(ID,Num)
Dim Pnumarry
If Num>999 Or Num<=0 Then '这里的数字可以根据实际情况修改
Response.Write("<Script>return false</Script>")
Exit Sub
End If
Pnumarry=Split(Request.Cookies("SSN")("ProductsNum") & "," ,",")
Pnumarry(ID)=Num
Response.Cookies("SSN")("ProductsNum")=ArryToStr(Pnumarry,",")
End Sub
'*********清空购物车*********
Public Sub Drop()
Response.Cookies("SSN")=""
End Sub
End Class