using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Web.Controls.Mvc; using Bowin.Common.Utility; using Bowin.Common.Data; using Bowin.Common.JSON; using EMIS.Web.Controls; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.OnlineChecking; using EMIS.CommonLogic.StudentManage.OnlineChecking; namespace EMIS.Web.Controllers.StudentManage.OnlineChecking { [Authorization] public class OpenObjectController : Controller { public Lazy OpenObjectServices { get; set; } /// /// 学生开放对象页面 /// /// public ActionResult List() { return View(); } /// /// 学生开放对象页面列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation"); var schoolyearNumID = pararms.getExtraInt("DictionarySchoolyearNum") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolyearNum"); var dateRange = pararms.getExtraDateTime("txtDateRange"); return base.Json(OpenObjectServices.Value.GetStudentEditObjectViewGrid(configuretView, educationID, schoolyearNumID, dateRange, (int)pararms.page, (int)pararms.rows)); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid studentEditObjectID) { OpenObjectView openObjectView = new OpenObjectView(); openObjectView = OpenObjectServices.Value.GetStudentEditObjectView(studentEditObjectID); return View("Edit", openObjectView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(OpenObjectView openObjectView) { openObjectView.StudentEditObjectsID = Guid.Empty; return this.Edit(openObjectView); } /// /// 编辑(新增、修改) /// /// /// [HttpGet] public ActionResult Edit(Guid? studentEditObjectID) { OpenObjectView openObjectView = new OpenObjectView(); if (studentEditObjectID.HasValue && studentEditObjectID != Guid.Empty) { openObjectView = OpenObjectServices.Value.GetStudentEditObjectView(studentEditObjectID); } else { openObjectView.Starttime = DateTime.Now; openObjectView.Endtime = DateTime.Now.AddMonths(1); } return View(openObjectView); } /// /// 编辑(新增、修改) /// /// /// [HttpPost] public ActionResult Edit(OpenObjectView openObjectView) { try { OpenObjectServices.Value.StudentEditObjectEdit(openObjectView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 开放对象信息批量新增 /// /// [HttpGet] public ActionResult OpenObjectBatchAdd() { OpenObjectView openObjectView = new OpenObjectView(); openObjectView.Starttime = DateTime.Now; openObjectView.Endtime = DateTime.Now.AddMonths(1); return View(openObjectView); } /// /// 开放对象信息批量新增 /// /// /// public ActionResult OpenObjectBatchAdd(OpenObjectView openObjectView) { try { var schoolyearNumIDList = Request["schoolyearNumIDList"].JsonToObject>(); string result = OpenObjectServices.Value.StudentEditObjectBatchAdd(schoolyearNumIDList, openObjectView); return Json(new ReturnMessage() { IsSuccess = true, Message = "新增成功" + result + "。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "新增失败,原因:" + ex.Message }); } } /// /// 查询对应的未新增开放学年信息DictionaryItemView /// /// /// [HttpPost] public ActionResult SchoolyearNumNoAddList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var educationID = pararms.getExtraInt("EducationID") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("EducationID"); return base.Json(OpenObjectServices.Value.GetSchoolyearNumNoAddGrid(configuretView, educationID, (int)pararms.page, (int)pararms.rows)); } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string studentEditObjectIDs) { try { List list = studentEditObjectIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); OpenObjectServices.Value.StudentEditObjectDelete(list); return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" }); } catch (Exception ex) { return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + ex.Message }); } } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var educationID = Request.Form["DictionaryEducation"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo(); var schoolyearNumID = Request.Form["DictionarySchoolyearNum"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolyearNum"].ParseStrTo(); var dateRange = Request.Form["txtDateRange"].ParseStrTo(); var dt = OpenObjectServices.Value.GetStudentEditObjectViewList(configuretView, educationID, schoolyearNumID, dateRange) .Select(x => new { x.EducationName, x.SchoolyearNumName, Starttime = x.Starttime == null ? null : x.Starttime.Value.ToString("yyyy-MM-dd HH:mm:ss"), Endtime = x.Endtime == null ? null : x.Endtime.Value.ToString("yyyy-MM-dd HH:mm:ss"), x.Remark, x.CreateUserName, x.ModifyUserName, ModifyTime = x.ModifyTime == null ? null : x.ModifyTime.Value.ToString("yyyy-MM-dd HH:mm:ss") }).ToTable(); string[] liststring = { "培养层次", "开放学年", "开始时间", "结束时间", "备注", "创建人", "修改人", "修改时间" }; neh.Export(dt, liststring, "开放对象信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }