private void btnImportListValues_Click(object sender, EventArgs e) { Epi.Windows.Dialogs.BaseReadDialog dlg = new Epi.Windows.Dialogs.BaseReadDialog(this); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (dlg.SelectedDataSource is Project) { Epi.Windows.MsgBox.ShowInformation(ImportExportSharedStrings.ERROR_CODE_TABLE_PROJECT_IMPORT_NOT_ALLOWED); } else { Epi.Data.IDbDriver db = (Epi.Data.IDbDriver)dlg.SelectedDataSource; if (string.IsNullOrEmpty(dlg.SQLQuery)) { DataTable DT = db.GetTopTwoTable(dlg.SelectedDataMember); List <string> columnNames = new List <string>(); foreach (DataColumn dc in DT.Columns) { columnNames.Add(dc.ColumnName); } Epi.Windows.ImportExport.Dialogs.FieldSelectionDialog fsd = new Windows.ImportExport.Dialogs.FieldSelectionDialog(columnNames); DialogResult fieldDialogResult = fsd.ShowDialog(); if (fieldDialogResult == System.Windows.Forms.DialogResult.OK) { string selectedColumn = fsd.SelectedField; string codeTableName = "code" + dlg.SelectedDataMember + selectedColumn; try { DT = db.GetTableData(dlg.SelectedDataMember); DT.TableName = codeTableName; codeTables.Add(DT); codeTableList.Add(codeTableName); ((DataGridViewComboBoxColumn)dgvFormFields.Columns["ListSourceTableName"]).Items.Clear(); foreach (string s in codeTableList) { ((DataGridViewComboBoxColumn)dgvFormFields.Columns["ListSourceTableName"]).Items.Add(s); } } catch (OutOfMemoryException) { Epi.Windows.MsgBox.ShowError(ImportExportSharedStrings.ERROR_OUT_OF_MEMORY_CODE_TABLE); DT.Rows.Clear(); } } } else { Epi.Windows.MsgBox.ShowInformation(ImportExportSharedStrings.ERROR_CODE_TABLE_QUERY_IMPORT_NOT_ALLOWED); } } } }
public override object Execute() { DataTable outputTable = null; DataSets.Config.DataDriverDataTable dataDrivers = Configuration.GetNewInstance().DataDrivers; Epi.Data.IDbDriverFactory dbFactory = null; foreach (DataSets.Config.DataDriverRow dataDriver in dataDrivers) { dbFactory = Epi.Data.DbDriverFactoryCreator.GetDbDriverFactory(dataDriver.Type); if (dbFactory.CanClaimConnectionString(this.Context.CurrentRead.File)) { break; } } Epi.Data.IDbDriver OutputDriver = Epi.Data.DBReadExecute.GetDataDriver(this.Context.CurrentRead.File, true); outputTable = OutputDriver.GetTableData(this.tableName); if (outputTable != null) { Type columnType = outputTable.Columns[variableName].DataType; List <string> values = new List <string>(); foreach (DataRow row in outputTable.Rows) { string value = row[variableName].ToString(); if (values.Contains(value) == false && string.IsNullOrEmpty(value) == false) { values.Add(value); } } this.DialogThenAssign(values); } return(null); }