SpecialtyController.cs 15 KB

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