asp.net 实现购物车详细代码

本文介绍了一个基于ASP.NET和C#实现的简单购物车系统,包括添加商品、更新购物车和结算等功能。通过实例展示了如何操作Session状态来维护用户的购物车信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

ExpandedBlockStart.gifContractedBlock.gif<%dot.gif@ Page language="c#" Codebehind="shoppingcart.aspx.cs" AutoEventWireup="false" Inherits="myshop.shoppingcart" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> 
None.gif
<title>shoppingcart 
None.gif
</title> 
None.gif
<meta http-equiv="Content-Type" content="text/html; 
None.gifcharset=gb2312"
> <LINK href="mycss.css" type="text/css" rel="stylesheet"> 
None.gif
<meta name="vs_defaultClientScript" content="JavaScript"> 
None.gif
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> 
None.gif
<body> <center> 
None.gif
<form id="Form1" runat="server"> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td> 
None.gif
<asp:DataGrid id="ShoppingCartDlt" runat="server" Width="500" BackColor="white" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#cecfd6" AutoGenerateColumns="false" MaintainState="true"> <Columns> 
None.gif
<asp:TemplateColumn HeaderText="删除"> 
None.gif
<ItemTemplate> <center> 
None.gif
<asp:CheckBox id="chkProductID" runat="server" /> </center> 
None.gif
</ItemTemplate> </asp:TemplateColumn> 
None.gif
<asp:BoundColumn DataField="ProdID" HeaderText="ID" /> 
None.gif
<asp:BoundColumn DataField="ProName" HeaderText="商品名称" /> 
None.gif
<asp:BoundColumn DataField="UnitPrice" HeaderText="单价" /> 
None.gif
<asp:TemplateColumn HeaderText="数量"> 
None.gif
<ItemTemplate> 
None.gif
<asp:TextBox id="CountTb" runat="server" Text='<%#DataBinder.Eval( Container.DataItem,"ProdCount" )%>'> </asp:TextBox> 
None.gif
</ItemTemplate> </asp:TemplateColumn> 
None.gif
<asp:BoundColumn DataField="TotalPrice" HeaderText="小计( 元 )" /> </Columns> </asp:DataGrid></td> </tr> </table> <br> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td> 
None.gif
<asp:Button id="update" runat="server" Text="更新我的购物车" CssClass="button2" /></td> <td> 
None.gif
<asp:Button id="CheckOut" runat="server" Text="结算" CssClass="button5" /> 
None.gif
None.gif
<input type="button" name="close2" value="继续购物" onClick="window.close( ); 
None.gifreturn false; 
None.gif"
 class="button2"></td> <td align="right"><br> 
None.gif
<asp:Label id="label" runat="server" Width="100px" Visible="True" ForeColor="#FF8080" Height="18px"></asp:Label></td> </tr> </table> 
None.gif
</form> </center> 
None.gif
</body></HTML>
None.gifusing System; 
None.gif
using System.Collections; 
None.gif
using System.ComponentModel; 
None.gif
using System.Web.SessionState; 
None.gif
using System.Web; 
None.gif
using System.Web.UI; 
None.gif
using System.Web.UI.HtmlControls; 
None.gif
using System.Web.UI.WebControls; 
None.gif
using System.Data; 
None.gif
using System.Data.OleDb; 
None.gif
using System.Configuration; 
None.gif
namespace myshop 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary> /// shoppingcart 的摘要说明. /// </summary> public class shoppingcart : System.Web.UI.Page 
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif
InBlock.gif
protected System.Web.UI.WebControls.DataGrid ShoppingCartDlt; 
InBlock.gif
protected System.Web.UI.WebControls.Button update; 
InBlock.gif
protected System.Web.UI.WebControls.Button CheckOut; 
InBlock.gif
protected System.Web.UI.HtmlControls.HtmlForm Form1; 
InBlock.gif
protected System.Web.UI.WebControls.Label label; 
InBlock.gif
protected System.Web.UI.WebControls.CheckBox chkProductID; 
InBlock.gif
protected System.Web.UI.WebControls.TextBox txtCount; 
InBlock.gif
protected System.Web.UI.WebControls.TextBox CountTb; 
InBlock.gif
string AddProID; 
InBlock.gif
private void Page_Load( object sender, System.EventArgs e ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if ( Session["logon"]!="yes"  Session["username"]==null ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifResponse.Redirect( 
"error.htm" ) ; 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
catch 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifResponse.Redirect( 
"error.htm" ) ; 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//////////////查看用户是否已经登陆. 
InBlock.gifif!IsPostBack ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if( Request.Params["mode"]=="view" ) //检测是否为直接查看购物车. 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifViewShoppingCart( ); 
InBlock.gifCaculator( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
if( Request.Params["productID"]!=null  Request.Params["productID"]!="" ) 
InBlock.gif
InBlock.gif
using System.Web; 
InBlock.gif
using System.Web.UI; 
InBlock.gif
using System.Web.UI.HtmlControls; 
InBlock.gif
using System.Web.UI.WebControls; 
InBlock.gif
using System.Data; 
InBlock.gif
using System.Data.OleDb; 
InBlock.gif
using System.Configuration; 
InBlock.gif
namespace myshop 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary> /// shoppingcart 的摘要说明. /// </summary> public class shoppingcart : System.Web.UI.Page 
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif
InBlock.gif
protected System.Web.UI.WebControls.DataGrid ShoppingCartDlt; 
InBlock.gif
protected System.Web.UI.WebControls.Button update; 
InBlock.gif
protected System.Web.UI.WebControls.Button CheckOut; 
InBlock.gif
protected System.Web.UI.HtmlControls.HtmlForm Form1; 
InBlock.gif
protected System.Web.UI.WebControls.Label label; 
InBlock.gif
protected System.Web.UI.WebControls.CheckBox chkProductID; 
InBlock.gif
protected System.Web.UI.WebControls.TextBox txtCount; 
InBlock.gif
protected System.Web.UI.WebControls.TextBox CountTb; 
InBlock.gif
string AddProID; 
InBlock.gif
private void Page_Load( object sender, System.EventArgs e ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
try 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if ( Session["logon"]!="yes"  Session["username"]==null ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifResponse.Redirect( 
"error.htm" ) ; 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
catch 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifResponse.Redirect( 
"error.htm" ) ; 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//////////////查看用户是否已经登陆. 
InBlock.gifif!IsPostBack ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if( Request.Params["mode"]=="view" ) //检测是否为直接查看购物车. 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifViewShoppingCart( ); 
InBlock.gifCaculator( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
if( Request.Params["productID"]!=null  Request.Params["productID"]!="" ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifAddProID
=Request["productID"]; 
InBlock.gifUpdateShoppingCart( ); 
InBlock.gifCaculator( ); 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
// 在此处放置用户代码以初始化页面 
ExpandedSubBlockEnd.gif
}
 
InBlock.gif
public void CreateCartTable( ) //创建购物车 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifDataSet ds 
= new DataSet( ); 
InBlock.gifDataTable newDT
=new DataTable( "CartTable" ); 
InBlock.gifds.Tables.Add( newDT ); 
InBlock.gifDataColumn newDC; 
InBlock.gifnewDC
=new DataColumn( "ProdID",System.Type.GetType( "System.Int32" ) ); 
InBlock.gifds.Tables[
"CartTable"].Columns.Add( newDC ); 
InBlock.gifnewDC
=new DataColumn( "ProdCount",System.Type.GetType( "System.Int32" ) ); 
InBlock.gifnewDC.DefaultValue
=1
InBlock.gifds.Tables[
"CartTable"].Columns.Add( newDC ); 
InBlock.gifnewDC
=new DataColumn( "ProName",System.Type.GetType( "System.String" ) ); 
InBlock.gifds.Tables[
"CartTable"].Columns.Add( newDC ); 
InBlock.gifnewDC
=new DataColumn( "UnitPrice",System.Type.GetType( "System.Double" ) ); 
InBlock.gifds.Tables[
"CartTable"].Columns.Add( newDC ); 
InBlock.gifnewDC
=new DataColumn( "TotalPrice",System.Type.GetType( "System.Double" ) ); 
InBlock.gifds.Tables[
"CartTable"].Columns.Add( newDC ); 
InBlock.gifnewDC
=new DataColumn( "IsDeleted",System.Type.GetType( "System.Int32" ) ); 
InBlock.gifnewDC.DefaultValue
=0
InBlock.gif
// public void WriteShoppingCart( ) 中 newDR[5]="0"; 
InBlock.gif
行,已被注销, ds.Tables["CartTable"].Columns.Add( newDC ); 
InBlock.gifSession[
"myCartTable"]=newDT; 
InBlock.gifShoppingCartDlt.DataSource
=ds.Tables["CartTable"].DefaultView; 
InBlock.gifShoppingCartDlt.DataBind( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public void UpdateShoppingCart( ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if( Session["myCartTable"]==null )//Session["myCartTable"]==null 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifCreateCartTable( ); 
InBlock.gif
//调用函数CreateCartTable( )新建一个DataTable WriteShoppingCart( ); 
ExpandedSubBlockEnd.gif
}
 
InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
//如果购物蓝中已有商品,则需要对购物信息表DataTable进行更新,并将其棒定到ShoppingCartDlt WriteShoppingCart( ); 
ExpandedSubBlockEnd.gif
}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public void ViewShoppingCart( ) //查看购物车 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gifif( Session["myCartTable"]!=null ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifDataTable viewTable
=new DataTable( "nowCartTable" ); 
InBlock.gifviewTable
=( DataTable )Session["myCartTable"]; 
InBlock.gifShoppingCartDlt.DataSource 
= viewTable.DefaultView; 
InBlock.gif
//购物车棒定到ShoppingCartDlt ShoppingCartDlt.DataBind( ); 
ExpandedSubBlockEnd.gif
}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public void WriteShoppingCart( ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if( Request.Params["mode"]!="view" ) //检查是否是直接查看购物车,如果直接查看,就不再写MYCARTTABLE 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifDataTable nowTable
=new DataTable( "nowCartTable" ); 
InBlock.gifnowTable
=( DataTable )Session["myCartTable"]; 
InBlock.gif
int pn=nowTable.Rows.Count; 
InBlock.gif
int i=0
InBlock.gif
bool hasone=false
InBlock.gif
int nowProdID; 
InBlock.gif
while( i<pn && !hasone ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifnowProdID
=Int32.Parse( nowTable.Rows[i][0].ToString( ) ); 
InBlock.gif
if( nowProdID==Int32.Parse( AddProID ) ) //判断购物信息表中,是否存有当前放入商品. if( nowProdID==Int32.Parse( AddProID ) ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifhasone
=true
ExpandedSubBlockEnd.gif}
 
InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifi
++
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
if( hasone ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
//如果已有该商品,则 hasone=true,更改该数据行 DataRow oldDR; 
InBlock.gif
oldDR=nowTable.Rows[i]; 
InBlock.gifoldDR[
"ProdCount"]=Int32.Parse( oldDR["ProdCount"].ToString( ) )+1
InBlock.gifoldDR[
"TotalPrice"]=Int32.Parse( oldDR["ProdCount"].ToString( ) )*Double.Parse( oldDR["UnitPrice"].ToString( ) ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
//如果没有该商品,在表中新加如一行. DataRow newDR; 
InBlock.gif
double unitp; 
InBlock.gifString strcon
="provider=Microsoft.jet.OLEDB.4.0; 
InBlock.gif
data Source="+Server.MapPath( ConfigurationSettings.AppSettings["MDBpath2"] )+"
InBlock.gif
"
InBlock.gif
OleDbConnection myConnection = new OleDbConnection( strcon ); 
InBlock.gif
string strSQL= "select * from pro where product_id="+AddProID+""
InBlock.gifOleDbDataAdapter myCommand 
= new OleDbDataAdapter( strSQL, myConnection ); 
InBlock.gifDataSet ds 
= new DataSet( ); 
InBlock.gifmyCommand.Fill( ds, 
"AddP" ); 
InBlock.gifnewDR
=nowTable.NewRow( ); 
InBlock.gifnewDR[
0]=AddProID; 
InBlock.gifnewDR[
2]=ds.Tables["Addp"].Rows[0]["product_name"].ToString( ); 
InBlock.gifunitp
=Double.Parse( ds.Tables["AddP"].Rows[0]["product_memprice"].ToString( ) ); 
InBlock.gif
//会员价 newDR[3]=unitp; 
InBlock.gif
newDR[4]=unitp; 
InBlock.gif
//第一次读库,所以总价格和单价是一样的. //newDR[5]="0"; 
InBlock.gif
nowTable.Rows.Add( newDR ); 
InBlock.gifmyConnection.Close( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gifShoppingCartDlt.DataSource 
= nowTable.DefaultView; 
InBlock.gif
//将更新后的 DataTable棒定到ShoppingCartDlt ShoppingCartDlt.DataBind( ); 
InBlock.gif
Session["myCartTable"= nowTable; 
InBlock.gif
//重新保存更新过的DataTable 
ExpandedSubBlockEnd.gif
}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public void Caculator( ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
if( Session["myCartTable"]!=null ) //购物车是否为空 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
int h; 
InBlock.gifDouble TotalPri; 
InBlock.gifTotalPri
=0
InBlock.gifDataTable nowTable3
=new DataTable( "nowCartTable3" ); 
InBlock.gifnowTable3
=( DataTable )Session["myCartTable"]; 
InBlock.gif
if( nowTable3.Rows.Count>0 ) //返回购物车中是否有货物 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
for( h=0
InBlock.gifh
<=nowTable3.Rows.Count-1
InBlock.gifh
++ ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifTotalPri
=TotalPri+Int32.Parse( nowTable3.Rows[h][4].ToString( ) ); 
InBlock.gif
//Double.Parse( ( string )TotalText.Text ); 
ExpandedSubBlockEnd.gif
}
 
InBlock.giflabel.Text
="总计: "+TotalPri.ToString( )+" 元" ; 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
public void Update( ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
int i; 
InBlock.gif
int j; 
InBlock.gif
int k; 
InBlock.gifArrayList deleteItem 
= new ArrayList( 10 ); 
InBlock.gifDataGridItem _item ; 
InBlock.gifj
=0
InBlock.gif
int deleteid; 
InBlock.gifk
=0
InBlock.gifDataTable nowTable2
=new DataTable( "nowCartTable2" ); 
InBlock.gifnowTable2
=( DataTable )Session["myCartTable"]; 
InBlock.gif
for( i=0
InBlock.gifi
<=this.ShoppingCartDlt.Items.Count-1
InBlock.gifi
++ ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif_item 
= this.ShoppingCartDlt.Items[i]; 
InBlock.gifTextBox CountText
=( TextBox )this.ShoppingCartDlt.Items[i].Cells[4].FindControl( "CountTb" ); 
InBlock.gif
//Controls[1]; 
InBlock.gif
//_item.FindControl( "CountTb" ); 
InBlock.gif
CheckBox ProductIDCheck =( CheckBox ) _item.FindControl( "chkProductID" ); 
InBlock.gifnowTable2.Rows[i][
1= Int32.Parse( CountText.Text.ToString( ) ); 
InBlock.gifnowTable2.Rows[i][
4= Int32.Parse( nowTable2.Rows[i][1].ToString( ) ) * Double.Parse( nowTable2.Rows[i][3].ToString( ) ); 
InBlock.gif
if( ProductIDCheck.Checked ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifnowTable2.Rows[i][
5= 1
InBlock.gif
//添加删除标记1 j=j+1; 
ExpandedSubBlockEnd.gif
}
 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
string strExpr="IsDeleted>0"
InBlock.gif
//http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfSystemDataDataTableClassSelectTopic.asp DataRow[] foundRows = nowTable2.Select( strExpr ); 
InBlock.gif
forint m = 0
InBlock.gif
< foundRows.Length; 
InBlock.gif
++ ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
//Console.WriteLine( foundRows[i][0] ); 
InBlock.gif
foundRows[m].Delete( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gifShoppingCartDlt.DataSource 
= nowTable2.DefaultView; 
InBlock.gifShoppingCartDlt.DataBind( ); 
InBlock.gifSession[
"myCartTable"= nowTable2; 
InBlock.gifCaculator( ); 
ExpandedSubBlockEnd.gif}
 
ContractedSubBlock.gifExpandedSubBlockStart.gif
Web 窗体设计器生成的代码 override protected void OnInit( EventArgs e )#region Web 窗体设计器生成的代码 override protected void OnInit( EventArgs e ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
// // CODEGEN: 该调用是 asp.NET Web 窗体设计器所必需的. // InitializeComponent( ); 
InBlock.gif
base.OnInit( e ); 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容. /// </summary> private void InitializeComponent( ) 
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif
InBlock.gif
this.update.Click += new System.EventHandler( this.update_Click ); 
InBlock.gif
this.CheckOut.Click += new System.EventHandler( this.CheckOut_Click ); 
InBlock.gif
this.Load += new System.EventHandler( this.Page_Load ); 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif
#endregion
 
InBlock.gif
private void update_Click( object sender, System.EventArgs e ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifUpdate( ); 
ExpandedSubBlockEnd.gif}
 
InBlock.gif
private void CheckOut_Click( object sender, System.EventArgs e ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gifUpdate( ); 
InBlock.gifResponse.Redirect( 
"checkout.aspx" ); 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockEnd.gif}

转载于:https://www.cnblogs.com/hzuIT/articles/713149.html

使用: 第1 '================================================= '建立购物车对象,该对象用于直接在程序中调用 '================================================= dim uCart set uCart= new UserCart 第二 建立一个购物车 uCart.CreateCart (可以重复建立,因为里面有IsArray判断。所以建议这句在建立购物车对象后必写) 第三 增加购物车里的商品,在客户端点了某产品后,服务器端处理的ASP文件中接受传过来的产品标志,并访问数据库。分别把AddItem(aID产品标 志如ID,aName产品名称,aPrice1产品价格一,如单价,aPrice2产品价格二如会员价,aPrice3产品价格三如金牌会员价,如果没这么多可以置空 或置0,aCount购买数量,一般是一个,多个的话后面可以用修改函数修改,aImage产品图片地址) 使用方法:aa=uCart.AddItem(aID产品标志如ID,aName产品名称,aPrice1产品价格一,如单价,aPrice2产品价格二如会员价,aPrice3产品价格 三如金牌会员价,如果没这么多可以置空或置0,aCount购买数量,一般是一个,多个的话后面可以用修改函数修改,aImage产品图片地址),返回 true表示成功,false表示失败 第四 增加了以后进如显示页面,就要用到查看购物车 mycart=uCart.ViewCart() For i =LBound(myCart,2) to UBound(myCart,2) if myCart(0,i)"" then myCart(0,i) '获取标号 myCart(1,i) '获取单价 。。。以此类推 end if next 第五 查看了,可以修改购物车,如更改数量等,或是删除其中的 call uCart.ModifItem(mID唯一标志号,mCount产品数量,mFlag-标志 0-添加 1-删除,2-修改 3-清空) '先用给后面参数赋值 修改其中的商品 可以用第四个显示,先接受session的值,然后循环修改 或清空购物车 uCart.RemoveAll() 然后结帐,很简单 myprice=uCart.TPrice() 然后myprice(0)是产品单价的总价格,myprice(1)是产品会员价的总价格,myprice(2)是高级会员的总价格,myprice(3)是产品总数量 将商品装入购物车,这时需要用cookie或session来做一个不同页面间传递的全局变量,也就是说关了浏览器(针对session)或清楚了cookie等原因,本次购物车会消失,就象你今天在商场买了一车的东西,最后没结帐,明天肯定没了,又归位了,当然要有特殊需要保存,可以写数据库!所以这里记录的只需要是该商品的相关信息就可以了,这里我们记录他的 物品ID, 物品单价, 物品名称, 物品数量
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值