//修改菜品做法类型,传入的参数需要包含: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); }
//根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true public bool DeleteDischesWayName(int id) { //先判断是否存在有做法,如果有做法,则不能返回false DischesWayDataService odws = new DischesWayDataService(); List <DischesWay> orgDischesWay = odws.FindAllDischesWay(id); if (orgDischesWay != null) { return(false); } //删除 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DischesWayName booktype = new DischesWayName() { DischesWayNameId = id, }; DbEntityEntry <DischesWayName> entry = entities.Entry <DischesWayName>(booktype); entry.State = System.Data.EntityState.Deleted; entities.SaveChanges(); var newtype = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == id); if (newtype != null) { //Console.WriteLine(newtype.name); return(false); } else { //Console.WriteLine("No Found"); return(true); } } }
//根据做法类型编码删除菜品做法类型,如果删除失败返回false,如果删除成功,则返回true public bool DeleteDishesWayNameByCode(int id) { //先判断是否存在有做法,如果有做法,则不能返回false List <DischesWay> orgDischesWay = 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 SaveData(SaveType index) { switch (index) { case SaveType.BIGTYPE: //做法类型 List <DischesWayName> dwns = _DataService.FindAllDishesWayName(); foreach (var item in DishesWayTypeItems) { if (item.DischesWayNameId == 0 && (string.IsNullOrEmpty(item.Name) || string.IsNullOrEmpty(item.Code))) //空名 { continue; } if (item.DischesWayNameId == 0 && string.IsNullOrEmpty(item.Name.Trim()) && string.IsNullOrEmpty(item.Code.Trim())) //空名 { continue; } DischesWayName dwn = item.CreateDishesWayName(item); if (item.DischesWayNameId == 0) { //先根据编号查询数据库中是否已存在 DischesWayName dd = _DataService.FindDishesWayNameByCode(item.Code); if (dd != null) { //表示数据库中已然存在 MessageBox.Show("对不起,编码重复,不能保存", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); return; } _DataService.AddDishesWayName(dwn); } if (dwns != null) { //数据库中如果已经存在的,并且名称是不相同的,则修改该条目,否则什么事也不做 foreach (var d in dwns) { if (item.DischesWayNameId == d.DischesWayNameId && !item.Name.Equals(d.Name)) { _DataService.UpdateDishesWayName(dwn); } } } } typeXaml.Close(); InitDishesWayTypeBaseData(); LoadTreeData(null); break; case SaveType.ITEM: //做法 SaveDishesWay(0); break; default: //继续 SaveDishesWay(0); InitAddData(); break; } }
/// <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; StringBuilder sb = new StringBuilder(); if (wayTypeId < 10) { if (wayTypeId == 0) { sb.Append(wayTypeId); } else { sb.Append("0").Append(wayTypeId); } } else { sb.Append(wayTypeId); } sb.Append(d.Code); _DishesWayBean.Code = sb.ToString(); if (!SelectedFlag) { DishesWaySelectedItem = DishesWayBean; SelectedFlag = true; } DishesWayTableItems.Add(_DishesWayBean); } } }
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); }
public void TestMethodupdateDischesWayName() { DischesWayNameDataService dd = new DischesWayNameDataService(); DischesWayName dw = new DischesWayName() { DischesWayNameId = 2, Code = "123", Name = "是的该死的", UpdateBy = 2, Status = 1, UpdateDatetime = DateTime.Now }; var f = dd.UpdateDischesWayName(dw); }
/// <summary> /// 加载树的选择节点下的数据 /// </summary> /// <param name="node"></param> private void LoadTreeData(TreeNodeModel node) { SelectedFlag = false; if (node != null && !RootTreeNode.Equals(node)) { SelectedTreeNode = node; DischesWayName dwn = _DataService.FindDishesWayNameById(int.Parse(node.Id)); LoadBaseData(dwn, 1); } else { //重新加载数据 InitTreeByDishesWayData(); } }
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 void TestMethodAddDischesWayName() { DischesWayNameDataService dd = new DischesWayNameDataService(); DischesWayName dw = new DischesWayName() { DischesWayNameId = 2, Code = "124", Name = "avv", CreateBy = 2, CreateDatetime = DateTime.Now, UpdateBy = 1, Status = 0 }; var f = dd.AddDischesWayName(dw); }
//添加做法类型,传入的做法类型参数需要包含:DischesWayNameId, Code,Name, CreateBy,CreateDatetime,Status,Deleted字段 public bool AddDischesWayName(DischesWayName dw) { //添加 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { entities.DischesWayName.Add(dw); entities.SaveChanges(); var type = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == dw.DischesWayNameId); if (type != null) { return(true); } } 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, 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); } } }
//修改菜品做法类型,传入的参数需要包含:DischesWayNameId/Code,Name,Status,Deleted,UpdateBy,UpdateDatetime字段 public bool UpdateDischesWayName(DischesWayName dwn) { //修改 直接修改 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { 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(); var newtype = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == dwn.DischesWayNameId); if (newtype != null) { return(true); } } return(false); }