private void InitializeDSNNames(string defaultDSNName) { string sqlDialect = this.GetDatabaseTypeName(this.comboBoxDatabase.SelectedIndex); List <ComboBoxDSNItem> comboItems = new List <ComboBoxDSNItem>(); List <string> dsnNames = ODBCUtils.GetDSNNames(); comboItems.Add(new ComboBoxDSNItem() { Text = "", IsDSN = false }); // add ODBC drivers foreach (var item in dsnNames) { comboItems.Add(new ComboBoxDSNItem() { Text = item, IsDSN = true }); } this.comboBoxDSNName.Items.Clear(); foreach (var item in comboItems) { this.comboBoxDSNName.Items.Add(item); } comboBoxDSNName.DisplayMember = "Text"; comboBoxDSNName.ValueMember = "IsDSN"; comboBoxDSNName.SelectedIndex = 0; // preselect driver int idx = 0; foreach (ComboBoxDSNItem item in comboBoxDSNName.Items) { if (defaultDSNName == item.Text) { comboBoxDSNName.SelectedIndex = idx; } idx++; } if (comboBoxDSNName.SelectedIndex < 0) { comboBoxDSNName.SelectedIndex = 0; } }
private void InitializeDrivers(string defaultDriverName) { string sqlDialect = this.GetDatabaseTypeName(this.comboBoxDatabase.SelectedIndex); ComboBoxDSNItem dsnItem = this.GetSelectedDSNName(); this.comboBoxDriverName.Items.Clear(); if (dsnItem.IsDSN) { this.comboBoxDriverName.Enabled = false; this.textBoxDatabaseName.Enabled = false; this.textBoxPort.Enabled = false; this.textBoxServerName.Enabled = false; } else { this.comboBoxDriverName.Enabled = true; this.textBoxDatabaseName.Enabled = true; this.textBoxPort.Enabled = true; this.textBoxServerName.Enabled = true; } List <ComboBoxDriverItem> comboItems = new List <ComboBoxDriverItem>(); List <string> odbcDrivers = null; switch (sqlDialect) { case "oracle": comboItems.Add(new ComboBoxDriverItem() { Text = UIConfig.DRIVER_NAME_NATIVE, UseDriverType = DBExecutor.UseDriver.ORACLE }); odbcDrivers = ODBCUtils.GetSystemDriverList().Where(x => x.IndexOf("oracle", StringComparison.InvariantCultureIgnoreCase) >= 0).ToList(); break; case "teradata": comboItems.Add(new ComboBoxDriverItem() { Text = UIConfig.DRIVER_NAME_NATIVE, UseDriverType = DBExecutor.UseDriver.TERADATA }); odbcDrivers = ODBCUtils.GetSystemDriverList().Where(x => x.IndexOf("teradata", StringComparison.InvariantCultureIgnoreCase) >= 0).ToList(); break; case "mssql": odbcDrivers = ODBCUtils.GetSystemDriverList().Where(x => x.IndexOf("SQL", StringComparison.InvariantCultureIgnoreCase) >= 0).ToList(); break; default: odbcDrivers = new List <string>(); break; } // add ODBC drivers foreach (var item in odbcDrivers) { comboItems.Add(new ComboBoxDriverItem() { Text = item, UseDriverType = DBExecutor.UseDriver.ODBC }); } foreach (var item in comboItems) { this.comboBoxDriverName.Items.Add(item); } comboBoxDriverName.DisplayMember = "Text"; comboBoxDriverName.ValueMember = "Value"; comboBoxDriverName.SelectedIndex = -1; // preselect driver int idx = 0; foreach (ComboBoxDriverItem item in comboBoxDriverName.Items) { if (defaultDriverName == item.Text) { if (idx != comboBoxDriverName.SelectedIndex) { comboBoxDriverName.SelectedIndex = idx; } else { break; } } idx++; } if (comboBoxDriverName.SelectedIndex < 0) { comboBoxDriverName.SelectedIndex = 0; } }