/// <summary> /// 添加组合商品明细,销售价格 /// 调用:FGoods.cs /// </summary> /// <param name="InGoodsId"></param> /// <param name="Price"></param> /// <param name="Ggdetail"></param> /// <returns></returns> public int SaveGoodsGroupDetail(int InGoodsId, double Price, GoodsGroupDetail[] Ggdetail) { int i = 0; Goods goods = new Goods(); goods.ModifyPrice(InGoodsId, Price); foreach (GoodsGroupDetail ggd in Ggdetail) { GoodsGroupDetail ggdetail = new GoodsGroupDetail(); ggdetail.GoodsGroupId = InGoodsId; //组合商品id ggdetail.GoodsId = ggd.GoodsId; // ggdetail.PackageId = ggd.PackageId; ggdetail.Num = ggd.Num; ggdetail.UserId = ggd.UserId; if (ggdetail.Save() > 0) { i += 1; } } return(i); }
/// <summary> /// 修改组合商品明细 /// </summary> /// <param name="InGoodsId"></param> /// <param name="Price"></param> /// <param name="Ggdetail"></param> /// <returns></returns> public bool ModifyGoodsGropDetail(int InGoodsId, double Price, GoodsGroupDetail[] Ggdetail) { Goods goods = new Goods(); goods.ModifyPrice(InGoodsId, Price); if (InGoodsId > 0) { GoodsGroupDetail ggd = new GoodsGroupDetail(); DataTable dtOld = ggd.GetGoodsGroupDetail(InGoodsId).Tables[0];//读取订单原来的明细 //循环新表,处理新增商品和 修改过数量和价格的商品 for (int i = 0; i < Ggdetail.Length; i++) { DataRow[] rows = dtOld.Select(string.Format(" GoodsId={0} ", Ggdetail[i].GoodsId)); if (rows.Length == 1)//有这个商品 { int oldNum = DBTool.GetIntFromRow(rows[0], "num", 0); if (Ggdetail[i].Num != oldNum)//有变化需要修改 { GoodsGroupDetail ggdl = new GoodsGroupDetail(); ggdl.Id = DBTool.GetIntFromRow(rows[0], "Id", 0); ggdl.Load(); ggdl.Num = Ggdetail[i].Num; ggdl.UserId = Ggdetail[i].UserId; if (ggdl.Save() > 0) { //记录修改明细记录 } } } else //新增商品 { GoodsGroupDetail ggdl = new GoodsGroupDetail(); ggdl.Id = 0; ggdl.GoodsGroupId = InGoodsId; ggdl.GoodsId = Ggdetail[i].GoodsId; ggdl.PackageId = 0; ggdl.Num = Ggdetail[i].Num; ggdl.UserId = Ggdetail[i].UserId; if (ggdl.Save() > 0) { //如果是组合商品,需要新增 组合的明细 } } //循环旧表,查找新表中没有的项。删除,记录明细 foreach (DataRow row in dtOld.Select()) { int goodsId = DBTool.GetIntFromRow(row, "goodsId", 0); bool isExsist = false; for (int z = 0; z < Ggdetail.Length; i++) { if (Ggdetail[z].GoodsId == goodsId) { isExsist = true; break; } } if (isExsist == false) { //新订单中无 此项 int odId = DBTool.GetIntFromRow(row, "Id", 0); GoodsGroupDetail ggdl = new GoodsGroupDetail(); ggdl.Id = odId; ggdl.GoodsId = goodsId; if (ggdl.Delete())//删除订单明细 如果是组合商品 删除 { //记录订单 修改记录 } } } } } return(true); }