<%
'=========================程序名称：购物车源代码=======================
'作者：senty
'时间：2003-10-20
'程序描述：无
'=========================程序名称：购物车源代码=======================

'清空购物车
sub clearProduct()
	Session("ProductList")=""
	Session("ProductCount")=""
end sub

'向购物车添加商品
sub AddProduct(strPcID,intCount)
	
	ProductList = Session("ProductList")		'商品ID列表
	ProductCount=Session("ProductCount")		'商品数量列表
	Products = Split(ProductList, ",")
	PtCounts = Split(ProductCount, ",")
	
	'寻求购物车中是否有该商品，如果没有则追加
	For i=0 To UBound(Products)
	   if Products(i)=strPcID then exit for
	Next
	
	'还没有该商品，追加
	if i>UBound(Products) then
		Session("ProductList") = ProductList & strPcID & ","
		Session("ProductCount") = ProductCount & intCount & "," 
	else
		'如果商品已在车中，累加数量
		PtCounts(i)=Cint(PtCounts(i)) + intCount
		Session("ProductList") =join(Products,",")
		Session("ProductCount") =join(PtCounts,",")
	end if
	
	'将数组转换成字串
	
end sub


'将商品列表转换成字串，以便session保存
sub PtToString(Products, PtCounts)
	ProductList = ""		'商品ID列表
	ProductCount=""			'商品数量列表
	For i=0 To UBound(Products)-1
		'如果商品数量大于0才放到商品列表中
		if Cint(PtCounts(i)) > 0 then
			ProductList = ProductList & Products(i) & ","
			ProductCount = ProductCount & PtCounts(i) & ","
		end if
	Next
	
	Session("ProductList") = ProductList		'商品ID列表
	Session("ProductCount") = ProductCount		'商品数量列表
end sub


'修改商品数量，为0表示删除
sub ModifyProduct(strPcID,intCount)
	ProductList = Session("ProductList")		'商品ID列表
	ProductCount=Session("ProductCount")		'商品数量列表
	Products = Split(ProductList, ",")
	PtCounts = Split(ProductCount, ",")
	
	'寻求购物车中是否有该商品，如果有则删除
	For i=0 To UBound(Products)
	   if Products(i)=strPcID then exit for
	Next
	
	'还有该商品，删除该商品指定的数量
	if i<=UBound(Products) then
		PtCounts(i)=intCount
		'防止溢出
		if PtCounts(i) < 0 then  PtCounts(i)=0
	end if
	
	'将数组转换成字串
		Session("ProductList") =join(Products,",")
		Session("ProductCount") =join(PtCounts,",")
end sub

%>


