private void selectTableToolStripMenuItem_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TableInformation.ServerName?.Trim() ?? TableInformation.ServerName)) { System.Media.SystemSounds.Asterisk.Play(); connectToDatabaseToolStripMenuItem_Click(null, null); return; } var form = new SelectTableForm { ServerName = TableInformation.ServerName, DataBase = TableInformation.Database, TableName = TableInformation.Tablename }; var result = form.ShowDialog(this); if (result == DialogResult.OK) { using (new WaitCursor()) { TableInformation.Database = form.DataBase; TableInformation.Tablename = form.TableName; Text = $@"DataGenerator - {TableInformation.ServerName}\{form.DataBase}\{TableInformation.Tablename}"; TableInformation.Columns = Dal.Instance.GetTableInformation(TableInformation.Tablename); LoadColums(TableInformation.Columns); TableInformation.Table = Dal.Instance.GetTable(TableInformation.Tablename); tableDataGridView.DataBindingComplete += OnDataBindingComplete; tableDataGridView.DataSource = TableInformation.Table; } } }
private static void AddListViewItem(SelectTableForm selectTableForm, EntitiesGenerator.Definitions.DataTable dataTable, int imageIndex) { ListViewItem item = new ListViewItem(); item.Text = dataTable.SourceName; item.Tag = dataTable; item.ImageIndex = imageIndex; item.Checked = true; selectTableForm.AddListViewItem(item); }
public EntitiesGenerator.Definitions.Definition ReadDatabase(string databaseType, string connectionString) { try { string dbSchemaProviderName = SQLSERVER2005_PROVIDER_NAME; switch (databaseType) { case "SQL Server": { dbSchemaProviderName = SQLSERVER_PROVIDER_NAME; break; } case "SQL Server 2005": { dbSchemaProviderName = SQLSERVER2005_PROVIDER_NAME; break; } case "Oracle": { dbSchemaProviderName = ORACLE_PROVIDER_NAME; break; } case "Oracle DataAccess": { dbSchemaProviderName = ORACLE_DATAACCESS_PROVIDER_NAME; break; } case "MySQL": { dbSchemaProviderName = MYSQL_PROVIDER_NAME; break; } case "SqlCe": { dbSchemaProviderName = SQLCE_PROVIDER_NAME; break; } } DBSchemaProvider dbSchemaProvider = GetDBSchemaProvider(dbSchemaProviderName); DatabaseSchema schema = new DatabaseSchema(dbSchemaProvider, connectionString); if (dbSchemaProvider != null) { EntitiesGenerator.Definitions.Definition definition = new EntitiesGenerator.Definitions.Definition(); SelectTableForm selectTableForm = new SelectTableForm(); string databaseName = dbSchemaProvider.GetDatabaseName(schema); TableSchemaCollection allTables = dbSchemaProvider.GetTables(schema, databaseName); if (allTables != null) { foreach (TableSchema table in allTables) { EntitiesGenerator.Definitions.DataTable dataTable = new EntitiesGenerator.Definitions.DataTable(); if (AutoApplyNamingConvention) { dataTable.TableName = GetConventionName(table.Name); } else { dataTable.TableName = table.Name; } dataTable.SourceName = table.Name; if (table.Columns != null) { foreach (ColumnSchema column in table.Columns) { EntitiesGenerator.Definitions.DataColumn dataColumn = new EntitiesGenerator.Definitions.DataColumn(); if (AutoApplyNamingConvention) { dataColumn.ColumnName = GetConventionName(column.Name); } else { dataColumn.ColumnName = column.Name; } dataColumn.SourceName = column.Name; dataColumn.DataType = GetDataColumnDataType(column); dataColumn.Type = GetDataColumnType(dataColumn, column); dataColumn.AllowDBNull = column.AllowDBNull; dataColumn.PrimaryKey = column.IsPrimaryKeyMember; dataColumn.Length = GetDataColumnLength(column); dataTable.Columns.Add(dataColumn); } } AddListViewItem(selectTableForm, dataTable, 0); //definition.Tables.Add(dataTable); } } try { ViewSchemaCollection allViews = dbSchemaProvider.GetViews(schema); if (allViews != null) { foreach (ViewSchema view in allViews) { EntitiesGenerator.Definitions.DataTable dataTable = new EntitiesGenerator.Definitions.DataTable(); dataTable.TableName = view.Name; dataTable.SourceName = view.Name; if (view.Columns != null) { foreach (ViewColumnSchema column in view.Columns) { EntitiesGenerator.Definitions.DataColumn dataColumn = new EntitiesGenerator.Definitions.DataColumn(); dataColumn.ColumnName = column.Name; dataColumn.SourceName = column.Name; dataColumn.DataType = GetDataColumnDataType(column); dataColumn.Type = GetDataColumnType(dataColumn, column); dataColumn.AllowDBNull = column.AllowDBNull; dataColumn.Length = GetDataColumnLength(column); dataTable.Columns.Add(dataColumn); } } AddListViewItem(selectTableForm, dataTable, 1); //definition.Tables.Add(dataTable); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (selectTableForm.ShowDialog() == DialogResult.OK) { System.Windows.Forms.ListView.CheckedListViewItemCollection checkedItems = selectTableForm.GetCheckedItems(); foreach (ListViewItem item in checkedItems) { definition.Tables.Add(item.Tag as EntitiesGenerator.Definitions.DataTable); } string message = "Do you want to apply Naming Convention to Table Name(s) and Column Name(s)?"; if (MessageBox.Show(message, "Naming Convention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { foreach (EntitiesGenerator.Definitions.DataTable dataTable in definition.Tables) { dataTable.TableName = GetConventionName(dataTable.TableName); foreach (EntitiesGenerator.Definitions.DataColumn dataColumn in dataTable.Columns) { dataColumn.ColumnName = GetConventionName(dataColumn.ColumnName); } } } } return definition; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); // TODO: return null; } return null; }