private void OpenSelectDataSourceDialog() { bool formNeedsRefresh = false; ComboBoxItem selectedPlugIn = cmbDataSourcePlugIns.SelectedItem as ComboBoxItem; if (selectedPlugIn == null) { throw new GeneralException("No data source plug-in is selected in combo box."); } if (selectedPlugIn.Key == null) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = SharedStrings.SELECT_DATA_SOURCE; openFileDialog.Filter = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj"; openFileDialog.InitialDirectory = config.Directories.Project; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { string filePath = openFileDialog.FileName.Trim(); if (System.IO.File.Exists(filePath)) { try { selectedDataSource = new Project(filePath); formNeedsRefresh = true; } catch (System.Security.Cryptography.CryptographicException ex) { MsgBox.ShowError(string.Format(SharedStrings.ERROR_CRYPTO_KEYS, ex.Message)); return; } catch (Exception ex) { MsgBox.ShowError(SharedStrings.CANNOT_OPEN_PROJECT_FILE + "\n\nError details: " + ex.Message); return; } } } } else { IDbDriverFactory dbFactory = null; selectedDataProvider = selectedPlugIn.Key; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(selectedPlugIn.Key); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); if (!string.IsNullOrEmpty(savedConnectionStringDescription)) { int splitIndex = savedConnectionStringDescription.IndexOf("::"); if (splitIndex > -1) { string serverName = savedConnectionStringDescription.Substring(0, splitIndex); string databaseName = savedConnectionStringDescription.Substring(splitIndex + 2, savedConnectionStringDescription.Length - splitIndex - 2); dialog.SetDatabaseName(databaseName); dialog.SetServerName(serverName); } } DialogResult result = ((Form)dialog).ShowDialog(); // dialog.UseManagerService if (result == DialogResult.OK && dialog.DbConnectionStringBuilder != null) { this.savedConnectionStringDescription = dialog.ConnectionStringDescription; bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; formNeedsRefresh = true; } else { this.selectedDataSource = null; } } else { if (selectedPlugIn.Text == "Epi Info Web & Cloud Services") { } else { this.selectedDataSource = null; } } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } } if (formNeedsRefresh) { RefreshForm(); } }
private void OpenSelectDataSourceDialog() { ComboBoxItem selectedPlugIn = cmbDataSourcePlugIns.SelectedItem as ComboBoxItem; if (selectedPlugIn == null) { throw new GeneralException("No data source plug-in is selected in combo box."); } if (selectedPlugIn.Key == null) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = SharedStrings.SELECT_DATA_SOURCE; openFileDialog.Filter = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { string filePath = openFileDialog.FileName.Trim(); if (System.IO.File.Exists(filePath)) { try { selectedDataSource = new Project(filePath); } catch (Exception ex) { MessageBox.Show("Could not load project: \n\n" + ex.Message); return; } } } } else { IDbDriverFactory dbFactory = null; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(selectedPlugIn.Key); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); DialogResult result = ((Form)dialog).ShowDialog(); if (result == DialogResult.OK) { bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; } else { this.selectedDataSource = null; } } else { this.selectedDataSource = null; } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } } RefreshForm(); }
private void btnGetFile_Click(object sender, System.EventArgs e) { ComboBoxItem selectedPlugIn = cmbOutputFormat.SelectedItem as ComboBoxItem; if (selectedPlugIn == null) { throw new GeneralException("No data source plug-in is selected in combo box."); } if (selectedPlugIn.Key == null) // default project { OpenFileDialog dlg = new OpenFileDialog(); if (cmbOutputFormat.Text == "Text" || cmbOutputFormat.Text.ToUpperInvariant() == "FLAT ASCII FILE") { dlg.Filter = "Text Files (*.txt) |*.txt"; } else { dlg.Filter = "Database Files (*.mdb) |*.mdb"; } dlg.CheckFileExists = false; dlg.CheckPathExists = false; if (dlg.ShowDialog() == DialogResult.OK) { if (cmbOutputFormat.Text.ToUpperInvariant() == "TEXT" || cmbOutputFormat.Text.ToUpperInvariant() == "FLAT ASCII FILE") { if (!dlg.FileName.EndsWith(".txt") && dlg.FileName.EndsWith(".csv")) { txtFileName.Text = dlg.FileName + ".csv"; } else { txtFileName.Text = dlg.FileName; } } else { txtFileName.Text = dlg.FileName; } } } else { IDbDriverFactory dbFactory = null; switch (selectedPlugIn.Key) { case "Epi.Data.SqlServer.SqlDBFactory, Epi.Data.SqlServer": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.SqlDriver); break; case "Epi.Data.MySQL.MySQLDBFactory, Epi.Data.MySQL": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.MySQLDriver); break; case "Epi.Data.Office.AccessDBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); break; case "Epi.Data.Office.ExcelWBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.ExcelDriver); break; case "Epi.Data.Office.Access2007DBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Access2007Driver); break; case "Epi.Data.Office.Excel2007WBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Excel2007Driver); break; case "Epi.Data.Office.CsvFileFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.CsvDriver); break; case "Epi.Data.PostgreSQL.PostgreSQLDBFactory, Epi.Data.PostgreSQL": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.PostgreSQLDriver); break; default: dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); break; } DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); dialog.ShouldIgnoreNonExistance = true; DialogResult result = ((Form)dialog).ShowDialog(); if (result == DialogResult.OK) { bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); txtFileName.Text = db.ConnectionString; try { success = db.TestConnection(); } catch { success = false; //MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; } else { this.selectedDataSource = null; } } else { this.selectedDataSource = null; } } if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; //this.txtDataSource.Text = db.ConnectionString; System.Collections.Generic.List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ComboBoxItem newItem = null; if (tableName.EndsWith("$") & (selectedPlugIn.Key == "Epi.Data.Office.ExcelWBFactory, Epi.Data.Office") || (selectedPlugIn.Key == "Epi.Data.Office.Excel2007WBFactory, Epi.Data.Office")) { newItem = new ComboBoxItem(tableName.Remove(tableName.Length - 1), tableName.Remove(tableName.Length - 1), tableName); } else { newItem = new ComboBoxItem(tableName, tableName, tableName); } this.cmbDataTable.Items.Add(newItem); } } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; //txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName; foreach (string s in project.GetViewNames()) { ComboBoxItem newItem = new ComboBoxItem(s, s, s); this.cmbDataTable.Items.Add(newItem); } } }
private void OpenSelectDataSourceDialog() { ComboBoxItem selectedPlugIn = cmbDataFormats.SelectedItem as ComboBoxItem; if (selectedPlugIn == null) { throw new GeneralException("No data source plug-in is selected in combo box."); } if (selectedPlugIn.Key == null) // default project { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = SharedStrings.SELECT_DATA_SOURCE; openFileDialog.Filter = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { string filePath = openFileDialog.FileName.Trim(); if (System.IO.File.Exists(filePath)) { try { selectedDataSource = new Project(filePath); } catch (Exception ex) { MessageBox.Show("Could not load project: \n\n" + ex.Message); return; } } } } else { IDbDriverFactory dbFactory = null; switch (selectedPlugIn.Key) { case "Epi.Data.SqlServer.SqlDBFactory, Epi.Data.SqlServer": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.SqlDriver); break; case "Epi.Data.MySQL.MySQLDBFactory, Epi.Data.MySQL": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.MySQLDriver); break; case "Epi.Data.Office.AccessDBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); break; case "Epi.Data.Office.ExcelWBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.ExcelDriver); break; case "Epi.Data.Office.Excel2007WBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Excel2007Driver); break; case "Epi.Data.Office.Access2007DBFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Access2007Driver); break; case "Epi.Data.Office.CsvFileFactory, Epi.Data.Office": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.CsvDriver); break; case "Epi.Data.PostgreSQL.PostgreSQLDBFactory, Epi.Data.PostgreSQL": dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.PostgreSQLDriver); break; default: dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); break; } DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); DialogResult result = ((Form)dialog).ShowDialog(); if (result == DialogResult.OK) { bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); txtFileName.Text = db.ConnectionDescription; try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; } else { this.selectedDataSource = null; } } else { this.selectedDataSource = null; } } LoadTables(); }
private void btnConnectionBrowse_Click(object sender, RoutedEventArgs e) { if (cmbDatabaseType.SelectedIndex >= 0) { ComboBoxItem item = cmbDatabaseType.SelectedItem as ComboBoxItem; switch (item.Text) { case "Epi Info 7 Project": System.Windows.Forms.OpenFileDialog projectDialog = new System.Windows.Forms.OpenFileDialog(); projectDialog.InitialDirectory = config.Directories.Project; projectDialog.Filter = "Epi Info 7 Project File|*.prj"; System.Windows.Forms.DialogResult projectDialogResult = projectDialog.ShowDialog(); if (projectDialogResult == System.Windows.Forms.DialogResult.OK) { try { Project project = new Project(projectDialog.FileName); LoadFormsFromProject(project); } catch (System.Security.Cryptography.CryptographicException ex) { Dialogs.MsgBox.ShowError(string.Format(SharedStrings.ERROR_CRYPTO_KEYS, ex)); return; } } else { return; } break; default: IDbDriverFactory dbFactory = null; selectedDataProvider = item.Key; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(item.Key); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); if (!string.IsNullOrEmpty(savedConnectionStringDescription)) { int splitIndex = savedConnectionStringDescription.IndexOf("::"); if (splitIndex > -1) { string serverName = savedConnectionStringDescription.Substring(0, splitIndex); string databaseName = savedConnectionStringDescription.Substring(splitIndex + 2, savedConnectionStringDescription.Length - splitIndex - 2); dialog.SetDatabaseName(databaseName); dialog.SetServerName(serverName); } } System.Windows.Forms.DialogResult result = ((System.Windows.Forms.Form)dialog).ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { this.savedConnectionStringDescription = dialog.ConnectionStringDescription; bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; LoadTablesFromDatabase(db); //formNeedsRefresh = true; } else { this.selectedDataSource = null; } } else { this.selectedDataSource = null; } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } break; } } }
private void SetupOutputDataSource() { try { ComboBoxItem selectedPlugIn = cmbDataFormats.SelectedItem as ComboBoxItem; IDbDriverFactory dbFactory = null; string plugin = string.Empty; foreach (Epi.DataSets.Config.DataDriverRow row in dashboardHelper.Config.DataDrivers) { if (row.Type == Configuration.PostgreSQLDriver || row.Type == Configuration.MySQLDriver) { continue; } string content = selectedPlugIn.Content.ToString(); if (content.Equals(row.DisplayName)) { plugin = row.Type; } } selectedDataProvider = plugin; bool isFlatFile = false; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(plugin); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); dialog.ShouldIgnoreNonExistance = true; System.Windows.Forms.DialogResult result = ((System.Windows.Forms.Form)dialog).ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { //this.savedConnectionStringDescription = dialog.ConnectionStringDescription; bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); DbDriverInfo dbInfo = new DbDriverInfo(); dbInfo.DBCnnStringBuilder = dbFactory.RequestNewConnection(db.DataSource); if (db.ConnectionDescription.ToLowerInvariant().Contains("csv file:")) { isFlatFile = true; } if (!isFlatFile) { if (!db.CheckDatabaseExistance(db.ConnectionString, "", true)) { dbFactory.CreatePhysicalDatabase(dbInfo); } try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } } else { success = true; } if (success) { this.SelectedDataSource = db; controlNeedsRefresh = true; txtConnectionInformation.Text = db.ConnectionString; } else { this.SelectedDataSource = null; } } else { this.SelectedDataSource = null; } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } if (selectedDataSource is IDbDriver) { db = selectedDataSource as IDbDriver; //this.txtDataSource.Text = db.ConnectionString; if (!isFlatFile) { System.Collections.Generic.List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ComboBoxItem newItem = new ComboBoxItem();//tableName, tableName, tableName); newItem.Content = tableName; cmbDestinationTable.Items.Add(tableName); //this.cmbDataTable.Items.Add(newItem); } } } } catch (Exception ex) { SetErrorMessage(ex.Message); } finally { pnlProgress.Visibility = System.Windows.Visibility.Collapsed; } }
private void SetupOutputDataSource() { ComboBoxItem selectedPlugIn = cmbSourceDataFormat.SelectedItem as ComboBoxItem; IDbDriverFactory dbFactory = null; string plugin = string.Empty; foreach (Epi.DataSets.Config.DataDriverRow row in dashboardHelper.Config.DataDrivers) { string content = selectedPlugIn.Content.ToString(); if (content.Equals(row.DisplayName)) { plugin = row.Type; } } selectedDataProvider = plugin; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(plugin); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); dialog.ShouldIgnoreNonExistance = true; System.Windows.Forms.DialogResult result = ((System.Windows.Forms.Form)dialog).ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { //this.savedConnectionStringDescription = dialog.ConnectionStringDescription; bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.SelectedDataSource = db; controlNeedsRefresh = true; txtConnectionInformation.Text = db.ConnectionString; } else { this.SelectedDataSource = null; } } else { this.SelectedDataSource = null; } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } if (selectedDataSource is IDbDriver) { db = selectedDataSource as IDbDriver; //this.txtDataSource.Text = db.ConnectionString; System.Collections.Generic.List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ComboBoxItem newItem = new ComboBoxItem();//tableName, tableName, tableName); newItem.Content = tableName; cmbSourceTable.Items.Add(tableName); //this.cmbDataTable.Items.Add(newItem); } } pnlProgress.Visibility = System.Windows.Visibility.Collapsed; }