SpecialtyController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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.Web.Controls.Mvc;
  11. using EMIS.Web.Controls;
  12. using EMIS.Utility;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  15. using EMIS.CommonLogic.EnrollManage.SpecialtyManage;
  16. namespace EMIS.Web.Controllers.EnrollManage.SpecialtyManage
  17. {
  18. [Authorization]
  19. public class SpecialtyController : Controller
  20. {
  21. public ISpecialtyServices SpecialtyServices { 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 standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  40. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  41. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  42. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  43. var scienceclassID = pararms.getExtraInt("DictionaryScienceclass") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryScienceclass");
  44. var propertyID = pararms.getExtraInt("DictionaryProperty") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryProperty");
  45. var recordStatus = pararms.getExtraInt("DictionaryRecordStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryRecordStatus");
  46. return base.Json(SpecialtyServices.GetSpecialtyViewGrid(configuretView, standardID, educationID, learningformID, learnSystem, scienceclassID, propertyID, recordStatus, (int)pararms.page, (int)pararms.rows));
  47. }
  48. /// <summary>
  49. /// 查询专业信息(只查询启用状态的信息)
  50. /// </summary>
  51. /// <param name="pararms"></param>
  52. /// <returns></returns>
  53. public ActionResult SpecialtyID(QueryParamsModel pararms)
  54. {
  55. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  56. return base.Json(SpecialtyServices.GetSpecialtyIDGrid(configuretView, (int)pararms.page, (int)pararms.rows));
  57. }
  58. /// <summary>
  59. /// 专业信息下拉列表(启用状态为是的信息)
  60. /// </summary>
  61. /// <param name="pararms"></param>
  62. /// <returns></returns>
  63. [HttpPost]
  64. public ActionResult GetIsEnableSpecialtyView(QueryParamsModel pararms)
  65. {
  66. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  67. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  68. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  69. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  70. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  71. var scienceclassID = pararms.getExtraInt("DictionaryScienceclass") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryScienceclass");
  72. var propertyID = pararms.getExtraInt("DictionaryProperty") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryProperty");
  73. var recordStatus = (int)SYS_STATUS.USABLE;
  74. return base.Json(SpecialtyServices.GetSpecialtyViewGrid(configuretView, standardID, educationID, learningformID, learnSystem, scienceclassID, propertyID, recordStatus, (int)pararms.page, (int)pararms.rows));
  75. }
  76. /// <summary>
  77. /// 专业信息下拉列表(启用状态为是或已使用的信息)
  78. /// </summary>
  79. /// <param name="pararms"></param>
  80. /// <returns></returns>
  81. [HttpPost]
  82. public ActionResult GetEnableAndUseSpecialtyView(QueryParamsModel pararms)
  83. {
  84. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  85. var specialtyID = Request["specialtyID"].ParseStrTo<Guid>();
  86. return base.Json(SpecialtyServices.GetEnableAndUseSpecialtyViewGrid(configuretView, specialtyID, (int)pararms.page, (int)pararms.rows));
  87. }
  88. /// <summary>
  89. /// 查询对应的专业信息(根据专业信息ID)
  90. /// </summary>
  91. /// <param name="specialtyID"></param>
  92. /// <returns></returns>
  93. [HttpPost]
  94. public ActionResult GetSpecialtyView(Guid? specialtyID)
  95. {
  96. try
  97. {
  98. var result = SpecialtyServices.GetSpecialtyView(specialtyID);
  99. return Json(new ReturnMessage<SpecialtyView>()
  100. {
  101. IsSuccess = true,
  102. Data = result
  103. });
  104. }
  105. catch (Exception ex)
  106. {
  107. return Json(new ReturnMessage()
  108. {
  109. IsSuccess = false,
  110. Message = ex.Message
  111. });
  112. }
  113. }
  114. /// <summary>
  115. /// 查询专业信息中专业名称信息
  116. /// </summary>
  117. /// <param name="pararms"></param>
  118. /// <returns></returns>
  119. public ActionResult Standard(QueryParamsModel pararms)
  120. {
  121. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  122. var standardName = pararms.getExtraString("DictionaryStandard");
  123. return base.Json(SpecialtyServices.GetStandardViewGrid(configuretView, standardName, (int)pararms.page, (int)pararms.rows));
  124. }
  125. /// <summary>
  126. /// 查询专业信息中学制信息
  127. /// </summary>
  128. /// <param name="pararms"></param>
  129. /// <returns></returns>
  130. public ActionResult LearnSystem(QueryParamsModel pararms)
  131. {
  132. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  133. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  134. return base.Json(SpecialtyServices.GetLearnSystemViewGrid(configuretView, learnSystem, (int)pararms.page, (int)pararms.rows));
  135. }
  136. /// <summary>
  137. /// 复制新增
  138. /// </summary>
  139. /// <param name="specialtyID"></param>
  140. /// <returns></returns>
  141. public ActionResult CopyAdd(Guid specialtyID)
  142. {
  143. SpecialtyView specialtyView = new SpecialtyView();
  144. specialtyView = SpecialtyServices.GetSpecialtyView(specialtyID);
  145. return View("Edit", specialtyView);
  146. }
  147. /// <summary>
  148. /// 复制新增
  149. /// </summary>
  150. /// <param name="specialtyView"></param>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public ActionResult CopyAdd(SpecialtyView specialtyView)
  154. {
  155. specialtyView.SpecialtyID = Guid.Empty;
  156. return this.Edit(specialtyView);
  157. }
  158. /// <summary>
  159. /// 编辑(新增、修改,业务主键:专业ID、培养层次、学习形式、学制)
  160. /// </summary>
  161. /// <param name="specialtyID"></param>
  162. /// <returns></returns>
  163. [HttpGet]
  164. public ActionResult Edit(Guid? specialtyID)
  165. {
  166. SpecialtyView specialtyView = new SpecialtyView();
  167. if (specialtyID.HasValue && specialtyID != Guid.Empty)
  168. {
  169. specialtyView = SpecialtyServices.GetSpecialtyView(specialtyID);
  170. }
  171. else
  172. {
  173. specialtyView.RecordStatus = (int)SYS_STATUS.USABLE;
  174. }
  175. return View(specialtyView);
  176. }
  177. /// <summary>
  178. /// 编辑(新增、修改,业务主键:专业ID、培养层次、学习形式、学制)
  179. /// </summary>
  180. /// <param name="specialtyView"></param>
  181. /// <returns></returns>
  182. [HttpPost]
  183. public ActionResult Edit(SpecialtyView specialtyView)
  184. {
  185. try
  186. {
  187. SpecialtyServices.SpecialtyEdit(specialtyView);
  188. return Json(new ReturnMessage()
  189. {
  190. IsSuccess = true,
  191. Message = "保存成功。"
  192. });
  193. }
  194. catch (Exception ex)
  195. {
  196. return Json(new ReturnMessage()
  197. {
  198. IsSuccess = false,
  199. Message = "保存失败,原因:" + ex.Message
  200. });
  201. }
  202. }
  203. /// <summary>
  204. /// 删除
  205. /// </summary>
  206. /// <param name="specialtyIDs"></param>
  207. /// <returns></returns>
  208. [HttpPost]
  209. public ActionResult Delete(string specialtyIDs)
  210. {
  211. try
  212. {
  213. List<Guid?> list = specialtyIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  214. SpecialtyServices.SpecialtyDelete(list);
  215. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  216. }
  217. catch (Exception ex)
  218. {
  219. string mge = ex.Message;
  220. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  221. if (num != null)
  222. {
  223. if (num.Number == 547)
  224. {
  225. mge = "请先删除所有关联的数据,如:招生专业、专业班级等。";
  226. }
  227. }
  228. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  229. }
  230. }
  231. /// <summary>
  232. /// Excel导入
  233. /// </summary>
  234. /// <param name="errorFile"></param>
  235. /// <param name="operationTips"></param>
  236. /// <returns></returns>
  237. [HttpGet]
  238. public ActionResult Import(string errorFile, string operationTips)
  239. {
  240. ViewBag.ErrorFile = errorFile;
  241. if (string.IsNullOrEmpty(operationTips))
  242. {
  243. operationTips = "点击查看失败原因...";
  244. }
  245. ViewBag.operationTips = operationTips;
  246. return View();
  247. }
  248. /// <summary>
  249. /// Excel导入
  250. /// </summary>
  251. /// <param name="file"></param>
  252. /// <returns></returns>
  253. [HttpPost]
  254. public ActionResult Import(HttpPostedFileBase file)
  255. {
  256. try
  257. {
  258. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  259. {
  260. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  261. }
  262. Dictionary<string, string> cellheader = new Dictionary<string, string>
  263. {
  264. { "StandardCode", "专业代码" },
  265. { "StandardName", "专业名称" },
  266. { "EducationStr", RSL.Get("EducationID") },
  267. { "LearningformStr", "学习形式" },
  268. { "LearnSystemStr", "学制" },
  269. { "ScienceclassStr", "专业科类" },
  270. { "PropertyStr", "专业属性" },
  271. { "StandardTitleStr", "专业称号" },
  272. { "StandardLevelStr", "称号级别" },
  273. { "Remark", "备注" },
  274. { "ErrorMessage", "未导入原因" }
  275. };
  276. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  277. string sourceWebPath = FileUploadHelper.UploadFile(file);
  278. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  279. List<SpecialtyView> errList = new List<SpecialtyView>();
  280. List<SpecialtyView> dataList = new List<SpecialtyView>();
  281. int? inCount = 0; //导入个数
  282. int? upCount = 0; //更新个数
  283. int? errCount = 0; //失败个数
  284. //导入
  285. SpecialtyServices.SpecialtyImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  286. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  287. if (errList.Count() > 0)
  288. {
  289. //获取错误数据文件路径
  290. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "专业信息导入失败文件", sourcePhysicalPath));
  291. ViewBag.ErrorFile = errorWebPath;
  292. string Errinfo = string.Format("提示:{0}条专业信息导入成功,{1}条专业信息更新成功,{2}条专业信息导入失败,点击查看。", inCount, upCount, errCount);
  293. ViewBag.operationTips = Errinfo;
  294. return RedirectToAction("MsgShow", "Common", new
  295. {
  296. WindowID = "none",
  297. msg = Errinfo,
  298. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  299. });
  300. }
  301. else
  302. {
  303. string successInfo = string.Format("提示:{0}条专业信息导入成功,{1}条专业信息更新成功。", inCount, upCount);
  304. return RedirectToAction("MsgShow", "Common", new
  305. {
  306. WindowID = Request["WindowID"],
  307. msg = successInfo,
  308. url = Url.Action("List").AddMenuParameter()
  309. });
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. return RedirectToAction("MsgShow", "Common", new
  315. {
  316. WindowID = "none",
  317. msg = "导入失败,原因:" + ex.Message,
  318. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  319. });
  320. }
  321. }
  322. /// <summary>
  323. /// Excel导出
  324. /// </summary>
  325. /// <param name="pararms"></param>
  326. /// <returns></returns>
  327. [HttpPost]
  328. public ActionResult Excel()
  329. {
  330. try
  331. {
  332. NpoiExcelHelper neh = new NpoiExcelHelper();
  333. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  334. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  335. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  336. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  337. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  338. var scienceclassID = Request.Form["DictionaryScienceclass"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryScienceclass"].ParseStrTo<int>();
  339. var propertyID = Request.Form["DictionaryProperty"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryProperty"].ParseStrTo<int>();
  340. var recordStatus = Request.Form["DictionaryRecordStatus"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryRecordStatus"].ParseStrTo<int>();
  341. var dt = SpecialtyServices.GetSpecialtyViewList(configuretView, standardID, educationID, learningformID,
  342. learnSystem, scienceclassID, propertyID, recordStatus)
  343. .Select(x => new
  344. {
  345. x.Code,
  346. x.StandardID,
  347. x.Name,
  348. x.EducationName,
  349. x.LearningformName,
  350. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  351. x.ScienceclassName,
  352. x.PropertyName,
  353. x.StandardTitleName,
  354. x.StandardLevelName,
  355. x.RecordStatusStr,
  356. x.Remark
  357. }).ToTable();
  358. string[] liststring = {
  359. "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"), "学习形式", "学制", "专业科类", "专业属性",
  360. "专业称号", "称号级别", "启用状态", "备注"
  361. };
  362. neh.Export(dt, liststring, "专业信息" + DateTime.Now.ToString("yyyyMMdd"));
  363. return Json(new ReturnMessage()
  364. {
  365. IsSuccess = true,
  366. Message = "导出成功。"
  367. });
  368. }
  369. catch (Exception ex)
  370. {
  371. return Json(new ReturnMessage()
  372. {
  373. IsSuccess = false,
  374. Message = "导出失败,原因:" + ex.Message
  375. });
  376. }
  377. }
  378. }
  379. }