using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.ViewModel; using EMIS.Web.Controls; using EMIS.CommonLogic.ExamManage; using Bowin.Common.Utility; using Bowin.Common.Exceptions; using Bowin.Common.Data; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.CalendarManage; namespace EMIS.Web.Controllers.ExamManage { [Authorization] public class ExaminationBatchController : Controller { public IExaminationBatchServices IExaminationBatchService { get; set; } public ISchoolYearServices ISchoolYearService { get; set; } // // GET: /ExaminationBatch/ public ActionResult List() { return View(); } /// /// 项目列表查询 /// /// /// [HttpPost] public ActionResult GetProjectListViewGrid(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault(); if (StartDate != null) StartDate.Condition = ">="; var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault(); if (EndDate != null) EndDate.Condition = "<="; return base.Json(IExaminationBatchService.GetBatchListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray())); } [HttpPost] public ActionResult DropDownList(DropdownListBindType? bindType, Guid? schoolyearID) { DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; var batchQuery = IExaminationBatchService.GetBatchList(new ConfiguretView()); if (schoolyearID.HasValue) { batchQuery = batchQuery.Where(x => x.SchoolyearID == schoolyearID); } else { var emptyList = new List(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList); return Json(emptyList); } List list = batchQuery .OrderBy(x => x.Name) .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationBatchID.ToString() }) .ToList(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 设置编辑页 /// /// /// [HttpGet] public ActionResult Edit(Guid? ExaminationBatchID) { EMIS.ViewModel.ExaminationBatchView projectFeeView = new EMIS.ViewModel.ExaminationBatchView() { ExaminationBatchID = Guid.NewGuid() }; if (ExaminationBatchID.HasValue && ExaminationBatchID != Guid.Empty) { projectFeeView = IExaminationBatchService.GetExamBatch(ExaminationBatchID); } else { var currentYear = ISchoolYearService.GetSchoolYearViewList(new ConfiguretView(), 1).FirstOrDefault(); if (currentYear != null) { projectFeeView.SchoolyearID = currentYear.SchoolYearID; projectFeeView.Schoolyear = currentYear.SchoolcodeName; } } return View(projectFeeView); } /// /// 设置编辑页提交 /// /// /// [HttpPost] public ActionResult Edit(ExaminationBatchView view) { try { //同一学年学期内批次名称需作唯一性判断 var model = IExaminationBatchService.GetExamBatch(x => x.Name == view.Name && x.SchoolyearID == view.SchoolyearID && x.ExaminationBatchID != view.ExaminationBatchID); if (model != null) { return Json(new ReturnMessage() { IsSuccess = false, Message = "同一学年学期内批次名称不允许相同!" }); } view.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.USABLE; IExaminationBatchService.Edit(view); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除项目设置 /// /// /// [HttpPost] public JsonResult DeleteBatch(string ExamBatchIDs) { try { List list = ExamBatchIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); IExaminationBatchService.DeleteBatch(list); return base.Json("删除成功。"); } catch (Exception ex) { string mge = ex.Message; System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex); if (num != null) { if (num.Number == 547) { mge = "请先删除与其有关联的数据"; } } return base.Json("删除失败,原因:" + mge); } } [HttpPost] public ActionResult Excel(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault(); if (StartDate != null) StartDate.Condition = ">="; var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault(); if (EndDate != null) EndDate.Condition = "<="; var query = IExaminationBatchService.GetBatchList(configuretViews.ToArray()); var SelectedID = Request.Form["SelectedID"]; List selectIDlist = new List(); if (SelectedID != "" && SelectedID != null) { selectIDlist = SelectedID.SplitIDString(); query = query.Where(x => selectIDlist.Contains(x.ExaminationBatchID)); } var dt = query.ToList().Select(q => new { q.Schoolyear, q.Name, StartDate = q.StartDate.ToStringEx("yyyy-MM-dd"), EndDate = q.EndDate.ToStringEx("yyyy-MM-dd"), q.Remark }).ToTable(); NpoiExcelHelper neh = new NpoiExcelHelper(); string[] liststring = { "学年学期","考试批次","报名起始时间","报名结束时间","备注"}; neh.Export(dt, liststring, "考试批次设置列表" + DateTime.Now.ToString("yyyyMMddhhmmss")); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/ExaminationBatc/List").AddMenuParameter() }); } } }