public List <CartGoods> GetCartList(string memberId) { List <CartGoods> list = new List <CartGoods>(); StringBuilder builder = new StringBuilder(); builder.AppendFormat(OrderSqls.SELECT_CART_LIST_BY_MEMBER_ID, memberId); string sql = builder.ToString(); DataTable dt = DatabaseOperationWeb.ExecuteSelectDS(sql, "T").Tables[0]; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { CartGoods cartGoods = new CartGoods { cartChecked = dr["CART_CHECKED"].ToString() == "0" ? false : true, edit = false, goodsId = dr["GOODS_ID"].ToString(), goodsImg = dr["GOODS_IMG"].ToString(), goodsName = dr["GOODS_NAME"].ToString(), goodsNum = Convert.ToInt32(dr["GOODS_NUM"]), goodsPrice = Convert.ToInt32(dr["GOODS_PRICE"]), cartId = dr["CART_ID"].ToString(), goodsStock = Convert.ToInt32(dr["GOODS_STOCK"]), }; list.Add(cartGoods); } } return(list); }
/// <summary> /// 添加信息信息 /// </summary> /// <param name="inputDtos">要添加的店铺信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> AddCartGoodses(params CartGoodsInputDto[] inputDtos) { CartGoodsRepository.UnitOfWork.TransactionEnabled = true; List <string> names = new List <string>(); foreach (CartGoodsInputDto dto in inputDtos) { CartGoods cartGoods = dto.MapTo <CartGoods>(); if (dto.GoodsId.HasValue && dto.GoodsId.Value > 0) { Goods.Models.Goods goods = GoodsRepository.GetByKey(dto.GoodsId.Value); if (goods == null) { throw new Exception("商品不存在"); } cartGoods.Goods = goods; } if (dto.UserId.HasValue && dto.UserId.Value > 0) { User user = UserRepository.GetByKey(dto.UserId.Value); if (user == null) { throw new Exception("用户不存在"); } cartGoods.User = user; } if (dto.SkuId.HasValue && dto.SkuId.Value > 0) { Goods.Models.Sku sku = SkuRepository.GetByKey(dto.SkuId.Value); if (sku == null) { throw new Exception("Sku不存在"); } cartGoods.Sku = sku; } //判断商品的重复性,如果是相同商品相同规格只改变购物数量 CartGoods repeatCartGoods = CartGoodsRepository.Entities.SingleOrDefault(cg => cg.User.Id == dto.UserId.Value && cg.Goods.Id == dto.GoodsId.Value && cg.Sku.Id == dto.SkuId.Value); if (repeatCartGoods == null) { await CartGoodsRepository.InsertAsync(cartGoods); } else { repeatCartGoods.BuyCount += dto.BuyCount; await CartGoodsRepository.UpdateAsync(repeatCartGoods); } names.Add(cartGoods.Name); } return(await CartGoodsRepository.UnitOfWork.SaveChangesAsync() > 0 ? new OperationResult(OperationResultType.Success, $"“{names.ExpandAndToString()}”创建成功") : OperationResult.NoChanged); }
public ShopPage(List <string> GoodsNameFromCatalog, List <int> GoodsPiece) { InitializeComponent(); GoodsName = GoodsNameFromCatalog; Piece = GoodsPiece; for (int i = 0; i < GoodsName.Count; i++) { Goods goods = GoodsDatabase.GetItemAsync(GoodsName[i]).Result; CartGoods CartGoods = new CartGoods(); CartGoods.GoodsID = goods.GoodsID; CartGoods.Name = goods.Name; CartGoods.Price = goods.Price; CartGoods.GoodsQauntity = Piece[i]; CartGoods.TotalPrice = Piece[i] * goods.Price; CartGoodsList.Add(CartGoods); } listView.ItemsSource = CartGoodsList; GetValueForShopCartInfo(CartGoodsList); }
public CartGoods GetCartGoodsByGoodsId(string memberId, string goodsId) { CartGoods cartGoods = null; StringBuilder builder = new StringBuilder(); builder.AppendFormat(OrderSqls.SELECT_CART_BY_MEMBER_ID_AND_GOODS_ID, memberId, goodsId); string sql = builder.ToString(); DataTable dt = DatabaseOperationWeb.ExecuteSelectDS(sql, "T").Tables[0]; if (dt != null && dt.Rows.Count == 1) { cartGoods = new CartGoods { cartChecked = dt.Rows[0]["CART_CHECKED"].ToString() == "0" ? false : true, goodsId = dt.Rows[0]["GOODS_ID"].ToString(), goodsNum = Convert.ToInt32(dt.Rows[0]["GOODS_NUM"]), cartId = dt.Rows[0]["CART_ID"].ToString(), }; } return(cartGoods); }
/// <summary> /// 购物车选中商品数据填充 /// </summary> /// <param name="table"></param> /// <returns></returns> public List <CartGoods> FillList(DataTable table) { List <CartGoods> lists = new List <CartGoods>(); foreach (DataRow item in table.Rows) { CartGoods goods = new CartGoods() { Article_Id = item["article_id"].ToString(), Quantity = decimal.Parse(item["quantity"].ToString()), Price = decimal.Parse(item["price"].ToString()), GoodsType = item["GoodsType"].ToString(), Fabh = item["Fabh"].ToString(), EntId = item["entId"].ToString(), Discount = decimal.Parse(item["discount"].ToString()), Derate = decimal.Parse(item["derate"].ToString()), PromScenario = item["PromScenario"].ToString() }; lists.Add(goods); } return(lists); }
/// <summary> /// 填充CartList,购物车列表【未分组】 /// </summary> /// <param name="ds"></param> /// <returns></returns> public CartList SetCartList(DataSet ds, int pageIndex = 1, int pageSize = 30) { ///获取网站ip string web_url = BaseConfiguration.SercerIp; CartList model = new CartList(); DataTable dt = new DataTable(); model.PageIndex = pageIndex; model.PageSize = pageSize; int cartNumber = 0; if (ds.Tables.Count >= 3) { model.PageCount = int.Parse(ds.Tables[2].Rows[0]["pageCount"].ToString()); model.RountCount = int.Parse(ds.Tables[2].Rows[0]["recordCount"].ToString()); dt = ds.Tables[1]; } else { model.PageCount = 1; model.RountCount = ds.Tables[0].Rows.Count; dt = ds.Tables[0]; } decimal real_Amount = 0M; //应付金额 decimal order_Amount = 0M; //总金额 decimal discount_Amount = 0M; //优惠金额 long InventoryShows = long.Parse(BaseConfiguration.InventoryShows); //页面商品库存最大显示数量 List <CartGoods> clist = new List <CartGoods>(); foreach (DataRow dr in dt.Rows) { if (dr["GoodsType"].ToString() != "ZP") { cartNumber += 1; } CartGoods c = new CartGoods(); c.Id = dr["cartId"].ToString(); c.Article_Id = dr["article_id"].ToString(); c.Sub_Title = dr["sub_title"].ToString(); c.Drug_Factory = dr["drug_factory"].ToString(); c.Drug_Spec = dr["drug_spec"].ToString(); c.Big_Package = BasisConfig.ObjToDecimal(dr["big_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); c.Quantity = BasisConfig.ObjToDecimal(dr["quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M); c.Stock_Quantity = BasisConfig.ObjToDecimal(dr["stock_quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M); c.Fabs = dr["fabs"].ToString().Trim(); c.Price = BasisConfig.ObjToDecimal(dr["price"].ToString(), BaseConfiguration.PricePlace, 0.00M); c.RealPrice = BasisConfig.ObjToDecimal(dr["realprice"].ToString(), BaseConfiguration.PricePlace, 0.00M); c.Scattered = dr["scattered"].ToString(); c.Amount = c.Quantity * c.RealPrice; c.Fabh = dr["Fabh"].ToString(); c.GoodsType = dr["GoodsType"].ToString(); c.Multiple = decimal.Parse(dr["multiple"].ToString()); //大包装控制 Y-取大包装 N-不取大包装 string packControl = dr["packControl"].ToString().Trim(); //中包装控制 Y-取中包装,不拆零 N-不取中包装,拆零 string scattered = dr["scattered"].ToString().Trim(); c.Zbz = BasisConfig.ObjToDecimal(dr["min_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); if (packControl == "Y") { c.Min_Package = BasisConfig.ObjToDecimal(dr["big_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } else { if (scattered == "Y") { c.Min_Package = BasisConfig.ObjToDecimal(dr["min_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } else { c.Min_Package = BasisConfig.ObjToDecimal(dr["scatteredPackage"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } } //图片 if (dr["img_url"].ToString() != "") { c.Img_Url = web_url + dr["img_url"].ToString().Trim(); } else { c.Img_Url = ""; } if (InventoryShows > 0 && c.Stock_Quantity > InventoryShows) { if (c.Stock_Quantity >= 1000) { c.Inventory = "充裕"; } else { c.Inventory = "紧张"; } } else { c.Inventory = BasisConfig.ObjToDecimal(dr["stock_quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M).ToString(); } //discount_Amount = discount_Amount + decimal.Parse(dr["discount_Amount"].ToString());//计算商品优惠金额 //order_Amount = order_Amount+(c.Quantity * c.Price);//计算订单金额 clist.Add(c); } model.Num = cartNumber; model.Order_Amount = order_Amount; model.Discount_Amount = discount_Amount; real_Amount = order_Amount - discount_Amount; if (real_Amount > 0) { model.Real_Amount = real_Amount; } else { model.Real_Amount = 0; } model.GoodsInfo = clist; return(model); }
private static void Assignment(DataRow dr, string web_url, long InventoryShows, ref int cartNumber, ref List <CartGoods> list) { if (dr["GoodsType"].ToString() != "ZP") { cartNumber += 1; } CartGoods c = new CartGoods { Id = dr["cartId"].ToString(), Article_Id = dr["article_id"].ToString(), Sub_Title = dr["sub_title"].ToString(), Drug_Factory = dr["drug_factory"].ToString(), Drug_Spec = dr["drug_spec"].ToString(), Big_Package = BasisConfig.ObjToDecimal(dr["big_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M), Quantity = BasisConfig.ObjToDecimal(dr["quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M), Stock_Quantity = BasisConfig.ObjToDecimal(dr["stock_quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M), Fabs = dr["fabs"].ToString().Trim(), Price = BasisConfig.ObjToDecimal(dr["price"].ToString(), BaseConfiguration.PricePlace, 0.00M), RealPrice = BasisConfig.ObjToDecimal(dr["realprice"].ToString(), BaseConfiguration.PricePlace, 0.00M), Scattered = dr["scattered"].ToString() }; c.Amount = c.Quantity * c.RealPrice; c.Fabh = dr["Fabh"].ToString(); c.GoodsType = dr["GoodsType"].ToString(); c.Multiple = decimal.Parse(dr["multiple"].ToString()); //大包装控制 Y-取大包装 N-不取大包装 string packControl = dr["packControl"].ToString().Trim(); //中包装控制 Y-取中包装,不拆零 N-不取中包装,拆零 string scattered = dr["scattered"].ToString().Trim(); if (packControl == "Y") { c.Min_Package = BasisConfig.ObjToDecimal(dr["big_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } else { if (scattered == "Y") { c.Min_Package = BasisConfig.ObjToDecimal(dr["min_package"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } else { c.Min_Package = BasisConfig.ObjToDecimal(dr["scatteredPackage"].ToString(), BaseConfiguration.PackagePlace, 0.00M); } } //图片 if (dr["img_url"].ToString() != "") { c.Img_Url = web_url + dr["img_url"].ToString().Trim(); } else { c.Img_Url = ""; } if (InventoryShows > 0 && c.Stock_Quantity > InventoryShows) { if (c.Stock_Quantity >= 1000) { c.Inventory = "充裕"; } else { c.Inventory = "紧张"; } } else { c.Inventory = BasisConfig.ObjToDecimal(dr["stock_quantity"].ToString(), BaseConfiguration.InventoryPlace, 0.00M).ToString(); } list.Add(c); }