using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Common.Data; using Bowin.Web.Controls.Mvc; using EMIS.Utility; using EMIS.Web.Controls; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.CalendarManage; using EMIS.CommonLogic.CalendarManage; using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan; namespace EMIS.Web.Controllers.CalendarManage { [Authorization] public class DutyController : Controller { public IDutyServices DutyServices { get; set; } public IDepartmentServices DepartmentServices { get; set; } /// /// 值班安排页面 /// /// public ActionResult List() { return View(); } /// /// 列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); var collegeID = pararms.getExtraGuid("CollegeDropdown"); var departmentID = pararms.getExtraGuid("DepartmentDropdown"); var timesSegment = pararms.getExtraInt("TimesSegmentDropdown"); return base.Json(DutyServices.GetDutyViewGrid(configuretView, campusID, collegeID, departmentID, timesSegment, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑页面 /// /// [HttpGet] public ActionResult Edit(Guid? dutyID) { DutyView dutyView = new DutyView(); if (dutyID != null && dutyID != Guid.Empty) dutyView = DutyServices.GetDutyView(dutyID); return View(dutyView); } /// /// 新增或更新 /// /// /// [HttpPost] public ActionResult Edit(DutyView dutyView) { try { if (!dutyView.DutyID.HasValue || dutyView.DutyID == Guid.Empty) { DutyServices.DutyAdd(dutyView); } else { DutyServices.DutyUpdate(dutyView); } return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string dutyIDs) { try { List list = new List(); for (int i = 0; i < dutyIDs.Split(',').Length; i++) { string id = dutyIDs.Split(',')[i]; if (!string.IsNullOrEmpty(id)) { Guid dutyID = new Guid(id); list.Add(dutyID); } } DutyServices.DutyDelete(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 campusID = Request.Form["CampusDropdown"].ParseStrTo(); var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo(); var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo(); var dt = DutyServices.GetDutyViewList(configuretView, campusID, collegeID, departmentID, timesSegment).Select(x => new { x.LoginID, x.UserName, DutyTime = x.DutyTime.Value.ToString("yyyy-MM-dd"), x.StartDate, x.EndDate, x.Description, x.TimesSegmentName, x.DepartmentName }).ToTable(); string[] liststring = { "工作证号", "值班人名", "值班日期", "开始时间", "结束时间", "任务描述", "时间段", "教研室" }; neh.Export(dt, liststring, "值班管理信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/Duty/List").AddMenuParameter() }); } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { msg = "导出失败,原因:" + ex.Message + "!", url = Url.Content("~/Duty/List").AddMenuParameter() }); } } } }