EducationMissionClassScheduleAdultController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.CalendarManage;
  7. using EMIS.CommonLogic.EducationSchedule;
  8. using EMIS.ViewModel;
  9. using EMIS.Web.Controls;
  10. using Bowin.Web.Controls.Mvc;
  11. using Bowin.Common.Utility;
  12. using System.Text;
  13. using EMIS.Utility;
  14. using Bowin.Common.Data;
  15. using EMIS.ViewModel.EducationManagement;
  16. using EMIS.ViewModel.EducationManage;
  17. using Bowin.Common.Exceptions;
  18. namespace EMIS.Web.Controllers.EducationSchedule
  19. {
  20. [Authorization]
  21. public class EducationMissionClassScheduleAdultController : Controller
  22. {
  23. //
  24. // GET: /EducationMissionClassScheduleAdult/
  25. public ISchoolYearServices SchoolYearServices { get; set; }
  26. public IEducationMissionClassScheduleAdultServices IEducationMissionClassScheduleAdultServices { get; set; }
  27. public ActionResult List()
  28. {
  29. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  30. ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
  31. return View();
  32. }
  33. #region 查询任务班排课列表
  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 schoolyearID = pararms.getExtraGuid("SchoolyearDropdownList");
  44. var coursematerialID = pararms.getExtraGuid("CoursematerialComboGrid");
  45. var campusID = pararms.getExtraGuid("ComboGridCampus");
  46. var collegeID = pararms.getExtraGuid("ComboGridCollege");
  47. var StandardID = pararms.getExtraInt("DictionaryStandard");
  48. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  49. var grademajorID = pararms.getExtraGuid("GrademajorComboGrid");
  50. var gradeYearID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
  51. var approvalStatus = pararms.getExtraInt("ApprovalStatusDropdownList") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ApprovalStatusDropdownList");
  52. var teachingMode = pararms.getExtraInt("DictionaryTeachingMode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeachingMode");
  53. var CoursesTimeID = pararms.getExtraGuid("TimeComboGrid");
  54. var learningformID = pararms.getExtraInt("LearningformDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("LearningformDictionaryDropDown");
  55. var education = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
  56. var LearnSystem = pararms.getExtraString("DictionaryLearnSystem");
  57. var result = IEducationMissionClassScheduleAdultServices.GetEducationMissionClassScheduleViewGrid(configuretView, campusID, collegeID, schoolyearID, departmentID, coursematerialID, approvalStatus, teachingMode, grademajorID, gradeYearID, StandardID, CoursesTimeID,learningformID,education,LearnSystem, (int)pararms.page, (int)pararms.rows);
  58. return Json(result);
  59. }
  60. #endregion
  61. [HttpPost]
  62. public ActionResult Delete(string educationMissionClassIDs)
  63. {
  64. try
  65. {
  66. List<Guid?> list = new List<Guid?>();
  67. var educationMissionClassArray = educationMissionClassIDs.Split(',');
  68. for (int i = 0; i < educationMissionClassArray.Length; i++)
  69. {
  70. if (!string.IsNullOrEmpty(educationMissionClassArray[i]))
  71. {
  72. Guid? educationMissionClassID = new Guid(educationMissionClassArray[i]);
  73. list.Add(educationMissionClassID);
  74. }
  75. }
  76. IEducationMissionClassScheduleAdultServices.EducationMissionClassScheduleDelete(list);
  77. return Json(new ReturnMessage { IsSuccess = true });
  78. }
  79. catch (Exception ex)
  80. {
  81. string mge = ex.Message;
  82. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  83. if (num != null)
  84. {
  85. if (num.Number == 547)
  86. mge = "请先删除所有关联的数据,排课课表,学生成绩,教学评价等";
  87. }
  88. return Json(new ReturnMessage { IsSuccess = false, Message = "删除失败:" + mge });
  89. }
  90. }
  91. [HttpGet]
  92. public ActionResult Import(string errorFile, string operationTips)
  93. {
  94. ViewBag.ErrorFile = errorFile;
  95. var schoolYearView = SchoolYearServices.GetSchoolYearIsCurrent(true);
  96. var schoolyear = SchoolYearServices.GetSchoolYearViewListAfterCurrent().OrderBy(x => x.Code).Where(x => x.Value > schoolYearView.Value).FirstOrDefault();
  97. EducationMissionImportClassView classView = new EducationMissionImportClassView();
  98. if (schoolyear != null)
  99. {
  100. classView.SchoolyearID = schoolyear.SchoolYearID;
  101. }
  102. else
  103. {
  104. classView.SchoolyearID = schoolYearView.SchoolyearID;
  105. }
  106. if (string.IsNullOrEmpty(operationTips))
  107. {
  108. operationTips = "错误数据下载";
  109. }
  110. ViewBag.operationTips = operationTips;
  111. return View(classView);
  112. }
  113. #region 导入
  114. [HttpPost]
  115. public ActionResult Import(HttpPostedFileBase file,EducationMissionClassView classView)
  116. {
  117. try
  118. {
  119. Guid schoolyearID = (Guid)classView.SchoolyearID;
  120. //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
  121. //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
  122. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  123. {
  124. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  125. }
  126. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  127. string sourceWebPath = FileUploadHelper.UploadFile(file);
  128. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  129. List<EducationMissionImportClassView> errList = new List<EducationMissionImportClassView>();
  130. int errCount = 0;//失败条数
  131. int OkCount = 0;//成功条数
  132. string errorWebPath = "";
  133. string Errinfo = "";
  134. IEducationMissionClassScheduleAdultServices.EducationMissionClassImport(out errCount, out errList, out OkCount, sourcePhysicalPath, sourceWebPath, out errorWebPath, out Errinfo,schoolyearID);
  135. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  136. if (errCount > 0)
  137. {
  138. ViewBag.ErrorFile = errorWebPath;
  139. ViewBag.operationTips = Errinfo;
  140. return RedirectToAction("MsgShow", "Common", new
  141. {
  142. WindowID = "none",
  143. msg = "导入失败!",
  144. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  145. });
  146. }
  147. else
  148. {
  149. return RedirectToAction("MsgShow", "Common", new
  150. {
  151. WindowID = Request["WindowID"],
  152. msg = "导入成功!",
  153. url = Url.Action("List").AddMenuParameter()
  154. });
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. return RedirectToAction("MsgShow", "Common", new
  160. {
  161. WindowID = Request["WindowID"],
  162. msg = "导入失败,原因:" + ex.Message + "!",
  163. url = Url.Action("List").AddMenuParameter()
  164. });
  165. }
  166. }
  167. #endregion
  168. #region 2.0 Excel导出
  169. /// <summary>
  170. /// 导出Excel
  171. /// </summary>
  172. /// <param name="pararms"></param>
  173. /// <returns></returns>
  174. [HttpPost]
  175. public ActionResult Excel()
  176. {
  177. NpoiExcelHelper neh = new NpoiExcelHelper();
  178. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  179. var EducationMissionClassID = Request.Form["EducationMissionClassID"];
  180. var campusID = Request.Form["ComboGridCampus"].ParseStrTo<Guid>();
  181. var collegeID = Request.Form["ComboGridCollege"].ParseStrTo<Guid>();
  182. var coursematerialID = Request.Form["CoursematerialComboGrid"].ParseStrTo<Guid>();
  183. var grademajorID = Request.Form["GrademajorComboGrid"].ParseStrTo<Guid>();
  184. var gradeYearID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  185. var schoolyearID = Request.Form["SchoolyearDropdownList"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolyearDropdownList"].ParseStrTo<Guid>();
  186. var approvalStatus = Request.Form["ApprovalStatusDropdownList"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ApprovalStatusDropdownList"].ParseStrTo<int>();
  187. var teachingModeID = Request.Form["DictionaryTeachingMode"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryTeachingMode"].ParseStrTo<int>();
  188. var StandardID = Request.Form["DictionaryStandard"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo<int>();
  189. var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
  190. List<Guid?> EducationMissionClassList =new List<Guid?>();
  191. var CoursesTimeID = Request.Form["TimeComboGrid"].ParseStrTo<Guid>();
  192. var learningformID = Request.Form["LearningformDictionaryDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["LearningformDictionaryDropDown"].ParseStrTo<int>();
  193. var education = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
  194. var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString();
  195. if (EducationMissionClassID != "")
  196. {
  197. EducationMissionClassList = EducationMissionClassID.SplitIDString();
  198. }
  199. else
  200. {
  201. EducationMissionClassList = null;
  202. }
  203. var dt = IEducationMissionClassScheduleAdultServices.GetEducationMissionClassScheduleViewGridExcel(configuretView, campusID, collegeID, schoolyearID, departmentID, coursematerialID, approvalStatus, teachingModeID, grademajorID, gradeYearID, StandardID, EducationMissionClassList, CoursesTimeID, learningformID, education, LearnSystem).Select(x => new
  204. {
  205. x.CollegeName,
  206. x.EducationName,
  207. x.LearningformName,
  208. x.ClassNum,
  209. x.Name,
  210. x.CourseName,
  211. x.Totalhours,
  212. x.ExamDay,
  213. x.date,
  214. x.showClassRoom,
  215. x.TeacherNames,
  216. x.ExaminationModeName,
  217. x.ExamWeekShow,
  218. x.Examedate_time,
  219. x.Assistant,
  220. x.StandardName,
  221. x.CourseCode,
  222. courseTimeShow = x.CourseTimeShow,
  223. x.TheoryCourse,
  224. x.Practicehours,
  225. teachingDay = x.TeachingDay,
  226. teachingHours = x.TeachingHours
  227. }).ToTable();
  228. string[] liststring = { RSL.Get("College"), RSL.Get("CultureModel"),"学习形式","班级人数", "任务班名称",
  229. "课程名称", "总学时","参考天数","上课时间","课室",
  230. "授课教师", "考试方式","考试周次","考试时间",
  231. "班主任","年级专业","课程代码","课时类别", "理论学时" ,
  232. "实践学时", "执行天数","执行学时"};
  233. neh.Export(dt, liststring, "教学任务班基础信息");
  234. return Json(new ReturnMessage()
  235. {
  236. IsSuccess = true,
  237. Message = "导出成功!"
  238. });
  239. }
  240. #endregion
  241. }
  242. }