using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.CommonLogic.SelectCourse; using EMIS.ViewModel; using EMIS.Web.Controls; using Bowin.Web.Controls.Mvc; using EMIS.ViewModel.SelectCourse; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Common.Data; namespace EMIS.Web.Controllers.SelectCourseManage { [Authorization] public class FreeSelectionCouseControlController : Controller { public IOpenControlSettingServices openControlSettingServices { get; set; } /// /// 任选控制页面 /// /// public ActionResult List() { return View(); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var schoolYearID = pararms.getExtraGuid("SchoolyearDropdown"); var Years = pararms.getExtraInt("SchoolyearDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolyearDictionaryDropDown"); return this.Json(openControlSettingServices.GetFreeSelectionCouseControlViewGrid(configuretView, schoolYearID, Years, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑 /// /// public ActionResult Edit(Guid? FreeSelectionCourseGradeYearSettingID) { FreeSelectionCouseControlView optionalCourseSettingView = new FreeSelectionCouseControlView(); if (FreeSelectionCourseGradeYearSettingID.HasValue && FreeSelectionCourseGradeYearSettingID != Guid.Empty) optionalCourseSettingView = openControlSettingServices.GetFreeSelectionCouseControlSettingViewInfo(FreeSelectionCourseGradeYearSettingID); ViewBag.RecordStatus = optionalCourseSettingView.RecordStatus; return View(optionalCourseSettingView); } /// /// 保存修改 /// /// /// [HttpPost] public ActionResult Edit(FreeSelectionCouseControlView optionalCourseSettingView) { try { openControlSettingServices.FreeSelectionCouseControlSave(optionalCourseSettingView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string freeSelectionCourseGradeYearSettingIDs) { try { List list = new List(); for (int i = 0; i < freeSelectionCourseGradeYearSettingIDs.Split(',').Length; i++) { if (!string.IsNullOrEmpty(freeSelectionCourseGradeYearSettingIDs.Split(',')[i])) { Guid optionalCourseSettingID = new Guid(freeSelectionCourseGradeYearSettingIDs.Split(',')[i]); list.Add(optionalCourseSettingID); } } openControlSettingServices.FreeSelectionCouseControlDelete(list); return this.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 this.Json("删除失败,原因:" + mge); } } [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); //避开全选值 if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; var schoolYearID = Request.Form["SchoolYear"].ParseStrTo(); var Years = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo(); var dt = openControlSettingServices.GetFreeSelectionCouseControlList(configuretView, schoolYearID, Years) .Select(x => new { x.SchoolyearCode, x.GradeYear, x.StartTime, x.EndTime, x.MaxSelectCount, x.MinSelectCount, x.MaxCredit, x.MinCredit }).ToTable(); string[] liststring = { "学年学期", "年级", "开始时间", "结束时间", "门数上限", "门数下限", "学分上限","学分下限"}; neh.Export(dt, liststring, "任选设定"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/FreeSelectionCouseControl/List").AddMenuParameter() }); } } }