protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string action = HYRequest.GetQueryString("action"); UserModel userInfo = this.LoginUser; OrderModel myorder = OrderFactory.GetCartOrder(userInfo.uid); if (action == "addtocart") //添加到购物车 { #region ==addtocart== int pid = HYRequest.GetFormInt("pid", 0); int buycount = HYRequest.GetFormInt("buycount", 0); int itemflag = HYRequest.GetFormInt("itemflag", 0); OrderModel myof = myorder; if (myof == null) { myof = new OrderModel(); myof.orderno = Utils.GenerateOutTradeNo(this.LoginUser.uid); myof.uid = userInfo.uid; myof.customername = userInfo.fullname; myof.tel = userInfo.tel; myof.address = userInfo.address; } ProductModel p = ProductFactory.Get(pid); OrderProduct op = new OrderProduct(); op.count = buycount; op.productinfo = p; op.price = p.price; //判断是否有属性 if (itemflag > 0) { int tmpflag = 1; foreach (KeyValuePair <string, decimal> kvp in p.itempricelist) { if (itemflag == tmpflag) { op.item = kvp.Key; op.price = kvp.Value; break; } tmpflag++; } } CheckIsAdd(myof.productlist, op); if (myorder == null) { OrderFactory.Add(myof); } else { OrderFactory.Update(myof); } string json = "{\"shopcount\":" + myof.productlist.Count + ",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; #endregion } else if (action == "addtofav") //添加到收藏夹 { #region ==addtofav== int pid = HYRequest.GetFormInt("pid", 0); bool isfav = FavoriteFactory.IsFavorite(this.LoginUser.uid, pid); if (!isfav) { FavoriteModel fm = new FavoriteModel(); fm.product = ProductFactory.Get(pid); fm.uid = this.LoginUser.uid; fm.productid = pid; FavoriteFactory.Add(fm); } string json = "{\"favtip\":\"已收藏\",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; #endregion } else if (action == "delfav") //删除收藏夹 { int fid = HYRequest.GetFormInt("fid", 0); FavoriteFactory.Delete(fid); } } }