优惠网 > 优惠大全 > 求一个购物车项目设计源代码

求一个购物车项目设计源代码

作者:优优 | 分类:优惠大全 | 浏览量:85
发表时间:2025-03-23 07:20:39
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;using System.Collections;public partial class AddCar : System.Web.UI.Page{ DataAccess db = new DataAccess(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request.QueryString[ id ].ToString(); if (Session[ car ] != null) { Hashtable hash = Session[ car ] as Hashtable; if (!hash.ContainsKey(id)) { hash.Add(id, 1); } else { hash[id] = int.Parse(hash[id].ToString()) + 1; } Session[ car ] = hash; } else { Hashtable hash = new Hashtable(); hash.Add(id, 1); Session[ car ] = hash; } Hashtable k = Session[ car ] as Hashtable; DataColumn dc0 = new DataColumn( id , typeof(string)); DataColumn dc1 = new DataColumn( 商品名 , typeof(string)); DataColumn dc2 = new DataColumn( 价格 , typeof(float)); DataColumn dc3 = new DataColumn( 数量 , typeof(int)); DataColumn dc4 = new DataColumn( 总价格 , typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+ +i.Value+ <br> ); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet( select * from product where p_id= + i.Key); dr[ id ] = ds.Tables[0].Rows[0][ p_id ].ToString(); dr[ 商品名 ] = ds.Tables[0].Rows[0][ p_name ].ToString(); dr[ 价格 ] = ds.Tables[0].Rows[0][ p_price ].ToString(); dr[ 数量 ] = int.Parse(k[i.Key].ToString()); dr[ 总价格 ] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0][ p_price ].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect( default2.aspx ); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); Hashtable k = Session[ car ] as Hashtable; Session[ car ] = k; k.Remove(id); DataColumn dc0 = new DataColumn( id , typeof(string)); DataColumn dc1 = new DataColumn( 商品名 , typeof(string)); DataColumn dc2 = new DataColumn( 价格 , typeof(float)); DataColumn dc3 = new DataColumn( 数量 , typeof(int)); DataColumn dc4 = new DataColumn( 总价格 , typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+ +i.Value+ <br> ); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet( select * from product where p_id= + i.Key); dr[ id ] = ds.Tables[0].Rows[0][ p_id ].ToString(); dr[ 商品名 ] = ds.Tables[0].Rows[0][ p_name ].ToString(); dr[ 价格 ] = ds.Tables[0].Rows[0][ p_price ].ToString(); dr[ 数量 ] = int.Parse(k[i.Key].ToString()); dr[ 总价格 ] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0][ p_price ].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } protected void Button2_Click(object sender, EventArgs e) { Hashtable k = Session[ car ] as Hashtable; string code = DateTime.Now.Ticks.ToString() + new Random().Next(); db.ExecuteNonQuery( insert into OrderList values( +code+ ) ); foreach(DictionaryEntry i in k) { db.ExecuteNonQuery( insert into DetailsList values( +code+ , +Session[ u_id ].ToString()+ , +i.Key+ , +i.Value+ ) ); } }}自己慢慢领悟把%D%A

粤ICP备2024332802号-3 | 优惠信息大全 | Sitemap
深圳市华诚易配电子商务有限公司 旗下网站
本站内容由AI生成或转载自网络,如有版侵,请与我们联系