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.Exceptions; using EMIS.Web.Controls; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentChange; using EMIS.CommonLogic.StudentManage.StudentChange; namespace EMIS.Web.Controllers.StudentManage.StudentChange { [Authorization] public class ChangeReportController : Controller { public IChangeReportServices ChangeReportServices { get; set; } /// /// 异动报表页面 /// /// public ActionResult List() { return View(); } /// /// 异动报表列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); return base.Json(ChangeReportServices.GetChangeReportViewGrid(configuretView, (int)pararms.page, (int)pararms.rows)); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid changeReportID) { var changeReportView = new ChangeReportView(); changeReportView = ChangeReportServices.GetChangeReportView(changeReportID); return View("Edit", changeReportView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(ChangeReportView changeReportView) { changeReportView.ChangeReportID = Guid.Empty; return this.Edit(changeReportView); } /// /// 编辑(新增、修改) /// /// /// [HttpGet] public ActionResult Edit(Guid? changeReportID) { var changeReportView = new ChangeReportView(); if (changeReportID.HasValue && changeReportID != Guid.Empty) { changeReportView = ChangeReportServices.GetChangeReportView(changeReportID); } return View(changeReportView); } /// /// 编辑(新增、修改) /// /// /// [HttpPost] public ActionResult Edit(ChangeReportView changeReportView) { try { ChangeReportServices.ChangeReportEdit(changeReportView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string changeReportIDs) { try { List list = changeReportIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); ChangeReportServices.ChangeReportDelete(list); return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" }); } 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(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge }); } } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var dt = ChangeReportServices.GetChangeReportViewList(configuretView) .Select(x => new { x.Code, x.Name, x.Url }).ToTable(); string[] liststring = { "报表代码", "报表名称", "报表Url" }; neh.Export(dt, liststring, "异动报表信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }