一个操作购物车的程序(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
%>
自己做的,贴出来希望大家给点意见
'数据格式:商品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
%>
自己做的,贴出来希望大家给点意见
相关文章推荐
- Asp.Net操作MSSQL数据库的类-从增删改查讲起-附带一个小程序测试
- 一个ASP.net购物车的代码程序.
- asp.net中 cookies的应用,自己写的一个简单登陆程序。
- ASP.NET程序的优化建议(转)一、数据库操作
- WF (Windows Workflow Foundation) 工作流学习(一)一个Asp.Net 状态机验证程序
- ASP程序中同一个用户不允许同时登陆两次
- asp.net程序优化 尽量减少数据库连接操作
- 一个演示多线程操作及同步的C#程序
- 编写一个程序,可以通过次程序完成一个表的创建操作,输入表的名称,各个列的名称及类型,输入完成后直接通过JDBC创建指定的表。
- asp.net+c#+access写的一个简单留言板程序
- 实现一个可host asp.net程序的小型IIS(Cassinidev介绍)
- 实现一个可host asp.net程序的小型IIS(Cassinidev介绍)
- 在ASP.NET 2.0中操作数据之五十四:添加新记录时包含一个文件上传选项
- asp.net发布一个很COOL的图片验证码程序[含源码]
- 一个使用ASP.NET来操作COM的磁盘配额代码.
- 一个查看ASP的JavaScript程序
- 实现一个可host asp.net程序的小型IIS(Cassinidev介绍)
- 小试牛刀,制作一个简单的ASP.NET程序
- 用ASP+XMLHTTP编写一个天气预报程序
- 每天一个python小程序 2使用python.MySQLdb执行数据库操作