public void ModifyColumn(object sender, ExecutedRoutedEventArgs e)
 {
     var menuItem = sender as MenuItem;
     if (menuItem == null) return;
     var menuInfo = menuItem.CommandParameter as MenuCommandParameters;
     if (menuInfo == null) return;
     try
     {
         using (IRepository repository = Helpers.DataConnectionHelper.CreateRepository(menuInfo.DatabaseInfo))
         {
             var generator = Helpers.DataConnectionHelper.CreateGenerator(repository, menuInfo.DatabaseInfo.DatabaseType);
             List<Column> columns = repository.GetAllColumns();
             var col = columns.SingleOrDefault(c => c.TableName == menuInfo.Description && c.ColumnName == menuInfo.Name);
             if (col == null)
             {
                 EnvDTEHelper.ShowError("Could not find the column in the table, has it been dropped?");
                 return;
             }
             TableBuilderDialog tbd = new TableBuilderDialog(menuInfo.Description, menuInfo.DatabaseInfo.DatabaseType);
             tbd.TableColumns = new List<Column> { col };
             tbd.Mode = 2;
             if (tbd.ShowModal() == true && tbd.TableColumns.Count == 1)
             {
                 generator.GenerateColumnAlterScript(tbd.TableColumns[0]);
                 var script = generator.GeneratedScript.ToString();
                 OpenSqlEditorToolWindow(menuInfo, script);
                 Helpers.DataConnectionHelper.LogUsage("TableBuildColumnEdit");
             }
         }
     }
     catch (Exception ex)
     {
         Helpers.DataConnectionHelper.SendError(ex, menuInfo.DatabaseInfo.DatabaseType);
     }
 }
 public void AddColumn(object sender, ExecutedRoutedEventArgs e)
 {
     var menuInfo = ValidateMenuInfo(sender);
     if (menuInfo == null) return;
     try
     {
         using (IRepository repository = Helpers.DataConnectionHelper.CreateRepository(menuInfo.DatabaseInfo))
         {
             TableBuilderDialog tbd = new TableBuilderDialog(menuInfo.Name, menuInfo.DatabaseInfo.DatabaseType);
             tbd.Mode = 1;
             if (tbd.ShowModal() == true && tbd.TableColumns.Count == 1)
             {
                 var generator = Helpers.DataConnectionHelper.CreateGenerator(repository, menuInfo.DatabaseInfo.DatabaseType);
                 generator.GenerateColumnAddScript(tbd.TableColumns[0]);
                 var script = generator.GeneratedScript.ToString();
                 OpenSqlEditorToolWindow(menuInfo, script);
                 Helpers.DataConnectionHelper.LogUsage("TableBuildColumnAdd");
             }
         }
     }
     catch (Exception ex)
     {
         Helpers.DataConnectionHelper.SendError(ex, menuInfo.DatabaseInfo.DatabaseType, false);
     }
 }
 public void BuildTable(object sender, ExecutedRoutedEventArgs e)
 {
     var databaseInfo = ValidateMenuInfo(sender);
     if (databaseInfo == null) return;
     try
     {
         using (IRepository repository = Helpers.DataConnectionHelper.CreateRepository(databaseInfo.DatabaseInfo))
         {
             var generator = Helpers.DataConnectionHelper.CreateGenerator(repository, databaseInfo.DatabaseInfo.DatabaseType);
             TableBuilderDialog tbd = new TableBuilderDialog(null, databaseInfo.DatabaseInfo.DatabaseType);
             if (tbd.ShowModal() == true)
             {
                 generator.GenerateTableCreate(tbd.TableName, tbd.TableColumns);
                 var script = generator.GeneratedScript.ToString();
                 if (databaseInfo.DatabaseInfo.DatabaseType == DatabaseType.SQLite)
                 {
                     script = script.Remove(script.Length - 6);
                     if (!string.IsNullOrEmpty(tbd.PkScript))
                     {
                         script += tbd.PkScript;
                     }
                     script += string.Format("{0});{1}", Environment.NewLine, Environment.NewLine);
                 }
                 else
                 {
                     if (!string.IsNullOrEmpty(tbd.PkScript))
                     {
                         script += tbd.PkScript;
                     }
                 }
                 SpawnSqlEditorWindow(databaseInfo.DatabaseInfo, script);
                 Helpers.DataConnectionHelper.LogUsage("TableBuild");
             }
         }
     }
     catch (Exception ex)
     {
         Helpers.DataConnectionHelper.SendError(ex, databaseInfo.DatabaseInfo.DatabaseType);
     }
 }