CustomStandardSettingController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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.Utility;
  8. using Bowin.Common.Data;
  9. using Bowin.Common.Linq;
  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 CustomStandardSettingController : Controller
  20. {
  21. public ICustomStandardSettingServices CustomStandardSettingServices { 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 campusID = pararms.getExtraGuid("CampusDropdown");
  40. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  41. var yearID = pararms.getExtraInt("DictionaryYear") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryYear");
  42. var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
  43. var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  44. var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
  45. var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
  46. var semesterID = pararms.getExtraInt("DictionarySemester") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySemester");
  47. return base.Json(CustomStandardSettingServices.GetCustomStandardSettingViewGrid(configuretView, campusID, collegeID, yearID, standardID, educationID, learningformID, learnSystem, semesterID, (int)pararms.page, (int)pararms.rows));
  48. }
  49. /// <summary>
  50. /// 复制新增
  51. /// </summary>
  52. /// <param name="customStandardSettingID"></param>
  53. /// <returns></returns>
  54. public ActionResult CopyAdd(Guid customStandardSettingID)
  55. {
  56. CustomStandardSettingView customStandardSettingView = new CustomStandardSettingView();
  57. customStandardSettingView = CustomStandardSettingServices.GetCustomStandardSettingView(customStandardSettingID);
  58. return View("Edit", customStandardSettingView);
  59. }
  60. /// <summary>
  61. /// 复制新增
  62. /// </summary>
  63. /// <param name="customStandardSettingView"></param>
  64. /// <returns></returns>
  65. [HttpPost]
  66. public ActionResult CopyAdd(CustomStandardSettingView customStandardSettingView)
  67. {
  68. customStandardSettingView.CustomStandardSettingID = Guid.Empty;
  69. return this.Edit(customStandardSettingView);
  70. }
  71. /// <summary>
  72. /// 编辑(新增、修改,业务主键:省招代码或学年、学期、院系所、专业信息ID唯一)
  73. /// </summary>
  74. /// <param name="customStandardSettingID"></param>
  75. /// <returns></returns>
  76. [HttpGet]
  77. public ActionResult Edit(Guid? customStandardSettingID)
  78. {
  79. CustomStandardSettingView customStandardSettingView = new CustomStandardSettingView();
  80. if (customStandardSettingID.HasValue && customStandardSettingID != Guid.Empty)
  81. {
  82. customStandardSettingView = CustomStandardSettingServices.GetCustomStandardSettingView(customStandardSettingID);
  83. }
  84. else
  85. {
  86. customStandardSettingView.YearID = BaseExtensions.GetNextYearID();
  87. customStandardSettingView.SemesterID = BaseExtensions.GetEntranceSemesterID();
  88. }
  89. return View(customStandardSettingView);
  90. }
  91. /// <summary>
  92. /// 编辑(新增、修改,业务主键:省招代码或学年、学期、院系所、专业信息ID唯一)
  93. /// </summary>
  94. /// <param name="customStandardSettingView"></param>
  95. /// <returns></returns>
  96. [HttpPost]
  97. public ActionResult Edit(CustomStandardSettingView customStandardSettingView)
  98. {
  99. try
  100. {
  101. CustomStandardSettingServices.CustomStandardSettingEdit(customStandardSettingView);
  102. return Json(new ReturnMessage()
  103. {
  104. IsSuccess = true,
  105. Message = "保存成功。"
  106. });
  107. }
  108. catch (Exception ex)
  109. {
  110. return Json(new ReturnMessage()
  111. {
  112. IsSuccess = false,
  113. Message = "保存失败,原因:" + ex.Message
  114. });
  115. }
  116. }
  117. /// <summary>
  118. /// 删除
  119. /// </summary>
  120. /// <param name="customStandardSettingIDs"></param>
  121. /// <returns></returns>
  122. [HttpPost]
  123. public ActionResult Delete(string customStandardSettingIDs)
  124. {
  125. try
  126. {
  127. List<Guid?> list = customStandardSettingIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  128. CustomStandardSettingServices.CustomStandardSettingDelete(list);
  129. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  130. }
  131. catch (Exception ex)
  132. {
  133. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + ex.Message });
  134. }
  135. }
  136. /// <summary>
  137. /// Excel导入
  138. /// </summary>
  139. /// <param name="errorFile"></param>
  140. /// <param name="operationTips"></param>
  141. /// <returns></returns>
  142. [HttpGet]
  143. public ActionResult Import(string errorFile, string operationTips)
  144. {
  145. ViewBag.ErrorFile = errorFile;
  146. if (string.IsNullOrEmpty(operationTips))
  147. {
  148. operationTips = "点击查看失败原因...";
  149. }
  150. ViewBag.operationTips = operationTips;
  151. return View();
  152. }
  153. /// <summary>
  154. /// Excel导入
  155. /// </summary>
  156. /// <param name="file"></param>
  157. /// <returns></returns>
  158. [HttpPost]
  159. public ActionResult Import(HttpPostedFileBase file)
  160. {
  161. try
  162. {
  163. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  164. {
  165. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  166. }
  167. Dictionary<string, string> cellheader = new Dictionary<string, string>
  168. {
  169. { "Code", "省招代码" },
  170. { "YearStr", "学年" },
  171. { "SemesterStr", "学期" },
  172. { "CollegeCode", RSL.Get("CollegeCode") },
  173. { "StandardCodeStr", "专业代码" },
  174. { "StandardNameStr", "专业名称" },
  175. { "EducationStr", RSL.Get("EducationID") },
  176. { "LearningformStr", "学习形式" },
  177. { "LearnSystemStr", "学制" },
  178. { "Remark", "备注" },
  179. { "ErrorMessage", "未导入原因" }
  180. };
  181. StringBuilder errorMsg = new StringBuilder();
  182. string sourceWebPath = FileUploadHelper.UploadFile(file);
  183. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  184. List<CustomStandardSettingView> errList = new List<CustomStandardSettingView>();
  185. List<CustomStandardSettingView> dataList = new List<CustomStandardSettingView>();
  186. int? inCount = 0; //导入个数
  187. int? upCount = 0; //更新个数
  188. int? errCount = 0; //失败个数
  189. //导入
  190. CustomStandardSettingServices.CustomStandardSettingImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  191. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  192. if (errList.Count() > 0)
  193. {
  194. //获取错误数据文件路径
  195. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "省招专业导入失败文件", sourcePhysicalPath));
  196. ViewBag.ErrorFile = errorWebPath;
  197. string Errinfo = string.Format("提示:{0}条省招专业导入成功,{1}条省招专业更新成功,{2}条省招专业导入失败,点击查看。", inCount, upCount, errCount);
  198. ViewBag.operationTips = Errinfo;
  199. return RedirectToAction("MsgShow", "Common", new
  200. {
  201. WindowID = "none",
  202. msg = Errinfo,
  203. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips="
  204. + Errinfo + "&WindowID=" + Request["WindowID"]
  205. });
  206. }
  207. else
  208. {
  209. string successInfo = string.Format("提示:{0}条省招专业导入成功,{1}条省招专业更新成功。", inCount, upCount);
  210. return RedirectToAction("MsgShow", "Common", new
  211. {
  212. WindowID = Request["WindowID"],
  213. msg = successInfo,
  214. url = Url.Action("List").AddMenuParameter()
  215. });
  216. }
  217. }
  218. catch (Exception ex)
  219. {
  220. return RedirectToAction("MsgShow", "Common", new
  221. {
  222. WindowID = "none",
  223. msg = "导入失败,原因:" + ex.Message,
  224. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  225. });
  226. }
  227. }
  228. /// <summary>
  229. /// Excel导出
  230. /// </summary>
  231. /// <returns></returns>
  232. [HttpPost]
  233. public ActionResult Excel()
  234. {
  235. NpoiExcelHelper neh = new NpoiExcelHelper();
  236. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  237. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  238. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  239. var yearID = Request.Form["DictionaryYear"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryYear"].ParseStrTo<int>();
  240. var standardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  241. var educationID = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  242. var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo<int>();
  243. var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  244. var semesterID = Request.Form["DictionarySemester"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySemester"].ParseStrTo<int>();
  245. var dt = CustomStandardSettingServices.GetCustomStandardSettingViewList(configuretView, campusID, collegeID, yearID, standardID, educationID, learningformID, learnSystem, semesterID)
  246. .Select(x => new
  247. {
  248. x.Code,
  249. x.Name,
  250. x.YearID,
  251. x.SemesterName,
  252. x.CollegeCode,
  253. x.CollegeName,
  254. x.CampusCode,
  255. x.CampusName,
  256. x.StandardCode,
  257. x.StandardID,
  258. x.StandardName,
  259. x.EducationName,
  260. x.LearningformName,
  261. LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
  262. x.Remark
  263. }).ToTable();
  264. string[] liststring = {
  265. "省招代码" ,"省招专业", "学年", "学期", RSL.Get("CollegeCode"), RSL.Get("CollegeName"), RSL.Get("CampusCode"),
  266. RSL.Get("CampusName"), "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"), "学习形式", "学制", "备注"
  267. };
  268. neh.Export(dt, liststring, "省招专业信息" + DateTime.Now.ToString("yyyyMMdd"));
  269. return Json(new ReturnMessage()
  270. {
  271. IsSuccess = true,
  272. Message = "导出成功。"
  273. });
  274. }
  275. }
  276. }