ChangeResultController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Data;
  8. using Bowin.Web.Controls.Mvc;
  9. using EMIS.Utility;
  10. using EMIS.Web.Controls;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.StudentManage.StudentChange;
  13. using EMIS.CommonLogic.StudentManage.StudentChange;
  14. namespace EMIS.Web.Controllers.StudentManage.StudentChange
  15. {
  16. [Authorization]
  17. public class ChangeResultController : Controller
  18. {
  19. public Lazy<IChangeResultServices> ChangeResultServices { get; set; }
  20. /// <summary>
  21. /// 异动结果页面
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult List()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 异动结果列表查询
  30. /// </summary>
  31. /// <param name="pararms"></param>
  32. /// <returns></returns>
  33. [HttpPost]
  34. public ActionResult List(QueryParamsModel pararms)
  35. {
  36. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  37. var campusID = pararms.getExtraGuid("CampusDropdown");
  38. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  39. var gradeID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
  40. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  41. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  42. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  43. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  44. var classmajorID = pararms.getExtraGuid("ClassmajorComboGrid");
  45. var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown");
  46. var changeTypeID = pararms.getExtraInt("DictionaryChangeType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryChangeType");
  47. var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus");
  48. return base.Json(ChangeResultServices.Value.GetChangeResultViewGrid(configuretView, campusID, collegeID, gradeID, standardID,
  49. educationID, learningformID, learnSystem, classmajorID, schoolyearID, changeTypeID, inSchoolStatus, (int)pararms.page, (int)pararms.rows));
  50. }
  51. /// <summary>
  52. /// 编辑
  53. /// </summary>
  54. /// <param name="studentChangeID"></param>
  55. /// <returns></returns>
  56. [HttpGet]
  57. public ActionResult Edit(Guid? studentChangeID)
  58. {
  59. StudentChangeView studentChangeView = new StudentChangeView();
  60. if (studentChangeID.HasValue && studentChangeID != Guid.Empty)
  61. {
  62. studentChangeView = ChangeResultServices.Value.GetStudentChangeView(studentChangeID);
  63. }
  64. return View(studentChangeView);
  65. }
  66. /// <summary>
  67. /// 编辑
  68. /// </summary>
  69. /// <param name="studentChangeView"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. public ActionResult Edit(StudentChangeView studentChangeView)
  73. {
  74. try
  75. {
  76. return Json(new ReturnMessage()
  77. {
  78. IsSuccess = true,
  79. Message = "保存成功。"
  80. });
  81. }
  82. catch (Exception ex)
  83. {
  84. return Json(new ReturnMessage()
  85. {
  86. IsSuccess = false,
  87. Message = "保存失败,原因:" + ex.Message + "。"
  88. });
  89. }
  90. }
  91. /// <summary>
  92. /// 删除
  93. /// </summary>
  94. /// <param name="studentChangeIDs"></param>
  95. /// <returns></returns>
  96. [HttpPost]
  97. public ActionResult Delete(string studentChangeIDs)
  98. {
  99. try
  100. {
  101. List<Guid?> list = studentChangeIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  102. ChangeResultServices.Value.ChangeResultDelete(list);
  103. return Json(new ReturnMessage()
  104. {
  105. IsSuccess = true,
  106. Message = "删除成功。"
  107. });
  108. }
  109. catch (Exception ex)
  110. {
  111. return Json(new ReturnMessage()
  112. {
  113. IsSuccess = false,
  114. Message = "删除失败,原因:" + ex.Message
  115. });
  116. }
  117. }
  118. /// <summary>
  119. /// Excel导入
  120. /// </summary>
  121. /// <param name="errorFile"></param>
  122. /// <param name="operationTips"></param>
  123. /// <returns></returns>
  124. [HttpGet]
  125. public ActionResult Import(string errorFile, string operationTips)
  126. {
  127. ViewBag.ErrorFile = errorFile;
  128. if (string.IsNullOrEmpty(operationTips))
  129. {
  130. operationTips = "点击查看失败原因...";
  131. }
  132. ViewBag.operationTips = operationTips;
  133. return View();
  134. }
  135. /// <summary>
  136. /// Excel导入
  137. /// </summary>
  138. /// <param name="file"></param>
  139. /// <returns></returns>
  140. [HttpPost]
  141. public ActionResult Import(HttpPostedFileBase file)
  142. {
  143. try
  144. {
  145. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  146. {
  147. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  148. }
  149. Dictionary<string, string> cellheader = new Dictionary<string, string>
  150. {
  151. { "StudentNo", "学号" },
  152. { "Name", "姓名" },
  153. { "Remark", "备注" },
  154. { "ErrorMessage", "未导入原因" }
  155. };
  156. int? inCount = 0;
  157. int? upCount = 0;
  158. int? errCount = 0;
  159. List<StudentChangeView> errList = new List<StudentChangeView>();
  160. string sourceWebPath = FileUploadHelper.UploadFile(file);
  161. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  162. ChangeResultServices.Value.StudentChangeImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  163. System.IO.File.Delete(sourcePhysicalPath);
  164. if (errList.Count() > 0)
  165. {
  166. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "学籍异动信息导入失败文件", sourcePhysicalPath));
  167. ViewBag.ErrorFile = errorWebPath;
  168. string Errinfo = string.Format("提示:{0}条学籍异动信息导入成功,{1}条学籍异动信息更新成功,{2}条学籍异动信息导入失败,点击查看。", inCount, upCount, errCount);
  169. ViewBag.operationTips = Errinfo;
  170. return RedirectToAction("MsgShow", "Common", new
  171. {
  172. WindowID = "none",
  173. msg = Errinfo,
  174. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  175. });
  176. }
  177. else
  178. {
  179. string successInfo = string.Format("提示:{0}条学籍异动信息导入成功,{1}条学籍异动信息更新成功。", inCount, upCount);
  180. return RedirectToAction("MsgShow", "Common", new
  181. {
  182. WindowID = Request["WindowID"],
  183. msg = successInfo,
  184. url = Url.Action("List").AddMenuParameter()
  185. });
  186. }
  187. }
  188. catch (Exception ex)
  189. {
  190. return RedirectToAction("MsgShow", "Common", new
  191. {
  192. WindowID = "none",
  193. msg = "导入失败,原因:" + ex.Message,
  194. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  195. });
  196. }
  197. }
  198. /// <summary>
  199. /// Excel导出
  200. /// </summary>
  201. /// <returns></returns>
  202. [HttpPost]
  203. public ActionResult Excel()
  204. {
  205. NpoiExcelHelper neh = new NpoiExcelHelper();
  206. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  207. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  208. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  209. var gradeID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  210. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  211. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  212. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  213. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  214. var classmajorID = Request.Form["ClassmajorComboGrid"].ParseStrTo<Guid>();
  215. var schoolyearID = Request.Form["SchoolyearDropdown"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["SchoolyearDropdown"].ParseStrTo<Guid>();
  216. var changeTypeID = Request.Form["DictionaryChangeType"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryChangeType"].ParseStrTo<int>();
  217. var inSchoolStatus = Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>();
  218. var dt = ChangeResultServices.Value.GetChangeResultViewList(configuretView, campusID, collegeID, gradeID, standardID, educationID, learningformID,
  219. learnSystem, classmajorID, schoolyearID, changeTypeID, inSchoolStatus)
  220. .Select(x => new
  221. {
  222. x.StudentNo,
  223. x.Name,
  224. x.SexName,
  225. BirthDate = (x.BirthDate.HasValue ? x.BirthDate.Value.ToString("yyyyMMdd") : ""),
  226. x.NationName,
  227. x.PoliticsName,
  228. x.InSchoolStatusName,
  229. x.StudentStatusName,
  230. x.GradeID,
  231. x.SemesterName,
  232. x.StandardCode,
  233. x.StandardID,
  234. x.StandardName,
  235. x.EducationName,
  236. x.LearningformName,
  237. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : "",
  238. x.ClassNum,
  239. x.ClassmajorNo,
  240. x.ClassmajorName,
  241. x.GrademajorCode,
  242. x.GrademajorName,
  243. x.FacultymajorCode,
  244. x.FacultymajorName,
  245. x.CollegeNo,
  246. x.CollegeName,
  247. x.CampusCode,
  248. x.CampusName,
  249. x.StartSchoolyearCode,
  250. x.SchoolyearCode,
  251. x.GraduateSchoolyearCode,
  252. x.ChangeTypeName,
  253. x.BeforeStandardName,
  254. x.BeforeClassmajorName,
  255. x.BeforeInSchoolStatusName,
  256. x.BeforeStudentStatusName,
  257. x.AfterStandardName,
  258. x.AfterClassmajorName,
  259. x.AfterInSchoolStatusName,
  260. x.AfterStudentStatusName,
  261. x.ReturnSchoolyearCode,
  262. x.ChangeApplyTypeName,
  263. x.ChangeReasonName,
  264. ChangeDate = (x.ChangeDate.HasValue ? x.ChangeDate.Value.ToString("yyyyMMdd") : ""),
  265. x.Description,
  266. x.ReportStatusName,
  267. x.ApprovalStatusName,
  268. x.Remark
  269. }).ToTable();
  270. string[] liststring = {
  271. "学号", "姓名", "性别", "出生日期", "民族", "政治面貌", "在校状态", "学籍状态", "年级", "入学学期",
  272. "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"), "学习形式", "学制", "班序",
  273. "班级编号", "班级名称", "年级专业编号", "年级专业名称", "院系专业编号", "院系专业名称",
  274. RSL.Get("CollegeCode"), RSL.Get("College"), RSL.Get("CampusCode"), RSL.Get("Campus"), "入学学年学期",
  275. "异动学期", "毕业学期", "异动类型", "异动前专业", "异动前班级", "在校状态(前)", "学籍状态(前)",
  276. "异动后专业", "异动后班级", "在校状态(后)", "学籍状态(后)", "返校学期", "异动渠道", "异动原因", "异动日期",
  277. "申请说明", "注册状态", "审核状态", "备注"
  278. };
  279. neh.Export(dt, liststring, "异动结果信息" + DateTime.Now.ToString("yyyyMMdd"));
  280. return Json(new ReturnMessage()
  281. {
  282. IsSuccess = true,
  283. Message = "导出成功。"
  284. });
  285. }
  286. }
  287. }