static ColumnModel() { ColumnModel.SetDataTypeSqlToDMSFrameColumnTypesDic(); ColumnModel.SetDataTypeSqlToCshapeDic(); }
/// <summary> /// 加载数据库结构 /// </summary> /// <param name="DBName">数据库名字</param> /// <param name="ConnStr">连接字符串</param> public void LoadDBSchema(string DBName, string ConnStr) { this.Name = DBName; this.connString = ConnStr; DataTable Dt = GetDBSchema(ConnStr); foreach (DataRow item in Dt.Rows) { string tableDescribe = item["表描述"].ToString(); string tableName = item["TableName"].ToString(); string num = item["序号"].ToString(); string columnName = item["列名"].ToString(); string columnDescribe = item["列说明"].ToString(); string dateType = item["数据类型"].ToString(); string typeLength = item["长度"].ToString(); string DecimalDigit = item["小数位数"].ToString(); string isIdentification = item["标识"].ToString(); string isPK = item["主键"].ToString(); string canNull = item["允许空"].ToString(); string defaultValue = item["默认值"].ToString(); ///创建列 ColumnModel column = new ColumnModel() { DBType = dateType, DBTypeLength = typeLength, DefaultValue = defaultValue, IsDBAutoIncrement = isIdentification == "1", Describe = columnDescribe, IsDBTypeNull = canNull == "1", IsPK = isPK == "1", Name = columnName }; if (column.DBType == "nchar" || column.DBType == "nvarchar") { int numLen = 0; if (int.TryParse(column.DBTypeLength, out numLen)) { column.DBTypeLength = (numLen / 2).ToString(); } } TableModel table = null; var tList = Tables.Where(w => w.Name == tableName).ToList(); if (tList.Count > 0) { table = tList[0]; } else { ////创建表 table = new TableModel() { Name = tableName, Describe = tableDescribe }; Tables.Add(table); } table.Columns.Add(column); } }