Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Communication.Data/OdbcDatabaseDriverConfigurationView.cs @ 1197

Last change on this file since 1197 was 591, checked in by abeham, 16 years ago

Put the GPL license in the files from the communication framework and simulation optimization project

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using Microsoft.Win32;
30using HeuristicLab.Core;
31using HeuristicLab.Data;
32
33namespace HeuristicLab.Communication.Data {
34  public partial class OdbcDatabaseDriverConfigurationView : ViewBase {
35    public OdbcDatabaseDriverConfiguration OdbcDatabaseDriverConfiguration {
36      get { return (OdbcDatabaseDriverConfiguration)base.Item; }
37      set { base.Item = value; }
38    }
39
40    public OdbcDatabaseDriverConfigurationView() {
41      InitializeComponent();
42      BuildOdbcDriverComboBox();
43    }
44
45    public OdbcDatabaseDriverConfigurationView(OdbcDatabaseDriverConfiguration odbcDatabaseDriverConfiguration)
46      : this() {
47      OdbcDatabaseDriverConfiguration = odbcDatabaseDriverConfiguration;
48    }
49
50    private void BuildOdbcDriverComboBox() {
51      RegistryKey lm = null;
52      try {
53        lm = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("ODBC").OpenSubKey("ODBCINST.INI").OpenSubKey("ODBC Drivers");
54      } catch (Exception e) {
55        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);
56      }
57      if (lm != null) {
58        string[] odbcDrivers = lm.GetValueNames();
59        odbcDriverComboBox.Items.AddRange(odbcDrivers);
60        odbcDriverComboBox.SelectedIndex = 0;
61      }
62    }
63
64    protected override void UpdateControls() {
65      base.UpdateControls();
66      if (OdbcDatabaseDriverConfiguration == null) {
67        odbcDriverComboBox.Enabled = false;
68        ipAddressStringDataView.Enabled = false;
69        ipAddressStringDataView.StringData = null;
70        portIntDataView.Enabled = false;
71        portIntDataView.IntData = null;
72        dbNameStringDataView.Enabled = false;
73        dbNameStringDataView.StringData = null;
74        dbUserStringDataView.Enabled = false;
75        dbUserStringDataView.StringData = null;
76        dbPasswordStringDataView.Enabled = false;
77        dbPasswordStringDataView.StringData = null;
78        dbTableStringDataView.Enabled = false;
79        dbTableStringDataView.StringData = null;
80        dbIDColumnNameStringDataView.Enabled = false;
81        dbIDColumnNameStringDataView.StringData = null;
82        dbCommunicationColumnNameStringDataView.Enabled = false;
83        dbCommunicationColumnNameStringDataView.StringData = null;
84        dbSynchronizationColumnNameStringDataView.Enabled = false;
85        dbSynchronizationColumnNameStringDataView.StringData = null;
86      } else {
87        odbcDriverComboBox.Enabled = true;
88        ipAddressStringDataView.StringData = OdbcDatabaseDriverConfiguration.IPAddress;
89        ipAddressStringDataView.Enabled = true;
90        portIntDataView.IntData = OdbcDatabaseDriverConfiguration.Port;
91        portIntDataView.Enabled = true;
92        dbNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBName;
93        dbNameStringDataView.Enabled = true;
94        dbUserStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBUser;
95        dbUserStringDataView.Enabled = true;
96        dbPasswordStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBPassword;
97        dbPasswordStringDataView.Enabled = true;
98        dbTableStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBTable;
99        dbTableStringDataView.Enabled = true;
100        dbIDColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBIDColumnName;
101        dbIDColumnNameStringDataView.Enabled = true;
102        dbCommunicationColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBCommunciationColumnName;
103        dbCommunicationColumnNameStringDataView.Enabled = true;
104        dbSynchronizationColumnNameStringDataView.StringData = OdbcDatabaseDriverConfiguration.DBSynchronizationColumnName;
105        dbSynchronizationColumnNameStringDataView.Enabled = true;
106      }
107    }
108
109    private void odbcDriverComboBox_SelectedIndexChanged(object sender, EventArgs e) {
110      if (odbcDriverComboBox.SelectedIndex >= 0 && OdbcDatabaseDriverConfiguration != null) {
111        OdbcDatabaseDriverConfiguration.OdbcDriver = new StringData((string)odbcDriverComboBox.SelectedItem);
112      }
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.