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 EMIS.CommonLogic.SystemSetting; using EMIS.ViewModel; using EMIS.Web.Controls; using EMIS.ViewModel.SystemSetting; namespace EMIS.Web.Controllers.SystemManage.SystemSetting { [Authorization] public class DictionaryController : Controller { public Lazy DictionaryServices { get; set; } /// /// 字典类型页面 /// /// [HttpGet] public ActionResult List() { return View(); } /// /// 字典类型列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //可否编辑 var isEditable = pararms.getExtraInt("DictionaryIsEditable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEditable"); return base.Json(DictionaryServices.Value.GetDictionaryViewGird(configuretView, isEditable, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑(修改) /// /// /// [HttpGet] public ActionResult Edit(string dictionaryCode) { DictionaryView dictionaryView = new DictionaryView(); if (!string.IsNullOrEmpty(dictionaryCode)) { dictionaryView = DictionaryServices.Value.GetDictionaryView(dictionaryCode); } else { dictionaryView.IsEditable = true; } return View(dictionaryView); } /// /// 编辑(修改) /// /// /// [HttpPost] public ActionResult Edit(DictionaryView dictionaryView) { try { DictionaryServices.Value.DictionaryEdit(dictionaryView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string dictionaryCodes) { try { var list = dictionaryCodes.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => x).ToList(); DictionaryServices.Value.DictionaryDelete(list); return Json(new ReturnMessage() { IsSuccess = true, Message = "删除成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "删除失败:" + ex.Message }); } } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); //可否编辑 var isEditable = Request.Form["DictionaryIsEditable"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEditable"].ParseStrTo(); var dt = DictionaryServices.Value.GetDictionaryViewList(configuretView, isEditable) .Select(x => new { x.OrderNo, x.DictionaryCode, x.DictionaryName, x.IsEditableName }).ToTable(); string[] liststring = { "序号 ", "类型代码 ", "类型名称 ", "可否编辑" }; neh.Export(dt, liststring, "字典类型信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }