《购物车代码(5页).doc》由会员分享,可在线阅读,更多相关《购物车代码(5页).doc(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-购物车代码-第 5 页 这是一个ASP.net购物车的代码程序. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; publ
2、ic partial class cart : System.Web.UI.Page public MyDb dd = new MyDb(); public string AddProID; protected string RefreshID; / public string total; protected void Page_Load(object sender, EventArgs e) if (!Page.IsPostBack) /if (RefreshID = ) / RefreshID =System.DateTime.Now.Ticks.ToString(); if (Requ
3、est.Paramsmode = view) /检测是否为直接查看购物车。 ViewShoppingCart(); Caculator(); if (Request.ParamsproductID != null | Request.ParamsproductID != ) this.rnd.Text = Requestitem; AddProID = RequestproductID; UpdateShoppingCart(); Caculator(); public void CreateCartTable() /创建购物车 DataSet ds = new DataSet(); Data
4、Table newDT = new DataTable(CartTable); ds.Tables.Add(newDT); DataColumn newDC; newDC = new DataColumn(ProductID, System.Type.GetType(System.Int32); ds.TablesCartTable.Columns.Add(newDC); newDC = new DataColumn(Name, System.Type.GetType(System.String); newDC.DefaultValue = 1; ds.TablesCartTable.Colu
5、mns.Add(newDC); newDC = new DataColumn(max, System.Type.GetType(System.String); ds.TablesCartTable.Columns.Add(newDC); newDC = new DataColumn(Unit, System.Type.GetType(System.String); ds.TablesCartTable.Columns.Add(newDC); newDC = new DataColumn(SellPrice, System.Type.GetType(System.Int32); ds.Table
6、sCartTable.Columns.Add(newDC); newDC = new DataColumn(IsDeleted, System.Type.GetType(System.Int32); newDC.DefaultValue = 0; ds.TablesCartTable.Columns.Add(newDC); SessionmyCartTable = newDT; ShoppingCartDlt.DataSource = ds.TablesCartTable.DefaultView; ShoppingCartDlt.DataBind(); public void UpdateSh
7、oppingCart() if (SessionmyCartTable = null)/SessionmyCartTable=null CreateCartTable(); /调用函数CreateCartTable()新建一个DataTable WriteShoppingCart(); else /如果购物蓝中已有商品,则需要对购物信息表DataTable进行更新,并将其棒定到 ShoppingCartDlt WriteShoppingCart(); public void ViewShoppingCart() /查看购物车 if (SessionmyCartTable != null) DataTable viewTable = new DataTable(nowCartTable); viewTable = (DataTable)SessionmyCartTable; ShoppingCartDlt.DataSource = viewTable.DefaultView; /购物车棒定到ShoppingCartDlt ShoppingCartDlt.DataBind();