您的位置:首页 > 编程语言 > ASP

一个操作购物车的程序(ASP)

2006-04-28 14:59 204 查看
<%

'数据格式:商品ID|||商品数量|||其他~~~~~下一个记录

%>
<%
class shoppingCar
public proid
public proNum
public other
Private shoppingStr
Private cars()
Private hand

public function open(str)'读入数据字符串
shoppingStr=str
hand=-1
if shoppingStr="" or isNull(shoppingStr) Then
else
tempCar=split(shoppingStr,"~~~~~")
ReDim cars(ubound(tempCar))
for i=0 to ubound(tempCar)
cars(i)=tempCar(i)
next
end if
end function

public function addshopping(shoppingId,shoppingNum,shoppingOther)'添加商品进入购物车
if shoppingStr="" Then
shoppingStr=shoppingId & "|||" & shoppingNum & "|||" & shoppingOther
else
do while getNext()=1
add=1
if proid=shoppingId and shoppingOther=Other Then
add=0
changeNum hand,Clng(proNum)+1
end if
loop
hand=-1
if add=1 Then
shoppingStr=shoppingStr & "~~~~~" & shoppingId & "|||" & shoppingNum & "|||" & shoppingOther
end if
end if
if shoppingStr="" or isNull(shoppingStr) Then
else
tempCar=split(shoppingStr,"~~~~~")
ReDim cars(ubound(tempCar))
for i=0 to ubound(tempCar)
cars(i)=tempCar(i)
next
end if
end function

public function getNext()'进入下一条记录,并返回是否结束
if shoppingStr="" Then
getNext=0
else
hand=hand+1
if hand>getCarLen() Then
getNext=0
else
getnext=1
tempArray=split(cars(hand),"|||")
proId=tempArray(0)
proNum=tempArray(1)
Other=tempArray(2)
end if
end if
end function

public function delShopping(k)'按排序号删除商品
delShopping=0
if shoppingStr="" Then exit function
if k<0 or k>getCarLen Then exit function
if shoppingStr="" Then
else
for i=k to ubound(cars)-1
cars(i)=cars(i+1)
next
redim Preserve cars(ubound(cars)-1)
shoppingStr=join(cars,"~~~~~")
delShopping=1
end if
end function

public function delShoppingbyId(id)'按商品ID删除商品
delShoppingbyId=0
for i=ubound(car) to 0 step -1
tempid=split(cars(i),"|||")(0)
if tempid=id Then
for j=i to ubound(cars)-1
cars(j)=cars(j+1)
next
redim Preserve cars(ubound(cars)-1)
shoppingStr=join(cars,"~~~~~")
delShoppingbyId=1
end if
next
end function

public function changeNum(k,num)'按排序位改变商品数量
changeNum=0
if k<0 or k>getCarLen() Then exit function
tempArray=split(cars(k),"|||")
tempid=tempArray(0)
tempNum=tempArray(1)
tempOther=tempArray(2)
tempNum="" & num
cars(k)=tempid & "|||" & tempNum & "|||" & tempOther
shoppingStr=join(cars,"~~~~~")
changeNum=1
end function

function changeNumById(id,num)'按商品ID改变商品数量
changeNumById=0
if shoppingStr="" Then exit function
for i=ubound(car) to 0 step -1
tempArray=split(cars(k),"|||")
tempid=tempArray(0)
tempNum=tempArray(1)
tempOther=tempArray(2)
if tempid=id Then
tempNum="" & num
cars(k)=tempid & "|||" & tempNum & "|||" & tempOther
shoppingStr=join(cars,"~~~~~")
delShoppingbyId=1
end if
next
end function

public function getCarLen()'获得购物车长度
if shoppingStr="" Then
getCarLen=-1
else
getCarLen=ubound(cars)
end if
end function

public function getHand()'取得当前句柄的位置
getHand=hand
end function

public function save()'保存(读出)当前数据字符串
save=shoppingStr
end function
end class
%>

自己做的,贴出来希望大家给点意见
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: