//根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true public bool DeleteDishesWayNameByCode(int id) { if (id == null) { return false; } //先判断是否存在有做法,如果有做法,则不能返回false DishesWayDataService odws = new DishesWayDataService(); List<DischesWay> orgDischesWay = odws.FindAllDishesWayByTypeId(id); if (orgDischesWay != null && orgDischesWay.Count > 0) { return false; } //删除 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { DischesWayName booktype = new DischesWayName() { DischesWayNameId = id, }; DbEntityEntry<DischesWayName> entry = entities.Entry<DischesWayName>(booktype); entry.State = System.Data.Entity.EntityState.Deleted; entities.SaveChanges(); return true; } catch (Exception e) { e.ToString(); return false; } } }
private void LoadDishesWayData(DischesWayName dwn, TreeNodeModel node) { ICollection<DischesWay> dws = dwn.DischesWay; if (dws != null) { foreach (var d in dws) { if (d.Deleted == 0) { _DishesWayBean = new DishesWayBean(); _DishesWayBean.CreateDishesWayBean(d); _DishesWayBean.LineNumber = DishesWayTableItems.Count + 1; DishesWayTableItems.Add(DishesWayBean); } } } }
//修改菜品做法类型,传入的参数需要包含:DischesWayNameId/Code,Name,Status,Deleted,UpdateBy,UpdateDatetime字段 public bool UpdateDishesWayName(DischesWayName dwn) { if (dwn == null) { return false; } //修改 直接修改 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { var type = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == dwn.DischesWayNameId); if (type != null) { type.Name = dwn.Name; type.Status = dwn.Status; type.UpdateBy = dwn.UpdateBy; type.UpdateDatetime = dwn.UpdateDatetime; type.Deleted = dwn.Deleted; entities.SaveChanges(); return true; } } catch (Exception e) { e.ToString(); return false; } } return false; }
//添加做法类型,传入的做法类型参数需要包含:DischesWayNameId, Code,Name, CreateBy,CreateDatetime,Status,Deleted字段 public bool AddDishesWayName(DischesWayName dw) { if (dw == null) { return false; } //添加 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { entities.DischesWayName.Add(dw); entities.SaveChanges(); return true; } catch (Exception e) { e.ToString(); return false; } } }
/// <summary> /// 根据做法类型id查询和显示该做法类型下的所有做法 /// </summary> /// <param name="wayTypeId">做法类型id</param> /// <param name="type">type=0表示全部加载数据,并显示到表格中,type!=0表示选中树节点时显示其对应的数据</param> private void LoadBaseData(DischesWayName dwn, int type) { if (dwn == null) { return; } int wayTypeId = dwn.DischesWayNameId; if (type != 0) { DishesWayTableItems.Clear(); } //加载数据 ICollection<DischesWay> dws = dwn.DischesWay; if (dws != null) foreach (var d in dws) { if (d.Deleted == 1) continue; _DishesWayBean = new DishesWayBean(); _DishesWayBean.CreateDishesWayBean(d); _DishesWayBean.DischesWayName = dwn.Name; //设置显示行号和编码 _DishesWayBean.LineNumber = DishesWayTableItems.Count + 1; _DishesWayBean.Code = d.Code; if (!SelectedFlag) { DishesWaySelectedItem = DishesWayBean; SelectedFlag = true; } DishesWayTableItems.Add(_DishesWayBean); } }
public DischesWayName CreateDishesWayName(DishesWayNameBean bean) { DischesWayName beanBack = new DischesWayName(); beanBack.DischesWayNameId = bean.DischesWayNameId; beanBack.Code = bean.Code; beanBack.Name = bean.Name; beanBack.CreateDatetime = bean.CreateDatetime; beanBack.CreateBy = bean.CreateBy; beanBack.Deleted = bean.Deleted; beanBack.Status = bean.Status; beanBack.UpdateDatetime = bean.UpdateDatetime; beanBack.UpdateBy = bean.UpdateBy; return beanBack; }
public DishesWayNameBean CreateDishesWayNameBean(DischesWayName bean) { this.DischesWayNameId = bean.DischesWayNameId; this.Code = bean.Code; this.Name = bean.Name; this.CreateDatetime = bean.CreateDatetime; this.CreateBy = bean.CreateBy; this.Deleted = bean.Deleted; this.Status = bean.Status; this.UpdateDatetime = bean.UpdateDatetime; this.UpdateBy = bean.UpdateBy; return this; }