Beispiel #1
0
        private string OnFailedViewDefinitionHandler(ViewSchema vs)
        {
            string updated = null;

            Invoke(new MethodInvoker(() =>
            {
                var dlg          = new ViewFailureDialog();
                dlg.View         = vs;
                DialogResult res = dlg.ShowDialog(this);
                if (res == DialogResult.OK)
                {
                    updated = dlg.ViewSQL;
                }
                else
                {
                    updated = null;
                }
            }));
            return(updated);
        }
Beispiel #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string sqlConnString;

            if (cbxIntegrated.Checked)
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem);
            }
            else
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem, txtUserDB.Text, txtPassDB.Text);
            }
            bool createViews = cbxCreateViews.Checked;

            string sqlitePath = txtSQLitePath.Text.Trim();

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg) {
                Invoke(new MethodInvoker(delegate() {
                    UpdateSensitivity();
                    lblMessage.Text   = msg;
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        btnStart.Enabled = true;
                        this.Cursor      = Cursors.Default;
                        UpdateSensitivity();

                        if (success)
                        {
                            MessageBox.Show(this,
                                            msg,
                                            "Conversion Finished",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                            pbrProgress.Value = 0;
                            lblMessage.Text   = string.Empty;
                        }
                        else
                        {
                            if (!_shouldExit)
                            {
                                MessageBox.Show(this,
                                                msg,
                                                "Conversion Failed",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                pbrProgress.Value = 0;
                                lblMessage.Text   = string.Empty;
                            }
                            else
                            {
                                Application.Exit();
                            }
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                List <TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    // Allow the user to select which tables to include by showing him the
                    // table selection dialog.
                    TableSelectionDialog dlg = new TableSelectionDialog();
                    DialogResult res         = dlg.ShowTables(schema, this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.IncludedTables;
                    }
                }));
                return(updated);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View         = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.ViewSQL;
                    }
                    else
                    {
                        updated = null;
                    }
                }));

                return(updated);
            });

            string password = txtPassword.Text.Trim();

            if (!cbxEncrypt.Checked)
            {
                password = null;
            }
            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, cbxTriggers.Checked, createViews);
        }
Beispiel #3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
        	string sqlConnString;
        	if (cbxIntegrated.Checked) {
        		sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem);
        	} else {
        		sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem, txtUserDB.Text, txtPassDB.Text);
        	}
            bool createViews = cbxCreateViews.Checked;
        	
            string sqlitePath = txtSQLitePath.Text.Trim();
            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                bool success, int percent, string msg) {
                    Invoke(new MethodInvoker(delegate() {
                        UpdateSensitivity();
                        lblMessage.Text = msg;
                        pbrProgress.Value = percent;

                        if (done)
                        {
                            btnStart.Enabled = true;
                            this.Cursor = Cursors.Default;
                            UpdateSensitivity();

                            if (success)
                            {
                                MessageBox.Show(this,
                                    msg,
                                    "Conversion Finished",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                                pbrProgress.Value = 0;
                                lblMessage.Text = string.Empty;
                            }
                            else
                            {
                                if (!_shouldExit)
                                {
                                    MessageBox.Show(this,
                                        msg,
                                        "Conversion Failed",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                                    pbrProgress.Value = 0;
                                    lblMessage.Text = string.Empty;
                                }
                                else
                                    Application.Exit();
                            }
                        }
                    }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List<TableSchema> schema)
            {
                List<TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    // Allow the user to select which tables to include by showing him the 
                    // table selection dialog.
                    TableSelectionDialog dlg = new TableSelectionDialog();
                    DialogResult res = dlg.ShowTables(schema, this);
                    if (res == DialogResult.OK)
                        updated = dlg.IncludedTables;
                }));
                return updated;
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                        updated = dlg.ViewSQL;
                    else
                        updated = null;
                }));

                return updated;
            });

            string password = txtPassword.Text.Trim();
            if (!cbxEncrypt.Checked)
                password = null;
            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler, 
                selectionHandler, viewFailureHandler, cbxTriggers.Checked, createViews);
        }
Beispiel #4
0
 private string OnFailedViewDefinitionHandler(ViewSchema vs)
 {
     string updated = null;
     Invoke(new MethodInvoker(() =>
                              {
                                  var dlg = new ViewFailureDialog();
                                  dlg.View = vs;
                                  DialogResult res = dlg.ShowDialog(this);
                                  if (res == DialogResult.OK)
                                  {
                                      updated = dlg.ViewSQL;
                                  }
                                  else
                                  {
                                      updated = null;
                                  }
                              }));
     return updated;
 }
        private void Iniciar()
        {
            string sqlConnString;
            sqlConnString = this.txtSqlServer.Text;

            bool createViews = cbxCreateViews.Checked;

            string sqlitePath = txtSQLite.Text.Trim();
            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                bool success, int percent, string msg)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    UpdateSensitivity();
                    lblMessage.Text = msg;
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        btnStart.Enabled = true;
                        this.Cursor = Cursors.Default;
                        UpdateSensitivity();

                        if (success)
                        {
                            pbrProgress.Value = 0;
                            lblMessage.Text = string.Empty;
                            Application.Exit();
                        }
                        else
                        {
                            if (!_shouldExit)
                            {
                                MessageBox.Show(this,
                                    msg,
                                    "Conversion Failed",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                pbrProgress.Value = 0;
                                lblMessage.Text = string.Empty;
                            }
                            else
                                Application.Exit();
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List<TableSchema> schema)
            {
                List<TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    updated = schema;
                }));
                return updated;
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                        updated = dlg.ViewSQL;
                    else
                        updated = null;
                }));

                return updated;
            });

            string password = txtPassword.Text.Trim();
            if (!cbxEncrypt.Checked)
                password = null;
            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                selectionHandler, viewFailureHandler, cbxTriggers.Checked, createViews);
        }
Beispiel #6
0
        private void btnSQLiteSqlServer_Click(object sender, EventArgs e)
        {
            string tempFilePath  = string.Empty;
            string SqlServerPath = string.Empty;
            string sqlConnString;
            string dbname;

            string tempDirPath = Path.GetTempPath() + @"\SqlConverter";

            if (Directory.Exists(tempDirPath))
            {
                Directory.Delete(tempDirPath, true);
            }
            System.IO.Directory.CreateDirectory(tempDirPath);
            DirectoryInfo     tempDirInfo     = new DirectoryInfo(tempDirPath);
            DirectorySecurity tempDirSecurity = tempDirInfo.GetAccessControl();

            tempDirSecurity.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl, AccessControlType.Allow));
            tempDirInfo.SetAccessControl(tempDirSecurity);

            string SQLitePath = Path.GetFullPath(txtSQLitePath.Text);

            if (!File.Exists(SQLitePath))
            {
                MessageBox.Show("Input file " + SQLitePath + " not found.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (txtSqlServerPath.Text != string.Empty)
            {
                tempFilePath = Path.GetFullPath(tempDirPath + @"\" + Path.GetFileName(txtSqlServerPath.Text));

                SqlServerPath = Path.GetFullPath(txtSqlServerPath.Text);
                if (cboWhatToCopy.SelectedIndex == 2)       //  ie if we are copying into an existing database
                {
                    if (!File.Exists(SqlServerPath))
                    {
                        MessageBox.Show("Output file '" + SqlServerPath + "' not found.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    System.IO.File.Copy(SqlServerPath, tempFilePath);
                }
                else
                {
                    if (File.Exists(SqlServerPath))
                    {
                        DialogResult result = MessageBox.Show("Replace existing file '" + SqlServerPath + "'?", "Confirm replace file", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (result != DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                string constr;
                if (cbxIntegrated.Checked)
                {
                    constr = GetSqlServerConnectionString(txtSqlAddress.Text, "master");
                }
                else
                {
                    constr = GetSqlServerConnectionString(txtSqlAddress.Text, "master", txtUserDB.Text, txtPassDB.Text);
                }

                using (SqlConnection conn = new SqlConnection(constr))
                {
                    conn.Open();
                    string queryString = "CREATE DATABASE SqlConverter on (NAME=N'" + Path.GetFileNameWithoutExtension(txtSqlServerPath.Text) + "',FILENAME=N'" + tempFilePath + "')";
                    if (cboWhatToCopy.SelectedIndex == 2)       //  ie if we are copying into an existing database
                    {
                        queryString += " FOR ATTACH";
                    }

                    SqlCommand query = new SqlCommand(queryString, conn);
                    query.ExecuteNonQuery();
                    dbname = "SqlConverter";
                }
            }
            else
            {
                dbname = (string)cboDatabases.SelectedItem;
            }

            if (cbxIntegrated.Checked)
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, dbname);
            }
            else
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, dbname, txtUserDB.Text, txtPassDB.Text);
            }

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    UpdateSensitivity();
                    lblMessage.Text   = msg;
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        if (txtSqlServerPath.Text != string.Empty)
                        {
                            dropSqlConverterDatabase();
                            if (success)
                            {
                                System.IO.File.Copy(tempFilePath, SqlServerPath, true);
                            }
                            Directory.Delete(tempDirPath, true);
                        }
                        if (success)
                        {
                            MessageBox.Show(this,
                                            msg,
                                            "Conversion Finished",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                            pbrProgress.Value = 0;
                            lblMessage.Text   = string.Empty;
                        }
                        else
                        {
                            if (!_shouldExit)
                            {
                                MessageBox.Show(this,
                                                msg,
                                                "Conversion Failed",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                pbrProgress.Value = 0;
                                lblMessage.Text   = string.Empty;
                            }
                            else
                            {
                                Application.Exit();
                            }
                        }
                        btnSQLiteSqlServer.Enabled = true;
                        this.Cursor = Cursors.Default;
                        UpdateSensitivity();
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                List <TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    // Allow the user to select which tables to include by showing him the
                    // table selection dialog.
                    TableSelectionDialog dlg = new TableSelectionDialog();
                    DialogResult res         = dlg.ShowTables(schema, this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.IncludedTables;
                    }
                }));
                return(updated);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View         = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.ViewSQL;
                    }
                    else
                    {
                        updated = null;
                    }
                }));

                return(updated);
            });

            string password = txtPassword.Text.Trim();

            if (!cbxEncrypt.Checked)
            {
                password = null;
            }

            bool copyStructure = (cboWhatToCopy.SelectedIndex != 2);
            bool copyData      = (cboWhatToCopy.SelectedIndex != 1);

            SQLiteToSqlServer.ConvertSQLiteToSqlServerDatabase(sqlConnString, SQLitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, copyStructure, copyData);
        }
Beispiel #7
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string sqlConnString = GetSqlServerConnectionString();

            bool createViews = cbxCreateViews.Checked;

            string sqlitePath = txtSQLitePath.Text.Trim();
            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                bool success, int percent, string msg) {
                    Invoke(new MethodInvoker(delegate() {
                        UpdateSensitivity();
                        lblMessage.Text = msg;
                        pbrProgress.Value = percent;

                        if (done)
                        {
                            btnStart.Enabled = true;
                            this.Cursor = Cursors.Default;
                            UpdateSensitivity();

                            if (success)
                            {
                                MessageBox.Show(this,
                                    msg,
                                    "Conversion Finished",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                                pbrProgress.Value = 0;
                                lblMessage.Text = string.Empty;
                            }
                            else
                            {
                                if (!_shouldExit)
                                {
                                    MessageBox.Show(this,
                                        msg,
                                        "Conversion Failed",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                                    pbrProgress.Value = 0;
                                    lblMessage.Text = string.Empty;
                                }
                                else
                                    Application.Exit();
                            }
                        }
                    }));
            });
            //            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List<string> schema, List<int> numRows)
            //            {
            //                return IncludedTables;
            //            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                        updated = dlg.ViewSQL;
                    else
                        updated = null;
                }));

                return updated;
            });

            string password = txtPassword.Text.Trim();
            if (!cbxEncrypt.Checked) password = null;

            List<string> includedTables = new List<string>();
            List<string> existedTables = new List<string>();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                bool include = (bool)row.Cells[0].Value;
                if (include)
                {
                    includedTables.Add((string)row.Cells[1].Value);
                    if ((string)row.Cells[5].Value == "Existed") existedTables.Add((string)row.Cells[1].Value);
                }
            } // foreach

            OracleToSQLite.ConvertOracleToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                includedTables, existedTables, viewFailureHandler, cbxTriggers.Checked, createViews);
        }