private List <TableSchema> OnSqlTableSelectionHandler(List <TableSchema> schema) { var config = _manager.CurrentConfiguration; if (config.SelectedTables.Count == 0) { List <TableSchema> updated = null; Invoke(new MethodInvoker(delegate { // Allow the user to select which tables to include by showing him the table selection dialog. var dlg = new TableSelectionDialog(); DialogResult res = dlg.ShowTables(schema, this); if (res == DialogResult.OK) { updated = dlg.IncludedTables; } })); List <String> selectedTables = updated.Select(obj => obj.TableName).ToList(); config.SelectedTables = selectedTables; return(updated); } else { List <TableSchema> tablesMatchingSavedList = new List <TableSchema>(); foreach (var tableSchema in schema) { if (config.SelectedTables.Contains(tableSchema.TableName)) { tablesMatchingSavedList.Add(tableSchema); } } return(tablesMatchingSavedList); } }
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); }
private List<TableSchema> OnSqlTableSelectionHandler(List<TableSchema> schema) { var config = _manager.CurrentConfiguration; if (config.SelectedTables.Count == 0) { List<TableSchema> updated = null; Invoke(new MethodInvoker(delegate { // Allow the user to select which tables to include by showing him the table selection dialog. var dlg = new TableSelectionDialog(); DialogResult res = dlg.ShowTables(schema, this); if (res == DialogResult.OK) { updated = dlg.IncludedTables; } })); List<String> selectedTables = updated.Select(obj => obj.TableName).ToList(); config.SelectedTables = selectedTables; return updated; } else { List<TableSchema> tablesMatchingSavedList = new List<TableSchema>(); foreach (var tableSchema in schema) { if (config.SelectedTables.Contains(tableSchema.TableName)) { tablesMatchingSavedList.Add(tableSchema); } } return tablesMatchingSavedList; } }
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); }
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); }