Exemplo n.º 1
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="UpdateEntity"></param>
        /// <returns></returns>
        public bool UpdateEntity(UserEntity UpdateEntity)
        {
            var db     = SugarDbContext.GetInstance();
            var result = db.Updateable <UserEntity>(UpdateEntity).Where(true).ExecuteCommand();

            return(result >= 0 ? true : false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 窗口数据初始化
        /// </summary>
        /// <returns></returns>
        public WeightInitDto GetInitData()
        {
            var model = new WeightInitDto();

            try
            {
                var nowTime = DateTime.Now.AddDays(-1);
                using (var sql = SugarDbContext.GetInstance())
                {
                    model.BatchInfo = sql.Queryable <Batches>().Where(s => s.weighingBeginTime > nowTime && s.flag == false).First();
                    model.Products  = sql.Queryable <AnimalTypes>().Where(s => s.price > 0).ToList();
                    var param = sql.Queryable <Params>().OrderBy(s => s.factoryId).First();
                    if (param != null)
                    {
                        model.HookCount   = param.hookCount;
                        model.HooksWeight = param.hooksWeight;
                    }
                }
            }
            catch (Exception ex)
            {
                LogNHelper.Exception(ex);
                return(null);
            }

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        public bool UpdatePassWord(string userId, string passWord)
        {
            var db     = SugarDbContext.GetInstance();
            var result = db.Updateable <UserEntity>(new { Password = passWord }).Where(t => t.UserId == userId).ExecuteCommand();

            return(result >= 0 ? true : false);
        }
Exemplo n.º 4
0
        public Loginer Login(string uname, string pwd)
        {
            Loginer userer = null;

            try
            {
                using (var sql = SugarDbContext.GetInstance())
                {
                    var user = sql.Queryable <Opers>().Where(s => s.userName == uname && s.password == pwd)
                               .First();
                    if (user == null)
                    {
                        return(null);
                    }
                    userer = new Loginer();
                    //存储登录用户信息
                    userer.Account     = user.userName;
                    userer.AccountName = user.operName;
                    userer.LoginTime   = DateTime.Now;
                }
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(userer);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 开始称重
        /// </summary>
        /// <returns></returns>
        public string SaveBatchInfo(Batches dto)
        {
            dto.originalPlace        = string.Empty;
            dto.istrace              = false;
            dto.upload               = false;
            dto.weighingBeginTime    = DateTime.Now;
            dto.weighingFinishedTime = TimeHelper.GetMinDateTime();

            try
            {
                var stime = new DateTime(dto.weighingBeginTime.Year, dto.weighingBeginTime.Month, dto.weighingBeginTime.Day);
                using (var sql = SugarDbContext.GetInstance())
                {
                    int sort = sql.Queryable <Batches>().Where(s => s.weighingBeginTime > stime)
                               .OrderBy(s => s.sort, OrderByType.Desc).Select(s => s.sort).First();
                    sort    += 1;
                    dto.sort = sort;
                    string sortNum = sort.ToString().PadLeft(2, '0');
                    dto.batchId = dto.yearNum + "-" + sortNum;
                    sql.Insertable(dto).ExecuteCommand();
                }

                return(dto.batchId);
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(string.Empty);
        }
Exemplo n.º 6
0
 public Params GetFactory()
 {
     using (var sql = SugarDbContext.GetInstance())
     {
         return(sql.Queryable <Params>().OrderBy(s => s.factoryId).First());
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 取消收藏
        /// </summary>
        /// <param name="knowledgeGUID"></param>
        /// <returns></returns>
        public bool CancelStoreKnowledge(string knowledgeGUID)
        {
            string userId = OperatorProvider.Provider.Current().UserId;
            var    db     = SugarDbContext.GetInstance();

            return(db.Deleteable <KnowledgeStoreEntity>(t => t.knowledgeGUID == knowledgeGUID && t.UserId == userId).ExecuteCommand() >= 0 ? true : false);
        }
Exemplo n.º 8
0
        public string UpdatePwd(string uname, string oldPwd, string newPwd)
        {
            try
            {
                string encodePwd = CEncoder.Encode(oldPwd);
                using (var sql = SugarDbContext.GetInstance())
                {
                    var id = sql.Queryable <Opers>().Where(s => s.userName == uname && s.password == encodePwd)
                             .Select(s => s.Id).First();
                    if (id == 0)
                    {
                        return("原始密码错误!!!");
                    }
                    string newEncodePwd = CEncoder.Encode(newPwd);

                    sql.Updateable <Opers>().UpdateColumns(s => new Opers()
                    {
                        password = newEncodePwd
                    })
                    .Where(s => s.Id == id).ExecuteCommand();
                }
            }
            catch (Exception ex)
            {
                LogNHelper.Exception(ex);
                return("密码修改失败!!!");
            }

            return(string.Empty);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 账户不能重复
        /// </summary>
        /// <param name="account">账户值</param>
        /// <param name="keyValue">主键</param>
        /// <returns></returns>
        public bool ExistAccount(string account)
        {
            var expression = LinqExt.True <UserEntity>();

            expression = expression.And(t => t.Account == account);
            var db = SugarDbContext.GetInstance();

            return(_knowledgeRepository.IQueryable(expression).Count() > 0 ? true : false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public KnowledgeInfoEntity GetEntity(string keyvalue)
        {
            //更新查看次数
            var db = SugarDbContext.GetInstance();

            db.Updateable <KnowledgeInfoEntity>().UpdateColumns(t => new KnowledgeInfoEntity()
            {
                ViewCount = t.ViewCount + 1
            }).Where(t => t.knowledgeGUID == keyvalue).ExecuteCommand();
            return(_knowledgeRepository.FindEntity(keyvalue));
        }
Exemplo n.º 11
0
 public IActionResult DbCreate()
 {
     try
     {
         //生成数据库表
         SugarDbContext db = new SugarDbContext();
         db.GetInstance().CodeFirst.SetStringDefaultLength(20).InitTables(typeof(MenuInfo), typeof(UserInfo), typeof(UserRelationRole), typeof(UserRoleInfo), typeof(UserRoleRelateMenu));
         var o = AspectCoreContainer.Resolve <IOptions <DbContextOption> >();
         return(Json(new { result = "成功生成数据库表", option = o.Value }));
     }
     catch (Exception e)
     {
         return(Json(new { result = "生成数据库表失败", message = e.Message }));
     }
 }
Exemplo n.º 12
0
 public bool DelById(int id)
 {
     try
     {
         using (var sql = SugarDbContext.GetInstance())
         {
             sql.Deleteable <Products>().Where(s => s.productId == id).ExecuteCommand();
         }
         return(true);
     }
     catch (Exception e)
     {
         LogNHelper.Exception(e);
     }
     return(false);
 }
Exemplo n.º 13
0
        /// <summary>
        /// 获取称重报表数据
        /// </summary>
        /// <param name="batchId"></param>
        /// <returns></returns>
        public List <WeightGridDto> GetWeightReport(WeightBatchDto dto)
        {
            var list = new List <WeightGridDto>();

            try
            {
                string batchId = dto.batchId.Trim();
                using (var sql = SugarDbContext.GetInstance())
                {
                    list = sql.Queryable <WeighingsRaw>().Where(s => s.batchId == batchId).Select(s =>
                                                                                                  new WeightGridDto()
                    {
                        BatchId     = s.batchId,
                        Num         = s.hooksCount,
                        MaoWeight   = s.grossWeights,
                        PiWeight    = s.hookWeights,
                        ProductName = s.productName,
                        Price       = s.ProductPrice,
                        WeightTime  = s.weighingTime
                    }).OrderBy(s => s.WeightTime).ToList();
                }

                if (list.Any())
                {
                    //int sort = 1;
                    foreach (var s in list)
                    {
                        //s.SerialNum = sort;
                        s.Name       = dto.hostName;
                        s.IdNumber   = dto.PIN;
                        s.NetWeight  = s.MaoWeight - s.PiWeight;
                        s.TotalPrice = s.NetWeight * s.Num;
                        // sort++;
                    }
                }

                return(list);
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(new List <WeightGridDto>());
        }
Exemplo n.º 14
0
        public bool SaveParam(Params dto)
        {
            try
            {
                using (var sql = SugarDbContext.GetInstance())
                {
                    sql.Deleteable <Params>().ExecuteCommand();
                    sql.Insertable(dto).ExecuteCommand();
                }
                return(true);
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(false);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 刷新货物列表
        /// </summary>
        /// <returns></returns>
        public List <AnimalTypes> GetProduct()
        {
            var list = new List <AnimalTypes>();

            try
            {
                using (var sql = SugarDbContext.GetInstance())
                {
                    list = sql.Queryable <AnimalTypes>().Where(s => s.price > 0).ToList();
                }
            }
            catch (Exception ex)
            {
                LogNHelper.Exception(ex);
            }

            return(list);
        }
Exemplo n.º 16
0
        public List <Products> GetProductList(int page, int psize)
        {
            var list = new List <Products>();

            try
            {
                //  var nowTime = DateTime.Now.AddDays(-1);
                using (var sql = SugarDbContext.GetInstance())
                {
                    list = sql.Queryable <Products>().OrderBy(s => s.productNo).ToList();
                }
            }
            catch (Exception ex)
            {
                LogNHelper.Exception(ex);
            }

            return(list);
        }
Exemplo n.º 17
0
        public bool UpdateHookWeight(string id, decimal weights, int count)
        {
            try
            {
                decimal perWeight = decimal.Round(weights / count, 2);
                using (var sql = SugarDbContext.GetInstance())
                {
                    sql.Updateable <Params>().UpdateColumns(s => new Params()
                    {
                        hookCount = count, hooksWeight = weights, hookWeight = perWeight
                    }).Where(s => s.factoryId == id).ExecuteCommand();
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(false);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 收藏
        /// </summary>
        /// <param name="knowledgeGUID"></param>
        /// <returns></returns>
        public bool StoreKnowledge(string knowledgeGUID)
        {
            KnowledgeStoreEntity entity = new KnowledgeStoreEntity();

            entity.F_ID          = Guid.NewGuid().ToString();
            entity.UserId        = OperatorProvider.Provider.Current().UserId;
            entity.knowledgeGUID = knowledgeGUID;
            entity.F_CreateDate  = DateTime.Now;

            var db = SugarDbContext.GetInstance();
            //判断是否已收藏
            var count = db.Queryable <KnowledgeStoreEntity>().Where(t => t.UserId == entity.UserId && t.knowledgeGUID == knowledgeGUID).Count();

            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(db.Insertable <KnowledgeStoreEntity>(entity).ExecuteCommand() >= 0 ? true : false);
            }
        }
Exemplo n.º 19
0
 public bool SaveData(Products dto)
 {
     try
     {
         using (var sql = SugarDbContext.GetInstance())
         {
             if (dto.productId > 0)
             {
                 sql.Updateable(dto).ExecuteCommand();
             }
             else
             {
                 sql.Insertable(dto).ExecuteCommand();
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         LogNHelper.Exception(e);
     }
     return(false);
 }
Exemplo n.º 20
0
 public bool SavePrice(AnimalTypes dto)
 {
     try
     {
         using (var sql = SugarDbContext.GetInstance())
         {
             if (dto.animalTypeId == 0)
             {
                 sql.Insertable(dto).ExecuteCommand();
             }
             else
             {
                 sql.Updateable(dto).ExecuteCommand();
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         LogNHelper.Exception(ex);
     }
     return(false);
 }
Exemplo n.º 21
0
        /// <summary>
        /// 完成称重
        /// </summary>
        /// <param name="batchId"></param>
        /// <returns></returns>
        public bool CompleteWeight(string batchId)
        {
            try
            {
                var stime = DateTime.Now;
                using (var sql = SugarDbContext.GetInstance())
                {
                    sql.Updateable <Batches>()
                    .UpdateColumns(s => new Batches()
                    {
                        flag = true, weighingFinishedTime = stime
                    })
                    .Where(s => s.batchId == batchId).ExecuteCommand();
                }

                return(true);
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(false);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 查询已完成的称重批次
        /// </summary>
        /// <param name="time"></param>
        /// <param name="name"></param>
        /// <param name="idnumber"></param>
        /// <returns></returns>
        public List <WeightBatchDto> GetWeightBatch(DateTime time, string name, string idnumber)
        {
            var list = new List <WeightBatchDto>();

            try
            {
                var yearNum = time.ToString("yyyyMMdd").ToInt();
                using (var sql = SugarDbContext.GetInstance())
                {
                    list = sql.Queryable <Batches>()
                           .Where(s => s.yearNum == yearNum && s.flag == true)
                           .WhereIF(!string.IsNullOrEmpty(name), s => s.hostName.Contains(name))
                           .WhereIF(!string.IsNullOrEmpty(idnumber), s => s.PIN.Contains(idnumber))
                           .OrderBy(s => s.sort, OrderByType.Desc)
                           .Select(s => new WeightBatchDto()
                    {
                        batchId = s.batchId, hostName = s.hostName, PIN = s.PIN, weighingBeginTime = s.weighingBeginTime
                    }).ToList();

                    if (list.Any())
                    {
                        list.ForEach(s =>
                        {
                            s.Num = sql.Queryable <WeighingsRaw>().Where(a => a.batchId == s.batchId)
                                    .Sum <int>(a => a.hooksCount);
                        });
                    }
                }
            }
            catch (Exception e)
            {
                LogNHelper.Exception(e);
            }

            return(list);
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var db = SugarDbContext.GetInstance();

            db.DbFirst.Where("knowledgeInfo").CreateClassFile("D:\\sugarEntityGenerate\\1");
        }
Exemplo n.º 24
0
 public BaseSugarRepository()
 {
     dbContext = new SugarDbContext();
     db        = dbContext.GetInstance();
     entitydb  = dbContext.GetEntityDB <TEntity>();
 }