ExaminationApplayStudentListController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.ExaminationApply;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Common.Data;
  10. using Bowin.Common.Utility;
  11. using EMIS.Utility;
  12. using Bowin.Common;
  13. using EMIS.CommonLogic.CalendarManage;
  14. using EMIS.CommonLogic.Students;
  15. using Bowin.Web.Controls.Mvc;
  16. using System.Text;
  17. using EMIS.ViewModel.ExaminationApply;
  18. namespace EMIS.Web.Controllers.ExaminationApply
  19. {
  20. [Authorization]
  21. public class ExaminationApplayStudentListController : Controller
  22. {
  23. public IExaminationSubjectServices ExaminationSubjectServices { get; set; }
  24. public ISchoolYearServices SchoolYearServices { get; set; }
  25. public IExamineApplyServices ExamineApplyService { get; set; }
  26. public ActionResult List()
  27. {
  28. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  29. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  30. return View();
  31. }
  32. public ActionResult Export()
  33. {
  34. return View();
  35. }
  36. [HttpPost]
  37. public ActionResult List(QueryParamsModel pararms)
  38. {
  39. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  40. var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  41. var subjectID = pararms.getExtraGuid("ddlExaminationSubject");
  42. var collegeID = pararms.getExtraGuid("cgCollege");
  43. var classmajorID = pararms.getExtraGuid("cgClassmajor");
  44. var examinationTypeID = pararms.getExtraGuid("cgExamination");
  45. var year = pararms.getExtraInt("ddlYear") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlYear");
  46. var standardID = pararms.getExtraInt("ddlStandard") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlStandard");
  47. var isPay = pararms.getExtraInt("IsPay") == DropdownList.SELECT_ALL ? (bool?)null : (pararms.getExtraInt("IsPay") == (int)CF_GeneralPurpose.IsYes);
  48. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  49. return base.Json(ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID,
  50. year, standardID, classmajorID, examinationTypeID, schoolyearID, isPay, (int)pararms.page, (int)pararms.rows));
  51. }
  52. [HttpPost]
  53. public ActionResult Excel()
  54. {
  55. NpoiExcelHelper neh = new NpoiExcelHelper();
  56. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  57. var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo<Guid>();
  58. var collegeID = Request.Form["cgCollege"].ParseStrTo<Guid>();
  59. var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  60. var classmajorID = Request.Form["cgClassmajor"].ParseStrTo<Guid>();
  61. var examinationTypeID = Request.Form["cgExamination"].ParseStrTo<Guid>();
  62. var year = Request.Form["ddlYear"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo<int>();
  63. var standardID = Request.Form["ddlStandard"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo<int>();
  64. var isPay = Request.Form["IsPay"];
  65. bool? IsPay = null;
  66. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo)
  67. {
  68. IsPay = false;
  69. }
  70. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes)
  71. {
  72. IsPay = true;
  73. }
  74. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  75. var dt = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID,
  76. year, standardID, null, examinationTypeID, schoolyearID,IsPay).Select(x => new
  77. {
  78. x.SchoolyearCode,
  79. x.StudentNo,
  80. x.Name,
  81. x.SexName,
  82. x.ClassmajorName,
  83. x.SubjectName,
  84. x.CertificatesTypeName,
  85. x.IDNumber,
  86. x.Cost,
  87. x.IsPay
  88. }).ToTable();
  89. string[] liststring = { "考试学年学期", "学号", "姓名", "性别", "班级名称", "科目名称", "证件类型", "证件号码", "报名费","是否交费" };
  90. neh.Export(dt, liststring, "报考学生名单");
  91. return RedirectToAction("MsgShow", "Common", new
  92. {
  93. msg = "导出成功!",
  94. url = Url.Content("~/ExaminationApplayStudentList/List").AddMenuParameter()
  95. });
  96. }
  97. public ActionResult ClassStudentStatisticsList()
  98. {
  99. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  100. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  101. return View();
  102. }
  103. [HttpPost]
  104. public ActionResult ClassStudentStatisticsList(QueryParamsModel pararms)
  105. {
  106. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  107. var campusID = pararms.getExtraGuid("CampusDropdown");
  108. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  109. var classmajorID = pararms.getExtraGuid("ClassmajorDropdown");
  110. var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
  111. //var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  112. //ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  113. var schoolYear = pararms.getExtraInt("SchoolyearDictionaryDropDown");
  114. var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown");
  115. var subjectID = pararms.getExtraGuid("ddlExaminationSubject");
  116. return base.Json(ExaminationSubjectServices.GetExaminationSubjectClassStudentStatisticsListView(subjectID, schoolYear, schoolyearID, (int)pararms.page, (int)pararms.rows, campusID, collegeID, classmajorID, standardID));
  117. }
  118. [HttpPost]
  119. public ActionResult ClassStudentStatisticsExcel()
  120. {
  121. NpoiExcelHelper neh = new NpoiExcelHelper();
  122. //ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  123. //if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  124. var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo<Guid>();
  125. var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  126. var dt = ExaminationSubjectServices.GetExaminationSubjectClassStudentStatisticsList(subjectID, schoolyearID).Select(x => new
  127. {
  128. x.Year,
  129. x.GrademajorName,
  130. x.ClassmajorName,
  131. x.SchoolyearCode,
  132. x.SubjectName,
  133. x.StudentCount,
  134. x.Cost,
  135. }).ToTable();
  136. string[] liststring = { "年级", "年级专业", "班级", "学期", "科目", "报名人数", "收费" };
  137. neh.Export(dt, liststring, "报考班级学生统计");
  138. return RedirectToAction("MsgShow", "Common", new
  139. {
  140. msg = "导出成功!",
  141. url = Url.Content("~/ExaminationApplayStudentList/ClassStudentStatisticsList").AddMenuParameter()
  142. });
  143. }
  144. public ActionResult ClassStudentStatisticsReport()
  145. {
  146. return View();
  147. }
  148. [HttpPost]
  149. public ActionResult ExportStudentData()
  150. {
  151. NpoiExcelHelper neh = new NpoiExcelHelper();
  152. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  153. var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  154. var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo<Guid>();
  155. var examinationTypeID = Request.Form["cgExamination"].ParseStrTo<Guid>();
  156. var collegeID = Request.Form["cgCollege"].ParseStrTo<Guid>();
  157. var year = Request.Form["ddlYear"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo<int>();
  158. var standardID = Request.Form["ddlStandard"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo<int>();
  159. var isPay = Request.Form["IsPay"];
  160. bool? IsPay = null;
  161. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo)
  162. {
  163. IsPay = false;
  164. }
  165. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes)
  166. {
  167. IsPay = true;
  168. }
  169. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  170. var dt = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID,
  171. year, standardID, null, examinationTypeID, schoolyearID,IsPay).Select(x => new
  172. {
  173. x.SchoolyearCode,
  174. x.StudentNo,
  175. x.Name,
  176. x.SexName,
  177. x.ClassmajorName,
  178. x.SubjectName,
  179. x.CertificatesTypeName,
  180. x.IDNumber,
  181. x.CardNo,
  182. //x.EducationName,
  183. //LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  184. x.CollegeName,
  185. x.Year,
  186. //x.SchoolyearNumName,
  187. x.StandardName,
  188. // x.ClassmajorNo
  189. }).ToTable(); //RSL.Get("EducationID"), "学制",
  190. string[] liststring = { "考试学年学期","学号", "姓名", "性别", "班级名称", "科目名称", "证件类型", "证件号码","银行卡号",
  191. "院系", "年级", "专业" };
  192. neh.Export(dt, liststring, "报考学生数据导出");
  193. return RedirectToAction("MsgShow", "Common", new
  194. {
  195. msg = "导出成功!",
  196. url = Url.Content("~/ExaminationApplayStudentList/Export").AddMenuParameter()
  197. });
  198. }
  199. [HttpPost]
  200. public ActionResult ExportStudentPic()
  201. {
  202. string tempVirtualFilePath = Const.LOCAL_SETTING_UPLOAD_FILEPATH + "/" + Guid.NewGuid().ToString();
  203. string tempPhysicalFilePath = HttpContext.Server.MapPath(tempVirtualFilePath);
  204. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  205. var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>();
  206. var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo<Guid>();
  207. var collegeID = Request.Form["cgCollege"].ParseStrTo<Guid>();
  208. var classmajorID = Request.Form["cgClassmajor"].ParseStrTo<Guid>();
  209. var examinationTypeID = Request.Form["cgExamination"].ParseStrTo<Guid>();
  210. var year = Request.Form["ddlYear"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo<int>();
  211. var standardID = Request.Form["ddlStandard"].ParseStrTo<int>() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo<int>();
  212. var isPay = Request.Form["IsPay"];
  213. bool? IsPay = null;
  214. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo)
  215. {
  216. IsPay = false;
  217. }
  218. if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes)
  219. {
  220. IsPay = true;
  221. }
  222. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  223. var studentList = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID,
  224. year, standardID, null, examinationTypeID, schoolyearID,IsPay).ToList();
  225. if (!System.IO.Directory.Exists(tempPhysicalFilePath))
  226. {
  227. System.IO.Directory.CreateDirectory(tempPhysicalFilePath);
  228. }
  229. var fileInfo = studentList.Where(x => x.PhotoUrl != null)
  230. .Select(x => new EMIS.Utility.FileUploadHelper.RemoteFileInfo { RemotePath = x.PhotoUrl, FileName = x.IDNumber + ".jpg" }).ToList();
  231. FileUploadHelper.DownLoadFiles("studentPhoto" + Guid.NewGuid().ToString(), "报考学生照片", fileInfo);
  232. return RedirectToAction("MsgShow", "Common", new
  233. {
  234. msg = "导出成功!",
  235. url = Url.Content("~/ExaminationApplayStudentList/Export").AddMenuParameter()
  236. });
  237. }
  238. public ActionResult ApplyCancel(string ExaminationRegistrationIDs)
  239. {
  240. try
  241. {
  242. var xaminationRegistrationIDList = ExaminationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList();
  243. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  244. ExamineApplyService.ApplyCancel(xaminationRegistrationIDList);
  245. return base.Json("撤销成功");
  246. }
  247. catch (Exception ex)
  248. {
  249. string mge = ex.Message;
  250. return base.Json("撤销失败,原因:" + mge);
  251. }
  252. }
  253. /// <summary>
  254. /// 学生名单导入
  255. /// </summary>
  256. /// <param name="errorFile"></param>
  257. /// <param name="operationTips"></param>
  258. /// <returns></returns>
  259. [HttpGet]
  260. public ActionResult Import(string errorFile, string operationTips)
  261. {
  262. ViewBag.ErrorFile = errorFile;
  263. if (string.IsNullOrEmpty(operationTips))
  264. {
  265. operationTips = "错误数据下载";
  266. }
  267. ViewBag.operationTips = operationTips;
  268. return View();
  269. }
  270. public ActionResult Import(HttpPostedFileBase file)
  271. {
  272. try
  273. {
  274. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  275. {
  276. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  277. }
  278. var excel = new NpoiExcelHelper();
  279. #region 表单头
  280. Dictionary<string, string> cellheader = new Dictionary<string, string>
  281. {
  282. { "SchoolyearCode", "考试学年学期" },
  283. { "StudentNo", "学号" },
  284. { "Name", "姓名" },
  285. { "SexForImpor", "性别" },
  286. { "ClassmajorName", "班级名称" },
  287. { "SubjectName", "科目名称" },
  288. { "CertificatesTypeNameForImport", "证件类型" },
  289. { "IDNumber", "证件号码" },
  290. { "CostForImpor", "报名费" },
  291. { "IsPay", "是否交费" },
  292. { "ErrorMessage", "错误信息" }
  293. };
  294. #endregion
  295. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  296. string sourceWebPath = FileUploadHelper.UploadFile(file);
  297. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  298. List<StudentListView> errList = new List<StudentListView>();
  299. List<StudentListView> dataList = new List<StudentListView>();
  300. int errCount = 0;
  301. int OkCount = 0;
  302. ExaminationSubjectServices.ExaminationSubjectStudentImport(cellheader, out OkCount, out errList, out errCount, sourcePhysicalPath);
  303. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  304. if (errCount > 0)
  305. {
  306. var errorPhysicalPath = sourcePhysicalPath;
  307. var errorWebPaths = sourceWebPath;
  308. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "学生缴费名单失败文件", errorWebPaths));
  309. ViewBag.ErrorFile = errorWebPath;
  310. string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount);
  311. ViewBag.operationTips = Errinfo;
  312. // //return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo });
  313. return RedirectToAction("MsgShow", "Common", new
  314. {
  315. WindowID = "none",
  316. msg = "导入失败!",
  317. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  318. });
  319. }
  320. else
  321. {
  322. return RedirectToAction("MsgShow", "Common", new
  323. {
  324. WindowID = Request["WindowID"],
  325. msg = "导入成功!",
  326. url = Url.Action("List").AddMenuParameter()
  327. });
  328. }
  329. }
  330. catch (Exception ex)
  331. {
  332. return RedirectToAction("MsgShow", "Common", new
  333. {
  334. WindowID = Request["WindowID"],
  335. msg = "导入失败,原因:" + ex.Message + "!",
  336. url = Url.Action("List").AddMenuParameter()
  337. });
  338. }
  339. }
  340. }
  341. }