public ActionResult DepartList(int pageIndex, int pageSize, string departName) { DepartProvider provider = new DepartProvider(); List<SysDepartEntity> list = provider.GetList(); List<SysDepartEntity> listResult = new List<SysDepartEntity>(); List<SysDepartEntity> returnList = new List<SysDepartEntity>(); if (!list.IsNullOrEmpty()) { listResult = list.Where(a => a.DepartName.Contains(departName) || a.DepartNum.Contains(departName)).ToList(); returnList = listResult.Skip((pageIndex - 1) * pageSize).Take(pageSize).OrderByDescending(a => a.ID).ToList(); } this.ReturnJson.AddProperty("Data", ConvertJson.ListToJson<SysDepartEntity>(returnList, "List")); this.ReturnJson.AddProperty("RowCount", listResult.Count); return Content(this.ReturnJson.ToString()); }
public ActionResult ToExcel() { PageInfo pageInfo = new Git.Framework.DataTypes.PageInfo() { PageIndex = 1, PageSize = Int32.MaxValue }; string departName = WebUtil.GetFormValue<string>("departName", string.Empty); DepartProvider provider = new DepartProvider(); SysDepartEntity entity = new SysDepartEntity(); List<SysDepartEntity> list = provider.GetList(); List<SysDepartEntity> listResult = new List<SysDepartEntity>(); if (!list.IsNullOrEmpty()) { listResult = list.Where(a => a.DepartName.Contains(departName) || a.DepartNum.Contains(departName)).OrderByDescending(a => a.ID).ToList(); } 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("创建时间")); int count = 1; foreach (SysDepartEntity t in listResult) { DataRow row = dt.NewRow(); row[0] = count; row[1] = t.DepartNum; row[2] = t.DepartName; row[3] = t.CreateTime; count++; 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()); }
/// <summary> /// 获得部门的下来列表 /// </summary> /// <param name="departNum"></param> /// <returns></returns> public static string GetDepartList(string departNum) { DepartProvider provider = new DepartProvider(); List<SysDepartEntity> list = provider.GetList(); StringBuilder sb = new StringBuilder(); string departTemplate = "<option value='{0}' {1}>{2}</option>"; sb.AppendFormat(departTemplate, "", "", "请选择部门"); if (!list.IsNullOrEmpty()) { foreach (SysDepartEntity depart in list) { sb.AppendFormat(departTemplate, depart.DepartNum, depart.DepartNum == departNum ? "selected='selected'" : string.Empty, depart.DepartName); } } return sb.ToString(); }