using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class ShoppingCart : System.Web.UI.Page { public double totle_fee; public static string UserID = null; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } } protected void Bind() { totle_fee = 0; #region string UserName; try { System.Data.DataTable dt = (DataTable)Session["member"]; UserName = dt.Rows[0].ToString(); } catch { //Response.Redirect("default.aspx"); PublicClass.AlertClass.Alert("请登录后再进行相关的操作.", "Login.aspx"); } if (Request.QueryString["p"] != null) { UserID = Request.QueryString["p"].ToString(); string sqlstr = "select shangpin.id as PID ,shangpin.spec as spec, car.amount as amount, shangpin.vip_price_rmb as price, pic.[FileName] as [FileName], shangpin.trade_name_cn as name_cn " + " from v3_shoppingcar as car left join v3_Pic_path as pic on car.pid = pic.pid " + "left join v3_merchandises as shangpin on shangpin.pid =car.pid where car.Cid = '" + UserID + "' and pic .show=1"; DataSet ds = new common().ExcuteReader(sqlstr); //dt = ds.Tables[0]; if (ds.Tables[0].Rows.Count > 0) { Repeater1.DataSource = ds; Repeater1.DataBind(); this.Panel1.Visible = false; this.Repeater1.Visible = true; Session["FreRme0"] = totle_fee; } else { this.Repeater1.Visible = false; this.Panel1.Visible = true; } } #endregion } protected string GetidBypic(string pid) { string sqltr = "select pid from v3_merchandises where id =" + pid; return new common().ExcuteReader(sqltr).Tables[0].Rows[0][0].ToString(); } /// /// 删除单个商品 /// /// /// protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "del") { string delBypic = "delete from v3_shoppingcar where cid = '" + UserID + "' and pid = " + GetidBypic(e.CommandArgument.ToString()); if (new common().ExcuteNoneQuery(delBypic, null)) { Bind(); } else { Methods1.Methods1.Alert(this, "删除失败!"); } } } /// /// 提交订单 /// /// /// protected void BtnJiesuan_Click(object sender, EventArgs e) { if (Panel1.Visible == true) { Methods1.Methods1.MsgBox("您还没有选购商品!!", "List.aspx"); } else { string sqlstr = " insert into v3_pay_the_bill(cID,aggregate_amount ,save_amount ,delivery_fee,amount_due ,tabdate,IsEnd)values('" + UserID + "','" + totle_fee + "',0,0,'" + totle_fee + "','" + DateTime.Now.ToString() + "',0)"; bool b = new common().ExcuteNoneQuery(sqlstr, null);//是否插入数据成功! if (b) { if (Session["member"] != null) { DataTable dt = (DataTable)Session["member"]; UserID = dt.Rows[0]["cid"].ToString(); } string OID = "D" + DateTime.Now.ToString("yyMMdd") + Convert.ToString(new Random().Next(0, 10000)).PadLeft(8, '0'); Session["dingdan"] = OID; ////收货地址 string sqlstrs = "INSERT INTO v3_order(cid,oid,oname,tel,code,mail,address)values ('" + UserID + "','" + OID + "','','','','','')"; bool result = new common().ExcuteNoneQuery(sqlstrs, null); string SelectPid = " select car.pid as pid, car.amount as [count] from v3_shoppingcar as car where cid = '" + UserID + "'"; DataSet ds = new common().ExcuteReader(SelectPid); bool bs = false; foreach (System.Data.DataRow row in ds.Tables[0].Rows) { //插入ID string InsertItem = " insert into v3_order_Item (cid,pID,OID,amount,IsEnd,EndTime,addtime) values('" + UserID + "','" + row[0].ToString() + "','" + Session["dingdan"].ToString() + " ','" + row[1].ToString() + "',0,0,'" + DateTime.Now.ToString() + "')"; bs = new common().ExcuteNoneQuery(InsertItem, null); } if (b) { string delallGOods = "delete from v3_shoppingcar where cid ='" + UserID + "'"; bool bdelSp = new common().ExcuteNoneQuery(delallGOods, null); //是否删除购物车数据 string DelCle = "update v3_pay_the_bill set Isend =1 where cid = '" + UserID + "'"; bool Cle = new common().ExcuteNoneQuery(DelCle, null); //跟新状态为1 if (bdelSp && Cle) { Response.Redirect("DingDan.aspx?Cid=" + UserID + "&OrderId=" + OID + "&fee=" + common.Encode(Session["FreRme0"].ToString(), "84186899")); } } } } } /// /// 清空购物车 /// /// /// protected void bTNqinGKONG_Click(object sender, EventArgs e) { string delallGOods = "delete from v3_shoppingcar where cid ='" + UserID + "'"; bool b = new common().ExcuteNoneQuery(delallGOods, null); if (b) { Methods1.Methods1.ShowAndRedirect(this, "清空完成,确定后继续购物", "list.aspx"); //Methods1.Methods1.MsgBox("清空完成,确定后继续购物", "list.aspx"); } } }