/**删除餐桌,逻辑删除**/ public bool DeleteTable(int tableId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { IShow.ChooseDishes.Data.Table table = new IShow.ChooseDishes.Data.Table(); table.TableId = tableId; DbEntityEntry <IShow.ChooseDishes.Data.Table> entry = entities.Entry <IShow.ChooseDishes.Data.Table>(table); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Deleted").IsModified = true; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return(true); } else { return(false); } } } catch (Exception e) { throw e; } }
public IShow.ChooseDishes.Data.Table LoadTableById(int tableId) { IShow.ChooseDishes.Data.Table table; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { table = (IShow.ChooseDishes.Data.Table)entities.Table.Where( info => info.Deleted == 0 && (info.TableId == tableId) ); if (table == null) { table = new IShow.ChooseDishes.Data.Table(); } return(table); }; }
//新增餐桌 public Hashtable SaveTable(IShow.ChooseDishes.Data.Table table) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { Hashtable hash = new Hashtable();//返回结果 List <IShow.ChooseDishes.Data.Table> tables; //检查类型编号或者类型名称是否重复 tables = entities.Table.Where(info => info.Name == table.Name || info.Code == table.Code).ToList(); if (tables != null && tables.Count > 0) { hash.Add("code", 1); if (tables[0].Name == table.Name) { hash.Add("message", "餐桌名称已经存在,请重新命名!"); } else if (tables[0].Code == table.Code) { hash.Add("message", "餐桌编号已经存在!"); } return(hash); } entities.Table.Add(table); int result = entities.SaveChanges(); if (result == 1) { hash.Add("code", 0); hash.Add("message", "新增成功!"); } else { hash.Add("code", 2); hash.Add("message", "新增失败,请稍后再试!"); } return(hash); } catch (Exception e) { throw e; } }; }
public bool UpdateTable(IShow.ChooseDishes.Data.Table table) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DbEntityEntry <IShow.ChooseDishes.Data.Table> entry = entities.Entry <IShow.ChooseDishes.Data.Table>(table); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Name").IsModified = true; entry.Property("Seat").IsModified = true; entry.Property("TableTypeId").IsModified = true; entry.Property("LocationId").IsModified = true; entry.Property("Status").IsModified = true; //TODO 是否已经启用,已启用则不能删除 entry.Property("TableId").IsModified = false; try { entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } } }
// public void SaveTableInBatch(int loop) { Table table = new Table(); if (CodePrefix != null && !CodePrefix.Trim().Equals("")) {//编号有前缀 int lengthDiff = Convert.ToInt32(CodeLength) - (CodePrefix.Length + loop.ToString().Length); if (lengthDiff <= 0) {//前缀加编号是否大于编号长度,如果小于则要补0 table.Code = CodePrefix + loop.ToString(); } else {//长度不达标,中间补0 for (int Cursor = 1; Cursor <= lengthDiff; Cursor++) { table.Code = CodePrefix + "0"; } table.Code = table.Code + loop.ToString(); } } else {//编号没有前缀 int lengthDiff = Convert.ToInt32(CodeLength) - loop.ToString().Length; if (lengthDiff <= 0) {//前缀加编号是否大于编号长度,如果小于则要补0 table.Code = loop.ToString(); } else {//长度不达标,中间补0 for (int Cursor = 1; Cursor <= lengthDiff; Cursor++) { table.Code = "0"; } table.Code = table.Code + loop.ToString(); } } table.Name = "桌" + table.Code; table.LocationId = LocationId; table.TableTypeId = TableTypeId; table.Seat = Convert.ToInt32(Seat); table.Deleted = 0; table.Status = Status; table.CreateBy = SubjectUtils.GetAuthenticationId(); table.CreateDatetime = DateTime.Now; table.UpdateBy = SubjectUtils.GetAuthenticationId(); table.UpdateDatetime = DateTime.Now; _TableService.SaveTable(table); //刷新餐桌列表数据 TableGrid.Add(table); }
/**删除餐桌,逻辑删除**/ public bool DeleteTable(int tableId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { IShow.ChooseDishes.Data.Table table = new IShow.ChooseDishes.Data.Table(); table.TableId = tableId; DbEntityEntry<IShow.ChooseDishes.Data.Table> entry = entities.Entry<IShow.ChooseDishes.Data.Table>(table); entry.State = System.Data.Entity.EntityState.Unchanged;//Modified entry.Property("Deleted").IsModified = true; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result == 1) { return true; } else { return false; } } } catch (Exception e) { throw e; } }
public IShow.ChooseDishes.Data.Table LoadTableById(int tableId) { IShow.ChooseDishes.Data.Table table; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { table = (IShow.ChooseDishes.Data.Table)entities.Table.Where( info => info.Deleted == 0 && (info.TableId == tableId) ); if (table == null) { table = new IShow.ChooseDishes.Data.Table(); } return table; }; }