NewStudentController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using Bowin.Web.Controls.Mvc;
  9. using Bowin.Common.Utility;
  10. using Bowin.Common.Data;
  11. using EMIS.Utility;
  12. using EMIS.Web.Controls;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.EnrollManage.NewStudentManage;
  15. using EMIS.CommonLogic.EnrollManage.NewStudentManage;
  16. namespace EMIS.Web.Controllers.EnrollManage.NewStudentManage
  17. {
  18. [Authorization]
  19. public class NewStudentController : Controller
  20. {
  21. public INewStudentServices newStudentServices { get; set; }
  22. /// <summary>
  23. /// 新生名单页面
  24. /// </summary>
  25. /// <returns></returns>
  26. public ActionResult List()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 新生名单页面列表查询
  32. /// </summary>
  33. /// <param name="pararms"></param>
  34. /// <returns></returns>
  35. [HttpPost]
  36. public ActionResult List(QueryParamsModel pararms)
  37. {
  38. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  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 isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown");
  45. return base.Json(newStudentServices.GetNewStudentViewGrid(configuretView, gradeID, standardID, educationID, learningformID, learnSystem, isPhotoUrl, (int)pararms.page, (int)pararms.rows));
  46. }
  47. /// <summary>
  48. /// 复制新增
  49. /// </summary>
  50. /// <param name="newStudentID"></param>
  51. /// <returns></returns>
  52. public ActionResult CopyAdd(Guid newStudentID)
  53. {
  54. NewStudentView newStudentView = new NewStudentView();
  55. newStudentView = newStudentServices.GetNewStudentView(newStudentID);
  56. return View("Edit", newStudentView);
  57. }
  58. /// <summary>
  59. /// 复制新增
  60. /// </summary>
  61. /// <param name="newStudentView"></param>
  62. /// <returns></returns>
  63. [HttpPost]
  64. public ActionResult CopyAdd(NewStudentView newStudentView)
  65. {
  66. newStudentView.NewStudentID = Guid.Empty;
  67. return this.Edit(newStudentView);
  68. }
  69. /// <summary>
  70. /// 编辑、复制新增(新增、修改,业务主键:考生号唯一)
  71. /// </summary>
  72. /// <param name="newNewStudentID"></param>
  73. /// <param name="type"></param>
  74. /// <returns></returns>
  75. [HttpGet]
  76. public ActionResult Edit(Guid? newNewStudentID, string type)
  77. {
  78. NewStudentView newStudentView = new NewStudentView();
  79. if (newNewStudentID.HasValue && newNewStudentID != Guid.Empty)
  80. {
  81. newStudentView = newStudentServices.GetNewStudentView(newNewStudentID);
  82. if (type == "copyAdd")
  83. {
  84. newStudentView.NewStudentID = Guid.Empty;
  85. newStudentView.RecruitPictureUrl = null;
  86. }
  87. }
  88. else
  89. {
  90. newStudentView.NationID = (int)CF_Nation.Han;
  91. newStudentView.PoliticsID = (int)CF_Politics.YouthLeague;
  92. newStudentView.CertificatesType = (int)CF_CertificatesType.IdCrad;
  93. newStudentView.GradeID = BaseExtensions.GetCurrentYearID();
  94. newStudentView.SemesterID = BaseExtensions.GetEntranceSemesterID();
  95. newStudentView.AssignStatus = (int)CF_AssignStatus.NotAssigned;
  96. }
  97. return View(newStudentView);
  98. }
  99. /// <summary>
  100. /// 编辑、复制新增(新增、修改,业务主键:考生号唯一)
  101. /// </summary>
  102. /// <param name="newStudentView"></param>
  103. /// <returns></returns>
  104. [HttpPost]
  105. public ActionResult Edit(NewStudentView newStudentView)
  106. {
  107. try
  108. {
  109. var accepts = new List<string> { ".jpg", ".jpeg", ".png", ".bmp" };
  110. var postedFile = Request.Files["RecruitPictureUrl"];
  111. if (!string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
  112. {
  113. throw new Exception("只允许上传.jpg、.jpeg、.png、.bmp格式的文件。");
  114. }
  115. string photoUrl = FileUploadHelper.UploadFile(postedFile);
  116. newStudentServices.NewStudentEdit(newStudentView, photoUrl);
  117. return RedirectToAction("MsgShow", "Common", new
  118. {
  119. WindowID = Request["WindowID"],
  120. msg = "保存成功。",
  121. url = Url.Action("List").AddMenuParameter()
  122. });
  123. }
  124. catch (Exception ex)
  125. {
  126. return RedirectToAction("MsgShowAndOpen", "Common", new
  127. {
  128. WindowID = Request["WindowID"],
  129. msg = "保存失败,原因:" + ex.Message
  130. });
  131. }
  132. }
  133. /// <summary>
  134. /// 删除
  135. /// </summary>
  136. /// <param name="newStudentIDs"></param>
  137. /// <returns></returns>
  138. [HttpPost]
  139. public ActionResult Delete(string newStudentIDs)
  140. {
  141. try
  142. {
  143. List<Guid?> list = newStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  144. newStudentServices.NewStudentDelete(list);
  145. return Json(new ReturnMessage()
  146. {
  147. IsSuccess = true,
  148. Message = "删除成功。"
  149. });
  150. }
  151. catch (Exception ex)
  152. {
  153. return Json(new ReturnMessage()
  154. {
  155. IsSuccess = false,
  156. Message = "删除失败,原因:" + ex.Message
  157. });
  158. }
  159. }
  160. /// <summary>
  161. /// 删除照片(单个删除)
  162. /// </summary>
  163. /// <param name="newStudentID"></param>
  164. /// <returns></returns>
  165. [HttpPost]
  166. public ActionResult DeletePhoto(Guid? newStudentID)
  167. {
  168. try
  169. {
  170. this.newStudentServices.DeletePhoto(newStudentID);
  171. return Json(new ReturnMessage()
  172. {
  173. IsSuccess = true,
  174. Message = "删除照片成功。"
  175. });
  176. }
  177. catch (Exception ex)
  178. {
  179. return Json(new ReturnMessage()
  180. {
  181. IsSuccess = false,
  182. Message = "删除照片失败:" + ex.Message
  183. });
  184. }
  185. }
  186. /// <summary>
  187. /// 删除照片(批量删除)
  188. /// </summary>
  189. /// <param name="newStudentIDs"></param>
  190. /// <returns></returns>
  191. [HttpPost]
  192. public ActionResult PicDelete(string newStudentIDs)
  193. {
  194. try
  195. {
  196. List<Guid?> list = newStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  197. newStudentServices.PicDelete(list);
  198. return Json(new ReturnMessage()
  199. {
  200. IsSuccess = true,
  201. Message = "删除照片成功。"
  202. });
  203. }
  204. catch (Exception ex)
  205. {
  206. return Json(new ReturnMessage()
  207. {
  208. IsSuccess = false,
  209. Message = "删除照片失败:" + ex.Message
  210. });
  211. }
  212. }
  213. /// <summary>
  214. /// 导入照片
  215. /// </summary>
  216. /// <param name="errorFile"></param>
  217. /// <param name="operationTips"></param>
  218. /// <returns></returns>
  219. [HttpGet]
  220. public ActionResult PicImport(string errorFile, string operationTips)
  221. {
  222. ViewBag.ErrorFile = errorFile;
  223. if (string.IsNullOrEmpty(operationTips))
  224. {
  225. operationTips = "点击查看失败原因...";
  226. }
  227. ViewBag.operationTips = operationTips;
  228. return View();
  229. }
  230. /// <summary>
  231. /// 导入照片
  232. /// </summary>
  233. /// <param name="file"></param>
  234. /// <param name="importPicType"></param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. public ActionResult PicImport(HttpPostedFileBase file, string importPicType)
  238. {
  239. try
  240. {
  241. if (file.ContentLength <= 0)
  242. {
  243. throw new Exception("请选择你要上传的照片(注:格式为zip或rar的压缩包文件)。");
  244. }
  245. var acceptFileExtensions = new[] { ".zip", ".rar" };
  246. var fileExtensionName = Path.GetExtension(file.FileName);
  247. if (!acceptFileExtensions.Contains(fileExtensionName))
  248. {
  249. throw new Exception("格式错误,只允许上传zip或rar格式的压缩包文件。");
  250. }
  251. string fileSourceWebPath = null;
  252. string errorSourceWebPath = null;
  253. var photoPathList = FileUploadHelper.UploadFileAndExtractFile(file, out fileSourceWebPath, out errorSourceWebPath);
  254. System.IO.File.Delete(Server.MapPath(fileSourceWebPath));
  255. if (photoPathList == null || photoPathList.Count <= 0)
  256. {
  257. throw new Exception("压缩包中文件为空。");
  258. }
  259. var acceptPicExtensions = new[] { ".jpg", ".jpeg", ".png", ".bmp" };
  260. List<string> newPhotoPathList = new List<string>();
  261. foreach (var photoPath in photoPathList)
  262. {
  263. string photoExtensionName = Path.GetExtension(photoPath).ToLower();
  264. if (acceptPicExtensions.Contains(photoExtensionName))
  265. {
  266. newPhotoPathList.Add(photoPath);
  267. }
  268. else
  269. {
  270. throw new Exception("压缩包中含有不支持的照片格式。");
  271. }
  272. }
  273. int? inCount = 0;
  274. int? errCount = 0;
  275. var errDataTable = new DataTable();
  276. newStudentServices.NewStudentPicImport(newPhotoPathList, importPicType, out inCount, out errCount, out errDataTable);
  277. if (errDataTable != null && errDataTable.Rows.Count > 0)
  278. {
  279. NpoiExcelHelper npoiExcelHelper = new NpoiExcelHelper();
  280. npoiExcelHelper.SaveInServer(errDataTable, Server.MapPath(errorSourceWebPath));
  281. string errorWebPath = string.Format("{0}", errorSourceWebPath);
  282. ViewBag.ErrorFile = errorWebPath;
  283. string Errinfo = string.Format("提示:{0}个照片导入成功,{1}个照片导入失败,点击查看。", inCount, errCount);
  284. ViewBag.operationTips = Errinfo;
  285. return RedirectToAction("MsgShow", "Common", new
  286. {
  287. WindowID = "none",
  288. msg = Errinfo,
  289. url = Url.Action("PicImport").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  290. });
  291. }
  292. else
  293. {
  294. string successInfo = string.Format("提示:{0}个照片导入成功。", inCount);
  295. return RedirectToAction("MsgShow", "Common", new
  296. {
  297. WindowID = Request["WindowID"],
  298. msg = successInfo,
  299. url = Url.Action("List").AddMenuParameter()
  300. });
  301. }
  302. }
  303. catch (Exception ex)
  304. {
  305. return RedirectToAction("MsgShow", "Common", new
  306. {
  307. WindowID = "none",
  308. msg = "导入照片失败,原因:" + ex.Message,
  309. url = Url.Action("PicImport").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  310. });
  311. }
  312. }
  313. /// <summary>
  314. /// Excel导入
  315. /// </summary>
  316. /// <param name="errorFile"></param>
  317. /// <param name="operationTips"></param>
  318. /// <returns></returns>
  319. [HttpGet]
  320. public ActionResult Import(string errorFile, string operationTips)
  321. {
  322. ViewBag.ErrorFile = errorFile;
  323. if (string.IsNullOrEmpty(operationTips))
  324. {
  325. operationTips = "点击查看失败原因...";
  326. }
  327. ViewBag.operationTips = operationTips;
  328. return View();
  329. }
  330. /// <summary>
  331. /// Excel导入
  332. /// </summary>
  333. /// <param name="file"></param>
  334. /// <returns></returns>
  335. [HttpPost]
  336. public ActionResult Import(HttpPostedFileBase file)
  337. {
  338. try
  339. {
  340. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  341. {
  342. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  343. }
  344. Dictionary<string, string> cellheader = new Dictionary<string, string>
  345. {
  346. { "ExamineeNum", "考生号" },
  347. { "AdmissionTicketNo", "准考证号" },
  348. { "Name", "姓名" },
  349. { "SexStr", "性别" },
  350. { "NationStr", "民族" },
  351. { "PoliticsStr", "政治面貌" },
  352. { "BirthDateStr", "出生日期" },
  353. { "CertificatesTypeStr", "证件类型" },
  354. { "IDNumber", "身份证号" },
  355. { "GradeStr", "年级" },
  356. { "SemesterStr", "学期" },
  357. { "StandardCode", "专业代码" },
  358. { "StandardName", "专业名称" },
  359. { "EducationStr", RSL.Get("EducationID") },
  360. { "LearningformStr", "学习形式" },
  361. { "LearnSystemStr", "学制" },
  362. { "EntranceDateStr", "入学日期" },
  363. { "ScoreStr", "总分" },
  364. { "Telephone", "联系电话" },
  365. { "Address", "通讯地址" },
  366. { "Dormitory", "宿舍地址" },
  367. { "Remark", "备注" },
  368. { "ErrorMessage", "未导入原因" }
  369. };
  370. int? inCount = 0;
  371. int? upCount = 0;
  372. int? errCount = 0;
  373. List<NewStudentView> errList = new List<NewStudentView>();
  374. string sourceWebPath = FileUploadHelper.UploadFile(file);
  375. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  376. newStudentServices.NewStudentImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  377. System.IO.File.Delete(sourcePhysicalPath);
  378. if (errList.Count() > 0)
  379. {
  380. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "新生信息导入失败文件", sourcePhysicalPath));
  381. ViewBag.ErrorFile = errorWebPath;
  382. string Errinfo = string.Format("提示:{0}条新生信息导入成功,{1}条新生信息更新成功,{2}条新生信息导入失败,点击查看。", inCount, upCount, errCount);
  383. ViewBag.operationTips = Errinfo;
  384. return RedirectToAction("MsgShow", "Common", new
  385. {
  386. WindowID = "none",
  387. msg = Errinfo,
  388. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  389. });
  390. }
  391. else
  392. {
  393. string successInfo = string.Format("提示:{0}条新生信息导入成功,{1}条新生信息更新成功。", inCount, upCount);
  394. return RedirectToAction("MsgShow", "Common", new
  395. {
  396. WindowID = Request["WindowID"],
  397. msg = successInfo,
  398. url = Url.Action("List").AddMenuParameter()
  399. });
  400. }
  401. }
  402. catch (Exception ex)
  403. {
  404. return RedirectToAction("MsgShow", "Common", new
  405. {
  406. WindowID = "none",
  407. msg = "导入失败,原因:" + ex.Message,
  408. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  409. });
  410. }
  411. }
  412. /// <summary>
  413. /// Excel导出
  414. /// </summary>
  415. /// <returns></returns>
  416. [HttpPost]
  417. public ActionResult Excel()
  418. {
  419. NpoiExcelHelper neh = new NpoiExcelHelper();
  420. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  421. var gradeID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  422. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  423. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  424. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  425. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  426. var isPhotoUrl = Request.Form["IsPhotoUrlDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsPhotoUrlDropdown"].ParseStrTo<int>();
  427. var dt = newStudentServices.GetNewStudentViewList(configuretView, gradeID, standardID, educationID, learningformID, learnSystem, isPhotoUrl)
  428. .Select(x => new
  429. {
  430. x.ExamineeNum,
  431. x.AdmissionTicketNo,
  432. x.Name,
  433. x.SexName,
  434. x.NationName,
  435. x.PoliticsName,
  436. BirthDate = x.BirthDate.HasValue ? x.BirthDate.Value.ToString("yyyy-MM-dd") : "",
  437. x.CertificatesTypeName,
  438. x.IDNumber,
  439. x.GradeID,
  440. x.SemesterName,
  441. x.StandardCode,
  442. x.StandardID,
  443. x.StandardName,
  444. x.EducationName,
  445. x.LearningformName,
  446. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  447. EntranceDate = x.EntranceDate.HasValue ? x.EntranceDate.Value.ToString("yyyy-MM-dd") : "",
  448. x.Score,
  449. x.Telephone,
  450. x.Address,
  451. x.Dormitory,
  452. x.RecruitPictureUrl,
  453. x.AssignStatusName,
  454. x.Remark
  455. }).ToTable();
  456. string[] liststring = {
  457. "考生号", "准考证号","姓名", "性别", "民族", "政治面貌", "出生日期", "证件类型", "身份证号",
  458. "年级", "学期", "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"), "学习形式", "学制",
  459. "入学日期", "总分", "联系电话", "通讯地址", "宿舍地址", "照片Url", "分配状态", "备注"
  460. };
  461. neh.Export(dt, liststring, "新生名单信息" + DateTime.Now.ToString("yyyyMMdd"));
  462. return Json(new ReturnMessage()
  463. {
  464. IsSuccess = true,
  465. Message = "导出成功。"
  466. });
  467. }
  468. }
  469. }