SchoolYearController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Web.Controls.Mvc;
  7. using EMIS.Utility;
  8. using EMIS.ViewModel;
  9. using EMIS.Web.Controls;
  10. using EMIS.CommonLogic.CalendarManage;
  11. using EMIS.ViewModel.CalendarManage;
  12. using EMIS.Entities;
  13. using Bowin.Common.Exceptions;
  14. using Bowin.Common.Utility;
  15. using Bowin.Common.Data;
  16. namespace EMIS.Web.Controllers.CalendarManage
  17. {
  18. [Authorization]
  19. public class SchoolYearController : Controller
  20. {
  21. public ISchoolYearServices SchoolYearServices { get; set; }
  22. public DictionaryHelper DictionaryHelper { get; set; }
  23. /// <summary>
  24. /// 学年学期页面
  25. /// </summary>
  26. /// <returns></returns>
  27. public ActionResult List()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 列表查询
  33. /// </summary>
  34. /// <param name="pararms"></param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. public ActionResult List(QueryParamsModel pararms)
  38. {
  39. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  40. var isCurrent = pararms.getExtraInt("IsCurrentDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsCurrentDropDown");
  41. return base.Json(SchoolYearServices.GetSchoolYearViewGrid(configuretView, isCurrent, (int)pararms.page, (int)pararms.rows));
  42. }
  43. /// <summary>
  44. /// 编辑页面
  45. /// </summary>
  46. /// <returns></returns>
  47. public ActionResult Edit(Guid? schoolyearID)
  48. {
  49. SchoolYearView schoolyearView = new SchoolYearView();
  50. if (schoolyearID != null && schoolyearID != Guid.Empty)
  51. schoolyearView = SchoolYearServices.GetSchoolYearView(schoolyearID);
  52. return View(schoolyearView);
  53. }
  54. /// <summary>
  55. /// 新增或更新
  56. /// </summary>
  57. /// <param name="schoolyearView"></param>
  58. /// <returns></returns>
  59. [HttpPost]
  60. public ActionResult Edit(SchoolYearView schoolyearView)
  61. {
  62. try
  63. {
  64. if (!schoolyearView.SchoolYearID.HasValue || schoolyearView.SchoolYearID == Guid.Empty)
  65. {
  66. SchoolYearServices.SchoolYearAdd(schoolyearView);
  67. }
  68. else
  69. {
  70. SchoolYearServices.SchoolYearUpdate(schoolyearView);
  71. }
  72. return Json(new ReturnMessage()
  73. {
  74. IsSuccess = true,
  75. Message = "保存成功!"
  76. });
  77. }
  78. catch (Exception ex)
  79. {
  80. return Json(new ReturnMessage()
  81. {
  82. IsSuccess = false,
  83. Message = "保存失败:" + ex.Message
  84. });
  85. }
  86. }
  87. /// <summary>
  88. /// 删除
  89. /// </summary>
  90. /// <param name="activitiesIDs"></param>
  91. /// <returns></returns>
  92. [HttpPost]
  93. public ActionResult Delete(string schoolyearIDs)
  94. {
  95. try
  96. {
  97. List<Guid> list = new List<Guid>();
  98. for (int i = 0; i < schoolyearIDs.Split(',').Length; i++)
  99. {
  100. string id = schoolyearIDs.Split(',')[i];
  101. if (!string.IsNullOrEmpty(id))
  102. {
  103. Guid schoolyearID = new Guid(id);
  104. list.Add(schoolyearID);
  105. }
  106. }
  107. SchoolYearServices.SchoolYearDelete(list);
  108. return base.Json("删除成功!");
  109. }
  110. catch (Exception ex)
  111. {
  112. string mge = ex.Message;
  113. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  114. if (num != null)
  115. {
  116. if (num.Number == 547)
  117. mge = "请先删除所有关联的数据,如学期注册、评价控制";
  118. }
  119. return base.Json("删除失败,原因:" + mge + "!");
  120. }
  121. }
  122. /// <summary>
  123. ///
  124. /// </summary>
  125. /// <param name="pararms"></param>
  126. /// <returns></returns>
  127. [HttpPost]
  128. public ActionResult GetYearsList(QueryParamsModel pararms)
  129. {
  130. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  131. var isCurrent = pararms.getExtraInt("IsCurrentDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsCurrentDropDown");
  132. return base.Json(SchoolYearServices.GetYearsViewGrid(configuretView, isCurrent, (int)pararms.page, (int)pararms.rows));
  133. }
  134. /// <summary>
  135. /// 学年学期下拉菜单(全部学年学期,以降序排列)
  136. /// </summary>
  137. /// <param name="bindType"></param>
  138. /// <returns></returns>
  139. [HttpPost]
  140. public ActionResult DropDown(DropdownListBindType? bindType)
  141. {
  142. var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
  143. List<DropdownListItem> list = SchoolYearServices.GetSchoolYearViewList(new ConfiguretView(), isCurrent)
  144. .Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
  145. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  146. DropdownList.FormatDropdownItemList(dbt, list);
  147. return base.Json(list);
  148. }
  149. /// <summary>
  150. /// 学年学期(全部学年学期,以降序排列-启用学年学期首位)
  151. /// </summary>
  152. /// <param name="pararms"></param>
  153. /// <returns></returns>
  154. [HttpPost]
  155. public ActionResult YearsDropdownListBanid(DropdownListBindType? bindType)
  156. {
  157. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  158. List<DropdownListItem> list = SchoolYearServices.GetSchoolYearViewList(configuretView, null).ToList()
  159. .OrderByDescending(x => x.IsCurrent).Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
  160. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  161. DropdownList.FormatDropdownItemList(dbt, list);
  162. return base.Json(list);
  163. }
  164. /// <summary>
  165. /// 学年学期下拉菜单(当前校历之后的学年学期,以降序排列)
  166. /// </summary>
  167. /// <param name="bindType"></param>
  168. /// <returns></returns>
  169. [HttpPost]
  170. public ActionResult DropDownAfterCurrent(DropdownListBindType? bindType)
  171. {
  172. //var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
  173. List<DropdownListItem> list = SchoolYearServices.GetSchoolYearViewListAfterCurrent()
  174. .Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
  175. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  176. DropdownList.FormatDropdownItemList(dbt, list);
  177. return base.Json(list);
  178. }
  179. /// <summary>
  180. /// 学年学期下拉菜单(当前校历之前的学年学期,以降序排列)
  181. /// </summary>
  182. /// <param name="bindType"></param>
  183. /// <returns></returns>
  184. [HttpPost]
  185. public ActionResult DropDownBeforeCurrent(DropdownListBindType? bindType)
  186. {
  187. //var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
  188. List<DropdownListItem> list = SchoolYearServices.GetSchoolYearViewListBeforeCurrent().Select(x => new DropdownListItem { Text = x.Code, Value = x.SchoolYearID.ToString() }).ToList();
  189. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  190. DropdownList.FormatDropdownItemList(dbt, list);
  191. return base.Json(list);
  192. }
  193. /// <summary>
  194. ///
  195. /// </summary>
  196. /// <param name="bindType"></param>
  197. /// <returns></returns>
  198. [HttpPost]
  199. public ActionResult CurrentWeekListDropdown(DropdownListBindType? bindType)
  200. {
  201. List<DropdownListItem> list = SchoolYearServices.GetCurrentSchoolyearWeekNumList().OrderByDescending(x => x).Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList();
  202. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  203. DropdownList.FormatDropdownItemList(dbt, list);
  204. return base.Json(list);
  205. }
  206. /// <summary>
  207. ///
  208. /// </summary>
  209. /// <param name="bindType"></param>
  210. /// <param name="schoolyearID"></param>
  211. /// <returns></returns>
  212. [HttpPost]
  213. public ActionResult GetWeekListDropdown(DropdownListBindType? bindType, Guid? schoolyearID)
  214. {
  215. var list = SchoolYearServices.GetSchoolyearWeekNumList(schoolyearID).OrderByDescending(x => x).Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList();
  216. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  217. DropdownList.FormatDropdownItemList(dbt, list);
  218. return base.Json(list);
  219. }
  220. /// <summary>
  221. ///
  222. /// </summary>
  223. /// <param name="bindType"></param>
  224. /// <param name="weekNum"></param>
  225. /// <returns></returns>
  226. [HttpPost]
  227. public ActionResult GetFutureWeekListDropdown(DropdownListBindType? bindType, int weekNum)
  228. {
  229. var list = SchoolYearServices.GetFutureWeekdayList(weekNum)
  230. .OrderBy(x => (x.WeekDay == 0 ? 7 : x.WeekDay)).Select(x => new DropdownListItem { Value = x.WeekDay.ToString(), Text = x.ChineseName.ToString() }).ToList();
  231. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  232. DropdownList.FormatDropdownItemList(dbt, list);
  233. return base.Json(list);
  234. }
  235. /// <summary>
  236. /// 导出Excel
  237. /// </summary>
  238. /// <param name="pararms"></param>
  239. /// <returns></returns>
  240. [HttpPost]
  241. public ActionResult Excel()
  242. {
  243. try
  244. {
  245. NpoiExcelHelper neh = new NpoiExcelHelper();
  246. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  247. var isCurrent = Request.Form["IsCurrentDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsCurrentDropDown"].ParseStrTo<int>();
  248. var dt = SchoolYearServices.GetSchoolYearViewList(configuretView, isCurrent).Select(x => new
  249. {
  250. x.Code,
  251. x.Years,
  252. x.SchoolcodeName,
  253. x.WeeksNum,
  254. FirstWeek = x.FirstWeek.Value.ToString("yyyy-MM-dd"),
  255. x.Current,
  256. x.WeekDays
  257. }).ToTable();
  258. string[] liststring = { "学年学期", "学年", "学期名称", "周数", "首周周一日期", "是否当前学期", "每周工作天数" };
  259. neh.Export(dt, liststring, "学年学期信息");
  260. return RedirectToAction("MsgShow", "Common", new
  261. {
  262. msg = "导出成功!",
  263. url = Url.Content("~/SchoolYear/List").AddMenuParameter()
  264. });
  265. }
  266. catch (Exception ex)
  267. {
  268. return RedirectToAction("MsgShow", "Common", new
  269. {
  270. msg = "导出失败,原因:" + ex.Message + "!",
  271. url = Url.Content("~/SchoolYear/List").AddMenuParameter()
  272. });
  273. }
  274. }
  275. }
  276. }