public void DeleteItemCrude(int sid) { try { DianDianEntities db = new DianDianEntities(); storage_item_crude ic = new storage_item_crude(); ic.sid = sid; db.storage_item_crude.Attach(ic); db.storage_item_crude.Remove(ic); db.SaveChanges(); } catch (Exception e) { log.Error("DeleteItemStandards error. msg=" + e.Message); throw; } }
public void SaveItemCrude(int sid, int itemkey, int guigeid, int crudeid, int num, sbyte type) { try { DianDianEntities db = new DianDianEntities(); if (sid != 0) { storage_item_crude ic = db.storage_item_crude.Find(sid); ic.num = num; ic.type = type; db.storage_item_crude.Attach(ic); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(ic); stateEntity.SetModifiedProperty("num"); stateEntity.SetModifiedProperty("type"); db.SaveChanges(); } else { storage_item_crude ic = new storage_item_crude(); ic.itemkey = itemkey; ic.guigeid = guigeid; ic.crudeid = crudeid; ic.num = num; ic.type = type; db.storage_item_crude.Add(ic); db.SaveChanges(); } } catch (Exception e) { log.Error("SaveItemCrude error. msg=" + e.Message); throw; } }
//22. 添加更新菜品接口 public void SaveItem(int itemkey, string name, string code, double discountPrice, double agioprice, int itemType, string imgs, int minnum, int isStandard, int isSet, int isPrint, sbyte selebyunit, string unit, sbyte ispayagio, sbyte ismust, string introduce, List <ItemCrudeInfo> crudeList, List <ItemTCInfo> tcList) { try { DianDianEntities db = new DianDianEntities(); item bean = db.item.Find(itemkey); if (bean == null) { bean = new item(); bean.name = name; bean.itemCode = code; bean.discountPrice = discountPrice; bean.agioprice = agioprice; bean.isDel = 0; bean.itemcategorykey = itemType; bean.imgs = imgs; bean.minnum = minnum; bean.isStandard = isStandard; bean.isSet = isSet; bean.isprint = isPrint; bean.selebyunit = selebyunit; bean.unit = unit; bean.ispayagio = ispayagio; bean.ismust = ismust; bean.introduce = introduce; bean.syncFlag = 1; db.item.Add(bean); } else { bean.name = name; bean.discountPrice = discountPrice; bean.agioprice = agioprice; bean.isDel = 0; bean.itemcategorykey = itemType; bean.imgs = imgs; bean.minnum = minnum; bean.isStandard = isStandard; bean.isSet = isSet; bean.isprint = isPrint; bean.selebyunit = selebyunit; bean.unit = unit; bean.ispayagio = ispayagio; bean.ismust = ismust; bean.introduce = introduce; bean.syncFlag = 1; db.item.Attach(bean); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(bean); stateEntity.SetModifiedProperty("name"); stateEntity.SetModifiedProperty("discountPrice"); stateEntity.SetModifiedProperty("agioprice"); stateEntity.SetModifiedProperty("isDel"); stateEntity.SetModifiedProperty("itemcategorykey"); stateEntity.SetModifiedProperty("imgs"); stateEntity.SetModifiedProperty("minnum"); stateEntity.SetModifiedProperty("isStandard"); stateEntity.SetModifiedProperty("isprint"); stateEntity.SetModifiedProperty("selebyunit"); stateEntity.SetModifiedProperty("unit"); stateEntity.SetModifiedProperty("ispayagio"); stateEntity.SetModifiedProperty("ismust"); stateEntity.SetModifiedProperty("introduce"); stateEntity.SetModifiedProperty("syncFlag"); } List <int> keepList = new List <int>(); foreach (var crude in crudeList) { storage_item_crude ic = db.storage_item_crude.Where(p => p.itemkey == bean.itemkey && p.crudeid == crude.crudeid && p.guigeid == crude.guigeid).FirstOrDefault(); if (ic != null) { ic.num = crude.crudenum; db.storage_item_crude.Attach(ic); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(ic); stateEntity.SetModifiedProperty("num"); keepList.Add(ic.sid); } else { ic = new storage_item_crude(); ic.itemkey = bean.itemkey; ic.crudeid = crude.crudeid; ic.num = crude.crudenum; ic.guigeid = crude.guigeid; ic.type = 0; db.storage_item_crude.Add(ic); } } var delList = db.storage_item_crude.Where(p => !keepList.Contains(p.sid)).ToList(); foreach (var delbean in delList) { db.storage_item_crude.Attach(delbean); db.storage_item_crude.Remove(delbean); } if (isSet == 1) { var setkeepList = new List <int>(); foreach (var tc in tcList) { item_set itemSet = db.item_set.Where(p => p.tcItemKey == bean.itemkey && p.itemkey == tc.itemid && p.guigeid == tc.guigeid).FirstOrDefault(); if (itemSet != null) { itemSet.itemnum = tc.itemnum; db.item_set.Attach(itemSet); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(itemSet); stateEntity.SetModifiedProperty("itemnum"); setkeepList.Add(itemSet.itemsetkey); } else { itemSet = new item_set(); itemSet.tcItemKey = bean.itemkey; itemSet.itemkey = tc.itemid; itemSet.guigeid = tc.guigeid; itemSet.itemnum = tc.itemnum; db.item_set.Add(itemSet); } } var setDelList = db.item_set.Where(p => !setkeepList.Contains(p.itemsetkey)).ToList(); foreach (var delbean in delList) { db.storage_item_crude.Attach(delbean); db.storage_item_crude.Remove(delbean); } } db.SaveChanges(); } catch (Exception e) { log.Error("SaveItem error. msg=" + e.Message); throw; } }