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())); }
/// <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); }
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())); }