/// <summary> /// 查询用户管理员分页 /// </summary> /// <param name="entity"></param> /// <param name="pageInfo"></param> /// <returns></returns> public List <AdminEntity> GetList(AdminEntity entity, ref PageInfo pageInfo) { entity.IncludeAll(); entity.OrderBy(a => a.ID, EOrderBy.DESC); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); SysRoleEntity roleEntity = new SysRoleEntity(); roleEntity.Include("RoleName", "RoleName"); entity.Left <SysRoleEntity>(roleEntity, new Params <string, string>() { Item1 = "RoleNum", Item2 = "RoleNum" }); SysDepartEntity departEntity = new SysDepartEntity(); departEntity.Include("DepartName", "DepartName"); entity.Left <SysDepartEntity>(departEntity, new Params <string, string>() { Item1 = "DepartNum", Item2 = "DepartNum" }); int rowCount = 0; List <AdminEntity> listResult = this.Admin.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount); pageInfo.RowCount = rowCount; return(listResult); }
/// <summary> /// 查询用户管理员分页 /// </summary> /// <param name="entity"></param> /// <param name="pageInfo"></param> /// <returns></returns> public List <AdminEntity> GetList(AdminEntity entity, ref PageInfo pageInfo) { entity.IncludeAll(); entity.Exclude(a => a.PassWord); entity.OrderBy(a => a.ID, EOrderBy.DESC); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); entity.And(a => a.CompanyID == entity.CompanyID); entity.And(item => item.UserCode != "DA_0000"); if (!entity.UserName.IsEmpty()) { entity.And("UserName", ECondition.Like, "%" + entity.UserName + "%"); } if (!entity.UserCode.IsEmpty()) { entity.And("UserCode", ECondition.Like, "%" + entity.UserCode + "%"); } if (!entity.RoleNum.IsEmpty()) { entity.And(a => a.RoleNum == entity.RoleNum); } if (!entity.DepartNum.IsEmpty()) { DepartProvider provider = new DepartProvider(this.CompanyID); List <SysDepartEntity> listDepart = provider.GetChildList(entity.DepartNum); string[] items = null; if (!listDepart.IsNullOrEmpty()) { items = listDepart.Select(item => item.SnNum).ToArray(); entity.And("DepartNum", ECondition.In, items); } } int rowCount = 0; List <AdminEntity> listResult = this.Admin.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount); pageInfo.RowCount = rowCount; if (!listResult.IsNullOrEmpty()) { SysRoleProvider RoleProvider = new SysRoleProvider(this.CompanyID); DepartProvider DepartProvider = new DepartProvider(this.CompanyID); foreach (AdminEntity item in listResult) { if (item.RoleNum.IsNotEmpty()) { SysRoleEntity RoleEntity = RoleProvider.GetRoleEntity(item.RoleNum); item.RoleName = RoleEntity != null ? RoleEntity.RoleName : string.Empty; } if (item.DepartNum.IsNotEmpty()) { SysDepartEntity DepartEntity = DepartProvider.GetSingle(item.DepartNum); item.DepartName = DepartEntity != null ? DepartEntity.DepartName : string.Empty; } } } return(listResult); }
/// <summary> /// 使用工号扫描 /// </summary> /// <param name="UserCode"></param> /// <returns></returns> public AdminEntity Scan(string UserCode) { AdminEntity entity = new AdminEntity(); entity.IncludeAll(); entity.Exclude(a => a.PassWord); entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete) .And <AdminEntity>(a => a.CompanyID == CompanyID) .And(item => item.UserCode == UserCode) ; entity = this.Admin.GetSingle(entity); if (entity != null) { SysRoleProvider RoleProvider = new SysRoleProvider(this.CompanyID); DepartProvider DepartProvider = new DepartProvider(this.CompanyID); if (entity.RoleNum.IsNotEmpty()) { SysRoleEntity RoleEntity = RoleProvider.GetRoleEntity(entity.RoleNum); entity.RoleName = RoleEntity != null ? RoleEntity.RoleName : string.Empty; } if (entity.DepartNum.IsNotEmpty()) { SysDepartEntity DepartEntity = DepartProvider.GetSingle(entity.DepartNum); entity.DepartName = DepartEntity != null ? DepartEntity.DepartName : string.Empty; } } return(entity); }
/// <summary> /// 添加用户 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int AddAdmin(AdminEntity entity) { entity.IsDelete = (int)EIsDelete.NotDelete; entity.CreateTime = DateTime.Now; entity.ParentCode = ""; entity.IncludeAll(); int line = this.Admin.Add(entity); return(line); }
/// <summary> /// 添加用户 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int AddAdmin(AdminEntity entity) { entity.UserNum = entity.UserNum.IsEmpty() ? ConvertHelper.NewGuid() : entity.UserNum; entity.UserCode = entity.UserCode.IsEmpty() ? new TNumProvider(this.CompanyID).GetSwiftNum(typeof(AdminEntity), 5) : entity.UserCode; entity.IsDelete = (int)EIsDelete.NotDelete; entity.Status = 0; entity.LoginCount = 0; entity.CreateTime = DateTime.Now; entity.UpdateTime = DateTime.Now; entity.IncludeAll(); int line = this.Admin.Add(entity); return(line); }
/// <summary> /// 用户登录 /// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public AdminEntity Login(string userName, string passWord) { AdminEntity entity = new AdminEntity(); entity.IncludeAll(); entity.Exclude(a => a.ParentName); entity.Where(a => a.UserName == userName) .And(a => a.PassWord == passWord) .And <AdminEntity>(a => a.CompanyID == CompanyID) .And(a => a.IsDelete == (int)EIsDelete.NotDelete) ; entity = this.Admin.GetSingle(entity); if (entity != null) { SysRoleProvider RoleProvider = new SysRoleProvider(this.CompanyID); DepartProvider DepartProvider = new DepartProvider(this.CompanyID); if (entity.RoleNum.IsNotEmpty()) { SysRoleEntity RoleEntity = RoleProvider.GetRoleEntity(entity.RoleNum); entity.RoleName = RoleEntity != null ? RoleEntity.RoleName : string.Empty; } if (entity.DepartNum.IsNotEmpty()) { SysDepartEntity DepartEntity = DepartProvider.GetSingle(entity.DepartNum); entity.DepartName = DepartEntity != null ? DepartEntity.DepartName : string.Empty; } Task.Factory.StartNew(() => { AdminEntity admin = new AdminEntity(); admin.LoginCount = entity.LoginCount + 1; admin.IncludeLoginCount(true); admin.Where(a => a.UserNum == entity.UserNum).And(item => item.CompanyID == this.CompanyID); this.Admin.Update(admin); }); } return(entity); }
/// <summary> /// 登录 /// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public AdminEntity Login(string userName, string passWord) { AdminEntity entity = new AdminEntity(); entity.IncludeAll(); entity.Where(a => a.UserName == userName).And(a => a.PassWord == passWord); SysRoleEntity roleEntity = new SysRoleEntity(); roleEntity.Include("RoleName", "RoleName"); entity.Left <SysRoleEntity>(roleEntity, new Params <string, string>() { Item1 = "RoleNum", Item2 = "RoleNum" }); entity = this.Admin.GetSingle(entity); if (entity != null) { AdminEntity admin = new AdminEntity(); admin.LoginCount = admin.LoginCount + 1; admin.IncludeLoginCount(true); admin.Where(a => a.UserCode == entity.UserCode); this.Admin.Update(admin); } return(entity); }