using Lottomat.Application.Busines.SystemManage; using Lottomat.Application.Cache; using Lottomat.Application.Code; using Lottomat.Application.Entity.SystemManage; using Lottomat.Application.Entity.SystemManage.ViewModel; using Lottomat.Util; using Lottomat.Util.WebControl; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Lottomat.Util.Extension; namespace Lottomat.Application.Admin.Areas.SystemManage.Controllers { /// /// 版 本 1.0 /// Copyright (c) 2016-2017 /// 创建人:赵轶 /// 日 期:2015.11.17 9:56 /// 描 述:数据字典明细 /// public class DataItemDetailController : MvcControllerBase { private DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL(); private DataItemCache dataItemCache = new DataItemCache(); #region 视图功能 /// /// 明细管理 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Index() { return View(); } /// /// 明细表单 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Form() { return View(); } /// /// 明细详细 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Detail() { return View(); } #endregion #region 获取数据 /// /// 明细列表 /// /// 分类Id /// 条件 /// 关键字查询 /// 返回树形列表Json [HttpGet] public ActionResult GetTreeListJson(string itemId, string condition, string keyword) { var data = dataItemDetailBLL.GetList(itemId).ToList(); if (!string.IsNullOrEmpty(keyword)) { #region 多条件查询 switch (condition) { case "ItemName": //项目名 data = data.TreeWhere(t => t.ItemName.Contains(keyword), "ItemDetailId"); break; case "ItemValue": //项目值 data = data.TreeWhere(t => t.ItemValue.Contains(keyword), "ItemDetailId"); break; case "SimpleSpelling": //拼音 data = data.TreeWhere(t => t.SimpleSpelling.Contains(keyword), "ItemDetailId"); break; default: break; } #endregion } var TreeList = new List(); foreach (DataItemDetailEntity item in data) { TreeGridEntity tree = new TreeGridEntity(); bool hasChildren = data.Count(t => t.ParentId == item.ItemDetailId) != 0; tree.id = item.ItemDetailId; tree.parentId = item.ParentId; tree.expanded = true; tree.hasChildren = hasChildren; tree.entityJson = item.ToJson(); TreeList.Add(tree); } return Content(TreeList.TreeJson()); } /// /// 明细实体 /// /// 主键值 /// 返回对象Json [HttpGet] public ActionResult GetFormJson(string keyValue) { var data = dataItemDetailBLL.GetEntity(keyValue); return Content(data.ToJson()); } /// /// 获取数据字典列表(绑定控件) /// /// 代码 /// 返回列表树Json [HttpGet] public ActionResult GetDataItemTreeJson(string EnCode) { var data = dataItemCache.GetDataItemList(EnCode); var treeList = new List(); foreach (DataItemModel item in data) { TreeEntity tree = new TreeEntity(); bool hasChildren = data.Count(t => t.ParentId == item.ItemDetailId) == 0 ? false : true; tree.id = item.ItemDetailId; tree.text = item.ItemName; tree.value = item.ItemValue; tree.parentId = item.ParentId; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; treeList.Add(tree); } return Content(treeList.TreeToJson()); } /// /// 获取数据字典列表(绑定控件) /// /// 代码 /// 返回列表Json [HttpGet] public ActionResult GetDataItemListJson(string EnCode) { var data = dataItemCache.GetDataItemList(EnCode); return Content(data.ToJson()); } /// /// 获取数据字典子列表(绑定控件) /// /// 代码 /// 项目值 /// 返回列表Json public ActionResult GetSubDataItemListJson(string EnCode, string ItemValue) { var data = dataItemCache.GetSubDataItemList(EnCode, ItemValue); return Content(data.ToJson()); } #endregion #region 验证数据 /// /// 项目值不能重复 /// /// 项目值 /// 主键 /// 分类Id /// [HttpGet] public ActionResult ExistItemValue(string ItemValue, string keyValue, string itemId) { bool IsOk = dataItemDetailBLL.ExistItemValue(ItemValue, keyValue, itemId); return Content(IsOk.ToString()); } /// /// 项目名不能重复 /// /// 项目名 /// 主键 /// 分类Id /// [HttpGet] public ActionResult ExistItemName(string ItemName, string keyValue, string itemId) { bool IsOk = dataItemDetailBLL.ExistItemName(ItemName, keyValue, itemId); return Content(IsOk.ToString()); } #endregion #region 提交数据 /// /// 删除明细 /// /// 主键值 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult RemoveForm(string keyValue) { dataItemDetailBLL.RemoveForm(keyValue); return Success("删除成功。"); } /// /// 保存明细表单(新增、修改) /// /// 主键值 /// 明细实体 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, DataItemDetailEntity dataItemDetailEntity) { dataItemDetailBLL.SaveForm(keyValue, dataItemDetailEntity); return Success("操作成功。"); } #endregion } }