using ce.autofac.extension; using learun.iapplication; using learun.util; using System.Collections.Generic; using System.Data; using System.Threading.Tasks; namespace learun.application { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.09.19 /// 描 述:数据库表管理 /// public class DatabaseTableBLL : BLLBase, DatabaseTableIBLL, BLL { #region 属性 private readonly DatabaseTableService databaseTableService = new DatabaseTableService(); private readonly DatabaseLinkIBLL _databaseLinkIBLL; #endregion 属性 /// /// /// /// public DatabaseTableBLL(DatabaseLinkIBLL databaseLinkIBLL) { _databaseLinkIBLL = databaseLinkIBLL; } #region 获取数据 /// /// 数据表列表 /// /// 数据库编码 /// 表名 /// public async Task> GetTableList(string code, string tableName = "") { List list = (List)await databaseTableService.GetTableList(code); if (!string.IsNullOrEmpty(tableName)) { list = list.FindAll(t => t.name == tableName); } return list; } /// /// 获取树形数据 /// /// 数据库编码 /// public async Task> GetTreeList(string code) { List list; if (string.IsNullOrEmpty(code)) { list = (List)await _databaseLinkIBLL.GetTreeListEx(); } else { list = new List(); List databaseTableList = (List)await GetTableList(code); foreach (var item in databaseTableList) { TreeModel node = new TreeModel(); node.id = code + item.name; node.text = item.name; node.value = code; node.title = item.tdescription; node.complete = true; node.isexpand = false; node.hasChildren = false; list.Add(node); } } return list; } /// /// 数据表字段列表 /// /// 数据库编码 /// 表名 /// public Task> GetTableFiledList(string code, string tableName) { return databaseTableService.GetTableFiledList(code, tableName); } /// /// 获取数据表字段树形数据 /// /// 数据库编码 /// 表名 /// public async Task> GetFiledTreeList(string code, string tableName) { var list = await GetTableFiledList(code, tableName); List treeList = new List(); foreach (var item in list) { TreeModel node = new TreeModel(); node.id = item.f_column; node.text = item.f_column; node.value = item.f_column; node.title = item.f_remark; node.complete = true; node.isexpand = false; node.hasChildren = false; node.showcheck = true; treeList.Add(node); } return treeList; } /// /// 数据库表数据列表 /// /// 数据库编码 /// 表名 /// 字段 /// 逻辑 /// 关键字 /// 分页参数 /// public Task GetTableDataList(string code, string tableName, string field, string logic, string keyword, Pagination pagination) { return databaseTableService.GetTableDataList(code, tableName, field, logic, keyword, pagination); } /// /// 数据库表数据列表 /// /// 数据库编码 /// 表名 /// public Task GetTableDataList(string code, string tableName) { return databaseTableService.GetTableDataList(code, tableName); } /// /// 给定查询语句查询字段 /// /// 数据库编码 /// 表名 /// public Task> GetSqlColName(string code, string strSql) { return databaseTableService.GetSqlColName(code, strSql); } #endregion 获取数据 #region 提交数据 /// /// 创建数据库表 /// /// 数据库编码 /// 编码 /// 表备注 /// 字段列表 /// public Task CreateTable(string code, string tableName, string tableRemark, List colList) { return databaseTableService.CreateTable(code, tableName, tableRemark, colList); } #endregion 提交数据 #region 扩展方法 /// /// C#实体数据类型 /// /// 数据库字段类型 /// public string FindModelsType(string datatype) { string res = ""; datatype = datatype.ToLower(); switch (datatype) { case "int": case "number": case "integer": case "smallint": res = "int?"; break; case "tinyint": res = "byte?"; break; case "numeric": case "real": case "decimal": case "number(8,2)": case "money": case "smallmoney": res = "decimal?"; break; case "float": res = "float?"; break; case "char": case "varchar": case "nvarchar2": case "text": case "nchar": case "nvarchar": case "ntext": res = "string"; break; case "bit": res = "bool?"; break; case "datetime2": case "datetime": case "date": case "smalldatetime": res = "DateTime?"; break; default: res = "string"; break; } if (datatype.Contains("number(")) { res = "decimal?"; } return res; } /// /// 判断数据表字段重复 /// /// 主键值 /// 表名 /// 主键名 /// 数据字段 /// public Task ExistFiled(string keyValue, string tableName, string keyName, string filedsJson) { return databaseTableService.ExistFiled(keyValue, tableName, keyName, filedsJson); } #endregion 扩展方法 } }