1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using Microsoft.Win32;
|
---|
9 | using HeuristicLab.Core;
|
---|
10 | using HeuristicLab.Data;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Communication.Data {
|
---|
13 | public partial class OdbcDatabaseDriverConfigurationView : ViewBase {
|
---|
14 | public OdbcDatabaseDriverConfiguration OdbcDatabaseDriverConfiguration {
|
---|
15 | get { return (OdbcDatabaseDriverConfiguration)base.Item; }
|
---|
16 | set { base.Item = value; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | public OdbcDatabaseDriverConfigurationView() {
|
---|
20 | InitializeComponent();
|
---|
21 | BuildOdbcDriverComboBox();
|
---|
22 | }
|
---|
23 |
|
---|
24 | public OdbcDatabaseDriverConfigurationView(OdbcDatabaseDriverConfiguration odbcDatabaseDriverConfiguration)
|
---|
25 | : this() {
|
---|
26 | OdbcDatabaseDriverConfiguration = odbcDatabaseDriverConfiguration;
|
---|
27 | }
|
---|
28 |
|
---|
29 | private void BuildOdbcDriverComboBox() {
|
---|
30 | RegistryKey lm = null;
|
---|
31 | try {
|
---|
32 | lm = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("ODBC").OpenSubKey("ODBCINST.INI").OpenSubKey("ODBC Drivers");
|
---|
33 | } catch (Exception e) {
|
---|
34 | MessageBox.Show("Unable to open registry:\n" + e.Message + "\n\nPlease provide the correct driver name for the ODBC connection driver.", "Registry error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
---|
35 | }
|
---|
36 | if (lm != null) {
|
---|
37 | string[] odbcDrivers = lm.GetValueNames();
|
---|
38 | odbcDriverComboBox.Items.AddRange(odbcDrivers);
|
---|
39 | odbcDriverComboBox.SelectedIndex = 0;
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void UpdateControls() {
|
---|
44 | base.UpdateControls();
|
---|
45 | if (OdbcDatabaseDriverConfiguration == null) {
|
---|
46 | odbcDriverComboBox.Enabled = false;
|
---|
47 | ipAddressStringDataView.Enabled = false;
|
---|
48 | ipAddressStringDataView.StringData = null;
|
---|
49 | portIntDataView.Enabled = false;
|
---|
50 | portIntDataView.IntData = null;
|
---|
51 | dbNameStringDataView.Enabled = false;
|
---|
52 | dbNameStringDataView.StringData = null;
|
---|
53 | dbUserStringDataView.Enabled = false;
|
---|
54 | dbUserStringDataView.StringData = null;
|
---|
55 | dbPasswordStringDataView.Enabled = false;
|
---|
56 | dbPasswordStringDataView.StringData = null;
|
---|
57 | dbTableStringDataView.Enabled = false;
|
---|
58 | dbTableStringDataView.StringData = null;
|
---|
59 | dbIDColumnNameStringDataView.Enabled = false;
|
---|
60 | dbIDColumnNameStringDataView.StringData = null;
|
---|
61 | dbCommunicationColumnNameStringDataView.Enabled = false;
|
---|
62 | dbCommunicationColumnNameStringDataView.StringData = null;
|
---|
63 | dbSynchronizationColumnNameStringDataView.Enabled = false;
|
---|
64 | dbSynchronizationColumnNameStringDataView.StringData = null;
|
---|
65 | } else {
|
---|
66 | odbcDriverComboBox.Enabled = true;
|
---|
67 | ipAddressStringDataView.StringData = OdbcDatabaseDriverConfiguration.IPAddress;
|
---|
68 | ipAddressStringDataView.Enabled = true;
|
---|
69 | portIntDataView.IntData = OdbcDatabaseDriverConfiguration.Port;
|
---|
70 | portIntDataView.Enabled = true;
|
---|
71 | dbNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBName;
|
---|
72 | dbNameStringDataView.Enabled = true;
|
---|
73 | dbUserStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBUser;
|
---|
74 | dbUserStringDataView.Enabled = true;
|
---|
75 | dbPasswordStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBPassword;
|
---|
76 | dbPasswordStringDataView.Enabled = true;
|
---|
77 | dbTableStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBTable;
|
---|
78 | dbTableStringDataView.Enabled = true;
|
---|
79 | dbIDColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBIDColumnName;
|
---|
80 | dbIDColumnNameStringDataView.Enabled = true;
|
---|
81 | dbCommunicationColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBCommunciationColumnName;
|
---|
82 | dbCommunicationColumnNameStringDataView.Enabled = true;
|
---|
83 | dbSynchronizationColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBSynchronizationColumnName;
|
---|
84 | dbSynchronizationColumnNameStringDataView.Enabled = true;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | private void odbcDriverComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
89 | if (odbcDriverComboBox.SelectedIndex >= 0 && OdbcDatabaseDriverConfiguration != null) {
|
---|
90 | OdbcDatabaseDriverConfiguration.OdbcDriver = new StringData((string)odbcDriverComboBox.SelectedItem);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|