<% '简单购物车类 '朱永创 ' 2005-9-24 '如出现问题,请联系我(belin2000@163.com QQ:63905649) class shopping private bb(10) private aa(10) private cc(10) '对session赋值 function pushsession() session("car")=aa session("one")=bb session("num")=cc end function '初始化session数组的值 function checksession() if not isarray(session("car")) then pushsession() end if end function '取得session的数据 function getsession() for i=0 to 9 aa(i)=session("car")(i) bb(i)=session("one")(i) cc(i)=session("num")(i) next end function
'购买产品 function buy(goods,one,num) dim isok,i isok=false getsession() for i=0 to 9 if aa(i)="" then aa(i)=goods bb(i)=one cc(i)=num isok=true exit for end if next pushsession() if not isok then response.Write("<script language='javascript'>alert('你的购物车已满');history.back();</script>") end function '修改产品的数量 'num 数量值 'i,sessin的代号 ,num数量 function upnum(i,num) getsession() cc(i)=num pushsession() end function '删除1个产品 'num session("car")的代号 function delgoods(num) getsession() aa(num)="" bb(num)="" cc(num)="" pushsession() end function
'删除多个产品 function delall() dim i getsession() for i=0 to 9 aa(i)="" bb(i)="" cc(i)="" next pushsession() end function '购物车的产品数量 function carcount() dim j,i getsession() j=0 for i=0 to 9 if aa(i)<>"" then j=j+1 next response.Write(j) end function '购物车的总价钱 function money() dim i dim carmoney getsession() carmoney=0 for i=0 to 9 if bb(i)<>"" then carmoney=carmoney+bb(i)*cc(i) end if next response.Write(carmoney) end function '显示单物品信息 function onegood(one) response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0>"&vbcrlf) response.Write("<tr>"&vbcrlf) response.Write("<td width=30% >"&session("car")(one)&"</td>") response.Write("<td width=25% >"&session("one")(one)&"</td>") response.Write("<td width=30% >"&session("num")(one)&"</td>") response.Write("<td width=15% ><a href=?action=del&num="&one&">删除</a></td>") response.Write("</tr>"&vbcrlf) response.Write("</table>"&vbcrlf) response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0>"&vbcrlf) response.Write("<tr>"&vbcrlf) response.Write("<td width=100% height=1 bgcolor=#001122 ></td>") response.Write("<tr>") response.Write("</table>") end function '显示购物车的信息 function show() dim i response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0>"&vbcrlf) for i=0 to 9 if session("car")(i)<>"" then response.Write("<tr><td colspan=3>"&vbcrlf) response.Write(""&onegood(i)&"</td>") response.Write("</tr>"&vbcrlf) end if next response.Write("<tr><td width=60% >共") carcount() response.Write("个产品</td><td width=40% >应付金额:") money() response.Write("</td><tr>") response.Write("</table>"&vbcrlf) response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0>"&vbcrlf) response.Write("<tr>"&vbcrlf) response.Write("<td width=100% height=4 style=filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#888888', gradientType='1') ></td>") response.Write("<tr>"&vbcrlf) response.Write("</table>"&vbcrlf) end function
end class %>