Ejemplo n.º 1
0
        public User GetAdmin()
        {
            var u = _db.Load <User>(MySearchUtil.New()
                                    .AndEqual("Name", "admin"));

            return(u);
        }
Ejemplo n.º 2
0
 public override string ValidUpdate(Asset entity, IAppUser user)
 {
     if (string.IsNullOrWhiteSpace(entity.Name))
     {
         return("资产名称不能为空");
     }
     //if (string.IsNullOrWhiteSpace(entity.Source))
     //{
     //    return "采购来源不能为空";
     //}
     //if (string.IsNullOrWhiteSpace(entity.Position))
     //{
     //    return "资产位置不能为空";
     //}
     //if (entity.AssignDate == null)
     //{
     //    return "登记时间不能为空";
     //}
     if (entity.AssetCateId <= 0)
     {
         return("资产类型不能为空");
     }
     if (!string.IsNullOrWhiteSpace(entity.Code))
     {
         var count = db.GetCount <Asset>(MySearchUtil.New()
                                         .AndEqual("Code", entity.Code)
                                         .AndEqual("IsDel", false)
                                         .AndNotEqual("Id", entity.Id));
         if (count > 0)
         {
             return("资产编号已存在");
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        protected override string ValidateCreate(DataItemEntity entity, IAppUser user)
        {
            if (user.Name != "admin")
            {
                return("仅管理员可创建字典项");
            }

            if (string.IsNullOrWhiteSpace(entity.K))
            {
                return("字典键不能为空");
            }

            if (string.IsNullOrWhiteSpace(entity.V))
            {
                return("字典值不能为空");
            }

            var count = db.GetCount <DataItemEntity>(MySearchUtil.New()
                                                     .AndEqual("K", entity.K.Trim())
                                                     .AndEqual("IsDel", false));

            if (count > 0)
            {
                return("该键已存在");
            }
            return(base.ValidateCreate(entity, user));
        }
Ejemplo n.º 4
0
        public override MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Key))
            {
                // util.AndContains(new string[] { "Title", "Name" }, Key.Trim());
            }

            if (SchoolId.HasValue)
            {
                util.AndEqual("SchoolId", SchoolId.Value);
            }

            if (StudentId.HasValue)
            {
                util.AndEqual("StudentId", StudentId.Value);
            }

            if (!string.IsNullOrWhiteSpace(StudentName))
            {
                util.AndContains("StudentName", StudentName.Trim());
            }

            if (!string.IsNullOrWhiteSpace(PaymentMethod))
            {
                util.AndContains("PaymentMethod", PaymentMethod.Trim());
            }

            util.OrderBy(SetOrderBy());

            return(util);
        }
Ejemplo n.º 5
0
        protected override string ValidateDelete(DataItemEntity entity, IAppUser user)
        {
            if (!entity.Editable && user.Name != "admin")
            {
                return("该项目不允许编辑");
            }

            if (string.IsNullOrWhiteSpace(entity.K))
            {
                return("字典键不能为空");
            }

            if (string.IsNullOrWhiteSpace(entity.V))
            {
                return("字典值不能为空");
            }

            var count = db.GetCount <DataItemEntity>(MySearchUtil.New()
                                                     .AndEqual("K", entity.K.Trim())
                                                     .AndEqual("IsDel", false)
                                                     .AndNotEqual("Id", entity.Id));

            if (count > 0)
            {
                return("该键已存在");
            }

            return(string.Empty);
        }
Ejemplo n.º 6
0
        public Result SetMaster(int departmentId, int userId)
        {
            var department = Load(departmentId);

            if (department == null || department.IsDel)
            {
                return(ResultUtil.AuthFail("请求的部门不存在"));
            }

            if (department.MasterId == userId)
            {
                return(ResultUtil.Success());
            }

            var user = Db.LoadWith <UserEntity, DepartmentEntity>(
                "SELECT * FROM Base_User WHERE Id=@Id;SELECT * FROM Base_Department WHERE Id IN (SELECT DepartmentId FROM Base_DepartmentUser WHERE UserId=@Id)",
                (u, d) =>
            {
                u.Departments = d;
                return(u);
            }, new { Id = userId });

            if (user == null || user.IsDel || !user.Departments.Any(d => !d.IsDel && d.Id == departmentId))
            {
                return(ResultUtil.AuthFail("请求的用户不存在或该用户非指定部门的员工"));
            }

            var row = Db.Update <DepartmentEntity>(
                new KeyValuePairs()
                .Add("MasterId", userId),
                MySearchUtil.New()
                .AndEqual("Id", departmentId));

            return(row > 0 ? ResultUtil.Success() : ResultUtil.Fail());
        }
Ejemplo n.º 7
0
        protected override string ValidateUpdate(SalerEntity t, IAppUser user)
        {
            if (string.IsNullOrWhiteSpace(t.Name))
            {
                return("业务员姓名不能为空");
            }

            if (t.DeptId == 0)
            {
                return("必须指定业务员所在部门");
            }

            if (string.IsNullOrWhiteSpace(t.EmployeeNumber))
            {
                return("员工编号不能为空");
            }

            var count = db.GetCount <SalerEntity>(
                MySearchUtil.New()
                .AndEqual("EmployeeNumber", t.EmployeeNumber.Trim())
                .AndEqual("IsDel", false)
                .AndNotEqual("Id", t.Id));

            if (count > 0)
            {
                return("员工编号已存在");
            }

            return(string.Empty);
        }
Ejemplo n.º 8
0
        public override MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().AndEqual("IsDel", false);

            if (SchoolId.HasValue)
            {
                util.AndEqual("SchoolId", SchoolId.Value);
            }

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            if (!string.IsNullOrWhiteSpace(Card))
            {
                util.AndEqual("Card", Card.Trim());
            }

            if (SalerId.HasValue)
            {
                util.AndEqual("SalerId", SalerId.Value);
            }

            if (!string.IsNullOrWhiteSpace(Mobile))
            {
                util.AndContains("Mobile", Mobile.Trim());
            }

            util.OrderBy(SetOrderBy());

            return(util);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 移除实体-逻辑删除
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="user">操作人</param>
        /// <returns></returns>
        public virtual Result Remove(T entity, AppUser user, Action <int> Cb = null)
        {
            var error = ValidateDelete(entity, user);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.AuthFail(error));
            }

            var row = db.Update <T>(KeyValuePairs.New()
                                    .Add("IsDel", true)
                                    .Add("Updator", user.Name)
                                    .Add("UpdateAt", DateTime.Now),
                                    MySearchUtil.New().AndEqual("Id", entity.Id));

            Cb?.Invoke(row);
            if (row > 0)
            {
                return(ResultUtil.Success());
            }
            else
            {
                return(ResultUtil.Fail());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 手动盘点
        /// </summary>
        /// <param name="assetId">资产id</param>
        /// <param name="stockId">盘点id</param>
        /// <param name="result">盘点结果</param>
        /// <param name="method">盘点方式,1扫码盘点|2手动盘点</param>
        /// <param name="checkor">盘点人</param>
        /// <returns></returns>
        public Result DirectCheck(int assetId, int stockId, int result, int method, string checkor)
        {
            var util = MySearchUtil.New()
                       .AndEqual("IsDel", false)
                       .AndEqual("IsFinish", false)
                       .AndEqual("StockId", stockId)
                       .AndEqual("AssetId", assetId);

            var item = _db.Load <StockItem>(util);

            if (item == null)
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "请求的资产未记录在本次盘点内"));
            }
            if (item.CheckResult > 0)
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "该资产已经盘点"));
            }

            const string sql = @"
                UPDATE [Asset_StockItem] SET 
                    CheckAt=GETDATE(),Checkor=@Checkor,CheckResult=@Result,
                    CheckMethod=@Method,UpdateAt=GETDATE(),Updator=@Checkor 
                WHERE Id=@Id;
                UPDATE [Asset_Asset] SET LastCheckTime=GETDATE() WHERE Id=@AssetId;";
            var          row = _db.Execute(sql, new { Checkor = checkor, Result = result, Method = method, item.Id, item.AssetId });

            return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "操作失败"));
        }
Ejemplo n.º 11
0
        public MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().OrderByDesc("Id");

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            if (!string.IsNullOrWhiteSpace(EmployeeNumber))
            {
                util.AndContains("EmployeeNumber", EmployeeNumber.Trim());
            }

            if (!string.IsNullOrWhiteSpace(Job))
            {
                util.AndEqual("Job", Job.Trim());
            }

            if (DeptId.HasValue)
            {
                util.AndEqual("DeptId", DeptId.Value);
            }

            return(util);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 移除数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Result Delete(int id, IAppUser user)
        {
            try
            {
                var entity = _db.Load <Account>(id);
                if (entity == null)
                {
                    return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在"));
                }

                var assetCount = _db.GetCount <Asset>(MySearchUtil.New()
                                                      .AndEqual("AccountId", id)
                                                      .AndEqual("IsDel", false));
                if (assetCount > 0)
                {
                    return(ResultUtil.Do(ResultCodes.验证失败, "此用户下资产不为空,禁止删除"));
                }

                var row = _db.Remove <Account>(id);
                return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败"));
            }
            catch (Exception ex)
            {
                return(ResultUtil.Exception(ex));
            }
        }
Ejemplo n.º 13
0
        protected override string ValidateCreate(AppUserEntity entity, IAppUser user)
        {
            if (entity.Name.ToLower() == "admin")
            {
                return("用户名不能为admin");
            }

            if (string.IsNullOrWhiteSpace(entity.Name))
            {
                return("用户名不能为空");
            }

            if (string.IsNullOrWhiteSpace(entity.Role))
            {
                return("用户角色不能为空");
            }

            var count = db.GetCount(MySearchUtil.New()
                                    .AndEqual("Name", entity.Name)
                                    .AndEqual("IsDel", false), "Base_User");

            if (count > 0)
            {
                return("当前用户名已经存在");
            }

            return(string.Empty);
        }
Ejemplo n.º 14
0
        public override MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            if (!Enabled.HasValue)
            {
                util.AndEqual("Enabled", true);
            }
            else
            {
                util.AndEqual("Enabled", Enabled.Value);
            }

            if (SchoolId.HasValue)
            {
                util.AndEqual("SchoolId", SchoolId);
            }

            util.OrderBy(SetOrderBy());

            return(util);
        }
Ejemplo n.º 15
0
        public MySearchUtil ToSearchUtil()
        {
            var util = MySearchUtil.New().AndEqual("IsDel", false).OrderByDesc("Id");

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains(new[] { "Name", "Mobile", "Phone", "Email" }, Key.Trim());
            }

            if (Dept <= 0)
            {
                return(util);
            }

            if (!IsStrict)
            {
                var deptIds = DeptUtil.GetSelfAndChildrenIds(Dept);
                util.AndIn("DeptId", deptIds);
            }
            else
            {
                util.AndEqual("DeptId", Dept);
            }

            return(util);
        }
Ejemplo n.º 16
0
        public Result Approve(int id, int result, string remark, string userId, string userName)
        {
            var entity = Load(id);

            if (entity == null)
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "请求的申请不存在"));
            }
            if (entity.Step != 1)
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "仅待审批的申请可以进行此操作"));
            }
            if (!entity.Approvers.Contains(userId))
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "您无权审批此申请"));
            }
            if (result == -1 && string.IsNullOrWhiteSpace(remark))
            {
                return(ResultUtil.Do(ResultCodes.验证失败, "未通过申请,请注明拒绝理由"));
            }

            entity.ApproveResult = result;
            entity.ApproveRemark = remark;
            entity.UpdateAt      = DateTime.Now;
            entity.Updator       = userName;

            var row = db.Update(KeyValuePairList.New()
                                .Add("ApproveResult", entity.ApproveResult)
                                .Add("ApproveRemark", entity.ApproveRemark)
                                .Add("UpdateAt", DateTime.Now)
                                .Add("Updator", userName), MySearchUtil.New().AndEqual("Id", id));

            var sql = "UPDATE [SC_Proposer] SET ApproveResult=@ApproveResult,ApproveRemark=@ApproveRemark,UpdateAt=getdate(),Updator=@UserName,"
        }
Ejemplo n.º 17
0
        public override MySearchUtil ToSearchUtil()
        {
            var util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            if (DepartmentId.HasValue)
            {
                util.And("Id IN (SELECT UserId FROM Base_DepartmentUser WHERE DepartmentId=@DepartmentId)",
                         new KeyValuePairs().Add("DepartmentId", DepartmentId.Value));
            }

            if (RoleId.HasValue)
            {
                util.AndEqual("Id IN (SELECT UserId FROM Base_RoleUser WHERE RoleId=@RoleId)",
                              new KeyValuePairs().Add("RoleId", RoleId.Value));
            }

            if (JobId.HasValue)
            {
                util.AndEqual("Id IN (SELECT UserId FROM Base_JobUser WHERE JobId=@JobId)",
                              new KeyValuePairs().Add("JobId", JobId.Value));
            }

            return(util);
        }
Ejemplo n.º 18
0
        public override MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Key))
            {
                // util.AndContains(new string[] { "Title", "Name" }, Key.Trim());
            }

            if (SchoolId.HasValue)
            {
                util.AndEqual("SchoolId", SchoolId.Value);
            }

            if (!string.IsNullOrWhiteSpace(Account))
            {
                util.AndContains("Account", Account.Trim());
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                util.AndContains("Name", Name.Trim());
            }

            if (!string.IsNullOrWhiteSpace(RoleIds))
            {
                util.AndContains("RoleIds", RoleIds.Trim());
            }

            util.OrderBy(SetOrderBy());

            return(util);
        }
Ejemplo n.º 19
0
        public Result Update(RoleEditDto dto, BaseAppUser user)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var error = BeforeUpdate(dto);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(ResultUtil.Fail(error));
            }

            var emptyArrayJson = JsonConvert.SerializeObject(new int[] { });

            var entity = new RoleEntity
            {
                Id   = dto.Id,
                Name = dto.Name,
                DataPermissionType = dto.DataPermissionType,
                DepartmentIdJson   = JsonConvert.SerializeObject(dto.Departments),
            };

            entity.BeforeCreate(user);

            using (var conn = _db.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        var row = conn.Update(entity);
                        conn.Delete <RolePowerEntity>(MySearchUtil.New().AndEqual("RoleId", dto.Id));
                        if (dto.Powers.Any())
                        {
                            conn.Create(dto.Powers
                                        .Select(p => new RolePowerEntity {
                                RoleId = dto.Id, PowerId = p, ColumnCodeJson = emptyArrayJson
                            })
                                        .ToList());
                        }
                        trans.Commit();
                        return(row > 0 ? ResultUtil.Success() : ResultUtil.Fail());
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                        conn.Close();
                        return(ResultUtil.Fail(e.Message));
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public override string ValidDelete(Menu entity, IAppUser user)
        {
            var count = db.GetCount <Menu>(MySearchUtil.New()
                                           .AndEqual("IsDel", false)
                                           .AndEqual("ParentId", entity.Id));

            return(count > 0 ? "下级菜单不为空,禁止删除" : string.Empty);
        }
        public MySearchUtil ToSearchUtil()
        {
            var util = MySearchUtil.New().AndEqual("IsDel", false).OrderByDesc("CreateAt");

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains(new[] { "AccountName", "Describe" }, Key);
            }

            if (Dept > 0)
            {
                util.AndEqual("DeptId", Dept);
            }

            if (!string.IsNullOrWhiteSpace(Type))
            {
                util.AndEqual("Type", Type);
            }

            if (ApplyAtStart.HasValue)
            {
                util.AndGreaterThanEqual("ApplyAt", (DateTime)ApplyAtStart);
            }

            if (ApplyAtEnd.HasValue)
            {
                util.AndLessThanEqual("ApplyAt", (DateTime)ApplyAtEnd);
            }

            if (RequireCompleteAtStart.HasValue)
            {
                util.AndLessThanEqual("RequireCompleteAt", (DateTime)RequireCompleteAtStart);
            }

            if (RequireCompleteAtEnd.HasValue)
            {
                util.AndLessThanEqual("RequireCompleteAt", (DateTime)RequireCompleteAtEnd);
            }

            if (CompleteAtStart.HasValue)
            {
                util.AndGreaterThanEqual("CompleteAt", (DateTime)CompleteAtStart);
            }

            if (CompleteAtEnd.HasValue)
            {
                util.AndLessThanEqual("CompleteAt", (DateTime)CompleteAtEnd);
            }

            if (!string.IsNullOrWhiteSpace(State))
            {
                util.AndEqual("State", State);
            }

            return(util);
        }
        /// <summary>
        /// 获取最近盘点的资产
        /// </summary>
        /// <param name="id"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public JsonResult GetLastCheckItems(int id, int count = 20)
        {
            MySearchUtil util = MySearchUtil.New()
                                .AndNotNullOrEmpty("CheckAt")
                                .OrderByDesc("CheckAt");

            var list = _db.Fetch(util, "Asset_StockItem", "DeptName,AccountName,AssetName,AssetCode,Checkor,CheckAt", count);

            return(Json(list));
        }
Ejemplo n.º 23
0
        public override string ValidCreate(DataItem entity, IAppUser user)
        {
            if (string.IsNullOrWhiteSpace(entity.K))
            {
                return("键不能为空");
            }

            var count = db.GetCount <DataItem>(MySearchUtil.New().AndEqual("K", entity.K).AndEqual("IsDel", false));

            return(count > 0 ? "键已存在" : string.Empty);
        }
Ejemplo n.º 24
0
        public MySearchUtil ToSearchUtil()
        {
            var util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Role))
            {
                util.AndContains("Roles", Role.Trim());
            }

            return(util);
        }
Ejemplo n.º 25
0
        public MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().OrderBy("Sort");

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            return(util);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 获取盘点项
        /// </summary>
        /// <param name="assetId">资产id</param>
        /// <param name="stockId">盘点id</param>
        /// <returns></returns>
        public Result <StockItem> Load(int assetId, int stockId)
        {
            var util = MySearchUtil.New()
                       .AndEqual("IsDel", false)
                       .AndEqual("IsFinish", false)
                       .AndEqual("StockId", stockId)
                       .AndEqual("AssetId", assetId);

            var item = _db.Load <StockItem>(util);

            return(item == null?ResultUtil.Do <StockItem>(ResultCodes.数据不存在, null) : ResultUtil.Success(item));
        }
Ejemplo n.º 27
0
        public List <AssetCateDto> Fetch()
        {
            var util = MySearchUtil.New().AndEqual("IsDel", false);
            var all  = _db.Fetch <AssetCate>(util);

            return(all.Select(a => new AssetCateDto
            {
                Id = a.Id,
                Name = a.Name,
                ParentId = a.ParentId,
                Sort = a.Sort
            }).ToList());
        }
Ejemplo n.º 28
0
        public override MySearchUtil ToSearchUtil()
        {
            MySearchUtil util = MySearchUtil.New().AndEqual("IsDel", false);

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }

            util.OrderBy(SetOrderBy());

            return(util);
        }
Ejemplo n.º 29
0
        protected override string ValidateDelete(MenuEntity entity, IAppUser user)
        {
            var count = db.GetCount <MenuEntity>(MySearchUtil.New()
                                                 .AndEqual("IsDel", false)
                                                 .AndEqual("ParentId", entity.Id));

            if (count > 0)
            {
                return("下级菜单不为空,禁止删除");
            }

            return(string.Empty);
        }
Ejemplo n.º 30
0
        public MySearchUtil ToSearchUtil()
        {
            var util = MySearchUtil.New()
                       .AndNotEqual("Name", "admin")
                       .AndEqual("IsDel", false)
                       .OrderBy("Id");

            if (!string.IsNullOrWhiteSpace(Key))
            {
                util.AndContains("Name", Key.Trim());
            }
            return(util);
        }