public int Add(string code, string name) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { var list = entities.DishesMenu.Where(t => t.Deleted == 0 && (t.Code == code || t.Name == name)).ToList(); if (list != null && list.Count > 0) { return(0); } DishesMenu menu = DishesMenuModel.build(code, name, SubjectUtils.GetAuthenticationId()); entities.DishesMenu.Add(menu); entities.SaveChanges(); return(menu.MenusId); } }
/// <summary> /// 给制定的角色赋予权限 /// </summary> /// <param name="roleId">角色编号</param> /// <param name="Function">权限ID列表</param> public void GrantFunctionForRole(int roleId, String functionId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { RoleRefFunction rp = new RoleRefFunction(); int authId = SubjectUtils.GetAuthenticationId(); rp.Deleted = 0; rp.RoleId = roleId; rp.FunctionId = functionId; rp.CreateBy = authId; rp.CreateDateTime = DateTime.Now; entities.RoleRefFunction.Add(rp); entities.SaveChanges(); } }
public int SaveTypeMethod() { try { TableType type = new TableType(); type.Code = Code; type.Name = Name; type.PeopleMax = Convert.ToInt32(PeopleMax); type.PeopleMin = Convert.ToInt32(PeopleMin); //type.Prefix = Prefix; type.PriceType = (int)PriceType; type.ServerfreeModel = (int)ServerfreeModel; type.LowConsCalcType = (int)LowConsCalcType; type.ServerFeeCalcType = (int)ServerFeeCalcType; type.Status = 0; type.Deleted = 0; type.ColorType = ColorType; type.CreateDatetime = DateTime.Now; type.CreateBy = SubjectUtils.GetAuthenticationId(); type.UpdateBy = SubjectUtils.GetAuthenticationId(); type.UpdateDatetime = DateTime.Now; ServerFeeDetail.CreateBy = SubjectUtils.GetAuthenticationId(); ServerFeeDetail.DataType = 1; ServerFeeDetail.ServerfreeAccountType = (int)ServerfreeAccountType; LowConsumerDetail.CreateBy = SubjectUtils.GetAuthenticationId(); LowConsumerDetail.DataType = 2; LowConsumerDetail.ConsumerMode = (int)ConsumerMode; int tableTypeId = TableService.SaveTableTypeAll(type, ServerFeeDetail, LowConsumerDetail); MessageBox.Show("新增成功!"); //刷新界面上的目录树 TableViewModel tableModel = ServiceLocator.Current.GetInstance <TableViewModel>(); _TableTypeTree = tableModel.TableTypeTree; TableTypeTreeNode tableTypeTreeNode = new TableTypeTreeNode(type.TableTypeId.ToString(), type.Name, tableModel.TableTypeTree[0], false, null); tableTypeTreeNode.Action = tableModel.LoadTableTypeAction; tableModel.TableTypeTree[0].Children.Add(tableTypeTreeNode); return(tableTypeId); } catch (Exception e) { throw new ServiceException(e.Message); } }
public bool ModifyStatus(int TableId, int Status) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { var type = entities.TableItem.SingleOrDefault(bt => bt.Deleted == 0 && bt.TableId == TableId); if (type != null) { type.UpdateBy = SubjectUtils.GetAuthenticationId(); type.UpdateDatetime = DateTime.Now; type.Status = Status; entities.SaveChanges(); return(true); } return(false); } }
/// <summary> /// 删除用户销售规则 /// </summary> /// <param name="userId"></param> public void RemoveSaleRuleByUserId(int userId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { UserSaleRule saleRule = entities.UserSaleRule.Where(t => t.UserId == userId && t.Deleted == 0).Single(); if (null == saleRule) { return; } int authId = SubjectUtils.GetAuthenticationId(); DateTime now = DateTime.Now; saleRule.Deleted = 1; saleRule.UpdateBy = authId; entities.SaveChanges(); } }
private void UpdateRoleStatus(int roleId, int status) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Role role = entities.Role.Where(t => t.RoleId == roleId).Single(); if (null == role) { throw new ServiceException("无法找到指定的角色【" + roleId + "】"); } int authId = SubjectUtils.GetAuthenticationId(); DateTime now = DateTime.Now; role.Deleted = status; role.UpdateBy = authId; entities.SaveChanges(); } }
/// <summary> /// 修改服务费低消设置 /// </summary> /// <param name="detail">服务费设置详细</param> /// <param name="serverFeeMode">服务费模式</param> /// <returns>成功则返回true,失败返回false</returns> public bool UpdateTableTypeDetail(TableTypeDetail detail) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { detail.UpdateBy = SubjectUtils.GetAuthenticationId(); detail.UpdateDatetime = DateTime.Now; DbEntityEntry <IShow.ChooseDishes.Data.TableTypeDetail> entry = entities.Entry <IShow.ChooseDishes.Data.TableTypeDetail>(detail); entry.State = System.Data.Entity.EntityState.Unchanged; entry.Property("StartMoney").IsModified = true; entry.Property("StartGetMoneyTime").IsModified = true; entry.Property("StartUnit").IsModified = true; entry.Property("StartDateTime").IsModified = true; entry.Property("EndDateTime").IsModified = true; entry.Property("OutMoney").IsModified = true; entry.Property("OutTime").IsModified = true; entry.Property("OutTimeFree").IsModified = true; entry.Property("ServerfreeNax").IsModified = true; entry.Property("ServerfreeAccountType").IsModified = true; entry.Property("ServerfreeNum").IsModified = true; entry.Property("Rate").IsModified = true; entry.Property("ConsumerMode").IsModified = true; entry.Property("ConsumerMoney").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; entry.Property("UpdateBy").IsModified = true; //entry.Property("TableTypeDetailId").IsModified = false; entities.Configuration.ValidateOnSaveEnabled = false; int result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = false; if (result == 1) { return(true); } else { return(false); } } } catch (Exception e) { throw e; } }
public void SaveOnUpdateForUserSaleRule(int userId, UserSaleRule saleRule) { if (null == saleRule) { throw new ServiceException("参数【saleRule】不能为空!"); } using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { UserSaleRule savedSaleRule = entities.UserSaleRule.Where(t => t.Deleted == 0 && t.UserId == userId).SingleOrDefault(); //不存在销售规则,则抛出异常 if (savedSaleRule == null) { savedSaleRule = new UserSaleRule(); try { savedSaleRule.CreateBy = SubjectUtils.GetAuthenticationId(); savedSaleRule.CreateDatetime = DateTime.Now; saleRule.UserId = userId; saleRule.CreateBy = SubjectUtils.GetAuthenticationId(); saleRule.CreateDatetime = DateTime.Now; entities.UserSaleRule.Add(saleRule); entities.SaveChanges(); } catch (DbUpdateException e) { e.ToString(); } } else { // savedSaleRule.DiscountAllowanceLimit = saleRule.DiscountAllowanceLimit; savedSaleRule.DiscountLimit = saleRule.DiscountLimit; savedSaleRule.AlowanceType = saleRule.AlowanceType; savedSaleRule.AllowanceLimit = saleRule.AllowanceLimit; savedSaleRule.PresentType = saleRule.PresentType; savedSaleRule.PresentLimit = saleRule.PresentLimit; savedSaleRule.UpdateDatetime = DateTime.Now; savedSaleRule.UpdateBy = SubjectUtils.GetAuthenticationId(); entities.SaveChanges(); } } catch (DbEntityValidationException e) { e.ToString(); } } }
public void UpdateTypeMethod() { try { TableType type = new TableType(); type.Code = Code; type.Name = Name; type.PeopleMax = Convert.ToInt32(PeopleMax); type.PeopleMin = Convert.ToInt32(PeopleMin); //type.Prefix = Prefix; type.PriceType = (int)PriceType; type.ServerfreeModel = (int)ServerfreeModel; type.LowConsCalcType = (int)LowConsCalcType; type.ServerFeeCalcType = (int)ServerFeeCalcType; type.Status = 0; type.Deleted = 0; type.ColorType = ColorType; type.CreateDatetime = DateTime.Now; type.CreateBy = SubjectUtils.GetAuthenticationId(); type.UpdateBy = SubjectUtils.GetAuthenticationId(); type.UpdateDatetime = DateTime.Now; type.CanDiscount = CanDiscount; type.InLowConsume = InLowConsume; TableViewModel tableViewModel = ServiceLocator.Current.GetInstance <TableViewModel>(); if (currentTableTypeId == null) {//修改窗口修改餐桌类型 type.TableTypeId = tableViewModel.SelectedType.TableTypeId; } else//新增窗口修改餐桌类型 { type.TableTypeId = (int)currentTableTypeId; } ServerFeeDetail.UpdateBy = SubjectUtils.GetAuthenticationId(); ServerFeeDetail.ServerfreeAccountType = (int)ServerfreeAccountType; LowConsumerDetail.ConsumerMode = (int)ConsumerMode; LowConsumerDetail.UpdateBy = SubjectUtils.GetAuthenticationId(); TableService.UpdateTableTypeAll(type, ServerFeeDetail, LowConsumerDetail); } catch (Exception e) { throw e; } }
/// <summary> /// 删除用户 /// </summary> /// <param name="userId"></param> public void Delete(int userId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { UserInfo userInfo = entities.UserInfo.Where(t => t.Deleted == 0 && t.UserId == userId).Single(); if (null == userInfo) { throw new ServiceException("无法找对删除的用户【" + userId + "】"); } int authId = SubjectUtils.GetAuthenticationId(); userInfo.Deleted = 1; userInfo.UpdateBy = authId; userInfo.UpdateDateTime = DateTime.Now; entities.SaveChanges(); Log.M(Loggers.USER_DELETE, authId, userId); } }
/// <summary> /// 删除角色 /// </summary> /// <param name="roleId"></param> public void DeleteRole(int roleId) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Role role = entities.Role.Where(t => t.RoleId == roleId).Single(); if (null == role) { throw new ServiceException("无法找到指定的角色【" + roleId + "】"); } int authId = SubjectUtils.GetAuthenticationId(); DateTime now = DateTime.Now; role.Deleted = 1; role.UpdateBy = authId; entities.SaveChanges(); // Log.M(Loggers.USER_DELETE_ROLE, authId, roleId); } }
/// <summary> /// 加载做法基本数据 /// </summary> private void InitDishesWayTypeBaseData() { List <DischesWayName> dwns = _DataService.FindAllDishesWayName(); DishesWayTypeItems.Clear(); if (dwns != null) { foreach (var dwn in dwns) { _DishesWayNameBean = new DishesWayNameBean(); _DishesWayNameBean.LineNumber = DishesWayTypeItems.Count + 1; _DishesWayNameBean.CreateDishesWayNameBean(dwn); _DishesWayNameBean.UpdateBy = SubjectUtils.GetAuthenticationId(); _DishesWayNameBean.UpdateDatetime = DateTime.Now; DishesWayTypeItems.Add(DishesWayNameBean); } } }
public bool update(int menusId, string code, string name) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { var list = entities.DishesMenu.Where(t => t.Deleted == 0 && (t.Code == code || t.Name == name)).ToList(); if (list != null && list.Count > 1) { return(false); } var type = entities.DishesMenu.SingleOrDefault(t => t.Deleted == 0 && t.MenusId == menusId); type.Code = code; type.Name = name; type.UpdateBy = SubjectUtils.GetAuthenticationId(); type.UpdateDatetime = DateTime.Now; entities.SaveChanges(); return(true); } }
//删除折扣方案明细 public bool DeleteDetail(int typeId) { bool flag = true; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Expression <Func <DiscountDetail, bool> > checkCourse = Detail => Detail.DiscountId == typeId && Detail.Deleted == 0; //先查询 后修改 List <DiscountDetail> type = entities.DiscountDetail.Where(checkCourse).ToList(); if (type != null && type.Count > 0) { foreach (var t in type) { t.UpdateBy = SubjectUtils.GetAuthenticationId(); t.UpdateDatetime = DateTime.Now; t.Deleted = 1; //直接修改的方式 DbEntityEntry <DiscountDetail> entry = entities.Entry <DiscountDetail>(t); entry.State = System.Data.Entity.EntityState.Modified; //设置修改状态为ture 否则数据库不会更新 entry.Property("UpdateBy").IsModified = true; entry.Property("Deleted").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; try { //关闭实体验证,不关闭验证需要整个对象全部传值 entities.Configuration.ValidateOnSaveEnabled = false; var result = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; if (result <= 0) { return(false); } } catch (Exception ex) { ex.ToString(); } } } return(flag); } }
public PromotionsDish CreatePromotionsDishObject(PromotionsDishDetailBean[] promotionsDishDetailBean) { PromotionsDish beanBack = CreatePromotionsDish(this); beanBack.Status = 1; beanBack.PromotionsDishDetail.Clear(); if (promotionsDishDetailBean != null && promotionsDishDetailBean.Length > 0) { foreach (var element in promotionsDishDetailBean) { element.CreateBy = SubjectUtils.GetAuthenticationId(); element.CreateDatetime = DateTime.Now; element.Status = 1; beanBack.PromotionsDishDetail.Add(element.CreatePromotionsDishDetail(element)); } } return(beanBack); }
public bool ModifyDeleted(int dishesId, int DishesWayId) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { var type = entities.DischesWayRef.SingleOrDefault(d => d.Deleted == 0 && d.DishId == dishesId && d.DischesWayId == DishesWayId); type.Deleted = 1; type.UpdateBy = SubjectUtils.GetAuthenticationId(); type.UpdateDatetime = DateTime.Now; entities.SaveChanges(); return(true); } } catch (Exception ex) { ex.ToString(); throw new ServiceException("删除菜品做法关联状态失败"); } }
/// <summary> /// 初始化新增做法基本数据 /// </summary> private void InitAddData() { DishesWayBean = new Model.DishesWayBean(); _DishesWayBean.CreateBy = SubjectUtils.GetAuthenticationId(); _DishesWayBean.CreateDatetime = DateTime.Now; _DishesWayBean.DischesWayName = SelectedTreeNode.Text; _DishesWayBean.DischesWayNameId = int.Parse(SelectedTreeNode.Id); List <DischesWay> dws = _DataService.FindAll(); StringBuilder sb = new StringBuilder(); if (DishesWayBean.DischesWayNameId < 10) { sb.Append("0").Append(DishesWayBean.DischesWayNameId); } else { sb.Append(DishesWayBean.DischesWayNameId); } _DishesWayBean.Code = sb.ToString() + (dws.Count + 1); }
/// <summary> /// 收回权限 /// </summary> /// <param name="userId"></param> /// <param name="roles"></param> public void Revoke(int userId, int[] roles) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { List <UserRoleRef> roleRes = entities.UserRoleRef.Where(t => t.UserId == userId && roles.Any(a => t.RoleId == a) && t.Deleted == 0).ToList(); if (null == roleRes || roleRes.Count == 0) { throw new ServiceException("无法收回不存在的用户【" + userId + "】的角色【" + Convert.ToString(roleRes) + "】!"); } int authId = SubjectUtils.GetAuthenticationId(); DateTime now = DateTime.Now; foreach (var role in roleRes) { role.Deleted = 1; role.UpdateBy = authId; role.UpdateDateTime = now; } entities.SaveChanges(); Log.M(Loggers.USER_REVOKE_ROLE, authId, userId, new object[] { roles }); } }
//修改逻辑 public void UpdateDishesObject() { //修改菜品 if (SelectedDishUnitItem != null) { //修改菜品单位 _DishBean.DishUnitId = SelectedDishUnitItem.DishUnitId; } _DishBean.UpdateDatetime = DateTime.Now; _DishBean.UpdateBy = SubjectUtils.GetAuthenticationId(); bool flag = _DataService.updateDish(_DishBean.CreateDish(_DishBean)); if (flag) { //修改菜品价格 DishPrice dp = _DishBean.CreateDishPrice(_DishBean); //修改菜品主价格 _DataService.UpdateDishPriceMain(dp); //批量修改菜品价格 if (!IsEditDishPrice) { foreach (var element in _DishePriceList) { element.CreateBy = 1; element.DishId = _DishBean.DishId; element.CreateTime = DateTime.Now; } _DataService.UpdateDishPrice(_DishBean.DishId, _DishePriceList.ToArray()); } //重新加载所有数据 LoadDishBase(_DishTypeIdLast); //关闭窗口 AddDishWin.Close(); } else { MessageBox.Show("修改菜品失败!"); } }
/// <summary> /// 重置密码 /// </summary> /// <param name="userId"></param> /// <param name="newPasswd"></param> public void ResetPasswd(int userId, string newPasswd) { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { UserInfo _UserInfo = entities.UserInfo.Find(userId); if (_UserInfo.Expired == 1) { throw new ServiceException("无法修改已经过期的用户!"); } if (_UserInfo.Disabled == 1) { throw new ServiceException("无法修改已经禁用的用户!"); } int authId = SubjectUtils.GetAuthenticationId(); _UserInfo.Salt = CryptoUtils.GetSalt(); _UserInfo.Password = CryptoUtils.MD5Encrypt(newPasswd); _UserInfo.UpdateBy = authId; _UserInfo.UpdateDateTime = DateTime.Now; entities.SaveChanges(); //记录日志 Log.M(Loggers.USER_RESET_PASSWORD, authId, userId, new object[] { authId, userId }); } }
public TableItem Add(int TableId) { //添加 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { TableItem mt = new TableItem(); mt.TableId = TableId; mt.CreateBy = SubjectUtils.GetAuthenticationId(); mt.CreateDatetime = DateTime.Now; var market = entities.TableItem.Add(mt); entities.SaveChanges(); return(market); } catch (Exception e) { e.ToString(); return(null); } } }
/// <summary> /// 0代表是新增做法类型 1表示修改做法类型 /// </summary> /// <param name="type"></param> private void OpenDishesWin(ButtonEventType type) { DishesWaySettingXaml = new DishesWaySettingWindow(); switch (type) { case ButtonEventType.ADD: if (SelectedTreeNode == null) { MessageBox.Show("请选择做法类型!"); return; } InitAddData(); DishesWaySettingXaml.AddDescription.Visibility = Visibility.Visible; DishesWaySettingXaml.Continue.Visibility = Visibility.Visible; DishesWaySettingXaml.UpdateRecord.Visibility = Visibility.Hidden; break; case ButtonEventType.UPDATE: if (DishesWaySelectedItem == null) { MessageBox.Show("请选择要修改的做法!"); return; } DishesWayBean = new DishesWayBean(); DishesWayBean.IsReadOnlyCode = true; DishesWaySelectedItem.UpdateBy = SubjectUtils.GetAuthenticationId(); DishesWaySelectedItem.UpdateDatetime = DateTime.Now; DishesWayBean.CreateDishesWayBean(DishesWaySelectedItem); DishesWayBean.CurrentScaleText = (DishesWayTableItems.IndexOf(DishesWaySelectedItem) + 1) + "/" + DishesWayTableItems.Count; DishesWaySettingXaml.AddDescription.Visibility = Visibility.Hidden; DishesWaySettingXaml.Continue.Visibility = Visibility.Hidden; DishesWaySettingXaml.UpdateRecord.Visibility = Visibility.Visible; break; } DishesWaySettingXaml.ShowDialog(); }
/// <summary> /// 新增做法 /// </summary> /// <param name="odw">做法对象</param> /// <returns></returns> public bool Add(DischesWay odw) { if (odw == null) { return(false); } //添加 using (ChooseDishesEntities entities = new ChooseDishesEntities()) { try { odw.CreateBy = SubjectUtils.GetAuthenticationId(); odw.CreateDatetime = DateTime.Now; entities.DischesWay.Add(odw); entities.SaveChanges(); return(true); } catch (Exception e) { e.ToString(); return(false); } } }
//确定落单 private void CommitOrder() { if (string.IsNullOrEmpty(ContactNumber)) { MessageBox.Show("请填写联系电话"); return; } if (string.IsNullOrEmpty(OrderPeople)) { MessageBox.Show("请填写或者选择订餐人"); return; } if (string.IsNullOrEmpty(Address)) { MessageBox.Show("请填写订餐人地址"); return; } bool flag = false; //1.将订餐人信息插入到外卖客户信息表中 TakeoutClientInfo info = _DataService.FindTakeoutClientByTelephone(ContactNumber); if (info == null) { info = new TakeoutClientInfo() { OrderPeopleId = new Random().Next(1000) + 1, Order_people = OrderPeople, Telephone = ContactNumber, Address = Address, Create_by = SubjectUtils.GetAuthenticationId(), //操作人id Create_datetime = DateTime.Now, Status = 0, Deleted = 0 }; flag = _DataService.AddTakeoutClientInfo(info); } else { info.Order_people = OrderPeople; info.Telephone = ContactNumber; info.Address = Address; info.Status = 0; info.Deleted = 0; info.Update_by = 0; //操作人id info.Update_datetime = DateTime.Now; flag = _DataService.UpdateTakeoutClientInfo(info); } if (flag) { TakeoutOrder to = new TakeoutOrder(); to.OrderPeopleId = info.OrderPeopleId; to.OrderId = 1222; //订单号,去订单中查询获取 to.DeliveryManNum = DeliveryMan; //需要去员工数据库查找确定 to.Num = "Q000"; to.AdvanceAmount = 0; to.DeliverTime = DateTime.Now; //送出时指定 to.SendTime = DateTime.Now; to.Status = 0; //0表示未送出状态,1表示在送出状态,2表示送达未签收状态,3.送达已签收状态 to.Deleted = 0; to.CreateBy = SubjectUtils.GetAuthenticationId(); //操作人id to.CreateDatetime = DateTime.Now; //2.将订单信息插入到订单表中 flag = _DataService.AddTakeoutOrder(to); if (flag) { //关闭所有页面 //通知主线程执行关闭操作 DispatcherHelper.CheckBeginInvokeOnUI(() => TakeoutOrderWindow.getInstance().Close()); //3.在厨房打印出厨打单 return; } } DispatcherHelper.CheckBeginInvokeOnUI(() => MessageBox.Show("外卖单录入失败")); }