using Lottomat.Application.Busines.SystemManage; using Lottomat.Application.Code; using Lottomat.Application.Entity.SystemManage; using Lottomat.Util; using Lottomat.Util.WebControl; using System.Collections.Generic; using System.Web.Mvc; namespace Lottomat.Application.Admin.Areas.SystemManage.Controllers { /// /// 版 本 1.0 /// Copyright (c) 2016-2017 /// 创建人:赵轶 /// 日 期:2015.11.18 11:02 /// 描 述:据库表管理 /// public class DataBaseTableController : MvcControllerBase { private DataBaseTableBLL dataBaseTableBLL = new DataBaseTableBLL(); private DataBaseLinkBLL databaseLinkBLL = new DataBaseLinkBLL(); #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 TableData() { return View(); } /// /// 数据表字段表单 /// /// [HttpGet] public ActionResult FieldForm() { return View(); } #endregion #region 获取数据 /// /// 数据库表列表 /// /// 库连接Id /// 关键字查询 /// 返回列表Json [HttpGet] public ActionResult GetTableListJson(string dataBaseLinkId, string keyword) { var data = dataBaseTableBLL.GetTableList(dataBaseLinkId, keyword); return ToJsonResult(data); } /// /// 数据库表字段列表 /// /// 库连接Id /// 表明 /// 字段Id /// 返回树形Json [HttpGet] public ActionResult GetTableFiledTreeJson(string dataBaseLinkId, string tableName, string nameId) { List nameArray = new List(); if (!string.IsNullOrEmpty(nameId)) { nameArray = new List(nameId.Split(',')); } var data = dataBaseTableBLL.GetTableFiledList(dataBaseLinkId, tableName); var treeList = new List(); TreeEntity tree = new TreeEntity(); tree.id = tableName; tree.text = tableName; tree.value = tableName; tree.parentId = "0"; tree.img = "fa fa-list-alt"; tree.isexpand = true; tree.complete = true; tree.hasChildren = true; treeList.Add(tree); foreach (DataBaseTableFieldEntity item in data) { tree = new TreeEntity(); tree.id = item.column; tree.text = item.remark + "(" + item.column + ")"; tree.value = item.remark; tree.parentId = tableName; tree.img = "fa fa-wrench"; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = nameArray.Contains(item.column) == true ? 1 : 0; tree.hasChildren = false; treeList.Add(tree); } return Content(treeList.TreeToJson()); } /// /// 数据库表字段列表 /// /// 库连接Id /// 表明 /// 返回列表Json [HttpGet] public ActionResult GetTableFiledListJson(string dataBaseLinkId, string tableName) { var data = dataBaseTableBLL.GetTableFiledList(dataBaseLinkId, tableName); return ToJsonResult(data); } /// /// 数据库表数据列表 /// /// 库连接Id /// 表明 /// 条件 /// 逻辑 /// 关键字 /// 分页参数 /// 返回列表Json [HttpGet] public ActionResult GetTableDataListJson(string dataBaseLinkId, string tableName, string switchWhere, string logic, string keyword, Pagination pagination) { var watch = CommonHelper.TimerStart(); var data = dataBaseTableBLL.GetTableDataList(dataBaseLinkId, tableName, switchWhere, logic, keyword, pagination); var JsonData = new { rows = data, total = pagination.total, page = pagination.page, records = pagination.records, costtime = CommonHelper.TimerEnd(watch) }; return ToJsonResult(JsonData); } #endregion #region 提交数据 /// /// 保存数据库表表单(新增、修改) /// /// 库连接Id /// 表名称 /// 表说明 /// 字段列表Json /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string dataBaseLinkId, string tableName, string tableDescription, string fieldListJson) { dataBaseTableBLL.SaveForm(dataBaseLinkId, tableName, tableDescription, fieldListJson); return Success("操作成功。"); } #endregion } }