RecruitSpecialtyController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Bowin.Common.Exceptions;
  8. using Bowin.Common.Utility;
  9. using Bowin.Common.Data;
  10. using Bowin.Common.Linq;
  11. using Bowin.Common.JSON;
  12. using Bowin.Web.Controls.Mvc;
  13. using EMIS.Web.Controls;
  14. using EMIS.Utility;
  15. using EMIS.ViewModel;
  16. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  17. using EMIS.CommonLogic.EnrollManage.SpecialtyManage;
  18. namespace EMIS.Web.Controllers.EnrollManage.SpecialtyManage
  19. {
  20. [Authorization]
  21. public class RecruitSpecialtyController : Controller
  22. {
  23. public IRecruitSpecialtyServices recruitSpecialtyServices { get; set; }
  24. public ISpecialtyApplyServices specialtyApplyServices { get; set; }
  25. /// <summary>
  26. /// 招生专业页面
  27. /// </summary>
  28. /// <returns></returns>
  29. public ActionResult List()
  30. {
  31. return View();
  32. }
  33. /// <summary>
  34. /// 招生专业页面列表查询
  35. /// </summary>
  36. /// <param name="pararms"></param>
  37. /// <returns></returns>
  38. [HttpPost]
  39. public ActionResult List(QueryParamsModel pararms)
  40. {
  41. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  42. var campusID = pararms.getExtraGuid("CampusDropdown");
  43. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  44. var gradeID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
  45. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  46. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  47. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  48. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  49. var isGenerated = pararms.getExtraInt("DictionaryIsGenerated") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsGenerated");
  50. return base.Json(recruitSpecialtyServices.GetRecruitSpecialtyViewGrid(configuretView, campusID, collegeID, gradeID, standardID, educationID,
  51. learningformID, learnSystem, isGenerated, (int)pararms.page, (int)pararms.rows));
  52. }
  53. /// <summary>
  54. /// 复制新增
  55. /// </summary>
  56. /// <param name="recruitSpecialtyID"></param>
  57. /// <returns></returns>
  58. public ActionResult CopyAdd(Guid recruitSpecialtyID)
  59. {
  60. RecruitSpecialtyView recruitSpecialtyView = new RecruitSpecialtyView();
  61. recruitSpecialtyView = recruitSpecialtyServices.GetRecruitSpecialtyView(recruitSpecialtyID);
  62. return View("Edit", recruitSpecialtyView);
  63. }
  64. /// <summary>
  65. /// 复制新增
  66. /// </summary>
  67. /// <param name="recruitSpecialtyView"></param>
  68. /// <returns></returns>
  69. [HttpPost]
  70. public ActionResult CopyAdd(RecruitSpecialtyView recruitSpecialtyView)
  71. {
  72. recruitSpecialtyView.RecruitSpecialtyID = Guid.Empty;
  73. return this.Edit(recruitSpecialtyView);
  74. }
  75. /// <summary>
  76. /// 编辑(新增、修改,业务主键:专业信息ID、院系所、年级、学期)
  77. /// </summary>
  78. /// <param name="recruitSpecialtyID"></param>
  79. /// <returns></returns>
  80. [HttpGet]
  81. public ActionResult Edit(Guid? recruitSpecialtyID)
  82. {
  83. RecruitSpecialtyView recruitSpecialtyView = new RecruitSpecialtyView();
  84. if (recruitSpecialtyID.HasValue && recruitSpecialtyID != Guid.Empty)
  85. {
  86. recruitSpecialtyView = recruitSpecialtyServices.GetRecruitSpecialtyView(recruitSpecialtyID);
  87. }
  88. else
  89. {
  90. recruitSpecialtyView.GradeID = BaseExtensions.GetNextYearID();
  91. recruitSpecialtyView.SemesterID = BaseExtensions.GetEntranceSemesterID();
  92. }
  93. return View(recruitSpecialtyView);
  94. }
  95. /// <summary>
  96. /// 编辑(新增、修改,业务主键:专业信息ID、院系所、年级、学期)
  97. /// </summary>
  98. /// <param name="recruitSpecialtyView"></param>
  99. /// <returns></returns>
  100. [HttpPost]
  101. public ActionResult Edit(RecruitSpecialtyView recruitSpecialtyView)
  102. {
  103. try
  104. {
  105. recruitSpecialtyServices.RecruitSpecialtyEdit(recruitSpecialtyView);
  106. return Json(new ReturnMessage()
  107. {
  108. IsSuccess = true,
  109. Message = "保存成功。"
  110. });
  111. }
  112. catch (Exception ex)
  113. {
  114. return Json(new ReturnMessage()
  115. {
  116. IsSuccess = false,
  117. Message = "保存失败,原因:" + ex.Message + "。"
  118. });
  119. }
  120. }
  121. /// <summary>
  122. /// 招生专业批量新增
  123. /// </summary>
  124. /// <returns></returns>
  125. [HttpGet]
  126. public ActionResult RecruitSpecialtyBatchAdd()
  127. {
  128. RecruitSpecialtyView recruitSpecialtyView = new RecruitSpecialtyView();
  129. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  130. recruitSpecialtyView.CollegeID = user.CollegeID;
  131. return View(recruitSpecialtyView);
  132. }
  133. /// <summary>
  134. /// 招生专业批量新增
  135. /// </summary>
  136. /// <param name="recruitSpecialtyView"></param>
  137. /// <returns></returns>
  138. public ActionResult RecruitSpecialtyBatchAdd(RecruitSpecialtyView recruitSpecialtyView)
  139. {
  140. try
  141. {
  142. var specialtyIDList = Request["specialtyIDs"].JsonToObject<List<Guid?>>();
  143. string result = recruitSpecialtyServices.RecruitSpecialtyBatchAdd(specialtyIDList, recruitSpecialtyView);
  144. return Json(new ReturnMessage()
  145. {
  146. IsSuccess = true,
  147. Message = "新增成功" + result + "。"
  148. });
  149. }
  150. catch (Exception ex)
  151. {
  152. return Json(new ReturnMessage()
  153. {
  154. IsSuccess = false,
  155. Message = "新增失败,原因:" + ex.Message
  156. });
  157. }
  158. }
  159. /// <summary>
  160. /// 查询招生专业中未新增的专业信息SpecialtyView
  161. /// </summary>
  162. /// <param name="pararms"></param>
  163. /// <returns></returns>
  164. [HttpPost]
  165. public ActionResult SpecialtyNoAddList(QueryParamsModel pararms)
  166. {
  167. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  168. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  169. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  170. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  171. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  172. var scienceclassID = pararms.getExtraInt("DictionaryScienceclass") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryScienceclass");
  173. var collegeID = pararms.getExtraGuid("CollegeID");
  174. var gradeID = pararms.getExtraInt("GradeID") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("GradeID");
  175. var semesterID = pararms.getExtraInt("SemesterID") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SemesterID");
  176. return base.Json(recruitSpecialtyServices.GetSpecialtyViewNoAdd(configuretView, collegeID, gradeID, semesterID, standardID, educationID,
  177. learningformID, learnSystem, scienceclassID, (int)pararms.page, (int)pararms.rows));
  178. }
  179. /// <summary>
  180. /// 专业班级生成(由于各高校生成规则不同,需分版本—个性化配置)
  181. /// </summary>
  182. /// <param name="recruitSpecialtyIDs"></param>
  183. /// <returns></returns>
  184. public ActionResult GenerateClass(string recruitSpecialtyIDs)
  185. {
  186. try
  187. {
  188. List<Guid?> list = recruitSpecialtyIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  189. string result = recruitSpecialtyServices.GenerateClass(list);
  190. return Json(new ReturnMessage()
  191. {
  192. IsSuccess = true,
  193. Message = "生成成功" + result + "。"
  194. });
  195. }
  196. catch (Exception ex)
  197. {
  198. return Json(new ReturnMessage()
  199. {
  200. IsSuccess = false,
  201. Message = "生成失败,原因:" + ex.Message
  202. });
  203. }
  204. }
  205. /// <summary>
  206. /// 删除(需根据业务主键删除对应的流程结束专业申请信息)
  207. /// </summary>
  208. /// <param name="recruitSpecialtyIDs"></param>
  209. /// <returns></returns>
  210. [HttpPost]
  211. public ActionResult Delete(string recruitSpecialtyIDs)
  212. {
  213. try
  214. {
  215. List<Guid?> list = recruitSpecialtyIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  216. recruitSpecialtyServices.RecruitSpecialtyDelete(list);
  217. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  218. }
  219. catch (Exception ex)
  220. {
  221. string mge = ex.Message;
  222. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  223. if (num != null)
  224. {
  225. if (num.Number == 547)
  226. {
  227. mge = "请先删除与其关联的数据,如:专业申请、专业审核等。";
  228. }
  229. }
  230. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  231. }
  232. }
  233. /// <summary>
  234. /// 招生专业导入
  235. /// </summary>
  236. /// <param name="errorFile"></param>
  237. /// <param name="operationTips"></param>
  238. /// <returns></returns>
  239. [HttpGet]
  240. public ActionResult Import(string errorFile, string operationTips)
  241. {
  242. ViewBag.ErrorFile = errorFile;
  243. if (string.IsNullOrEmpty(operationTips))
  244. {
  245. operationTips = "点击查看失败原因...";
  246. }
  247. ViewBag.operationTips = operationTips;
  248. return View();
  249. }
  250. /// <summary>
  251. /// Excel导入
  252. /// </summary>
  253. /// <param name="file"></param>
  254. /// <returns></returns>
  255. [HttpPost]
  256. public ActionResult Import(HttpPostedFileBase file)
  257. {
  258. try
  259. {
  260. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  261. {
  262. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  263. }
  264. Dictionary<string, string> cellheader = new Dictionary<string, string>
  265. {
  266. { "StandardCode", "专业代码" },
  267. { "StandardName", "专业名称" },
  268. { "EducationStr", RSL.Get("EducationID") },
  269. { "LearningformStr", "学习形式" },
  270. { "LearnSystemStr", "学制" },
  271. { "GradeStr", "年级" },
  272. { "SemesterStr", "学期" },
  273. { "CollegeNo", RSL.Get("CollegeCode") },
  274. { "Remark", "备注" },
  275. { "ErrorMessage", "未导入原因" }
  276. };
  277. StringBuilder errorMsg = new StringBuilder();
  278. string sourceWebPath = FileUploadHelper.UploadFile(file);
  279. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  280. List<RecruitSpecialtyView> errList = new List<RecruitSpecialtyView>();
  281. List<RecruitSpecialtyView> dataList = new List<RecruitSpecialtyView>();
  282. int? inCount = 0; //导入个数
  283. int? upCount = 0; //更新个数
  284. int? errCount = 0; //失败个数
  285. //导入
  286. recruitSpecialtyServices.RecruitSpecialtyImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  287. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  288. if (errList.Count() > 0)
  289. {
  290. //获取错误数据文件路径
  291. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "专业信息导入失败文件", sourcePhysicalPath));
  292. ViewBag.ErrorFile = errorWebPath;
  293. string Errinfo = string.Format("提示:{0}条招生专业信息导入成功,{1}条招生专业更新成功,{2}条招生专业导入失败,点击查看。", inCount, upCount, errCount);
  294. ViewBag.operationTips = Errinfo;
  295. return RedirectToAction("MsgShow", "Common", new
  296. {
  297. WindowID = "none",
  298. msg = Errinfo,
  299. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  300. });
  301. }
  302. else
  303. {
  304. string successInfo = string.Format("提示:{0}条招生专业导入成功,{1}条招生专业更新成功。", inCount, upCount);
  305. return RedirectToAction("MsgShow", "Common", new
  306. {
  307. WindowID = Request["WindowID"],
  308. msg = successInfo,
  309. url = Url.Action("List").AddMenuParameter()
  310. });
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. return RedirectToAction("MsgShow", "Common", new
  316. {
  317. WindowID = "none",
  318. msg = "导入失败,原因:" + ex.Message,
  319. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  320. });
  321. }
  322. }
  323. /// <summary>
  324. /// Excel导出
  325. /// </summary>
  326. /// <returns></returns>
  327. [HttpPost]
  328. public ActionResult Excel()
  329. {
  330. NpoiExcelHelper neh = new NpoiExcelHelper();
  331. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  332. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  333. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  334. var gradeID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  335. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  336. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  337. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  338. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  339. var isGenerated = Request.Form["DictionaryIsGenerated"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsGenerated"].ParseStrTo<int>();
  340. var dt = recruitSpecialtyServices.GetRecruitSpecialtyViewList(configuretView, campusID, collegeID, gradeID, standardID,
  341. educationID, learningformID, learnSystem, isGenerated)
  342. .Select(x => new
  343. {
  344. x.Code,
  345. x.StandardID,
  346. x.StandardName,
  347. x.EducationName,
  348. x.LearningformName,
  349. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  350. x.GradeID,
  351. x.SemesterName,
  352. x.CollegeNo,
  353. x.CollegeName,
  354. x.ScienceclassName,
  355. x.PropertyName,
  356. x.isGeneratedName,
  357. x.Remark
  358. }).ToTable();
  359. string[] liststring = {
  360. "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"),"学习形式", "学制", "年级", "学期",
  361. RSL.Get("CollegeCode"), RSL.Get("CollegeName"), "专业科类", "专业属性", "生成状态", "备注"
  362. };
  363. neh.Export(dt, liststring, "招生专业信息" + DateTime.Now.ToString("yyyyMMdd"));
  364. return Json(new ReturnMessage()
  365. {
  366. IsSuccess = true,
  367. Message = "导出成功。"
  368. });
  369. }
  370. }
  371. }