这个是我以前用去年用ASP写的一个购物车主体,已经功过测试,运行良好,希望能给ASP的爱好者带来益处.(程序...

发表于:2007-06-30来源:作者:点击数: 标签:
%@ Language= VB Script % %Response.Expires=0% % ‘’写入COOKIE ‘’Response.Write Request.Cookies(warebuycount) sub setcookie(Aname,warenum,warename,price,warecount,pricelow) Response.Cookies(Aname).domain=application(wareurl) ‘’wareurl代
<%@ Language=VBScript %>
<%Response.Expires=0%>
<%
‘’写入COOKIE
‘’Response.Write Request.Cookies("warebuycount")
sub setcookie(Aname,warenum,warename,price,warecount,pricelow)
  Response.Cookies(Aname).domain=application("wareurl") ‘’wareurl代表域名
  Response.Cookies(Aname).expires=date()+30 ‘’COOKIE过期日期
  Response.Cookies(Aname).path="/"
  Response.Cookies(Aname).Secure = FALSE
  Response.Cookies(Aname)("warenum")=warenum ‘’商品编号
  Response.Cookies(Aname)("warename")=warename ‘’商品名称
  Response.Cookies(Aname)("price")=price ‘’价格
  Response.Cookies(Aname)("warecount")=warecount ‘’购买的数量
  Response.Cookies(Aname)("pricelow")=pricelow ‘’会员价格
end sub

sub setcount(warebuycount) ‘’用于计算客户购买的商品种类
  Response.Cookies("warebuycount").domain=application("wareurl")
  Response.Cookies("warebuycount").expires=date()+30
  Response.Cookies("warebuycount").path="/"
  Response.Cookies("warebuycount").secure=false
  Response.Cookies("warebuycount")=warebuycount
end sub

‘’写入COOKIES
sub setcookies(warenum,warename,price,warecount,pricelow,warebuycount)
  setcookie "warenum"+Cstr(warebuycount),warenum,warename,price,warecount,pricelow
end sub

sub delcookies(delwarenum)
    warebuycount=Request("warebuycount")-1
    while Cint(delwarenum)<=Cint(warebuycount)
        setcookies Request.Cookies("warenum"+Cstr(delwarenum+1))("warenum"),Request.Cookies("warenum"+Cstr(delwarenum+1))("warename"),Request.Cookies("warenum"+Cstr(delwarenum+1))("price"),Request.Cookies("warenum"+Cstr(delwarenum+1))("warecount"),Request.Cookies("warenum"+Cstr(delwarenum+1))("pricelow"),delwarenum
        delwarenum=delwarenum+1
    wend
    setcount warebuycount
end sub

warenum=Request.QueryString("warenum") ‘’从GET返回的商品编号,当然,这个商品也一定要存在于你的商品表中
warename=Request.QueryString("warename") ‘’从GET返回的商品名称
price=Request.querystring("price") ‘’价格
warecount=Request.QueryString("warecount") ‘’购买数量
pricelow=Request.QueryString("pricelow") ‘’会员价格
‘’setcount 4

warebuycount=Request.Cookies("warebuycount")
‘’Response.Write warebuycount
if Request.ServerVariables("REQUEST_METHOD")="POST" then
    dum=request("del")
    dim delnum
    delnum=split(dum,",")
    T1=1
    warebuycount=Request.Cookies("warebuycount")
    while T1<=Cint(warebuycount)
        tm=request("warenum"+Cstr(T1))
        rm="warenum"+Cstr(T1)
        nomodi=false
        if tm="" then
            tm=0
        end if
        if instr(1,Cstr(tm),".") or tm=0 then
            nomodi=true
        else
                 setcookies Request.Cookies("warenum"+Cstr(T1))("warenum"),Request.Cookies("warenum"+Cstr(T1))("warename"),Request.Cookies("warenum"+Cstr(T1))("price"),tm,Request.Cookies("warenum"+Cstr(T1))("pricelow"),T1
        end if
        T1=T1+1
    wend
    if dum<>"" then
        Cwarenum=0
        while Cwarenum<=ubound(delnum)
            delcookies delnum(Cwarenum)-Cwarenum
            Cwarenum=Cwarenum+1
        wend
        ‘’setcount Request.Cookies("warebuycount")-(ubound(delnum)+1)
    end if
else
  if warenum<>"" then
      warebuycount=Request.Cookies("warebuycount")
    if warebuycount="" then
        warebuycount=0
    else
        if warebuycount<0 then
            warebuycount=0
        end if
    end if
    i=1
    allready=false
    ‘’Response.Write warebuycount
    ‘’Response.End
    while i<=Cint(warebuycount)
        tsf="warenum"+trim(Cstr(i))
        if Request.Cookies(tsf)("warenum")=warenum then
            allready=true
            mut=Request.Cookies(tsf)("warecount")
            mtp=i
        end if
        i=i+1
    wend

    if allready=false then
      warebuycount=warebuycount+1
    end if
    
    if pricelow="" then
        pricelow=0
    end if
  

    if allready=false then
        setcookies  warenum,warename,price,warecount,pricelow,warebuycount
    else
        setcookies warenum,warename,price,warecount+Cint(mut),pricelow,mtp
    end if
    setcount warebuycount
    
  end if
  
end if
‘’T=1
‘’ while T<20
‘’    setcookies "warenum"+Cstr(T),"","","","",""
‘’    T=T+1
‘’  wend
‘’  setcount 0
‘’  Response.Write request.cookies("warebuycount")
‘’Response.End

warebuycount=Request.Cookies("warebuycount")
‘’Response.Write warebuycount
‘’Response.Write Request.Cookies("warenum1")+"+"
‘’Response.Write Request.Cookies("warenum2")+"+"
‘’Response.Write Request.Cookies("warenum3")+"+"
‘’Response.Write request.cookies("warenum4")+"+"
‘’Response.Write "fdas"
‘’Response.Write Request.Cookies("warebuycount")
‘’Response.End
‘’Response.Write warebuycount
‘’Response.Write Request.Cookies("price1")


‘’检测客户端是否打开COOKIE功能
  Response.Cookies("checkcookie").domain=application("wareurl")
  Response.Cookies("checkcookie").expires=date()+30
  Response.Cookies("checkcookie").path="/"
  Response.Cookies("checkcookie").Secure = FALSE
  Response.Cookies("checkcookie")="ok"
  if Request.Cookies("checkcookie")="" then
    Response.Write "你的浏览器不支持COOKIE功能或者你没有启用COOKIE能,请你先进行设置然后再购买商品,谢谢!"
    Response.End
  end if
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

%>

<html>
<head>
<script language=javascript>
<!--
function Wopen(){
    window.open("warejs.asp","warejs","menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=1,resizable=0,width=800,top=0,left=0,height=500");
    window.close();
    }
-->
</script>
<meta NAME="GENERATOR" Content="Microsoft FrontPage 3.0">
<title>购物车</title>
<link rel="stylesheet" type="text/css" href="boyi-sheet.css">
</head>

<body>
<%‘’  Response.Write warebuycount%>
<table border="0" width="100%" cellspacing="1" cellpadding="4" bgcolor="#ffc184"
height="82">
  <tr>
    <td width="12%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">商品名称</td>
    <td width="12%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">零售价</td>
    <td width="12%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">会员价</td>
    <td width="12%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">数量</td>
    <td width="13%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">零售价小计</td>
    <td width="13%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">会员价小计</td>
    <td width="13%" bgcolor="#008080" style="COLOR: rgb(255,255,255)" align="middle" nowrap
    
    height="14">取消购买</td>
  </tr><form action="lookware.asp" name="modiware" method="POST" ><input type=hidden name="warecount" value="<%=warebuycount%>">
  <%
  Tcou=1
  pricetot=0
  pricelowtot=0
‘’Response.Write warebuycount
   while Tcou<=Cint(warebuycount) %>
  <tr>
    <td width="12%" bgcolor="#f5fade" align="middle" nowrap height="25"><%if tcou=warebuycount then%><font color=red><%end if%><%=Request.Cookies("warenum"+Cstr(Tcou))("warename")%><%if tcou=warebuycount then%><font color=red><%end if%></td>
    <td width="12%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"><font
    color="red">¥</font><%=Request.Cookies("warenum"+Cstr(Tcou))("price")%></p></td>
    <td width="12%" bgcolor="#f5fade" align="middle" nowrap height="25"><font color="red"><p
    align="left">¥</font><%=Request.Cookies("warenum"+Cstr(Tcou))("pricelow")%></P></td>
    <td width="12%" bgcolor="#f5fade" align="middle" nowrap height="25"><input id="text1"
    name="<%="warenum"+Cstr(Tcou)%>" style="HEIGHT: 22px; WIDTH: 33px" value="<%=Request.Cookies("warenum"+Cstr(Tcou))("warecount")%>"></td>
    <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"><font
    color="red">¥</font><%=Request.Cookies("warenum"+Cstr(Tcou))("price")*Request.Cookies("warenum"+Cstr(Tcou))("warecount")%></p></td>
    <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"><font
    color="red">¥</font><%=Request.Cookies("warenum"+Cstr(Tcou))("pricelow")*Request.Cookies("warenum"+Cstr(Tcou))("warecount")%></p></td>
    <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><input id="checkbox1"
    name="del" type="checkbox" value="<%=Cstr(Tcou)%>"> </td>
  </tr><%
  pricetot=pricetot+Request.Cookies("warenum"+Cstr(Tcou))("price")*Request.Cookies("warenum"+Cstr(Tcou))("warecount")
  ‘’Response.Write Request.Cookies("warenum"+Cstr(Tcou))("price")
  pricelowtot=pricelowtot+Request.Cookies("warenum"+Cstr(Tcou))("pricelow")*Request.Cookies("warenum"+Cstr(Tcou))("warecount")
  Tcou=Tcou+1
  ‘’Response.Write Tcou
  ‘’Response.Write warebuycount
  wend%>
  <tr>
        <td width="63%" bgcolor="#f5fade" align="right" nowrap height="25" colspan="4">总计:</td>
        <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"><font color="red">¥</font><%=pricetot%></td>
        <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"><font color="red">¥</font><%=pricelowtot%></td>
        <td width="13%" bgcolor="#f5fade" align="middle" nowrap height="25"><p align="left"></td>
  </tr>
  <tr>
    <td width="87%" align="middle" nowrap height="13" colspan="7" bgcolor="#f5fade"><table
    border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="19%" align="middle"><INPUT id=button1 name=button1 style="BACKGROUND-COLOR: orange; HEIGHT: 24px; WIDTH: 58px" type=button value=继续购物 onclick="window.close()"></td>
        <td width="20%" align="middle"><INPUT id=button2 name=button2 style="BACKGROUND-COLOR: orange; HEIGHT: 24px; WIDTH: 59px" type=submit value=修改数量></td>
        <td width="20%" align="middle"><INPUT id=button3 name=button3 style="BACKGROUND-COLOR: orange; HEIGHT: 24px; WIDTH: 58px" type=submit value=取消购买></td>
        <td width="20%" align="middle"><INPUT id=button4 name=button4 style="BACKGROUND-COLOR: orange; HEIGHT: 24px; WIDTH: 60px" type=button value=清空购物车 onclick="javascript:document.location=‘’clearcar.asp‘’"></td>
        <td width="20%" align="middle"><INPUT id=button5 name=button5 style="BACKGROUND-COLOR: orange; HEIGHT: 24px; WIDTH: 56px" type=button value=去收银台 onclick="javascript:Wopen()"></td>
      </tr>
    </table>
    </td>
  </tr></form>
   <tr>
    <td width="87%" align="middle" nowrap height="13" colspan="7" bgcolor="#f5fade"><font color=red><%if nomodi=true then%>商品数量修改失败!请输入正确的数字。<%else%>数据修改成功!<%end if%></font></td></tr>
</table>
</body>
</html>

原文转自:http://www.ltesting.net