Beispiel #1
0
        private IList <PdmTableInfoModel> GetTables(List <string> tableNames)
        {
            List <PdmTableInfoModel> list = new List <PdmTableInfoModel>();

            foreach (var item in tableNames)
            {
                string tableName, tableDescription;
                List <DbTableColumnSchema> dbColumnList = DbSchemaBLL.GetDbTableColumnSchema(item, sqlconnection, out tableName, out tableDescription);
                if (dbColumnList == null)
                {
                    throw new Exception("table {0} 不存在,请确认表名及数据库名是否正确!".Formats(item));
                }
                PdmTableInfoModel tbmodel = new PdmTableInfoModel()
                {
                    Code = tableName, Comment = tableDescription, Name = tableDescription
                };
                dbColumnList.ForEach(p =>
                {
                    PdmColumnInfoModel pcim = new PdmColumnInfoModel(tbmodel);
                    pcim.Code     = p.columnName;
                    pcim.Comment  = p.Description;
                    pcim.DataType = GetDataType(p);
                    pcim.ColumnId = p.columnName;
                    if (p.isPrimarykey == 1)
                    {
                        var keymodel = new PdmKeyModel(tbmodel)
                        {
                            KeyId = p.columnName
                        };
                        keymodel.AddColumnObjCode(p.columnName);
                        tbmodel.Keys.Add(keymodel);
                        tbmodel.PrimaryKeyRefCode = p.columnName;
                    }
                    pcim.Identity  = p.isIdentity == 1;
                    pcim.Mandatory = p.isAllowNull == 1;
                    tbmodel.Columns.Add(pcim);
                });
                list.Add(tbmodel);
            }
            return(list);
        }
        /// <summary>
        /// 表过滤
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFilterDb_Click(object sender, RoutedEventArgs e)
        {
            string sqlconnection = getSqlConnection();
            var    tableList     = DbSchemaBLL.GetDbTablesList(this.txtDbLikeName.Text.Trim(), getSqlConnection());

            if (tableList.Count == 0)
            {
                MessageBox.Show("未查询到符合条件的表!");
                return;
            }
            dbExclueList.Clear();
            foreach (var table in tableList)
            {
                table.sqlconnection = sqlconnection;
                if (this.dbInclueList.FirstOrDefault(p => p.Name == table.Name) != null)
                {
                    table.IsChecked = true;
                }
                dbExclueList.Add(table);
            }
        }