async void Add_To_ShoppingCart(object sender, System.EventArgs e) { HomepageListView.IsVisible = true; var button = sender as Button; var product = button.CommandParameter as Product_Retailer; await conn.CreateTableAsync <shoppingcart>(); //System.Diagnostics.Debug.WriteLine(product.ProductName); var item = new shoppingcart { ProductID = product.ProductID, ProductName = product.ProductName, Price = product.Price, Brand = product.Brand, Category = product.Category, ImageUrl = product.ImageUrl, BigImageUrl = product.BigImageUrl, Description = product.Description, Retailer_Name = product.Retailer_Name, Latitude = product.Latitude, Longitude = product.Longitude }; await conn.InsertAsync(item); await DisplayAlert("Successfully added to Shopping Cart", item.ProductName, "OK"); }
public ActionResult Add_To_Cart(int id) { //Console.WriteLine("Add to wishlist is succesfully called"); int?ProductId; ProductId = id; using (new_testEntities db = new new_testEntities()) { product product = db.product.FirstOrDefault(x => x.ID == id); string userid = "0"; if (Request.IsAuthenticated) { userid = User.Identity.GetUserId(); } shoppingcart shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id && x.UserId == userid); wishlist Wishlist = db.wishlist.FirstOrDefault(x => x.ProductId == id); if (shoppingcart == null) { db.shoppingcart.Add(new shoppingcart { ProductId = Wishlist.ProductId, UserId = User.Identity.GetUserId(), Quantity = Wishlist.Quantity, ProductName = Wishlist.ProductName, Price = Wishlist.Price, Imagepath = Wishlist.Imagepath }); db.SaveChanges(); } else { shoppingcart.Quantity += Wishlist.Quantity; db.SaveChanges(); } return(RedirectToAction("Index", "Shoppingcart")); } }
public ActionResult Minus_To_Cart(int id) { //Console.WriteLine("Add to shoppingcart is succesfully called"); int?ProductId; ProductId = id; using (new_testEntities db = new new_testEntities()) { //user user = db.user.FirstOrDefault(x => x.ID == id); shoppingcart Shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id); Shoppingcart.Quantity -= 1; db.SaveChanges(); if (Shoppingcart.Quantity <= 0) { db.shoppingcart.Remove(Shoppingcart); db.SaveChanges(); } return(RedirectToAction("Index", "Shoppingcart")); } }
public JsonResult AddShopcart(string prodId, int num, string prodPrice) { string res = string.Empty; string userOpenId = base.getUserOpenIdFromCookie(); if (string.IsNullOrEmpty(userOpenId)) { res = "false";//这里可以扩展,可以换成枚举,目前功能不需要 } else { try { ShopCartBiz shopcartBiz = ShopCartBiz.CreateNew(); shoppingcart userShopcart = shopcartBiz.checkProdExistInCarts(userOpenId, prodId); if (userShopcart != null) { int addNum = userShopcart.num + num; shopcartBiz.UpdateProdInCarts(userOpenId, prodId, addNum, prodPrice); } else { shopcartBiz.AddProdInCarts(userOpenId, prodId, num, prodPrice); } res = shopcartBiz.getUserCartsNum(userOpenId).ToString(); } catch (Exception e) { _Apilog.WriteLog("添加购物车异常: " + e.Message); res = "false"; } } return(Json(res)); }
static void Main(string[] args) { Console.WriteLine("Welcome"); Console.WriteLine("Enter your name"); string person_name = Console.ReadLine(); shoppingcart client = new shoppingcart(); Console.ReadKey(); }
public ActionResult Delete(int id) { using (new_testEntities db = new new_testEntities()) { shoppingcart shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id); db.shoppingcart.Remove(shoppingcart); db.SaveChanges(); } return(RedirectToAction("Index", "Shoppingcart")); }
/// <summary> /// 检查购物车中是否有这个商品 /// </summary> /// <param name="userOpenId">用户微信openId</param> /// <param name="prodId">商品Id</param> public shoppingcart checkProdExistInCarts(string userOpenId, string prodId) { shoppingcart queryshoppingcart = new shoppingcart(); using (IDbConnection conn = DapperHelper.MySqlConnection()) { string sqlCommandText = @"SELECT * FROM ShoppingCart WHERE userOpenId=@userOpenId and productId=@productId and status=1 "; queryshoppingcart = conn.Query <shoppingcart>(sqlCommandText, new { userOpenId = userOpenId, productId = prodId }).FirstOrDefault(); } return(queryshoppingcart); }
public int InsertShoppingCart(shoppingcart Shoppingcart) { string sql = "insert into shoppingcart(user_id,goods_id,unit_price,number,total_price)values(@UserID,@GoodsID,@UnitPrice,@Number,@TotalAmount)"; SqlParameter[] para = { new SqlParameter("@UserID", Shoppingcart.user_id), new SqlParameter("@GoodsID", Shoppingcart.goods_id), new SqlParameter("@UnitPrice", Shoppingcart.unit_price), new SqlParameter("@Number", Shoppingcart.number), new SqlParameter("@TotalAmount", Shoppingcart.total_price) }; return(DBHelper.GetExcuteNonQuery(sql, para)); }
public JsonResult CreateOrderFromShopcart(string prodIds) { string userOpenId = base.getUserOpenIdFromCookie(); string res = "fail"; if (!string.IsNullOrEmpty(userOpenId)) { try { //订单付款页面用户回退购物车页面,然后再创单时实际没有商品,规避此类垃圾数据 string[] prods = prodIds.Split(','); bool prodExist = false; for (int i = 0; i < prods.Length; i++) { shoppingcart checkResult = ShopCartBiz.CreateNew().checkProdExistInCarts(userOpenId, prods[i]); if (checkResult != null) { prodExist = true; break; } } if (prodExist) { string salesNo = WxPayApi.GenerateOutTradeNo();// Guid.NewGuid().ToString(); OrderBiz.CreateNew().createOrderFromShopcart(prodIds, userOpenId, salesNo); res = salesNo; } else { res = "noProds"; } } catch (Exception e) { res = "fail"; _Apilog.WriteLog("ProductsController/CreateOrderFromShopcart 异常: " + e.Message); } } else { _Apilog.WriteLog("ProductsController/CreateOrderFromShopcart 用户userOpenId 为空: " + prodIds); } return(Json(res)); }
async void Add_To_ShoppingCart(object sender, System.EventArgs e) { var button = sender as Button; var product = button.CommandParameter as Product; await conn.CreateTableAsync <shoppingcart>(); var item = new shoppingcart { ProductID = product.ProductID, ProductName = product.ProductName, Price = product.Price, Brand = product.Brand, Category = product.Category, ImageUrl = product.ImageUrl, BigImageUrl = product.BigImageUrl, Description = product.Description }; await conn.InsertOrReplaceAsync(item); await DisplayAlert("Successfully added to Shopping Cart", item.ProductName, "OK"); }
protected void LVgoods_ItemCommand(object sender, ListViewCommandEventArgs e) { int num = int.Parse(ViewState["stock"].ToString()); string Eventname = e.CommandName; switch (Eventname) { case "Minus": { int i = Convert.ToInt32(ViewState["ShoppingCartNumber"]); if (i > 0) { i--; ViewState["ShoppingCartNumber"] = i; Bindgoods(); } } break; case "Add": { int i = Convert.ToInt32(ViewState["ShoppingCartNumber"]); if (i < num) { i++; ViewState["ShoppingCartNumber"] = i; Bindgoods(); } } break; //加入购物车 case "AddShoppingCart": { if (Session["user_name"] != null) { int number = Convert.ToInt32(ViewState["ShoppingCartNumber"]); if (number > 0) { int user_id = Convert.ToInt32(Session["user_id"]); int goods_id = Convert.ToInt32(ViewState["goods_id"]); DataTable goods = GoodsManager.JudgeMallYorN(user_id, goods_id); if (goods != null && goods.Rows.Count != 0) { float total_price = (float.Parse(((Label)e.Item.FindControl("RTprice")).Text)) * (Convert.ToInt32(ViewState["ShoppingCartNumber"])); int result = GoodsManager.UpdateShoppingCart(user_id, goods_id, number, total_price); if (result >= 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>"); BindUserMallCart(); } } else { shoppingcart Shoppingcart = new shoppingcart(); Shoppingcart.user_id = Convert.ToInt32(Session["user_id"]); Shoppingcart.goods_id = Convert.ToInt32(ViewState["goods_id"]); Shoppingcart.unit_price = float.Parse(((Label)e.Item.FindControl("RTprice")).Text); Shoppingcart.number = Convert.ToInt32(ViewState["ShoppingCartNumber"]); Shoppingcart.total_price = (float.Parse(((Label)e.Item.FindControl("RTprice")).Text)) * (Convert.ToInt32(ViewState["ShoppingCartNumber"])); int result = GoodsManager.InsertShoppingCart(Shoppingcart); if (result >= 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>"); BindUserMallCart(); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请确定购买数量');</script>"); } } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('已经卖光了。。。');</script>"); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请先登录');</script>"); Response.Redirect("login1.aspx"); } } break; } }
public static int InsertShoppingCart(shoppingcart Shoppingcart) { return(igoods.InsertShoppingCart(Shoppingcart)); }
public void addcar(object sender, EventArgs e) { int num = int.Parse(ViewState["stock"].ToString()); if (num > 0) { if (Session["user_name"] != null) { int number = Convert.ToInt32(ViewState["ShoppingCartNumber"]); if (number > 0) { int user_id = Convert.ToInt32(Session["user_id"]); int goods_id = Convert.ToInt32(ViewState["goods_id"]); DataTable goods = GoodsManager.JudgeMallYorN(user_id, goods_id); if (goods != null && goods.Rows.Count != 0) { Button btn = (Button)sender; Label RTprice = btn.Parent.FindControl("RTprice") as Label; string str = RTprice.Attributes["data-value"]; float total_price = float.Parse(str) * (Convert.ToInt32(ViewState["ShoppingCartNumber"])); int result = GoodsManager.UpdateShoppingCart(user_id, goods_id, number, total_price); if (result >= 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>"); BindUserMallCart(); } } else { Button btn = (Button)sender; Label gprices = btn.Parent.FindControl("RTprice") as Label; float str = float.Parse(gprices.Attributes["data-value"]); shoppingcart Shoppingcart = new shoppingcart(); Shoppingcart.user_id = Convert.ToInt32(Session["user_id"]); Shoppingcart.goods_id = 1033; Convert.ToInt32(ViewState["goods_id"]); Shoppingcart.unit_price = str; //float.Parse(((Label)e.Item.FindControl("RTprice")).Text); Shoppingcart.number = Convert.ToInt32(ViewState["ShoppingCartNumber"]); Shoppingcart.total_price = str * (Convert.ToInt32(ViewState["ShoppingCartNumber"])); int result = GoodsManager.InsertShoppingCart(Shoppingcart); if (result >= 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('加入购物车成功!');</script>"); BindUserMallCart(); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请确定购买数量');</script>"); } } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('已经卖光了。。。');</script>"); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "true", "<script>alert('请先登录');</script>"); Response.Redirect("login1.aspx"); } } }