Example #1
0
        public ActionResult GetAdminList()
        {
            int    pageIndex = WebUtil.GetFormValue <int>("pageIndex", 1);
            int    pageSize  = WebUtil.GetFormValue <int>("pageSize", 15);
            string userCode  = WebUtil.GetFormValue <string>("userCode", string.Empty);
            string userName  = WebUtil.GetFormValue <string>("userName", string.Empty);
            string roleNum   = WebUtil.GetFormValue <string>("roleNum", string.Empty);
            string departNum = WebUtil.GetFormValue <string>("departNum", string.Empty);
            string search    = WebUtil.GetFormValue <string>("search", string.Empty);

            PageInfo pageInfo = new PageInfo()
            {
                PageIndex = pageIndex, PageSize = pageSize
            };
            AdminProvider provider = new AdminProvider();
            AdminEntity   entity   = new AdminEntity();

            if (!search.IsEmpty())
            {
                entity.Where("UserCode", ECondition.Like, "%" + search + "%");
                entity.Or("RealName", ECondition.Like, "%" + search + "%");
                entity.Or("UserName", ECondition.Like, "%" + search + "%");
            }
            else
            {
                if (!userCode.IsEmpty())
                {
                    entity.Where("UserCode", ECondition.Like, "%" + userCode + "%");
                    entity.Or("RealName", ECondition.Like, "%" + userCode + "%");
                }
                if (!userName.IsEmpty())
                {
                    entity.Where("UserName", ECondition.Like, "%" + userName + "%");
                }
                if (!roleNum.IsEmpty())
                {
                    entity.And(a => a.RoleNum == roleNum);
                }
                if (!departNum.IsEmpty())
                {
                    entity.And(a => a.DepartNum == departNum);
                }
            }
            List <AdminEntity> listResult = provider.GetList(entity, ref pageInfo);
            string             json       = ConvertJson.ListToJson <AdminEntity>(listResult, "List");

            this.ReturnJson.AddProperty("Data", new JsonObject(json));
            this.ReturnJson.AddProperty("RowCount", pageInfo.RowCount);
            return(Content(this.ReturnJson.ToString()));
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        public async Task <IActionResult> Login(string username, string password, string returnUrl = null)
        {
            password = SM3.GetSM3(password);
            var admin = AdminEntity.Where(x => x.UserName == username && x.Password == password).First();

            if (admin == null)
            {
                ViewBag.errormsg = "用户名或密码错误";
                return(View());
            }
            var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);

            identity.AddClaim(new Claim(ClaimTypes.Sid, admin.Id.ToString()));
            identity.AddClaim(new Claim(ClaimTypes.Name, admin.UserName));
            identity.AddClaim(new Claim(ClaimTypes.Role, Constants.AdminRoleName));
            await AuthExtension.LoginAsync(new AdminAuthenticationAttribute(), HttpContext,
                                           new ClaimsPrincipal(identity));

            if (returnUrl != null)
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #6
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(AdminEntity entity)
        {
            entity.Include(a => new { a.Phone, a.Email, a.Mobile, a.RealName, a.RoleNum, a.DepartNum, a.UserName, a.PassWord, a.UpdateTime });
            entity.Where(a => a.UserCode == entity.UserCode);
            int line = this.Admin.Update(entity);

            return(line);
        }
Example #7
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UpdatePwd(AdminEntity entity)
        {
            entity.Include(a => a.PassWord);
            entity.Where(a => a.UserCode == entity.UserCode);
            int line = this.Admin.Update(entity);

            return(line);
        }
Example #8
0
        /// <summary>
        /// 根据用户编号获得用户信息
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public AdminEntity GetAdmin(string userCode)
        {
            AdminEntity entity = new AdminEntity();

            entity.Include(a => new { a.ID, a.UserCode, a.UserName, a.PassWord, a.Email, a.Phone, a.Mobile, a.RealName, a.RoleNum, a.DepartNum });
            entity.Where(a => a.UserCode == userCode);
            entity = this.Admin.GetSingle(entity);
            return(entity);
        }
Example #9
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public int Delete(string userCode)
        {
            AdminEntity entity = new AdminEntity();

            entity.IsDelete = (int)EIsDelete.Deleted;
            entity.IncludeIsDelete(true);
            entity.Where(a => a.UserCode == userCode);
            int line = this.Admin.Update(entity);

            return(line);
        }
Example #10
0
        /// <summary>
        /// 管理员修改密码
        /// </summary>
        /// <param name="UserNum"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public int AdminEditPass(string UserNum, string Password)
        {
            AdminEntity entity = new AdminEntity();

            entity.PassWord = Password;
            entity.Where(item => item.CompanyID == this.CompanyID)
            .And(item => item.UserNum == UserNum);
            entity.IncludePassWord(true);

            int line = this.Admin.Update(entity);

            return(line);
        }
Example #11
0
        /// <summary>
        /// 检查用户名是否存在
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool IsExist(string userName)
        {
            AdminEntity entity = new AdminEntity();

            entity.Include(a => new { a.ID, a.UserCode, a.UserName, a.PassWord, a.Email, a.Phone, a.Mobile, a.RealName, a.RoleNum, a.DepartNum });
            entity.Where(a => a.UserName == userName).And(a => a.IsDelete == (int)EIsDelete.NotDelete);
            entity = this.Admin.GetSingle(entity);
            if (entity.IsNotNull())
            {
                return(true);
            }
            return(false);
        }
Example #12
0
        /// <summary>
        /// 修改员工登录次数
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="passWord"></param>
        /// <param name="loginCount"></param>
        /// <returns></returns>
        public int UpdateLoginCount(string userName, string passWord, int loginCount)
        {
            AdminEntity countEntity = new AdminEntity()
            {
                UserName = userName, PassWord = passWord
            };

            countEntity.IncludeLoginCount(true);
            countEntity.LoginCount = loginCount + 1;
            countEntity.Where <AdminEntity>("UserName", ECondition.Eth).And <AdminEntity>("PassWord", ECondition.Eth);
            int line = this.Admin.Update(countEntity);

            return(line);
        }
Example #13
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Delete(IEnumerable <string> list)
        {
            AdminEntity entity = new AdminEntity();

            entity.IsDelete   = (int)EIsDelete.Deleted;
            entity.UpdateTime = DateTime.Now;
            entity.IncludeIsDelete(true)
            .IncludeUpdateTime(true);

            entity.Where(a => a.CompanyID == CompanyID)
            .And("UserNum", ECondition.In, list.ToArray());

            int line = this.Admin.Update(entity);

            return(line);
        }
Example #14
0
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(AdminEntity entity)
        {
            entity.Include(a => new
            {
                a.RealName,
                a.Email,
                a.Mobile,
                a.Phone,
                a.DepartNum,
                a.ParentNum,
                a.RoleNum,
                a.Picture,
                a.Remark
            });
            entity.Where(a => a.UserNum == entity.UserNum);
            int line = this.Admin.Update(entity);

            return(line);
        }
Example #15
0
        /// <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);
        }
Example #16
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="UserNum"></param>
        /// <param name="OldPass"></param>
        /// <param name="NewPass"></param>
        /// <returns></returns>
        public DataResult UpdatePwd(string UserNum, string OldPass, string NewPass)
        {
            AdminEntity entity = new AdminEntity();

            entity.Where(a => a.UserNum == UserNum)
            .And(a => a.PassWord == OldPass)
            .And(a => a.CompanyID == this.CompanyID)
            ;
            int        count      = this.Admin.GetCount(entity);
            DataResult dataResult = new DataResult();

            if (count == 0)
            {
                dataResult.Code    = (int)EResponseCode.Exception;
                dataResult.Message = "旧密码不正确";
                return(dataResult);
            }
            entity          = new AdminEntity();
            entity.PassWord = NewPass;
            entity.IncludePassWord(true);
            entity.Where(a => a.PassWord == OldPass)
            .And(a => a.CompanyID == this.CompanyID)
            ;
            int line = this.Admin.Update(entity);

            if (line > 0)
            {
                dataResult.Code    = (int)EResponseCode.Success;
                dataResult.Message = "密码修改成功";
            }
            else
            {
                dataResult.Code    = (int)EResponseCode.Exception;
                dataResult.Message = "密码修改失败";
            }

            return(dataResult);
        }
Example #17
0
        /// <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);
        }
Example #18
0
        public ActionResult ToExcel()
        {
            PageInfo pageInfo = new Git.Framework.DataTypes.PageInfo()
            {
                PageIndex = 1, PageSize = Int32.MaxValue
            };
            string        userCode  = WebUtil.GetFormValue <string>("userCode", string.Empty);
            string        userName  = WebUtil.GetFormValue <string>("userName", string.Empty);
            string        roleNum   = WebUtil.GetFormValue <string>("roleNum", string.Empty);
            string        departNum = WebUtil.GetFormValue <string>("departNum", string.Empty);
            AdminProvider provider  = new AdminProvider();
            AdminEntity   entity    = new AdminEntity();

            if (!userCode.IsEmpty())
            {
                entity.Where("UserCode", ECondition.Like, userCode + "%");
            }
            if (!userName.IsEmpty())
            {
                entity.Where("UserName", ECondition.Like, userName + "%");
            }
            if (!roleNum.IsEmpty())
            {
                entity.And(a => a.RoleNum == roleNum);
            }
            if (!departNum.IsEmpty())
            {
                entity.And(a => a.DepartNum == departNum);
            }
            List <AdminEntity> listResult = provider.GetList(entity, ref pageInfo);

            if (!listResult.IsNullOrEmpty())
            {
                DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("用户名"));
                dt.Columns.Add(new DataColumn("编号"));
                dt.Columns.Add(new DataColumn("真名"));
                dt.Columns.Add(new DataColumn("Email"));
                dt.Columns.Add(new DataColumn("联系方式"));
                dt.Columns.Add(new DataColumn("登录次数"));
                dt.Columns.Add(new DataColumn("部门"));
                dt.Columns.Add(new DataColumn("角色"));
                foreach (AdminEntity t in listResult)
                {
                    DataRow row = dt.NewRow();
                    row[0] = t.UserName;
                    row[1] = t.UserCode;
                    row[2] = t.RealName;
                    row[3] = t.Email;
                    row[4] = t.Mobile;
                    row[5] = t.LoginCount;
                    row[6] = t.DepartName;
                    row[7] = t.RoleName;
                    dt.Rows.Add(row);
                }
                string filePath = Server.MapPath("~/UploadFiles/");
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                string    filename = string.Format("员工管理{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss"));
                NPOIExcel excel    = new NPOIExcel("员工管理", "员工", System.IO.Path.Combine(filePath, filename));
                excel.ToExcel(dt);
                this.ReturnJson.AddProperty("Path", ("/UploadFiles/" + filename).Escape());
            }
            else
            {
                this.ReturnJson.AddProperty("d", "无数据导出!");
            }
            return(Content(this.ReturnJson.ToString()));
        }