ExamBatchProjectController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 EMIS.CommonLogic.ExamManage;
  9. using Bowin.Common.Utility;
  10. using Bowin.Common.Exceptions;
  11. using Bowin.Common.Data;
  12. using Bowin.Web.Controls.Mvc;
  13. using Bowin.Common.Linq.Entity;
  14. namespace EMIS.CommonLogic.ExamManage
  15. {
  16. [Authorization]
  17. public class ExamBatchProjectController : Controller
  18. {
  19. public IExaminationBatchServices IExaminationBatchService { get; set; }
  20. public IExamBatchProjectServices IExamBatchProjectService { get; set; }
  21. //
  22. // GET: /ExaminationBatch/
  23. public ActionResult List()
  24. {
  25. return View();
  26. }
  27. public ActionResult Select()
  28. {
  29. return View();
  30. }
  31. [HttpPost]
  32. public ActionResult TypeDropDownList(DropdownListBindType? bindType, Guid? examinationBatchID)
  33. {
  34. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  35. var projectQuery = IExamBatchProjectService.GetBatchProjectList(new ConfiguretView());
  36. if (examinationBatchID.HasValue)
  37. {
  38. projectQuery = projectQuery.Where(x => x.ExaminationBatchID == examinationBatchID);
  39. }
  40. else
  41. {
  42. var emptyList = new List<DropdownListItem>();
  43. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList);
  44. return Json(emptyList);
  45. }
  46. List<DropdownListItem> list = projectQuery.Select(x => new { x.ExaminationTypeID, x.ExaminationType }).Distinct()
  47. .OrderBy(x => x.ExaminationType)
  48. .Select(x => new DropdownListItem { Text = x.ExaminationType, Value = x.ExaminationTypeID.ToString() }).ToList();
  49. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  50. return base.Json(list);
  51. }
  52. [HttpPost]
  53. public ActionResult DropDownList(DropdownListBindType? bindType, Guid? examinationBatchID, Guid? examinationTypeID)
  54. {
  55. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  56. var projectQuery = IExamBatchProjectService.GetBatchProjectList(new ConfiguretView());
  57. if (examinationBatchID.HasValue)
  58. {
  59. projectQuery = projectQuery.Where(x => x.ExaminationBatchID == examinationBatchID);
  60. }
  61. else
  62. {
  63. var emptyList = new List<DropdownListItem>();
  64. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList);
  65. return Json(emptyList);
  66. }
  67. if (examinationTypeID.HasValue)
  68. {
  69. projectQuery = projectQuery.Where(x => x.ExaminationTypeID == examinationTypeID);
  70. }
  71. List<DropdownListItem> list = projectQuery
  72. .OrderBy(x => x.Name)
  73. .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationProjectID.ToString() }).ToList();
  74. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  75. return base.Json(list);
  76. }
  77. /// <summary>
  78. /// 项目类型列表查询
  79. /// </summary>
  80. /// <param name="pararms"></param>
  81. /// <returns></returns>
  82. [HttpPost]
  83. public ActionResult GetExamTypeListViewGrid(QueryParamsModel pararms)
  84. {
  85. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  86. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  87. configuretViews.AddRange(pararms.getConditions());
  88. var queryList = IExamBatchProjectService.GetBatchProjectList(configuretViews.ToArray()).Select(q => new
  89. {
  90. q.ExaminationType,
  91. q.ExaminationTypeID,
  92. }).Distinct().OrderBy(x => x.ExaminationTypeID)
  93. .ToGridResultSet<Object>((int)pararms.page, (int)pararms.rows);
  94. return base.Json(queryList);
  95. }
  96. /// <summary>
  97. /// 项目列表查询
  98. /// </summary>
  99. /// <param name="pararms"></param>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public ActionResult GetExamBatchProjectListViewGrid(QueryParamsModel pararms)
  103. {
  104. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  105. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  106. configuretViews.AddRange(pararms.getConditions());
  107. configuretViews.Add(new ConfiguretView()
  108. {
  109. Attribute = "RecordStatus",
  110. Condition = "=",
  111. ConditionValue = ((int)SYS_STATUS.USABLE).ToString()
  112. });
  113. var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault();
  114. if (StartDate != null) StartDate.Condition = ">=";
  115. var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault();
  116. if (EndDate != null) EndDate.Condition = "<=";
  117. return base.Json(IExamBatchProjectService.GetBatchProjectListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
  118. }
  119. /// <summary>
  120. /// 批次考试类型列表查询
  121. /// </summary>
  122. /// <param name="pararms"></param>
  123. /// <returns></returns>
  124. [HttpPost]
  125. public ActionResult GetExamBatchExamTypeListViewGrid(QueryParamsModel pararms)
  126. {
  127. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  128. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  129. configuretViews.AddRange(pararms.getConditions());
  130. return base.Json(IExamBatchProjectService.GetExamBatchExamTypeListViewGrid((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
  131. }
  132. /// <summary>
  133. /// 编辑页项目列表查询
  134. /// </summary>
  135. /// <param name="pararms"></param>
  136. /// <returns></returns>
  137. [HttpPost]
  138. public ActionResult GetExamBatchProjectListEdiGrid(QueryParamsModel pararms)
  139. {
  140. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  141. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  142. configuretViews.AddRange(pararms.getConditions());
  143. if (configuretViews.Count == 1)
  144. return null;
  145. var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault();
  146. if (StartDate != null) StartDate.Condition = ">=";
  147. var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault();
  148. if (EndDate != null) EndDate.Condition = "<=";
  149. return base.Json(IExamBatchProjectService.GetBatchProjectListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
  150. }
  151. /// <summary>
  152. /// 设置编辑页
  153. /// </summary>
  154. /// <param name="ExaminationProjectFeeID"></param>
  155. /// <returns></returns>
  156. [HttpGet]
  157. public ActionResult Edit(Guid? ExaminationBatchProjectID)
  158. {
  159. EMIS.ViewModel.ExamBatchProjectView projectFeeView = new EMIS.ViewModel.ExamBatchProjectView() { ExaminationBatchID = Guid.NewGuid(), SchoolyearID = BaseExtensions.GetCurrentSchoolYearID()};
  160. if (ExaminationBatchProjectID.HasValue && ExaminationBatchProjectID != Guid.Empty)
  161. {
  162. ConfiguretView config = new ConfiguretView();
  163. config.Attribute = "ExaminationBatchProjectID";
  164. config.Condition = "=";
  165. config.ConditionValue = ExaminationBatchProjectID.ToString();
  166. projectFeeView = IExamBatchProjectService.GetBatchProjectList(config).Single();
  167. }
  168. return View(projectFeeView);
  169. }
  170. /// <summary>
  171. /// 新增项目提交操作
  172. /// </summary>
  173. /// <param name="campusIDs"></param>
  174. /// <returns></returns>
  175. [HttpPost]
  176. public JsonResult SelectProjects(Guid ExaminationBatchID, string ExamProjectIDs)
  177. {
  178. try
  179. {
  180. List<Guid?> list = ExamProjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  181. .Select(x => (Guid?)new Guid(x)).ToList();
  182. var addlist = IExamBatchProjectService.SelectProjects(ExaminationBatchID, list);
  183. //返回新增的行数
  184. return Json(new ReturnMessage<List<EMIS.ViewModel.ExamBatchProjectView>> { IsSuccess = true, Message = "新增成功。", Data = addlist });
  185. }
  186. catch (Exception ex)
  187. {
  188. return Json(new ReturnMessage { IsSuccess = true, Message = "新增失败,原因:" + ex.Message });
  189. }
  190. }
  191. /// <summary>
  192. /// 收费项目编辑页提交
  193. /// </summary>
  194. /// <param name="campusView"></param>
  195. /// <returns></returns>
  196. [HttpPost]
  197. public ActionResult Edit(ExamBatchProjectView view)
  198. {
  199. try
  200. {
  201. var listData = DataGrid.GetTableData<ExamBatchProjectView>("dgProjectList");
  202. //IExamBatchProjectService.Edit(view, listData);
  203. //新增时候是批量,修改为单条操作
  204. if (listData == null || listData.Count == 0)
  205. {
  206. IExamBatchProjectService.Edit(view);
  207. }
  208. else
  209. {
  210. IExamBatchProjectService.Edit(view, listData);
  211. }
  212. return Json(new ReturnMessage()
  213. {
  214. IsSuccess = true,
  215. Message = "保存成功。"
  216. });
  217. }
  218. catch (Exception ex)
  219. {
  220. return Json(new ReturnMessage()
  221. {
  222. IsSuccess = false,
  223. Message = "保存失败,原因:" + ex.Message
  224. });
  225. }
  226. }
  227. /// <summary>
  228. /// 删除项目设置
  229. /// </summary>
  230. /// <param name="campusIDs"></param>
  231. /// <returns></returns>
  232. [HttpPost]
  233. public JsonResult DeleteBatchProject(string ExamBatchProjectIDs)
  234. {
  235. try
  236. {
  237. List<Guid?> list = ExamBatchProjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  238. .Select(x => (Guid?)new Guid(x)).ToList();
  239. IExamBatchProjectService.DeleteBatchProject(list);
  240. return base.Json("删除成功。");
  241. }
  242. catch (Exception ex)
  243. {
  244. string mge = ex.Message;
  245. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  246. if (num != null)
  247. {
  248. if (num.Number == 547)
  249. {
  250. mge = "请先删除与其有关联的数据";
  251. }
  252. }
  253. return base.Json("删除失败,原因:" + mge);
  254. }
  255. }
  256. [HttpPost]
  257. public ActionResult Excel(QueryParamsModel pararms)
  258. {
  259. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  260. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  261. configuretViews.AddRange(pararms.getConditions());
  262. var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault();
  263. if (StartDate != null) StartDate.Condition = ">=";
  264. var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault();
  265. if (EndDate != null) EndDate.Condition = "<=";
  266. var query = IExamBatchProjectService.GetBatchProjectList(configuretViews.ToArray());
  267. var SelectedID = Request.Form["SelectedID"];
  268. List<Guid?> selectIDlist = new List<Guid?>();
  269. if (SelectedID != "" && SelectedID != null)
  270. {
  271. selectIDlist = SelectedID.SplitIDString();
  272. query = query.Where(x => selectIDlist.Contains(x.ExaminationBatchProjectID));
  273. }
  274. var dt = query.ToList().Select(q =>
  275. new
  276. {
  277. q.Schoolyear,
  278. q.BatchName,
  279. StartDate = q.StartDate.ToStringEx("yyyy-MM-dd"),
  280. EndDate = q.EndDate.ToStringEx("yyyy-MM-dd"),
  281. q.ExaminationType,
  282. q.Name,
  283. q.SimulateTime,
  284. q.Training,
  285. q.TakeCourseTime,
  286. q.MaxRegistCount,
  287. }).ToTable();
  288. NpoiExcelHelper neh = new NpoiExcelHelper();
  289. string[] liststring = {
  290. "学年学期","考试批次","报名起始时间","报名结束时间","考试类型","项目名称","预考试时间","培训情况","预开课时间","最大报名人数"};
  291. neh.Export(dt, liststring, "批次项目设置信息列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
  292. return RedirectToAction("MsgShow", "Common", new
  293. {
  294. msg = "导出成功!",
  295. url = Url.Content("~/ExaminationBatc/List").AddMenuParameter()
  296. });
  297. }
  298. }
  299. }