using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.ViewModel; using EMIS.Web.Controls; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.SystemSetting; using EMIS.ViewModel.SystemView; using Bowin.Common.Utility; using Bowin.Common.Data; namespace EMIS.Web.Controllers.SystemManage.SystemSetting { [Authorization] public class DictionaryItemController : Controller { public Lazy DictionaryItemServices { get; set; } /// /// 数据字典(字典元素)页面 /// /// public ActionResult List() { return View(); } /// /// 数据字典列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //类型名称 var dictionaryCode = pararms.getExtraString("DictionaryDropdown"); //可否编辑 var isEditable = pararms.getExtraInt("DictionaryIsEditable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEditable"); //可否显示 var isVisible = pararms.getExtraInt("DictionaryIsVisible") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsVisible"); return base.Json(DictionaryItemServices.Value.GetDictionaryItemViewGird(configuretView, dictionaryCode, isEditable, isVisible, (int)pararms.page, (int)pararms.rows)); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid dictionaryItemID) { DictionaryItemView dictionaryItemView = new DictionaryItemView(); dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID); return View("Edit", dictionaryItemView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(DictionaryItemView dictionaryItemView) { dictionaryItemView.DictionaryItemID = Guid.Empty; return this.Edit(dictionaryItemView); } /// /// 编辑(新增、修改,业务主键:类型代码、元素值-Value) /// /// /// [HttpGet] public ActionResult Edit(Guid? dictionaryItemID) { ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限 DictionaryItemView dictionaryItemView = new DictionaryItemView(); if (dictionaryItemID.HasValue && dictionaryItemID != Guid.Empty) { dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID); } else { dictionaryItemView.IsEditable = true; dictionaryItemView.IsVisible = true; } return View(dictionaryItemView); } /// /// 编辑(新增、修改,业务主键:类型代码、元素值-Value) /// /// /// [HttpPost] public ActionResult Edit(DictionaryItemView dictionaryItemView) { try { DictionaryItemServices.Value.DictionaryItemEdit(dictionaryItemView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除(只可删除可编辑的信息) /// /// /// [HttpPost] public ActionResult Delete(string dictionaryItemIDs) { try { List list = dictionaryItemIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); DictionaryItemServices.Value.DictionaryItemDelete(list); return Json(new ReturnMessage() { IsSuccess = true, Message = "删除成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "删除失败,原因:" + ex.Message }); } } /// /// 数据字典下拉列表 /// /// /// /// [HttpPost] public ActionResult ComboGridList(QueryParamsModel pararms, string dictionaryCode = null) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); //避开全选值 if (string.IsNullOrEmpty(dictionaryCode)) { dictionaryCode = pararms.getExtraString("DictionaryDropdown"); } if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) { configuretView.Attribute = ""; } return base.Json(DictionaryItemServices.Value.GetDictionaryViewComboGrid(configuretView, dictionaryCode, (int)pararms.page, (int)pararms.rows)); } /// /// 数据字典下拉列表(市) /// /// /// [HttpPost] public ActionResult CityComboGridList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var proviceCode = pararms.getExtraString("ProviceCode"); if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) { configuretView.Attribute = ""; } return base.Json(DictionaryItemServices.Value.GetCityComboGrid(configuretView, (int)pararms.page, (int)pararms.rows, proviceCode)); } /// /// 数据字典下拉列表(县、区) /// /// /// [HttpPost] public ActionResult DistrictComboGridList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var cityCode = pararms.getExtraString("CityCode"); if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) { configuretView.Attribute = ""; } return base.Json(DictionaryItemServices.Value.GetDistrictComboGrid(configuretView, (int)pararms.page, (int)pararms.rows, cityCode)); } /// /// Excel导出 /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); //类型名称 var dictionaryCode = Request.Form["DictionaryDropdown"].ToString(); //可否编辑 var isEditable = Request.Form["DictionaryIsEditable"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEditable"].ParseStrTo(); //可否显示 var isVisible = Request.Form["DictionaryIsVisible"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsVisible"].ParseStrTo(); var dt = DictionaryItemServices.Value.GetDictionaryItemViewList(configuretView, dictionaryCode, isEditable, isVisible) .Select(x => new { x.DictionaryCode, x.DictionaryName, x.OrderNo, x.Code, x.Name, x.Value, x.IsEditableName, x.IsVisibleName }).ToTable(); string[] liststring = { "类型代码 ", "类型名称 ", "序号 ", "元素代码 ", "元素名称 ", "元素值 ", "可否编辑", "可否显示" }; neh.Export(dt, liststring, "数据字典信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }