public ActionResult List(FormCollection collection) { /* * 变量定义 */ var db = new YGSDbContext(); OrgMgr orgMgr = new OrgMgr(); // 开始日期 DateTime startDate = new DateTime(); // 结束日期 DateTime endDate = new DateTime(); // 页数 int page = WHConstants.Default_Page; // 分页大小 int pageSize = WHConstants.Default_Page_Size; // 申请列表 var applyList = db.Apply.Where(n => n.IsDelete == false); /* * 参数获取 */ // 开始日期 var startDateString = collection["startDate"]; // 结束日期 var endDateString = collection["endDate"]; // 状态 var status = collection["status"]; // 关键字 var keyword = collection["keyword"]; // 页数 var pageString = collection["page"]; // 分页大小 var pageSizeString = collection["pageSize"]; /* * 参数校验 */ // 验证开始日期 if (!string.IsNullOrEmpty(startDateString)) { if (DateTime.TryParse(startDateString, out startDate)) { applyList = applyList.Where(t => DbFunctions.TruncateTime(t.CreateTime) >= DbFunctions.TruncateTime(startDate)); } else { // 验证出错 return(ResponseUtil.Error(400, "开始日期错误")); } } // 验证结束日期 if (!string.IsNullOrEmpty(endDateString)) { if (DateTime.TryParse(endDateString, out endDate)) { applyList = applyList.Where(t => DbFunctions.TruncateTime(t.CreateTime) <= DbFunctions.TruncateTime(endDate)); } else { // 验证出错 return(ResponseUtil.Error(400, "结束日期错误")); } } // 验证状态 if (string.IsNullOrEmpty(status)) { return(ResponseUtil.Error(400, "验证状态不能为空")); } else { applyList = applyList.Where(n => n.ApplyStatus == status); } // 关键字 if (!string.IsNullOrEmpty(keyword)) { applyList = applyList.Where(n => n.OutName.Contains(keyword)); } // 验证分页大小 if (!string.IsNullOrEmpty(pageString)) { if (int.TryParse(pageString, out page)) { if (page <= 0) { return(ResponseUtil.Error(400, "分页大小错误")); } } else { // 验证出错 return(ResponseUtil.Error(400, "分页大小错误")); } } // 验证页数 if (!string.IsNullOrEmpty(pageSizeString)) { if (int.TryParse(pageSizeString, out pageSize)) { if (pageSize <= 0) { return(ResponseUtil.Error(400, "页数错误")); } } else { // 验证出错 return(ResponseUtil.Error(400, "页数错误")); } } /* * 获取数据 */ // 记录总数 var totalCount = applyList.Count(); // 记录总页数 var totalPage = (int)Math.Ceiling((float)totalCount / pageSize); // 查询结果数据 var resultRecords = applyList.OrderByDescending(n => n.CreateTime).Skip((page - 1) * pageSize).Take(pageSize).ToList(); //预约列表格式 List <object> applys = new List <object>(); foreach (var apply in resultRecords) { var applyEmployee = orgMgr.GetEmployee(apply.UserId); // 获得所有外出人员id var outUserIds = apply.OutUsers.Split(',').Select(int.Parse).ToList(); applys.Add(new { id = apply.ID, outName = apply.OutName, desc = apply.Desc, applyDate = apply.ApplyDate.ToString("yyyy/MM/dd"), applyUser = applyEmployee == null ? null : string.Format("{0} {1}", applyEmployee.DeptName, applyEmployee.EmplName), outUsers = db.User.ToList().Where(m => outUserIds.Contains(m.ID)).Select(m => new { id = m.ID, name = m.Name, status = m.CredNo == null ? "fatal" : (db.Cred.Where(n => n.UserID == m.ID).Count() > 0 ? "normal" : "warn") }), checkOpinion = apply.CheckOpinion }); } return(new JsonNetResult(new { code = 200, data = new { records = applys, meta = new { current_page = page, total_page = totalPage, current_count = (page - 1) * pageSize + resultRecords.ToList().Count(), total_count = totalCount, per_page = pageSize } } })); }
public ActionResult List(FormCollection collection) { using (var db = new YGSDbContext()) { /* * 变量定义 */ var employee = (User.Identity as AppkizIdentity).Employee; OrgMgr orgMgr = new OrgMgr(); // 页数 int page = WHConstants.Default_Page; // 分页大小 int pageSize = WHConstants.Default_Page_Size; // 申请数据 var applyList = db.Apply.Where(n => n.UserId == employee.EmplID && n.IsDelete == false); /* * 参数获取 */ // 申请单状态 var status = collection["status"]; // 关键字 var keyword = collection["keyword"]; // 页数 var pageString = collection["page"]; // 分页大小 var pageSizeString = collection["pageSize"]; /* * 参数校验 */ // 验证状态 if (string.IsNullOrEmpty(status)) { return(ResponseUtil.Error(400, "状态不能为空")); } else { applyList = applyList.Where(n => n.ApplyStatus == status); } // 关键字 if (!string.IsNullOrEmpty(keyword)) { applyList = applyList.Where(n => n.OutName.Contains(keyword)); } // 验证分页大小 if (!string.IsNullOrEmpty(pageString)) { if (int.TryParse(pageString, out page)) { if (page <= 0) { return(ResponseUtil.Error(400, "分页大小错误")); } } else { // 验证出错 return(ResponseUtil.Error(400, "分页大小错误")); } } // 验证页数 if (!string.IsNullOrEmpty(pageSizeString)) { if (int.TryParse(pageSizeString, out pageSize)) { if (pageSize <= 0) { return(ResponseUtil.Error(400, "页数错误")); } } else { // 验证出错 return(ResponseUtil.Error(400, "页数错误")); } } /* * 查询申请 */ // 记录总数 var totalCount = applyList.Count(); // 记录总页数 var totalPage = (int)Math.Ceiling((float)totalCount / pageSize); // 查询结果数据 var resultRecords = applyList.OrderByDescending(n => n.CreateTime).Skip((page - 1) * pageSize).Take(pageSize).ToList(); //预约列表格式 List <object> applys = new List <object>(); // 履历表 foreach (var apply in resultRecords) { var applyEmployee = orgMgr.GetEmployee(apply.UserId); // 获得所有外出人员id var historyIdList = apply.OutUsers.Split(',').Select(int.Parse).ToList(); applys.Add(new { id = apply.ID, outName = apply.OutName, desc = apply.Desc, applyDate = apply.ApplyDate.ToString("yyyy/MM/dd"), applyUser = applyEmployee == null ? null : string.Format("{0} {1}", applyEmployee.DeptName, applyEmployee.EmplName), outUsers = db.User.ToList().Where(m => historyIdList.Contains(m.ID)).Select(m => new { id = m.ID, name = m.Name }).ToList(), checkOpinion = apply.CheckOpinion, nextStep = apply.ApplyStatus == WHConstants.Apply_Status_Examing ? "等待领导审批" : (apply.ApplyStatus == WHConstants.Apply_Status_Passed ? "下载并填写表格" : "修改并重新提交审核") }); } return(new JsonNetResult(new { code = 200, data = new { records = applys, meta = new { current_page = page, total_page = totalPage, current_count = (page - 1) * pageSize + resultRecords.ToList().Count(), total_count = totalCount, per_page = pageSize } } })); } }