void item_Click(object sender, EventArgs e)
        {
            try
            {
                string connectionString = Helper.FixConnectionString(this.Parent.Connection.ConnectionString, this.Parent.Connection.ConnectionTimeout);

                using (IRepository repository = new DBRepository(connectionString))
                {
                    using (RenameOptions ro = new RenameOptions(this.Parent.Name))
                    {
                        if (ro.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(ro.NewName))
                        {
                            repository.RenameTable(this.Parent.Name, ro.NewName);
                            RefreshTree();
                        }
                    }
                }
            }

            catch (System.Data.SqlServerCe.SqlCeException sqlCe)
            {
                Connect.ShowErrors(sqlCe);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        void item_Click(object sender, EventArgs e)
        {
            if (Connect.CurrentAddin == null)
            {
                return;
            }

            if (Connect.CurrentApplication == null)
            {
                return;
            }

            Connect.CurrentTable     = this.Parent.Name;
            Connect.ConnectionString = Helper.FixConnectionString(this.Parent.Connection.ConnectionString, this.Parent.Connection.ConnectionTimeout);

            try
            {
                if (!Connect.EditTracked)
                {
                    Connect.EditTracked = true;
                }

                Windows2 windows2 = Connect.CurrentApplication.Windows as Windows2;

                if (windows2 != null)
                {
                    object controlObject           = null;
                    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();

                    string dbName = System.IO.Path.GetFileNameWithoutExtension(this.Parent.Connection.ServerName);

                    EnvDTE.Window toolWindow = windows2.CreateToolWindow2(Connect.CurrentAddin,
                                                                          asm.Location,
                                                                          "SqlCeScripter.ResultsetGrid",
                                                                          string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1}", dbName, this.Parent.Name),
                                                                          "{" + Guid.NewGuid().ToString() + "}",
                                                                          ref controlObject);

                    if (toolWindow != null)
                    {
                        toolWindow.IsFloating = false;
                        toolWindow.Linkable   = false;
                        toolWindow.Visible    = true;
                    }
                }
            }

            catch (System.Data.SqlServerCe.SqlCeException sqlCe)
            {
                Connect.ShowErrors(sqlCe);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 3
0
 private void toolStripButton2_Click(object sender, EventArgs e)
 {
     try
     {
         LoadData();
     }
     catch (System.Data.SqlServerCe.SqlCeException sqlCe)
     {
         Connect.ShowErrors(sqlCe);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 4
0
        void item_Click(object sender, EventArgs e)
        {
            try
            {
                DataSource sqlDataSource = new DataSource("MicrosoftSqlServer", "Microsoft SQL Server");
                sqlDataSource.Providers.Add(DataProvider.SqlDataProvider);
                DataConnectionDialog dcd = new DataConnectionDialog();
                dcd.DataSources.Add(sqlDataSource);
                dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
                dcd.SelectedDataSource   = sqlDataSource;
                if (DataConnectionDialog.Show(dcd) == DialogResult.OK)
                {
                    string connectionString = dcd.ConnectionString;
                    string fileName;

                    ToolStripMenuItem item  = (ToolStripMenuItem)sender;
                    Scope             scope = (Scope)item.Tag;

                    SaveFileDialog fd = new SaveFileDialog();
                    fd.AutoUpgradeEnabled = true;
                    fd.Title           = "Save generated database script as";
                    fd.Filter          = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|";
                    fd.OverwritePrompt = true;
                    fd.ValidateNames   = true;
                    if (fd.ShowDialog() == DialogResult.OK)
                    {
                        fileName = fd.FileName;
                        using (IRepository repository = new ServerDBRepository(connectionString))
                        {
                            var generator = new Generator(repository, fd.FileName);
                            System.Windows.Forms.MessageBox.Show(generator.ScriptDatabaseToFile(scope));
                        }
                    }
                }
            }
            catch (System.Data.SqlClient.SqlException sql)
            {
                Connect.ShowErrors(sql);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 5
0
        private void ResultsetGrid_Load(object sender, EventArgs e)
        {
            this.isView    = Connect.ViewsSelected;
            this.tableName = Connect.CurrentTable;
            this.btnNewVersion.ForeColor = SystemColors.ControlText;
            this.btnNewVersion.Text      = "Check for updates";

            try
            {
                this.dataGridView1.AutoGenerateColumns = true;
                this.dataGridView1.DataError          += new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
                if (this.isView)
                {
                    this.toolStripButton1.Enabled = false;
                }
                else
                {
                    imageContext.Items.Add("Import Image", null, new EventHandler(ImportImage));
                    imageContext.Items.Add("Export Image", null, new EventHandler(ExportImage));
                    imageContext.Items.Add("Delete Image", null, new EventHandler(DeleteImage));
                }
                LoadData();

                this.dataGridView1.ClipboardCopyMode       = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
                this.dataGridView1.AllowUserToOrderColumns = true;

                this.dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown);
                dgs = new DataGridViewSearch(this.dataGridView1);
            }
            catch (System.Data.SqlServerCe.SqlCeException sqlCe)
            {
                Connect.ShowErrors(sqlCe);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 6
0
 /// <SUMMARY>
 /// Checks if there is a row with changes and
 /// writes it to the database
 /// </SUMMARY>
 private void UpdateRowToDatabase()
 {
     try
     {
         if (LastDataRow != null)
         {
             if (LastDataRow.RowState ==
                 DataRowState.Modified)
             {
                 DataRow[] rows = new DataRow[1];
                 rows[0] = LastDataRow;
                 dAdapter.Update(rows);
             }
         }
     }
     catch (System.Data.SqlServerCe.SqlCeException sqlCe)
     {
         Connect.ShowErrors(sqlCe);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 7
0
        void item_Click(object sender, EventArgs e)
        {
            string connectionString = Helper.FixConnectionString(this.Parent.Connection.ConnectionString, this.Parent.Connection.ConnectionTimeout);
            string fileName;

            ToolStripMenuItem item  = (ToolStripMenuItem)sender;
            Scope             scope = (Scope)item.Tag;

            SaveFileDialog fd = new SaveFileDialog();

            fd.AutoUpgradeEnabled = true;
            fd.Title           = "Save generated database script as";
            fd.Filter          = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|";
            fd.OverwritePrompt = true;
            fd.ValidateNames   = true;
            if (fd.ShowDialog() == DialogResult.OK)
            {
                fileName = fd.FileName;
                try
                {
                    using (IRepository repository = new DBRepository(connectionString))
                    {
                        var generator = new Generator(repository, fd.FileName);
                        System.Windows.Forms.MessageBox.Show(generator.ScriptDatabaseToFile(scope));
                    }
                }
                catch (System.Data.SqlServerCe.SqlCeException sqlCe)
                {
                    Connect.ShowErrors(sqlCe);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Ejemplo n.º 8
0
        void item_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            string fileName = string.Empty;

            Action action = (Action)item.OwnerItem.Tag;
            Output output = (Output)item.Tag;

            try
            {
                string connectionString = Helper.FixConnectionString(this.Parent.Connection.ConnectionString, this.Parent.Connection.ConnectionTimeout);
                using (IRepository repository = new DBRepository(connectionString))
                {
                    var generator = new Generator(repository);

                    switch (output)
                    {
                    case Output.Editor:
                        // create new document
                        ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.SqlCe);
                        break;

                    case Output.File:
                        SaveFileDialog fd = new SaveFileDialog();
                        fd.AutoUpgradeEnabled = true;
                        fd.Title           = "Save generated script as";
                        fd.Filter          = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|";
                        fd.OverwritePrompt = true;
                        fd.ValidateNames   = true;
                        if (fd.ShowDialog() == DialogResult.OK)
                        {
                            fileName = fd.FileName;
                        }
                        break;

                    default:
                        break;
                    }

                    switch (action)
                    {
                    case Action.Create:
                        generator.GenerateIndexScript(this.Parent.Parent.Name, this.Parent.Name);
                        break;

                    case Action.Drop:
                        generator.GenerateIndexDrop(this.Parent.Parent.Name, this.Parent.Name);
                        break;

                    case Action.DropAndCreate:
                        generator.GenerateIndexDrop(this.Parent.Parent.Name, this.Parent.Name);
                        generator.GenerateIndexScript(this.Parent.Parent.Name, this.Parent.Name);
                        break;

                    case Action.Statistics:
                        generator.GenerateIndexStatistics(this.Parent.Parent.Name, this.Parent.Name);
                        break;

                    default:
                        break;
                    }
                    switch (output)
                    {
                    case Output.Editor:
                        // insert SQL script to document
                        EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(null);
                        doc.EndPoint.CreateEditPoint().Insert(generator.GeneratedScript);
                        doc.DTE.ActiveDocument.Saved = true;
                        break;

                    case Output.File:
                        if (!string.IsNullOrEmpty(fileName))
                        {
                            System.IO.File.WriteAllText(fileName, generator.GeneratedScript);
                        }
                        break;

                    case Output.Clipboard:
                        Clipboard.Clear();
                        Clipboard.SetText(generator.GeneratedScript, TextDataFormat.UnicodeText);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (System.Data.SqlServerCe.SqlCeException sqlCe)
            {
                Connect.ShowErrors(sqlCe);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 9
0
        void item_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            string fileName = string.Empty;

            Action action = (Action)item.OwnerItem.Tag;
            Output output = (Output)item.Tag;

            try
            {
                string connectionString = Helper.FixConnectionString(this.Parent.Connection.ConnectionString, this.Parent.Connection.ConnectionTimeout);

                using (IRepository repository = new DBRepository(connectionString))
                {
                    var generator = new Generator(repository);

                    using (ImportOptions imo = new ImportOptions(this.Parent.Name))
                    {
                        imo.SampleHeader = generator.GenerateTableColumns(this.Parent.Name);
                        imo.Separator    = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToCharArray()[0];

                        if (imo.ShowDialog() == DialogResult.OK)
                        {
                            switch (output)
                            {
                            case Output.Editor:
                                // create new document
                                ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.SqlCe);
                                break;

                            case Output.File:
                                SaveFileDialog fd = new SaveFileDialog();
                                fd.AutoUpgradeEnabled = true;
                                fd.Title           = "Save generated database script as";
                                fd.Filter          = "SQL Server Compact Script (*.sqlce)|*.sqlce|SQL Server Script (*.sql)|*.sql|All Files(*.*)|";
                                fd.OverwritePrompt = true;
                                fd.ValidateNames   = true;
                                if (fd.ShowDialog() == DialogResult.OK)
                                {
                                    fileName = fd.FileName;
                                }
                                break;

                            default:
                                break;
                            }

                            switch (action)
                            {
                            case Action.Csv:
                                using (var reader = new CsvReader(imo.FileName))
                                {
                                    reader.ValueSeparator = imo.Separator;
                                    HeaderRecord hr = reader.ReadHeaderRecord();
                                    if (generator.ValidColumns(this.Parent.Name, hr.Values))
                                    {
                                        foreach (DataRecord record in reader.DataRecords)
                                        {
                                            generator.GenerateTableInsert(this.Parent.Name, hr.Values, record.Values);
                                        }
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                            switch (output)
                            {
                            case Output.Editor:
                                // insert SQL script to document
                                EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(null);
                                doc.EndPoint.CreateEditPoint().Insert(generator.GeneratedScript);
                                doc.DTE.ActiveDocument.Saved = true;
                                break;

                            case Output.File:
                                if (!string.IsNullOrEmpty(fileName))
                                {
                                    System.IO.File.WriteAllText(fileName, generator.GeneratedScript);
                                }
                                break;

                            case Output.Clipboard:
                                Clipboard.Clear();
                                Clipboard.SetText(generator.GeneratedScript, TextDataFormat.UnicodeText);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }

            catch (System.Data.SqlServerCe.SqlCeException sqlCe)
            {
                Connect.ShowErrors(sqlCe);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }