/// <summary> /// GetVariableMarkup gets both the markup used in the HTMLRESULTS section and a DataTable /// with a row for each TABLES and its properties. /// </summary> /// <param name="table">An instance of a DataTable containing properties of TABLES.</param> /// <returns>Returns the markup used in the HTMLRESULTS section.</returns> private string GetTableMarkup(out DataTable table) { StringBuilder sb = new StringBuilder(); table = new DataTable(); table.Columns.Add(ColumnNames.DATA_TABLE_NAME, typeof(string)); table.Columns.Add(ColumnNames.TYPE, typeof(string)); table.Columns.Add(ColumnNames.NUMBER_OF_FIELDS, typeof(Int16)); table.Columns.Add(ColumnNames.LINK, typeof(string)); table.Columns.Add(ColumnNames.PRIMARY_KEY, typeof(string)); table.Columns.Add(ColumnNames.DESCRIPTION, typeof(string)); try { IDbDriver driver = null; if (this.Context.CurrentRead != null) { driver = Epi.Data.DBReadExecute.GetDataDriver(this.Context.CurrentRead.File); } if (!string.IsNullOrEmpty(dbViewsOpt)) { driver = Epi.Data.DBReadExecute.GetDataDriver(dbViewsOpt); } List <string> tableNames = driver.GetTableNames(); int colCount; foreach (string name in tableNames) { StringBuilder primaryKeys = new StringBuilder(); colCount = driver.GetTableData(name).Columns.Count; foreach (DataColumn key in driver.GetTableData(name).PrimaryKey) { primaryKeys.Append(string.Format("{0} ", key.ColumnName)); } DataRow row = table.NewRow(); row[ColumnNames.DATA_TABLE_NAME] = name; row[ColumnNames.TYPE] = GetTableTypeName(name, colCount); row[ColumnNames.NUMBER_OF_FIELDS] = colCount; row[ColumnNames.LINK] = string.Empty; row[ColumnNames.PRIMARY_KEY] = primaryKeys.ToString(); row[ColumnNames.DESCRIPTION] = string.Empty; table.Rows.Add(row); } } catch (NullReferenceException) { throw new GeneralException(SharedStrings.NO_DATA_SOURCE); } return(BuildMarkupFromTable(table, string.Empty)); }
private void RefreshForm() { lvDataSourceObjects.Groups.Clear(); lvDataSourceObjects.Items.Clear(); //txtCurrentProj.Text = (selectedProject == null) ? "(none)" : selectedProject.FullName; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ListViewItem newItem = new ListViewItem(new string[] { tableName, tableName }); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName; ListViewGroup tablesGroup = new ListViewGroup("Tables"); this.lvDataSourceObjects.Groups.Add(tablesGroup); foreach (string s in project.GetNonViewTableNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "Table" }, tablesGroup); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else { // Clear ... this.txtDataSource.Text = "(none)"; this.lvDataSourceObjects.Items.Clear();// DataSource = null; gbxExplorer.Enabled = false; } this.CheckForInputSufficiency(); }
private void LoadTables() { //lbxShowViews.DataSource = null; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); //lbxShowViews.DataSource = tableNames; lbxShowAll.DataSource = tableNames; /* * rbAll.Checked = true; * rbView.Checked = false; * rbView.Enabled = false; * lbxShowViews.SelectedIndex = -1;*/ } else if (selectedDataSource is Project) { //rbView.Enabled = true; Project project = selectedDataSource as Project; txtDataSource.Text = project.FullName; List <string> tableNames = project.GetViewNames(); this.lbxShowViews.DataSource = tableNames; tableNames = project.GetNonViewTableNames(); this.lbxShowAll.DataSource = tableNames; this.lbxShowViews.SelectedIndex = -1; this.lbxShowAll.SelectedIndex = -1; } else { // Clear ... this.txtDataSource.Text = string.Empty; this.lbxShowViews.DataSource = null; this.lbxShowAll.DataSource = null; } tabctrlShow.TabPages[1].Show(); }
private void LoadTablesFromDatabase(IDbDriver db) { lbxTables.ItemsSource = null; lbxTables.Items.Clear(); lbxTables.ItemTemplate = null; txtConnectionInformation.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { if (!string.IsNullOrEmpty(tableName.Trim())) { lbxTables.Items.Add(tableName); } } }
private void LoadTables() { lbxDataSourceObjects.DataSource = null; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); lbxDataSourceObjects.DataSource = tableNames; rbAll.Checked = true; rbView.Checked = false; rbView.Enabled = false; lbxDataSourceObjects.SelectedIndex = -1; } else if (selectedDataSource is Project) { rbView.Enabled = true; Project project = selectedDataSource as Project; txtDataSource.Text = project.FullName; if (rbView.Checked) { List <string> tableNames = project.GetViewNames(); lbxDataSourceObjects.DataSource = tableNames; } else if (rbAll.Checked) { List <string> tableNames = project.GetNonViewTableNames(); lbxDataSourceObjects.DataSource = tableNames; } lbxDataSourceObjects.SelectedIndex = -1; } else { // Clear ... this.txtDataSource.Text = string.Empty; lbxDataSourceObjects.DataSource = null; rbView.Enabled = true; } }
/// <summary> /// Populate internal translation table using Epi 3.x db /// </summary> /// <param name="legacyLanguageDatabasePath"></param> public void ReadDatabase(string legacyLanguageDatabasePath) { //IDbDriver db = DatabaseFactory.CreateDatabaseInstanceByFileExtension(legacyLanguageDatabasePath); IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Epi.Configuration.AccessDriver); OleDbConnectionStringBuilder dbCnnStringBuilder = new OleDbConnectionStringBuilder(); dbCnnStringBuilder.FileName = legacyLanguageDatabasePath; IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { List <string> columnNames = db.GetTableColumnNames(tableName); if (columnNames.Contains("English") && columnNames.Count == 2) { DataTable span = db.Select(db.CreateQuery("select * from " + tableName)); int sourceColumnOrdinal, translationColumnOrdinal; if (string.Compare(span.Columns[0].ColumnName, "English", true) == 0) { sourceColumnOrdinal = 0; translationColumnOrdinal = 1; } else { sourceColumnOrdinal = 1; translationColumnOrdinal = 0; } foreach (DataRow row in span.Rows) { AddTranslationTableEntry(sourceColumnOrdinal, translationColumnOrdinal, row); } } } }
private void LoadTables() { cmbTableName.DataSource = null; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtFileName.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); cmbTableName.DataSource = tableNames; cmbTableName.SelectedIndex = -1; } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; txtFileName.Text = project.FullName; if (rdbView.Checked) { List <string> tableNames = project.GetViewNames(); cmbTableName.DataSource = tableNames; } else if (rdbTable.Checked) { List <string> tableNames = project.GetNonViewTableNames(); cmbTableName.DataSource = tableNames; } cmbTableName.SelectedIndex = -1; } else { // Clear ... this.txtFileName.Text = string.Empty; cmbTableName.DataSource = null; } }
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 { pnlProgress.Visibility = System.Windows.Visibility.Collapsed; } }
///// <summary> ///// Constructor for the class. ///// </summary> ///// <param name="proj">Project the metadata belongs to</param> //public MetadataDbProvider(Project proj) : base(proj) //{ //} #endregion Constructors #region Public Methods public List <string> GetTableNames() { List <string> tableNames = db.GetTableNames(); return(tableNames); }
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 RefreshForm() { lvDataSourceObjects.Groups.Clear(); lvDataSourceObjects.Items.Clear(); if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; switch (db.ToString()) { case "Epi.Data.Office.AccessDatabase": case "Epi.Data.Office.Access2007Database": case "Epi.Data.Office.ExcelWorkbook": case "Epi.Data.Office.Excel2007Workbook": this.txtDataSource.Text = db.DataSource; break; default: this.txtDataSource.Text = db.ConnectionString; break; } List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ListViewItem newItem = new ListViewItem(new string[] { tableName, tableName }); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName; if (chkViews.Checked) { ListViewGroup viewGroup = new ListViewGroup("Epi Info Views"); this.lvDataSourceObjects.Groups.Add(viewGroup); foreach (string s in project.GetViewNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "View" }, viewGroup); this.lvDataSourceObjects.Items.Add(newItem); } } if (chkTables.Checked) { ListViewGroup tablesGroup = new ListViewGroup("Tables"); this.lvDataSourceObjects.Groups.Add(tablesGroup); foreach (string s in project.GetNonViewTableNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "Table" }, tablesGroup); this.lvDataSourceObjects.Items.Add(newItem); } } gbxExplorer.Enabled = true; } else { // Clear ... this.txtDataSource.Text = "(none)"; this.lvDataSourceObjects.Items.Clear();// DataSource = null; gbxExplorer.Enabled = false; } this.CheckForInputSufficiency(); }
/// <summary> /// GetViewMarkup gets both the markup used in the HTMLRESULTS section and a DataTable /// with a row for each DBVIEW and its properties. /// </summary> /// <param name="table">An instance of a DataTable containing properties of DBVIEW.</param> /// <returns>Returns the markup used in the HTMLRESULTS section.</returns> private string GetViewMarkup(out DataTable table) { StringBuilder sb = new StringBuilder(); table = new DataTable(); table.Columns.Add(ColumnNames.DATA_TABLE_NAME, typeof(string)); table.Columns.Add(ColumnNames.TYPE, typeof(string)); table.Columns.Add(ColumnNames.LINK, typeof(string)); table.Columns.Add(ColumnNames.PARENT_VIEW, typeof(string)); table.Columns.Add(ColumnNames.CHILD_TYPE, typeof(string)); table.Columns.Add(ColumnNames.CHILD_TABLES, typeof(string)); try { IDbDriver driver = null; if (this.Context.CurrentRead != null) { driver = Epi.Data.DBReadExecute.GetDataDriver(this.Context.CurrentRead.File); } if (!string.IsNullOrEmpty(dbViewsOpt)) { driver = Epi.Data.DBReadExecute.GetDataDriver(dbViewsOpt); } List <string> tableNames = driver.GetTableNames(); int colCount; ///////////////////////////////// //ViewCollection Views = metadata.GetViews(); //////Views parent list //List<string> pViewsList = new List<string>(); //foreach (var view in Views) //{ // pViewsList.Add(metadata.GetAvailDataTableName(((Epi.View)(view)).Name)); //} //////Views list //List<string> ViewsList = new List<string>(); //foreach (var view in Views) //{ // ViewsList.Add(((Epi.View)(view)).Name); //} //////Code table list //List<string> CodeTableList = new List<string>(); //DataTable CodeTables = metadata.GetCodeTableList(); //foreach (DataRow CodeTable in CodeTables.Rows) //{ // CodeTableList.Add(((Epi.DataSets.TableSchema.TablesRow)(CodeTable)).TABLE_NAME); //} //////Data table list //List<string> DataTableList = new List<string>(); //DataTableList = metadata.GetDataTableList(); //////////////////////////////// foreach (string name in tableNames) { StringBuilder primaryKeys = new StringBuilder(); DataTable currentTable = driver.GetTableData(name); colCount = table.Columns.Count; DataRow row = table.NewRow(); row[ColumnNames.DATA_TABLE_NAME] = name; //issue 769 start //if (this.Context.CurrentRead != null) //{ // if (this.Context.CurrentProject != null && this.Context.CurrentProject.Views.Exists(this.Context.CurrentRead.Identifier)) // { // row[ColumnNames.TYPE] = "View"; // } // else // { // row[ColumnNames.TYPE] = "Data"; // } //} //else //{ // row[ColumnNames.TYPE] = "Data"; //} row[ColumnNames.TYPE] = GetTableTypeName(name, colCount); //issue 769 end row[ColumnNames.LINK] = string.Empty; row[ColumnNames.PARENT_VIEW] = string.Empty; row[ColumnNames.CHILD_TYPE] = string.Empty; row[ColumnNames.CHILD_TABLES] = string.Empty; table.Rows.Add(row); } } catch (NullReferenceException) { throw new GeneralException(SharedStrings.NO_DATA_SOURCE); } return(BuildMarkupFromTable(table, string.Empty)); }
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 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; }
private void LoadTablesFromDatabase(IDbDriver db) { lbxTables.ItemsSource = null; lbxTables.Items.Clear(); lbxTables.ItemTemplate = null; txtConnectionInformation.Text = db.ConnectionString; List<string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { if (!string.IsNullOrEmpty(tableName.Trim())) { lbxTables.Items.Add(tableName); } } }
private void RefreshForm() { lvDataSourceObjects.Groups.Clear(); lvDataSourceObjects.Items.Clear(); if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.DataSource; var SelectedDataSource = db.ConnectionString.Split('@'); if (SelectedDataSource[0].Contains("Epi Info Web Survey")) { this.txtDataSource.Text = "Epi Info Web & Cloud Services"; } List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ListViewItem newItem = new ListViewItem(new string[] { tableName, tableName }); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName; try { if (chkViews.Checked) { ListViewGroup viewGroup = new ListViewGroup("Forms", "Epi Info Forms"); this.lvDataSourceObjects.Groups.Add(viewGroup); foreach (string s in project.GetViewNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "View" }, viewGroup); this.lvDataSourceObjects.Items.Add(newItem); } } if (chkTables.Checked) { ListViewGroup tablesGroup = new ListViewGroup("Tables", "Tables"); this.lvDataSourceObjects.Groups.Add(tablesGroup); foreach (string s in project.GetNonViewTableNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "Table" }, tablesGroup); this.lvDataSourceObjects.Items.Add(newItem); } } } catch (Exception ex) { Epi.Windows.MsgBox.ShowException(ex); txtDataSource.Text = string.Empty; return; } gbxExplorer.Enabled = true; } else { // Clear ... this.txtDataSource.Text = "(none)"; this.lvDataSourceObjects.Items.Clear();// DataSource = null; gbxExplorer.Enabled = false; } this.CheckForInputSufficiency(); }
/// <summary> /// GetVariableMarkup gets both the markup used in the HTMLRESULTS section and a DataTable /// with a row for each DBVARIABLE and its properties. /// </summary> /// <param name="table">An instance of a DataTable containing properties of DBVARIABLES.</param> /// <returns>Returns the markup used in the HTMLRESULTS section.</returns> private string GetVariableMarkup(out DataTable table) { StringBuilder sb = new StringBuilder(); string[] varNames = null; table = new DataTable(); if (!string.IsNullOrEmpty(this.identifierList)) { varNames = this.identifierList.Split(' '); foreach (string s in varNames) { s.Trim(); } } VariableCollection vars = this.GetVariables(varNames, this.dbVariablesOpt); this.Context.GetOutput(); /* * table.Columns.Add(new DataColumn(ColumnNames.VARIABLE, typeof(string))); * table.Columns.Add(new DataColumn(ColumnNames.TABLE, typeof(string))); * table.Columns.Add(new DataColumn(ColumnNames.FIELDTYPE, typeof(string))); * table.Columns.Add(new DataColumn(ColumnNames.FORMATVALUE, typeof(string))); * table.Columns.Add(new DataColumn(ColumnNames.SPECIALINFO, typeof(string))); * table.Columns.Add(new DataColumn(ColumnNames.PROMPT, typeof(string))); */ table.Columns.Add(new DataColumn(ColumnNames.PAGE_NUMBER, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.PROMPT, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.FIELDTYPE, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.VARIABLE, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.VARIABLE_VALUE, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.FORMATVALUE, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.SPECIALINFO, typeof(string))); table.Columns.Add(new DataColumn(ColumnNames.TABLE, typeof(string))); string tableText = string.Empty; string pattern = string.Empty; IDbDriver driver = null; DataTable viewTable = null; DataRow[] rows = null; Dictionary <string, string> formatStrings = new Dictionary <string, string>(); if (this.Context.CurrentRead != null) { tableText = this.Context.CurrentRead.Identifier; driver = Epi.Data.DBReadExecute.GetDataDriver(this.Context.CurrentRead.File); List <string> tableNames = driver.GetTableNames(); string viewTableName = "view" + tableText; List <string> tableNamesUpper = new List <string> { }; foreach (string name in tableNames) { tableNamesUpper.Add(name.ToUpperInvariant()); } //if TableNamesUpper contains an Epi 3 viewTable then get that table's data if (tableNamesUpper.Contains(viewTableName.ToUpperInvariant())) { viewTable = driver.GetTableData(viewTableName); if (varNames == null) { rows = viewTable.Select(); } else { StringBuilder filter = new StringBuilder(); foreach (string name in varNames) { filter.Append(string.Format(" OR Name = '{0}'", name)); } rows = viewTable.Select(filter.ToString().Substring(4)); } foreach (DataRow row in rows) { formatStrings.Add(row[ColumnNames.NAME].ToString(), row[ColumnNames.FORMATSTRING].ToString()); } } } List <string> RelatedTableList = new List <string>(); if (this.Context.CurrentRead != null) { for (int i = 0; Context.CurrentRead.RelatedTables.Count > i; i++) { RelatedTableList.Add(Context.CurrentRead.RelatedTables[i]); } } List <string> varnamelist = new List <string>(); if (varNames != null) { foreach (string name in varNames) { varnamelist.Add(name); } } //foreach (IVariable var in vars) foreach (DataColumn dataColumn in this.Context.DataSet.Tables["output"].Columns) { string ColumnsNames = ""; tableText = ""; if (this.Context.CurrentRead != null) { foreach (var RTable in RelatedTableList) { if (this.Context.CurrentRead.IsEpi7ProjectRead && this.Context.CurrentProject.Views.Exists(RTable)) { View tempView = this.Context.CurrentProject.Metadata.GetViewByFullName(RTable); ColumnsNames = this.Context.CurrentProject.Metadata.GetTableColumnNames(tempView.Id); if (ColumnsNames.Contains(dataColumn.ToString())) { tableText = RTable; break; } } } if (string.IsNullOrEmpty(tableText)) { tableText = this.Context.CurrentRead.Identifier; } } else { tableText = "output"; } if (varNames != null) { if (varnamelist.Contains(dataColumn.Caption.ToString().ToUpperInvariant())) { table.Rows.Add(GetDataTable(dataColumn, tableText, pattern, formatStrings, rows, table)); } } else if (vars != null) { if (vars.Contains(dataColumn.Caption.ToString().ToUpperInvariant())) { if (this.dbVariablesOpt == "FIELDVAR") { IVariable var = (IVariable)this.Context.GetVariable(dataColumn.ColumnName); if (var.VarType == VariableType.DataSource || var.VarType == VariableType.DataSourceRedefined) { table.Rows.Add(GetDataTable(dataColumn, tableText, pattern, formatStrings, rows, table)); } } else { table.Rows.Add(GetDataTable(dataColumn, tableText, pattern, formatStrings, rows, table)); } } } else { if (this.dbVariablesOpt == "FIELDVAR") { IVariable var = (IVariable)this.Context.GetVariable(dataColumn.ColumnName); if (var.VarType == VariableType.DataSource || var.VarType == VariableType.DataSourceRedefined) { table.Rows.Add(GetDataTable(dataColumn, tableText, pattern, formatStrings, rows, table)); } } else { table.Rows.Add(GetDataTable(dataColumn, tableText, pattern, formatStrings, rows, table)); } } //pattern = string.Empty; //IVariable var = (IVariable)this.Context.GetVariable(dataColumn.ColumnName); //if (var != null && (var.VarType == VariableType.DataSource) || (var.VarType == VariableType.DataSourceRedefined)) //{ // formatStrings.TryGetValue(var.Name, out pattern); //} //else //{ // tableText = "Defined"; //} //DataRow row = table.NewRow(); /* * row[ColumnNames.VARIABLE] = var.Name; * row[ColumnNames.TABLE] = tableText; * row[ColumnNames.FIELDTYPE] = var.DataType.ToString(); * row[ColumnNames.FORMATVALUE] = pattern; * row[ColumnNames.SPECIALINFO] = var.VarType.ToString(); * row[ColumnNames.PROMPT] = var.PromptText; */ // row[ColumnNames.PAGE_NUMBER] = var.???; //if (this.Context.CurrentRead.IsEpi7ProjectRead && this.Context.CurrentProject.Views.Exists(this.Context.CurrentRead.Identifier) && this.Context.CurrentProject.Views[this.Context.CurrentRead.Identifier].Fields.Exists(var.Name)) //{ // Epi.Fields.Field field = this.Context.CurrentProject.Views[this.Context.CurrentRead.Identifier].Fields[var.Name]; // if (field is FieldWithSeparatePrompt) // { // row[ColumnNames.PROMPT] = ((FieldWithSeparatePrompt)field).PromptText; // } // else // { // row[ColumnNames.PROMPT] = var.PromptText; // } //} //else //{ // row[ColumnNames.PROMPT] = var.PromptText; //} //if (this.Context.DataSet.Tables.Contains("output")) //{ // row[ColumnNames.FIELDTYPE] = this.Context.DataSet.Tables["output"].Columns[var.Name].DataType.ToString(); //} //else //{ // row[ColumnNames.FIELDTYPE] = var.DataType.ToString(); //} //row[ColumnNames.VARIABLE] = var.Name; ////row[ColumnNames.VARIABLE_VALUE] = var.???; //row[ColumnNames.FORMATVALUE] = pattern; //row[ColumnNames.SPECIALINFO] = var.VarType.ToString(); //row[ColumnNames.TABLE] = tableText; //table.Rows.Add(row); } return(BuildMarkupFromTable(table, string.Format("{0} ASC, {1} ASC", ColumnNames.TABLE, ColumnNames.VARIABLE))); }