//0添加失败,-1添加重复
        public int addLocation(Location location)
        {
            int flag = 0;
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                //查询编码是否存在
                var type = entities.Location.SingleOrDefault(bt => bt.Code == location.Code && bt.Deleted == 0);
                if (type == null)
                {
                    //实体绑定数据
                    entities.Location.Add(location);
                    try
                    {
                        //操作数据库
                        flag = entities.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                    flag = -1;
                }
            }
            return flag;
        }
        public bool UpdateRawUnit(RawUnit rw)
        {
            if (rw == null)
            {
                return false;
            }
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    var type = entities.RawUnit.SingleOrDefault(bt => bt.UnitId == rw.UnitId);
                    if (type != null)
                    {
                        type.Deleted = rw.Deleted;
                        type.Name = rw.Name;
                        type.Status = rw.Status;
                        type.UpdateBy = rw.UpdateBy;
                        type.UpdateDatetime = rw.UpdateDatetime;
                        entities.SaveChanges();
                        return true;
                    }

                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
                return false;
            }
        }
        //根据外卖客户id修改外卖客户信息
        public bool UpdateTakeoutClientInfo(TakeoutClientInfo info)
        {
            if (info == null)
            {
                return false;
            }
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    var type = entities.TakeoutClientInfo.SingleOrDefault(bt => bt.OrderPeopleId == info.OrderPeopleId);
                    if (type != null)
                    {
                        type.Order_people = info.Order_people;
                        type.Mobile = info.Mobile;
                        type.Status = info.Status;
                        type.Telephone = info.Telephone;
                        type.Update_by = info.Update_by;
                        type.Update_datetime = info.Update_datetime;
                        type.Address = info.Address;
                        type.Deleted = info.Deleted;
                        entities.SaveChanges();
                        return true;
                    }

                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
                return false;
            }
        }
Ejemplo n.º 4
0
        //新增桌类
        public int SaveTableType(TableType type)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    Hashtable hash = new Hashtable();//返回结果

                    List<TableType> types;
                    //检查类型编号或者类型名称是否重复
                    types = entities.TableType.Where(info => info.Name == type.Name || info.Code == type.Code).ToList();
                    if (types != null && types.Count > 0)
                    {
                        hash.Add("code", 1);
                        if (types[0].Name == type.Name)
                        {
                            throw new ServiceException("类型名称已经存在,请重新命名!");
                        }
                        else if (types[0].Code == type.Code)
                        {
                            throw new ServiceException("类型编号已经存在!");
                        }
                    }
                    entities.TableType.Add(type);
                    entities.SaveChanges();
                    return type.TableTypeId;
                }
                catch (Exception e)
                {
                    throw new ServiceException(e.Message);
                }
            };
        }
 public int Add(string code, string name)
 {
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         DishesMenu menu = DishesMenuModel.build(code, name, 1000);
        entities.DishesMenu.Add(menu);
        entities.SaveChanges();
        return menu.MenusId;
     }
   
   }
        /// <summary>
        /// 更新指定的参数的值
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void Update(string name, string value) {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                Config config = entities.Config.Single(c => c.Name.Equals(name));
               if (null == config) {
                   throw new NotFoundException("参数名【"+name+"】未找到匹配的项!");
               }
               config.Value = value;
               entities.SaveChanges();
            }

        }
 public void Delete(int dishesMenuId)
 {
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         var delObj=entities.DishesMenu.Find(dishesMenuId);
         if (null == delObj) {
             throw new NotFoundException();
         }
         entities.DishesMenu.Remove(delObj);
         entities.SaveChanges();
     }
 }
        public bool UpdateRawMaterial(RawMaterial rw)
        {
            if (rw == null)
            {
                return false;
            }
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    var type = entities.RawMaterial.SingleOrDefault(bt => bt.Id == rw.Id);
                    if (type != null)
                    {
                        type.CheckDay = rw.CheckDay;
                        type.Deleted = rw.Deleted;
                        type.Detail = rw.Detail;
                        type.Format = rw.Format;
                        type.FormulaUnit = rw.FormulaUnit;
                        type.InGoodsPrice = rw.InGoodsPrice;
                        type.InGoodsStock = rw.InGoodsStock;
                        type.InGoodsUnit = rw.InGoodsUnit;
                        type.IsWeight = rw.IsWeight;
                        type.MaterialName = rw.MaterialName;
                        type.OrderRawAdd = rw.OrderRawAdd;
                        type.Pinying = rw.Pinying;
                        type.Raw = rw.Raw;
                        type.RawAddPrice = rw.RawAddPrice;
                        type.SaleUnit = rw.SaleUnit;
                        type.Status = rw.Status;
                        type.StockFormula = rw.StockFormula;
                        type.StockMax = rw.StockMax;
                        type.StockMin = rw.StockMin;
                        type.StockUnit = rw.StockUnit;
                        type.UpdateBy = rw.UpdateBy;
                        type.UpdateDatetime = rw.UpdateDatetime;
                        type.WriteDowns = rw.WriteDowns;
                        entities.SaveChanges();
                        return true;
                    }

                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
                return false;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="app"></param>
        /// <param name="function"></param>
        /// <param name="actor"></param>
        /// <param name="itemId"></param>
        /// <param name="message"></param>
        /// <param name="args"></param>
      public  void Log(Format format,LogType type, int actor, int objectId,object[] args) {
          SystemLog _Log = new SystemLog();
          _Log.ItemId = Convert.ToString(objectId);
          _Log.Actor = Convert.ToString(actor);
          _Log.CreateDatetime = DateTime.Now;
          _Log.Module = format.Function.Module.Name;
          _Log.Function = format.Function.Name;
          _Log.Body = LoggerUtils.Format(format, args);
          _Log.OpType = Enum.GetName(typeof(LogType), type);

          using (ChooseDishesEntities entities = new ChooseDishesEntities()) {
              entities.SystemLog.Add(_Log);
              entities.SaveChanges();
          }      
      }
Ejemplo n.º 10
0
 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;
     }
 }
Ejemplo n.º 11
0
 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;
     }
   
   }
	    public bool Add(int dishesId, int DishesWayId) {
            try
            {
                using (ChooseDishesEntities entities = new ChooseDishesEntities())
                {
                    entities.DischesWayRef.Add(GetDischesWayRef(dishesId, DishesWayId));
                    entities.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw new ServiceException("新增菜品做法关联失败");
            }
	    }
	    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("删除菜品做法关联状态失败");
            }
	    }
Ejemplo n.º 14
0
  /// <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 MarketType AddMarketType(MarketType mt) {
            if (mt == null)
            {
                return null;
            }
            //添加
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                try
                {
                    MarketType market=entities.MarketType.Add(mt);
                    entities.SaveChanges();
                    return market;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return null;
                }
            }
	    }
 /// <summary>
 /// 新增做法
 /// </summary>
 /// <param name="odw">做法对象</param>
 /// <returns></returns>
 public bool Add(DischesWay odw)
 {
     if (odw == null)
     {
         return false;
     }
     //添加
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             entities.DischesWay.Add(odw);
             entities.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             e.ToString();
             return false;
         }
     }
 }
        public bool AddTakeoutClientInfo(TakeoutClientInfo info)
        {
            if (info == null)
            {
                return false;
            }
            //添加
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                try
                {
                    entities.TakeoutClientInfo.Add(info);
                    entities.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
            }
        }
        public RawUnit AddRawUnit(RawUnit rw)
        {
            if (rw == null)
            {
                return null;
            }
            //添加
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                try
                {
                    RawUnit ru=entities.RawUnit.Add(rw);
                    entities.SaveChanges();
                    return ru;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return null;
                }
            }
        }
        public bool AddRawMaterial(RawMaterial rw)
        {
            if (rw == null)
            {
                return false;
            }
            //添加
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {

                try
                {
                    entities.RawMaterial.Add(rw);
                    entities.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
            }
        }
Ejemplo n.º 20
0
        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;
                }
            }
        }
        /**根据做法对象id作为参数修改做法
                     type.Name = odw.Name;   
                    type.Status = odw.Status;
                    type.UpdateBy = odw.UpdateBy;    //修改人编号
                    type.UpdateDatetime = odw.UpdateDatetime;   //修改时间
                    type.WayDetail = odw.WayDetail;
                    type.DischesWayId = odw.DischesWayId;
                    type.AddPrice = odw.AddPrice;
                    type.AddPriceByNum = odw.AddPriceByNum;
                    type.Deleted = odw.Deleted;
                    type.PingYing = odw.PingYing;
         */
        public bool Modify(DischesWay odw)
        {
            if (odw == null)
            {
                return false;
            }
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    var type = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId == odw.DischesWayId);
                    if (type != null)
                    {
                        type.Name = odw.Name;
                        type.Status = odw.Status;
                        type.UpdateBy = odw.UpdateBy;
                        type.UpdateDatetime = odw.UpdateDatetime;
                        type.WayDetail = odw.WayDetail;
                        type.AddPrice = odw.AddPrice;
                        type.AddPriceByNum = odw.AddPriceByNum;
                        type.Deleted = odw.Deleted;
                        type.PingYing = odw.PingYing;
                        entities.SaveChanges();
                        return true;
                    }

                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
                return false;
            }
        }
 //删除收银方式 返回true 为修改成功
 public bool deleteDish(int Id)
 {
     try
     {
         using (ChooseDishesEntities entities = new ChooseDishesEntities())
         {
             var type = entities.Dish.SingleOrDefault(bt => bt.DishId == Id);
             if (type != null)
             {
                 type.Deleted = 1;
                 type.UpdateDatetime = DateTime.Now;
                 type.UpdateBy = SubjectUtils.GetAuthenticationId();
                 entities.SaveChanges();
             }
             else
             {
                 return false;
             }
         }
         return true;
     }
     catch (Exception e)
     {
         e.ToString();
         return false;
     }
 }
        //根据 一个 菜品 id 和菜品价格集合 新增 菜品价格 
        public bool SaveDishPrice(int DishId, DishPrice[] dishPrices)
        {
            if (dishPrices != null) {
                using (ChooseDishesEntities entities = new ChooseDishesEntities())
                {
                    for (int i = 0; i < dishPrices.Length; i++)
                    {

                            entities.DishPrice.Add(dishPrices[i]);
                            entities.SaveChanges();
                        
                    }
                }
               
            }

            return false;
        }
        //根据菜品id 和 菜品价格id 删除菜品价格 
        public bool DeleteDishPrice(DishPrice dishPrice)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                var type = entities.DishPrice.SingleOrDefault(bt => bt.DishId == dishPrice.DishId && bt.IsMainPrice != 1&&bt.Id ==dishPrice.Id);
                if (type != null)
                {
                    type.Deleted = 1;
                    type.Update_by = SubjectUtils.GetAuthenticationId();
                    type.UpdateTime = DateTime.Now;
                    entities.SaveChanges();
                }
            }

            return true;
        }
        /**根据做法id更新做法删除的状态*/
        public bool UpdateDeletedById(int id,int deletedStatus)
        {
            //修改  直接修改
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    var type = entities.DischesWay.SingleOrDefault(bt => bt.DischesWayId==id);
                    if (type != null)
                    {
                        type.Deleted = deletedStatus;
                        entities.SaveChanges();
                        return true;
                    }

                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }
                return false;
            }
        }
        //根据做法类型编码删除菜品做法类型,如果删除失败返回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;
                }

            }

        }
 //根据做法类型id修改删除状态
 public bool UpdateDishesWayNameDeletedTypeById(int Id)
 {
     if (Id==null)
     {
         return false;
     }
     //修改  直接修改
     using (ChooseDishesEntities entities = new ChooseDishesEntities())
     {
         try
         {
             var type = entities.DischesWayName.SingleOrDefault(bt => bt.DischesWayNameId == Id);
             if (type != null)
             {
                 type.UpdateBy = SubjectUtils.GetAuthenticationId();     //操作人员id
                 type.UpdateDatetime =DateTime.Now;
                 type.Deleted = 1;
                 entities.SaveChanges();
                 return true;
             }
         }
         catch (Exception e)
         {
             e.ToString();
             return false;
         }
     }
     return false;
 }
 //修改菜品做法类型,传入的参数需要包含: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;
 }
        //根据菜品id 和 菜品价格id 修改菜品价格 
        public bool UpdateDishPrice(int DishId, DishPrice[] dishPrices)
        {
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                foreach (var dishPrice in dishPrices)
                {
                    if (dishPrice.IsMainPrice != 1) { 
                        var type = entities.DishPrice.SingleOrDefault(bt => bt.Id == dishPrice.Id);
                        if (type != null)
                        {
                            type.Price1 = dishPrice.Price1;
                            type.Price2 = dishPrice.Price2;
                            type.Price3 = dishPrice.Price3;
                            type.MemberPrice1 = dishPrice.MemberPrice1;
                            type.MemberPrice2 = dishPrice.MemberPrice2;
                            type.MemberPrice3 = dishPrice.MemberPrice3;
                            type.Update_by = SubjectUtils.GetAuthenticationId();
                            type.UpdateTime = DateTime.Now;
                            entities.SaveChanges();
                        }
                        else {
                            dishPrice.CreateTime = DateTime.Now;
                            entities.DishPrice.Add(dishPrice);
                            entities.SaveChanges();
                        }
                    }
                }

            }
            return true;
        }
        /**根据指定编码删除对应做法*/
        public bool Deleted(int id)
        {
            if (id < 0)
            {
                return false;
            }
            using (ChooseDishesEntities entities = new ChooseDishesEntities())
            {
                try
                {
                    DischesWay booktype = new DischesWay()
                    {
                        DischesWayId = id,
                    };
                    DbEntityEntry<DischesWay> entry = entities.Entry<DischesWay>(booktype);
                    entry.State = EntityState.Deleted;
                    entities.SaveChanges();
                    return true;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return false;
                }

            }
        }