using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Web.Controls.Mvc; using EMIS.Utility; using EMIS.ViewModel; using EMIS.Web.Controls; using EMIS.CommonLogic.CalendarManage; using EMIS.ViewModel.CalendarManage; using EMIS.Entities; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Common.Data; using EMIS.CommonLogic.EducationSchedule; namespace EMIS.Web.Controllers.CalendarManage { [Authorization] public class CoursesTimeController : Controller { public ICoursesTimeServices CoursesTimeServices { get; set; } public IScheduleServices scheduleServices { get; set; } //public EducationSchedulingDAL EducationSchedulingDAL { get; set; } /// /// 节次时间页面 /// /// public ActionResult List() { return View(); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var timesSegment = pararms.getExtraInt("TimesSegmentDropdown"); return base.Json(CoursesTimeServices.GetCoursesTimeViewGrid(configuretView, timesSegment, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑页面 /// /// [HttpGet] public ActionResult Edit(Guid? coursesTimeID) { CoursesTimeView coursesTimeView = new CoursesTimeView(); if (coursesTimeID != null && coursesTimeID != Guid.Empty) coursesTimeView = CoursesTimeServices.GetCoursesTimeView(coursesTimeID); return View(coursesTimeView); } /// /// 新增或更新 /// /// /// [HttpPost] public ActionResult Edit(CoursesTimeView coursesTimeView) { try { if (!coursesTimeView.CoursesTimeID.HasValue || coursesTimeView.CoursesTimeID == Guid.Empty) { CoursesTimeServices.CoursesTimeAdd(coursesTimeView); } else { CoursesTimeServices.CoursesTimeUpdate(coursesTimeView); } return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string coursesTimeIDs) { try { List list = new List(); for (int i = 0; i < coursesTimeIDs.Split(',').Length; i++) { string id = coursesTimeIDs.Split(',')[i]; if (!string.IsNullOrEmpty(id)) { Guid coursesTimeID = new Guid(id); list.Add(coursesTimeID); } } CoursesTimeServices.CoursesTimeDelete(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 + "!"); } } /// /// 导出Excel /// /// /// [HttpPost] public ActionResult Excel() { try { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo(); var dt = CoursesTimeServices.GetCoursesTimeViewList(configuretView, timesSegment).Select(x => new { TimeGroupName = (x.StartTimes == x.EndTimes) ? x.StartTimes.Value.ToString() : x.StartTimes.Value.ToString() + "-" + x.EndTimes.Value.ToString(), x.TimesSegmentName, x.StartDate, x.EndDate }).ToTable(); string[] liststring = { "节次", "时间段", "开始时间", "结束时间" }; neh.Export(dt, liststring, "课程时间信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/CoursesTime/List").AddMenuParameter() }); } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { msg = "导出失败,原因:" + ex.Message + "!", url = Url.Content("~/CoursesTime/List").AddMenuParameter() }); } } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult ListAll() { return base.Json(CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null)); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult DropDown(DropdownListBindType? bindType) { var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null); List list = coursesTimeViewList .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult DropDownForSegment(DropdownListBindType? bindType) { var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null); List list = coursesTimeViewList .Select(x => new DropdownListItem { Text = string.Format("第{0}-{1}节", x.StartTimes, x.EndTimes), Value = x.CoursesTimeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult DropDownFuture(DropdownListBindType? bindType, string educationSchedulingIDs, int? weekNum, int? weekday, Guid? teacherID, Guid? schoolyearID) { var educationSchedulingWeekNumIDList = educationSchedulingIDs.Split(',') .Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewFutureList(educationSchedulingWeekNumIDList, weekNum, weekday); //var coursesTimeViewList = scheduleServices.GetNotUseCoursesTimeViewListForBatchAdjustment(schoolyearID, weekday, weekNum, teacherID, educationSchedulingWeekNumIDList); List list = coursesTimeViewList .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult DropDownForAdjustmentBatch(DropdownListBindType? bindType, string educationSchedulingIDs, int? weekNum, int? weekday, Guid? teacherID, Guid? schoolyearID) { var educationSchedulingWeekNumIDList = educationSchedulingIDs.Split(',') .Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); var coursesTimeViewList = scheduleServices.GetNotUseCoursesTimeViewListForBatchAdjustment(schoolyearID, weekday, weekNum, teacherID, educationSchedulingWeekNumIDList); List list = coursesTimeViewList .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } } }