private void LoadTablesFromDatabase(RecentDataSourceInfo info) { string connectionString = Configuration.Decrypt(info.ConnStr); string name = info.Name; string provider = info.Provider; mruSelectedDatabaseName = name; selectedDataProvider = provider; IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(provider); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); db.ConnectionString = connectionString; try { db.TestConnection(); cmbDatabaseType.Text = info.ProviderDesc; LoadTablesFromDatabase(db); } catch (Exception ex) { Epi.Windows.MsgBox.ShowException(ex); return; } this.selectedDataSource = db; } }
private void cmbRecentSources_SelectedIndexChanged(object sender, EventArgs e) { try { //this.RefreshForm(); if (cmbRecentSources.SelectedItem != null && !string.IsNullOrEmpty(cmbRecentSources.SelectedItem.ToString())) { string connectionString = Configuration.Decrypt(((ComboBoxItem)cmbRecentSources.SelectedItem).Value.ToString()); string name = ((ComboBoxItem)cmbRecentSources.SelectedItem).Text.ToString(); string provider = ((ComboBoxItem)cmbRecentSources.SelectedItem).Key.ToString(); mruSelectedDatabaseName = name; selectedDataProvider = provider; if (name.ToLowerInvariant().EndsWith(".prj")) { Project project = new Project(connectionString); this.selectedDataSource = project; this.selectedProject = project; } else { IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(provider); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); db.ConnectionString = connectionString; this.selectedDataSource = db; } } } else if (cmbRecentSources.SelectedItem != null && string.IsNullOrEmpty(cmbRecentSources.SelectedItem.ToString())) { mruSelectedDatabaseName = string.Empty; } RefreshForm(); } catch (DirectoryNotFoundException ex) { MsgBox.ShowException(ex); mruSelectedDatabaseName = string.Empty; cmbRecentSources.SelectedIndex = -1; } catch (FileNotFoundException ex) { MsgBox.ShowException(ex); mruSelectedDatabaseName = string.Empty; cmbRecentSources.SelectedIndex = -1; } catch (Exception ex) { MsgBox.ShowException(ex); mruSelectedDatabaseName = string.Empty; cmbRecentSources.SelectedIndex = -1; } }
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) { Epi.Windows.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 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); txtDataSource.Text = filePath; LoadTables(); } catch (Exception ex) { MessageBox.Show("Could not load project: \n\n" + ex.Message); return; } } } } else { IDbDriverFactory 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(); txtDataSource.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 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) { 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.ToLower().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 { messagePanel.Visibility = System.Windows.Visibility.Hidden; } }
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 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; }