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 Bowin.Common.Linq.Entity; namespace EMIS.CommonLogic.ExamManage { [Authorization] public class ExamBatchProjectController : Controller { public IExaminationBatchServices IExaminationBatchService { get; set; } public IExamBatchProjectServices IExamBatchProjectService { get; set; } // // GET: /ExaminationBatch/ public ActionResult List() { return View(); } public ActionResult Select() { return View(); } [HttpPost] public ActionResult TypeDropDownList(DropdownListBindType? bindType, Guid? examinationBatchID) { DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; var projectQuery = IExamBatchProjectService.GetBatchProjectList(new ConfiguretView()); if (examinationBatchID.HasValue) { projectQuery = projectQuery.Where(x => x.ExaminationBatchID == examinationBatchID); } else { var emptyList = new List(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList); return Json(emptyList); } List list = projectQuery.Select(x => new { x.ExaminationTypeID, x.ExaminationType }).Distinct() .OrderBy(x => x.ExaminationType) .Select(x => new DropdownListItem { Text = x.ExaminationType, Value = x.ExaminationTypeID.ToString() }).ToList(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } [HttpPost] public ActionResult DropDownList(DropdownListBindType? bindType, Guid? examinationBatchID, Guid? examinationTypeID) { DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; var projectQuery = IExamBatchProjectService.GetBatchProjectList(new ConfiguretView()); if (examinationBatchID.HasValue) { projectQuery = projectQuery.Where(x => x.ExaminationBatchID == examinationBatchID); } else { var emptyList = new List(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList); return Json(emptyList); } if (examinationTypeID.HasValue) { projectQuery = projectQuery.Where(x => x.ExaminationTypeID == examinationTypeID); } List list = projectQuery .OrderBy(x => x.Name) .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationProjectID.ToString() }).ToList(); Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 项目类型列表查询 /// /// /// [HttpPost] public ActionResult GetExamTypeListViewGrid(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); var queryList = IExamBatchProjectService.GetBatchProjectList(configuretViews.ToArray()).Select(q => new { q.ExaminationType, q.ExaminationTypeID, }).Distinct().OrderBy(x => x.ExaminationTypeID) .ToGridResultSet((int)pararms.page, (int)pararms.rows); return base.Json(queryList); } /// /// 项目列表查询 /// /// /// [HttpPost] public ActionResult GetExamBatchProjectListViewGrid(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); configuretViews.Add(new ConfiguretView() { Attribute = "RecordStatus", Condition = "=", ConditionValue = ((int)SYS_STATUS.USABLE).ToString() }); 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(IExamBatchProjectService.GetBatchProjectListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray())); } /// /// 批次考试类型列表查询 /// /// /// [HttpPost] public ActionResult GetExamBatchExamTypeListViewGrid(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); return base.Json(IExamBatchProjectService.GetExamBatchExamTypeListViewGrid((int)pararms.page, (int)pararms.rows, configuretViews.ToArray())); } /// /// 编辑页项目列表查询 /// /// /// [HttpPost] public ActionResult GetExamBatchProjectListEdiGrid(QueryParamsModel pararms) { List configuretViews = new List(); configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms)); configuretViews.AddRange(pararms.getConditions()); if (configuretViews.Count == 1) return null; 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(IExamBatchProjectService.GetBatchProjectListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray())); } /// /// 设置编辑页 /// /// /// [HttpGet] public ActionResult Edit(Guid? ExaminationBatchProjectID) { EMIS.ViewModel.ExamBatchProjectView projectFeeView = new EMIS.ViewModel.ExamBatchProjectView() { ExaminationBatchID = Guid.NewGuid(), SchoolyearID = BaseExtensions.GetCurrentSchoolYearID()}; if (ExaminationBatchProjectID.HasValue && ExaminationBatchProjectID != Guid.Empty) { ConfiguretView config = new ConfiguretView(); config.Attribute = "ExaminationBatchProjectID"; config.Condition = "="; config.ConditionValue = ExaminationBatchProjectID.ToString(); projectFeeView = IExamBatchProjectService.GetBatchProjectList(config).Single(); } return View(projectFeeView); } /// /// 新增项目提交操作 /// /// /// [HttpPost] public JsonResult SelectProjects(Guid ExaminationBatchID, string ExamProjectIDs) { try { List list = ExamProjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); var addlist = IExamBatchProjectService.SelectProjects(ExaminationBatchID, list); //返回新增的行数 return Json(new ReturnMessage> { IsSuccess = true, Message = "新增成功。", Data = addlist }); } catch (Exception ex) { return Json(new ReturnMessage { IsSuccess = true, Message = "新增失败,原因:" + ex.Message }); } } /// /// 收费项目编辑页提交 /// /// /// [HttpPost] public ActionResult Edit(ExamBatchProjectView view) { try { var listData = DataGrid.GetTableData("dgProjectList"); //IExamBatchProjectService.Edit(view, listData); //新增时候是批量,修改为单条操作 if (listData == null || listData.Count == 0) { IExamBatchProjectService.Edit(view); } else { IExamBatchProjectService.Edit(view, listData); } return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除项目设置 /// /// /// [HttpPost] public JsonResult DeleteBatchProject(string ExamBatchProjectIDs) { try { List list = ExamBatchProjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); IExamBatchProjectService.DeleteBatchProject(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 = IExamBatchProjectService.GetBatchProjectList(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.ExaminationBatchProjectID)); } var dt = query.ToList().Select(q => new { q.Schoolyear, q.BatchName, StartDate = q.StartDate.ToStringEx("yyyy-MM-dd"), EndDate = q.EndDate.ToStringEx("yyyy-MM-dd"), q.ExaminationType, q.Name, q.SimulateTime, q.Training, q.TakeCourseTime, q.MaxRegistCount, }).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() }); } } }