GetTableNames() public static method

public static GetTableNames ( IDbConnection connection ) : List
connection IDbConnection
return List
Esempio n. 1
0
        private void ConnectionsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this._tables.Clear();

            if (this.ConnectionsCombo.SelectedItem != null)
            {
                var conn = (GeneratorConfig.Connection) this.ConnectionsCombo.SelectedItem;

                try
                {
                    using (var connection = SqlConnections.New(conn.ConnectionString, conn.ProviderName))
                    {
                        connection.Open();

                        foreach (var t in SqlSchemaInfo.GetTableNames(connection))
                        {
                            _tables.Add(((t.Item1 != null) ? (t.Item1 + ".") : "") + t.Item2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Esempio n. 2
0
        private void ConnectionsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this._tables.Clear();

            if (this.ConnectionsCombo.SelectedItem != null)
            {
                string connStr = (string)this.ConnectionsCombo.SelectedItem;

                try
                {
                    using (var connection = CreateConnection(connStr))
                    {
                        connection.Open();

                        foreach (var t in SqlSchemaInfo.GetTableNames(connection))
                        {
                            _tables.Add(((t.Item1 != null && t.Item1 != "dbo") ? (t.Item1 + ".") : "") + t.Item2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Esempio n. 3
0
        private void ConnectionsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this._tables.Clear();
            GenerateCodeButton.IsEnabled = false;

            if (this.ConnectionsCombo.SelectedItem != null)
            {
                var conn = (GeneratorConfig.Connection) this.ConnectionsCombo.SelectedItem;

                try
                {
                    using (var connection = SqlConnections.New(conn.ConnectionString, conn.ProviderName))
                    {
                        connection.Open();

                        foreach (var t in SqlSchemaInfo.GetTableNames(connection))
                        {
                            var table = conn != null?conn.Tables.FirstOrDefault(x => x.Tablename == t.Tablename) : null;

                            var identifier = (table == null || table.Identifier.IsEmptyOrNull()) ?
                                             RowGenerator.ClassNameFromTableName(t.Table) : table.Identifier;
                            var permission    = table == null ? "Administration:General" : table.PermissionKey;
                            var connectionKey = (table != null && !table.ConnectionKey.IsEmptyOrNull()) ?
                                                table.ConnectionKey : conn.Key;

                            var module = (table != null && table.Module != null) ? table.Module :
                                         Inflector.Inflector.Capitalize(connectionKey);

                            var tableItem = new TableItem
                            {
                                IsChecked     = false,
                                ConnectionKey = conn.Key,
                                Module        = module,
                                Identifier    = identifier,
                                PermissionKey = permission,
                                FullName      = t.Tablename
                            };

                            _tables.Add(tableItem);
                            tableItem.PropertyChanged += (s, e2) =>
                            {
                                var t2 = conn.Tables.FirstOrDefault(x => x.Tablename == tableItem.FullName);
                                if (t2 == null)
                                {
                                    t2           = new GeneratorConfig.Table();
                                    t2.Tablename = tableItem.FullName;
                                    conn.Tables.Add(t2);
                                }
                                t2.Identifier    = tableItem.Identifier;
                                t2.Module        = tableItem.Module;
                                t2.ConnectionKey = tableItem.ConnectionKey;
                                t2.PermissionKey = tableItem.PermissionKey;
                                this.config.Save();

                                GenerateCodeButton.IsEnabled = _tables.Any(x => x.IsChecked);
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }