MinorSpecialtyCourseController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.MinorManage;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.ViewModel.MinorManage.MinorCourseManage;
  11. using Bowin.Common.Exceptions;
  12. using Bowin.Common.Utility;
  13. using EMIS.Utility;
  14. using Bowin.Common.Data;
  15. namespace EMIS.Web.Controllers.MinorManage
  16. {
  17. [Authorization]
  18. public class MinorSpecialtyCourseController : Controller
  19. {
  20. public IMinorSpecialtyCourseServices minorSpecialtyCourseServices { get; set; }
  21. //
  22. // GET: /MinorCourse/
  23. public ActionResult List()
  24. {
  25. return View();
  26. }
  27. [HttpPost]
  28. public ActionResult List(QueryParamsModel pararms)
  29. {
  30. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  31. var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
  32. var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo");
  33. var startYearID = pararms.getExtraInt("DictionarySchoolYearNum") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolYearNum");
  34. var schoolcodeID = pararms.getExtraInt("DictionarySchoolcode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolcode");
  35. var isEnable = pararms.getExtraInt("DictionaryIsEnable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEnable");
  36. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  37. return this.Json(minorSpecialtyCourseServices.GetMinorSpecialtyCourseViewGrid(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, (int)pararms.page, (int)pararms.rows));
  38. }
  39. /// <summary>
  40. /// 复制新增
  41. /// </summary>
  42. /// <param name="sourceMinorCourseID"></param>
  43. /// <returns></returns>
  44. public ActionResult CopyAdd(Guid sourceMinorCourseID)
  45. {
  46. MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
  47. minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(sourceMinorCourseID);
  48. minorSpecialtyCourseView.MinorCourseID = null;
  49. return View("Edit", minorSpecialtyCourseView);
  50. }
  51. [HttpPost]
  52. public ActionResult CopyAdd(MinorSpecialtyCourseView minorSpecialtyCourseView)
  53. {
  54. return this.Edit(minorSpecialtyCourseView);
  55. }
  56. /// <summary>
  57. /// 编辑
  58. /// </summary>
  59. /// <param name="MinorCourseID"></param>
  60. /// <returns></returns>
  61. public ActionResult Edit(Guid? MinorCourseID)
  62. {
  63. MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
  64. if (MinorCourseID.HasValue)
  65. {
  66. minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(MinorCourseID);
  67. }
  68. else
  69. {
  70. minorSpecialtyCourseView.ResultTypeID = (int)CF_ResultType.Percentage;
  71. minorSpecialtyCourseView.Credit = 0;
  72. minorSpecialtyCourseView.TheoryCourse = 0;
  73. minorSpecialtyCourseView.Practicehours = 0;
  74. minorSpecialtyCourseView.Trialhours = 0;
  75. minorSpecialtyCourseView.Totalhours = 0;
  76. minorSpecialtyCourseView.TheoryWeeklyNum = 0;
  77. minorSpecialtyCourseView.PracticeWeeklyNum = 0;
  78. minorSpecialtyCourseView.TrialWeeklyNum = 0;
  79. minorSpecialtyCourseView.SchoolweeksNum = 0;
  80. minorSpecialtyCourseView.WeeklyHours = 0;
  81. minorSpecialtyCourseView.WeeklyNum = 0;
  82. minorSpecialtyCourseView.IsEnable = true;
  83. }
  84. return View(minorSpecialtyCourseView);
  85. }
  86. /// <summary>
  87. /// 编辑
  88. /// </summary>
  89. /// <param name="minorSpecialtyCourseView"></param>
  90. /// <returns></returns>
  91. [HttpPost]
  92. public ActionResult Edit(MinorSpecialtyCourseView minorSpecialtyCourseView)
  93. {
  94. try
  95. {
  96. minorSpecialtyCourseServices.MinorSpecialtyCourseAdd(minorSpecialtyCourseView);
  97. return Json(new ReturnMessage()
  98. {
  99. IsSuccess = true,
  100. Message = "保存成功。"
  101. });
  102. }
  103. catch (Exception ex)
  104. {
  105. return Json(new ReturnMessage()
  106. {
  107. IsSuccess = false,
  108. Message = "保存失败:" + ex.Message
  109. });
  110. }
  111. }
  112. /// <summary>
  113. /// 获取已经存在在授课方式
  114. /// </summary>
  115. /// <param name="MinorCourseID"></param>
  116. /// <returns></returns>
  117. [HttpPost]
  118. public ActionResult TeachingModeType(Guid? MinorCourseID)
  119. {
  120. List<string> list = new List<string>();
  121. if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
  122. list = minorSpecialtyCourseServices.GetTeachingModeType(MinorCourseID);
  123. else
  124. list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory).ToString());
  125. return base.Json(list);
  126. }
  127. /// <summary>
  128. /// 获取已经存在在授课地点
  129. /// </summary>
  130. /// <param name="MinorCourseID"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public ActionResult TeachingPlace(Guid? MinorCourseID)
  134. {
  135. List<string> list = new List<string>();
  136. if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
  137. list = minorSpecialtyCourseServices.GetTeachingPlace(MinorCourseID);
  138. return base.Json(list);
  139. }
  140. /// <summary>
  141. /// 删除
  142. /// </summary>
  143. /// <param name="MinorCourseIDs"></param>
  144. /// <returns></returns>
  145. [HttpPost]
  146. public ActionResult Delete(string MinorCourseIDs)
  147. {
  148. try
  149. {
  150. List<Guid?> list = new List<Guid?>();
  151. for (int i = 0; i < MinorCourseIDs.Split(',').Length; i++)
  152. {
  153. string id = MinorCourseIDs.Split(',')[i];
  154. if (!string.IsNullOrEmpty(id))
  155. {
  156. Guid MinorCourseID = new Guid(id);
  157. list.Add(MinorCourseID);
  158. }
  159. }
  160. minorSpecialtyCourseServices.MinorCourseDelete(list);
  161. return base.Json("删除成功");
  162. }
  163. catch (Exception ex)
  164. {
  165. string mge = ex.Message;
  166. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  167. if (num != null)
  168. {
  169. if (num.Number == 547)
  170. mge = "请先删除所有关联的数据,如:计划申请、专业计划、选修计划等!";
  171. }
  172. return base.Json("删除失败,原因:" + mge);
  173. }
  174. }
  175. /// <summary>
  176. /// 导出Excel
  177. /// </summary>
  178. /// <returns></returns>
  179. [HttpPost]
  180. public ActionResult Excel()
  181. {
  182. NpoiExcelHelper neh = new NpoiExcelHelper();
  183. var MinorCourseID = Request.Form["MinorCourseID"];
  184. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  185. var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["StandardDictionaryDropDown"].ParseStrTo<int>();
  186. var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo<Guid>();
  187. var startYearID = Request.Form["DictionarySchoolYearNum"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolYearNum"].ParseStrTo<int>();
  188. var schoolcodeID = Request.Form["DictionarySchoolcode"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolcode"].ParseStrTo<int>();
  189. var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo<int>();
  190. var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
  191. List<Guid?> MinorCourseIDList = new List<Guid?>();
  192. if (MinorCourseID != "")
  193. {
  194. MinorCourseIDList = MinorCourseID.SplitIDString();
  195. }
  196. else
  197. {
  198. MinorCourseIDList = null;
  199. }
  200. var dt = minorSpecialtyCourseServices.GetMinorCourseViewList(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, MinorCourseIDList).Select(x => new
  201. {
  202. x.SpecialtyCode,
  203. x.StandardName,
  204. x.CourseCode,
  205. x.CourseName,
  206. x.CourseTypeName,
  207. x.Credit,
  208. x.TheoryCourse,
  209. x.Practicehours,
  210. x.Trialhours,
  211. x.Totalhours,
  212. x.SchoolyearNumName,
  213. x.SchoolcodeName,
  214. x.DepartmentName,
  215. x.IsEnableName
  216. }).ToTable();
  217. string[] liststring = { "专业代码", "专业名称", "课程代码", "课程名称", "课程类型","学分",
  218. "理论学时","实践学时","实验学时","总学时","开课学年","开课学期","开课教研室","是否启用"};
  219. neh.Export(dt, liststring, "辅修课程信息");
  220. return Json(new ReturnMessage()
  221. {
  222. IsSuccess = true,
  223. Message = "导出成功。"
  224. });
  225. }
  226. #region 辅修课程信息导入
  227. [HttpGet]
  228. public ActionResult Import(string errorFile, string operationTips)
  229. {
  230. ViewBag.ErrorFile = errorFile;
  231. if (string.IsNullOrEmpty(operationTips))
  232. {
  233. operationTips = "错误数据下载";
  234. }
  235. ViewBag.operationTips = operationTips;
  236. return View();
  237. }
  238. [HttpPost]
  239. public ActionResult Import(HttpPostedFileBase file)
  240. {
  241. try
  242. {
  243. //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
  244. //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
  245. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  246. {
  247. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  248. }
  249. #region 构建单元头
  250. Dictionary<string, string> cellheader = new Dictionary<string, string>
  251. {
  252. { "SpecialtyCodeStr", "专业代码" },
  253. { "StandardNameStr", "专业名称" },
  254. {"CourseCode","课程代码"}, { "CourseName", "课程名称" },
  255. { "DepartmentName", "教研室" }, { "SchoolyearNumNameStr", "授课年级" },
  256. { "SchoolcodeStr", "学期" }, { "CourseTypeStr", "课程类型" },
  257. { "CourseCategoryNameStr", "课程属性" }, { "CourseQualityNameStr", "课程性质" },
  258. { "CourseStructureNameStr", "课程结构" }, { "CreditStr", "学分" },
  259. { "TheoryCourseStr", "理论学时" }, { "PracticehoursStr", "实践学时" },
  260. { "TrialhoursStr", "实验学时" }, { "PracticeTypeNameStr", "实践方式" },
  261. { "ExaminationModeNameStr", "考试方式" },{ "ResultTypeNameStr", "成绩类型" },
  262. { "IsSpecialtycoreName", "是否专业核心" },{ "IsCooperationName", "是否校企开发" },
  263. { "IsRequiredName", "是否课证融通" },/*是否必修课*/{ "IsMainCourseName", "是否学位主干" },
  264. { "IsElectiveName", "是否选修" },{ "IsNetworkCourseName", "是否网络" },
  265. { "CourseFineNameStr", "精品课程" },{ "TeachinglanguageNameStr", "授课语言" },
  266. { "TeachingModeStr", "授课方式" },{ "TeachingPlaceStr", "授课地点" },
  267. { "Remarks", "备注" }, { "ErrorMessage", "错误信息" }
  268. };
  269. #endregion
  270. string sourceWebPath = FileUploadHelper.UploadFile(file);
  271. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  272. List<MinorSpecialtyCourseView> errList = new List<MinorSpecialtyCourseView>();
  273. int errCount = 0;
  274. int OkCount = 0;
  275. minorSpecialtyCourseServices.MinorSpecialtyCourseImport(cellheader, out OkCount, out errList, out errCount, sourcePhysicalPath);
  276. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  277. if (errList.Count() > 0)
  278. {
  279. //将异常文件路径显示
  280. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, " 专业课程导入失败文件", sourcePhysicalPath));
  281. ViewBag.ErrorFile = errorWebPath;
  282. string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount);
  283. ViewBag.operationTips = Errinfo;
  284. //return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo });
  285. return RedirectToAction("MsgShow", "Common", new
  286. {
  287. WindowID = "none",
  288. msg = "导入失败!",
  289. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  290. });
  291. }
  292. else
  293. {
  294. return RedirectToAction("MsgShow", "Common", new
  295. {
  296. WindowID = Request["WindowID"],
  297. msg = "导入成功!",
  298. url = Url.Action("List").AddMenuParameter()
  299. });
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. return RedirectToAction("MsgShow", "Common", new
  305. {
  306. WindowID = Request["WindowID"],
  307. msg = "导入失败,原因:" + ex.Message + "!",
  308. url = Url.Action("List").AddMenuParameter()
  309. });
  310. }
  311. }
  312. #endregion
  313. }
  314. }