LevelScoreController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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.Common.Linq;
  9. using Bowin.Common.JSON;
  10. using Bowin.Web.Controls.Mvc;
  11. using EMIS.Utility;
  12. using EMIS.Web.Controls;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.WorkflowManage;
  15. using EMIS.ViewModel.ScoreManage.LevelScoreManage;
  16. using EMIS.CommonLogic.ScoreManage.LevelScoreManage;
  17. namespace EMIS.Web.Controllers.ScoreManage.LevelScoreManage
  18. {
  19. [Authorization]
  20. public class LevelScoreController : Controller
  21. {
  22. public Lazy<ILevelScoreServices> LevelScoreServices { get; set; }
  23. /// <summary>
  24. /// 科目成绩页面
  25. /// </summary>
  26. /// <returns></returns>
  27. public ActionResult List()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 科目成绩列表查询
  33. /// </summary>
  34. /// <param name="pararms"></param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. public ActionResult List(QueryParamsModel pararms)
  38. {
  39. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  40. var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown");
  41. var campusID = pararms.getExtraGuid("CampusDropdown");
  42. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  43. var gradeID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
  44. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  45. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  46. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  47. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  48. var classmajorID = pararms.getExtraGuid("ClassmajorComboGrid");
  49. var examinationSubjectID = pararms.getExtraGuid("ExaminationSubjectComboGrid");
  50. var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus");
  51. var approvalStatus = pararms.getExtraInt("DictionaryApprovalStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryApprovalStatus");
  52. return base.Json(LevelScoreServices.Value.GetLevelScoreViewGrid(configuretView, schoolyearID, campusID, collegeID, gradeID, standardID, educationID,
  53. learningformID, learnSystem, classmajorID, examinationSubjectID, inSchoolStatus, approvalStatus, (int)pararms.page, (int)pararms.rows));
  54. }
  55. /// <summary>
  56. /// 复制新增
  57. /// </summary>
  58. /// <param name="levelScoreID"></param>
  59. /// <returns></returns>
  60. public ActionResult CopyAdd(Guid levelScoreID)
  61. {
  62. var levelScoreView = new LevelScoreView();
  63. levelScoreView = LevelScoreServices.Value.GetLevelScoreView(levelScoreID);
  64. return View("Edit", levelScoreView);
  65. }
  66. /// <summary>
  67. /// 复制新增
  68. /// </summary>
  69. /// <param name="levelScoreView"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. public ActionResult CopyAdd(LevelScoreView levelScoreView)
  73. {
  74. levelScoreView.LevelScoreID = Guid.Empty;
  75. return this.Edit(levelScoreView);
  76. }
  77. /// <summary>
  78. /// 编辑
  79. /// </summary>
  80. /// <param name="levelScoreID"></param>
  81. /// <returns></returns>
  82. [HttpGet]
  83. public ActionResult Edit(Guid? levelScoreID)
  84. {
  85. var levelScoreView = new LevelScoreView();
  86. if (levelScoreID.HasValue && levelScoreID != Guid.Empty)
  87. {
  88. levelScoreView = LevelScoreServices.Value.GetLevelScoreView(levelScoreID);
  89. }
  90. else
  91. {
  92. levelScoreView.ExaminationDate = DateTime.Now;
  93. }
  94. return View(levelScoreView);
  95. }
  96. /// <summary>
  97. /// 编辑
  98. /// </summary>
  99. /// <param name="levelScoreView"></param>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public ActionResult Edit(LevelScoreView levelScoreView)
  103. {
  104. try
  105. {
  106. LevelScoreServices.Value.LevelScoreEdit(levelScoreView);
  107. return Json(new ReturnMessage()
  108. {
  109. IsSuccess = true,
  110. Message = "保存成功。"
  111. });
  112. }
  113. catch (Exception ex)
  114. {
  115. return Json(new ReturnMessage()
  116. {
  117. IsSuccess = false,
  118. Message = "保存失败,原因:" + ex.Message
  119. });
  120. }
  121. }
  122. /// <summary>
  123. /// 删除
  124. /// </summary>
  125. /// <param name="levelScoreIDs"></param>
  126. /// <returns></returns>
  127. [HttpPost]
  128. public ActionResult Delete(string levelScoreIDs)
  129. {
  130. try
  131. {
  132. List<Guid?> list = levelScoreIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  133. LevelScoreServices.Value.LevelScoreDelete(list);
  134. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  135. }
  136. catch (Exception ex)
  137. {
  138. return base.Json(new ReturnMessage() { IsSuccess = false, Message = "删除失败,原因:" + ex.Message });
  139. }
  140. }
  141. /// <summary>
  142. /// 提交
  143. /// </summary>
  144. /// <param name="levelScoreIDs"></param>
  145. /// <returns></returns>
  146. [HttpPost]
  147. public ActionResult Submit(string levelScoreIDs)
  148. {
  149. try
  150. {
  151. List<Guid> list = levelScoreIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => new Guid(x)).ToList();
  152. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  153. string result = LevelScoreServices.Value.LevelScoreSubmit(list, user.UserID, "");
  154. return Json(new ReturnMessage()
  155. {
  156. IsSuccess = true,
  157. Message = "提交成功" + result + "。"
  158. });
  159. }
  160. catch (Exception ex)
  161. {
  162. return Json(new ReturnMessage()
  163. {
  164. IsSuccess = false,
  165. Message = "提交失败,原因:" + ex.Message
  166. });
  167. }
  168. }
  169. /// <summary>
  170. /// 审核页面(单个)
  171. /// </summary>
  172. /// <param name="levelScoreID"></param>
  173. /// <returns></returns>
  174. [HttpGet]
  175. public ActionResult Approve(Guid? levelScoreID)
  176. {
  177. var levelScoreView = LevelScoreServices.Value.GetLevelScoreView(levelScoreID);
  178. if (levelScoreView == null)
  179. {
  180. return RedirectToAction("MsgShow", "Common", new
  181. {
  182. WindowID = Request["WindowID"],
  183. msg = "操作失败,原因:数据有误。",
  184. url = Url.Action("List").AddMenuParameter()
  185. });
  186. }
  187. //对已结束的流程状态进行判断(包括正常结束、非正常结束[BP]标识)
  188. var endStatusList = LevelScoreServices.Value.GetBackpointStatus();
  189. var correctEndStatusID = LevelScoreServices.Value.GetCorrectEndStatus();
  190. endStatusList.Add(correctEndStatusID);
  191. foreach (var endStatus in endStatusList)
  192. {
  193. if (levelScoreView.ApprovalStatus == endStatus)
  194. {
  195. return RedirectToAction("MsgShow", "Common", new
  196. {
  197. WindowID = Request["WindowID"],
  198. msg = "无法对已结束的流程进行审核。",
  199. url = Url.Action("List").AddMenuParameter()
  200. });
  201. }
  202. }
  203. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  204. //根据当前环节ID、用户ID查询下一步审批动作信息List(ActionView)
  205. var actionViewList = LevelScoreServices.Value.GetActionView((Guid)levelScoreID, user.UserID);
  206. if (actionViewList == null || actionViewList.Count() <= 0)
  207. {
  208. return RedirectToAction("MsgShow", "Common", new
  209. {
  210. WindowID = Request["WindowID"],
  211. msg = "对不起,您没权限操作。",
  212. url = Url.Action("List").AddMenuParameter()
  213. });
  214. }
  215. var dropList = actionViewList.Select(x => new DropdownListItem
  216. {
  217. Text = x.ActionName,
  218. Value = x.ToJson()
  219. }).ToList();
  220. ViewBag.ListAction = dropList;
  221. return View(levelScoreView);
  222. }
  223. /// <summary>
  224. /// 审核页面(单个)
  225. /// </summary>
  226. /// <param name="levelScoreView"></param>
  227. /// <returns></returns>
  228. [HttpPost]
  229. public ActionResult Approve(LevelScoreView levelScoreView)
  230. {
  231. try
  232. {
  233. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  234. string action = Request.Form["ddlAction"];
  235. if (string.IsNullOrEmpty(action))
  236. {
  237. throw new Exception("请选择处理动作");
  238. }
  239. var actionID = action.JsonToObject<ActionView>().ActionID;
  240. List<Guid?> list = new List<Guid?>();
  241. list.Add(levelScoreView.LevelScoreID);
  242. LevelScoreServices.Value.LevelScoreApproveConfirm(list, user.UserID, actionID, levelScoreView.Comment);
  243. return Json(new ReturnMessage()
  244. {
  245. IsSuccess = true,
  246. Message = "审核成功。"
  247. });
  248. }
  249. catch (Exception ex)
  250. {
  251. return Json(new ReturnMessage()
  252. {
  253. IsSuccess = false,
  254. Message = "审核失败,原因:" + ex.Message
  255. });
  256. }
  257. }
  258. /// <summary>
  259. /// 查询对应的流程环节动作List(ActionView)
  260. /// </summary>
  261. /// <param name="levelScoreID"></param>
  262. /// <returns></returns>
  263. [HttpPost]
  264. public ActionResult ApprovalHandle(Guid? levelScoreID)
  265. {
  266. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  267. //根据当前环节ID、用户ID查询下一步审批动作信息List(ActionView)
  268. var actionViewList = LevelScoreServices.Value.GetActionView((Guid)levelScoreID, user.UserID);
  269. var dropList = actionViewList.Select(x => new DropdownListItem { Text = x.ActionName, Value = x.ToJson() }).ToList();
  270. return View(dropList);
  271. }
  272. /// <summary>
  273. /// 审批确定(批量)
  274. /// </summary>
  275. /// <param name="levelScoreIDs"></param>
  276. /// <param name="actionID"></param>
  277. /// <param name="comment"></param>
  278. /// <returns></returns>
  279. [HttpPost]
  280. public ActionResult ApproveConfirm(string levelScoreIDs, Guid actionID, string comment)
  281. {
  282. try
  283. {
  284. List<Guid?> list = levelScoreIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  285. var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  286. LevelScoreServices.Value.LevelScoreApproveConfirm(list, user.UserID, actionID, comment);
  287. return Json(new ReturnMessage()
  288. {
  289. IsSuccess = true,
  290. Message = "审核成功。"
  291. });
  292. }
  293. catch (Exception ex)
  294. {
  295. return Json(new ReturnMessage()
  296. {
  297. IsSuccess = false,
  298. Message = "审核失败,原因:" + ex.Message
  299. });
  300. }
  301. }
  302. /// <summary>
  303. /// Excel导入
  304. /// </summary>
  305. /// <param name="errorFile"></param>
  306. /// <param name="operationTips"></param>
  307. /// <returns></returns>
  308. [HttpGet]
  309. public ActionResult Import(string errorFile, string operationTips)
  310. {
  311. ViewBag.ErrorFile = errorFile;
  312. if (string.IsNullOrEmpty(operationTips))
  313. {
  314. operationTips = "点击查看失败原因...";
  315. }
  316. ViewBag.operationTips = operationTips;
  317. return View();
  318. }
  319. /// <summary>
  320. /// Excel导入
  321. /// </summary>
  322. /// <param name="file"></param>
  323. /// <returns></returns>
  324. [HttpPost]
  325. public ActionResult Import(HttpPostedFileBase file)
  326. {
  327. try
  328. {
  329. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  330. {
  331. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  332. }
  333. Dictionary<string, string> cellheader = new Dictionary<string, string>
  334. {
  335. { "StudentNo", "学号" },
  336. { "ExaminationSubjectName", "考试科目" },
  337. { "SchoolyearCode", "学年学期" },
  338. { "ExaminationDateStr", "考试日期" },
  339. { "ScoreNo", "成绩单编号" },
  340. { "TotalScoreStr", "总成绩" },
  341. { "Remark", "备注" },
  342. { "ErrorMessage", "未导入原因" }
  343. };
  344. int? inCount = 0;
  345. int? upCount = 0;
  346. int? errCount = 0;
  347. List<LevelScoreView> errList = new List<LevelScoreView>();
  348. string sourceWebPath = FileUploadHelper.UploadFile(file);
  349. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  350. LevelScoreServices.Value.LevelScoreImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  351. System.IO.File.Delete(sourcePhysicalPath);
  352. if (errList.Count() > 0)
  353. {
  354. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "科目成绩导入失败文件", sourcePhysicalPath));
  355. ViewBag.ErrorFile = errorWebPath;
  356. string Errinfo = string.Format("提示:{0}条科目成绩信息导入成功,{1}条科目成绩信息更新成功,{2}条科目成绩信息导入失败,点击查看。", inCount, upCount, errCount);
  357. ViewBag.operationTips = Errinfo;
  358. return RedirectToAction("MsgShow", "Common", new
  359. {
  360. WindowID = "none",
  361. msg = Errinfo,
  362. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  363. });
  364. }
  365. else
  366. {
  367. string successInfo = string.Format("提示:{0}条科目成绩信息导入成功,{1}条科目成绩信息更新成功。", inCount, upCount);
  368. return RedirectToAction("MsgShow", "Common", new
  369. {
  370. WindowID = Request["WindowID"],
  371. msg = successInfo,
  372. url = Url.Action("List").AddMenuParameter()
  373. });
  374. }
  375. }
  376. catch (Exception ex)
  377. {
  378. return RedirectToAction("MsgShow", "Common", new
  379. {
  380. WindowID = "none",
  381. msg = "导入失败,原因:" + ex.Message,
  382. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  383. });
  384. }
  385. }
  386. /// <summary>
  387. /// Excel导出
  388. /// </summary>
  389. /// <returns></returns>
  390. [HttpPost]
  391. public ActionResult Excel()
  392. {
  393. try
  394. {
  395. NpoiExcelHelper neh = new NpoiExcelHelper();
  396. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  397. var schoolyearID = Request.Form["SchoolyearDropdown"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["SchoolyearDropdown"].ParseStrTo<Guid>();
  398. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  399. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  400. var gradeID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  401. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  402. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  403. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  404. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  405. var classmajorID = Request.Form["ClassmajorComboGrid"].ParseStrTo<Guid>();
  406. var examinationSubjectID = Request.Form["ExaminationSubjectComboGrid"].ParseStrTo<Guid>();
  407. var inSchoolStatus = Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryInschoolStatus"].ParseStrTo<int>();
  408. var approvalStatus = Request.Form["DictionaryApprovalStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryApprovalStatus"].ParseStrTo<int>();
  409. var dt = LevelScoreServices.Value.GetLevelScoreViewList(configuretView, schoolyearID, campusID, collegeID, gradeID, standardID, educationID,
  410. learningformID, learnSystem, classmajorID, examinationSubjectID, inSchoolStatus, approvalStatus)
  411. .Select(x => new
  412. {
  413. x.StudentNo,
  414. x.Name,
  415. x.SexName,
  416. x.InSchoolStatusName,
  417. x.StudentStatusName,
  418. x.GradeID,
  419. x.StandardCode,
  420. x.StandardID,
  421. x.StandardName,
  422. x.EducationName,
  423. x.LearningformName,
  424. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  425. x.ClassmajorNo,
  426. x.ClassmajorName,
  427. x.GrademajorCode,
  428. x.GrademajorName,
  429. x.CollegeNo,
  430. x.CollegeName,
  431. x.CampusCode,
  432. x.CampusName,
  433. x.ExaminationSubjectName,
  434. x.SchoolyearCode,
  435. ExaminationDate = x.ExaminationDate.HasValue ? x.ExaminationDate.Value.ToString("yyyy-MM") : "",
  436. x.ScoreNo,
  437. x.TotalScore,
  438. x.LevelName,
  439. x.Remark,
  440. x.ApprovalStatusName,
  441. x.CreateUserName,
  442. x.ModifyUserName,
  443. ModifyTime = x.ModifyTime == null ? null : x.ModifyTime.Value.ToString("yyyy-MM-dd HH:mm:ss")
  444. }).ToTable();
  445. string[] liststring = {
  446. "学号", "姓名", "性别", "在校状态", "学籍状态", "年级", "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"),
  447. "学习形式", "学制", "班级编号", "班级名称", "年级专业编号", "年级专业名称", RSL.Get("CollegeCode"), RSL.Get("CollegeName"),
  448. RSL.Get("CampusCode"), RSL.Get("CampusName"), "考试科目", "学年学期", "考试日期", "成绩单编号", "总成绩", "成绩等级",
  449. "备注", "审批状态", "创建人", "修改人", "修改时间"
  450. };
  451. neh.Export(dt, liststring, "科目成绩信息" + DateTime.Now.ToString("yyyyMMdd"));
  452. return Json(new ReturnMessage()
  453. {
  454. IsSuccess = true,
  455. Message = "导出成功。"
  456. });
  457. }
  458. catch (Exception ex)
  459. {
  460. return Json(new ReturnMessage()
  461. {
  462. IsSuccess = false,
  463. Message = "导出失败,原因:" + ex.Message
  464. });
  465. }
  466. }
  467. }
  468. }