コード例 #1
0
        /// <summary>
        /// Method that gives one ODBC DSN object
        /// </summary>
        /// <param name="baseKey"></param>
        /// <param name="dsnName"></param>
        /// <returns>ODBC DSN object</returns>
        private static ODBCDSN GetDSN(RegistryKey baseKey, string dsnName)
        {
            int         j             = 0;
            string      dsnDriverName = null;
            RegistryKey dsnNamesKey   = null;
            RegistryKey dsnNameKey    = null;

            string [] dsnElements = null;
            string [] dsnElmVals  = null;
            ODBCDSN   odbcDSN     = null;

            // Get the key for (using the baseKey parmetre passed in)
            // "\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\" (DSN_LOC_IN_REGISTRY)
            // that contains all the configured Data Source Name (DSN) entries.
            dsnNamesKey = OpenComplexSubKey(baseKey, DSN_LOC_IN_REGISTRY, false);

            if (dsnNamesKey != null)
            {
                // Get the name of the driver for which the DSN is
                // defined.
                dsnDriverName = dsnNamesKey.GetValue(dsnName).ToString();
                dsnNamesKey.Close();
            }

            // Get the key for ODBC_INI_LOC_IN_REGISTRY+dsnName.
            dsnNameKey = OpenComplexSubKey(baseKey,
                                           ODBC_INI_LOC_IN_REGISTRY + dsnName, false);

            if (dsnNameKey != null)
            {
                // Get all elements defined in the above key
                dsnElements = dsnNameKey.GetValueNames();

                // Create DSN Element values array.
                dsnElmVals = new string[dsnElements.Length];

                // For each element defined for a typical DSN get
                // its value.
                foreach (string dsnElement in dsnElements)
                {
                    dsnElmVals[j] = dsnNameKey.GetValue(dsnElement).ToString();
                    j++;
                }

                // Create ODBCDSN Object.
                odbcDSN = ODBCDSN.ParseForODBCDSN(dsnName, dsnDriverName,
                                                  dsnElements, dsnElmVals);

                dsnNamesKey.Close();
            }
            return(odbcDSN);
        }
コード例 #2
0
        void DSNOnClick(object sender, EventArgs e)
        {
            foreach (ToolStripMenuItem item in mnuDataSource.DropDown.Items)
            {
                item.Checked = false;
            }

            ToolStripMenuItem mnu = (ToolStripMenuItem)sender;

            mnu.Checked    = true;
            currentDSN     = mnu.Tag as ODBCDSN;
            txtStatus.Text = "DSN: " + mnu.Text;
            myTreeView1.Nodes.Clear();
        }
コード例 #3
0
        /// <summary>
        /// Method that gives the Data Source Name (DSN) entries as array of
        /// ODBCDSN objects.
        /// </summary>
        /// <returns>Array of DSNs based on the baseKey parameter</returns>
        private static ODBCDSN[] GetDSNList(RegistryKey baseKey)
        {
            ArrayList dsnList = new ArrayList();

            ODBCDSN[] odbcDSNs = new ODBCDSN[] {};

            if (baseKey == null)
            {
                return(null);
            }

            // Get the key for (using the baseKey parmetre passed in)
            // "\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\" (DSN_LOC_IN_REGISTRY)
            // that contains all the configured Data Source Name (DSN) entries.
            RegistryKey dsnNamesKey = OpenComplexSubKey(baseKey,
                                                        DSN_LOC_IN_REGISTRY, false);

            if (dsnNamesKey != null)
            {
                // Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
                string [] dsnNames = dsnNamesKey.GetValueNames();
                if (dsnNames != null)
                {
                    // Foreach DSN entry in the DSN_LOC_IN_REGISTRY, goto the
                    // Key ODBC_INI_LOC_IN_REGISTRY+dsnName and get elements of
                    // the DSN entry to create ODBCDSN objects.
                    foreach (string dsnName in dsnNames)
                    {
                        // Get ODBC DSN object.
                        ODBCDSN odbcDSN = GetDSN(baseKey, dsnName);
                        if (odbcDSN != null)
                        {
                            dsnList.Add(odbcDSN);
                        }
                    }
                    if (dsnList.Count > 0)
                    {
                        // Create ODBCDSN objects equal to number of valid objects
                        // in the DSN ArrayList.
                        odbcDSNs = new ODBCDSN[dsnList.Count];
                        dsnList.CopyTo(odbcDSNs, 0);
                    }
                }

                dsnNamesKey.Close();
            }
            return(odbcDSNs);
        }
コード例 #4
0
        public frmMain()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            EmbeddedSyntaxModeProvider syntax = new EmbeddedSyntaxModeProvider();

            HighlightingManager.Manager.AddSyntaxModeFileProvider(syntax);             // Attach to the text editor.

            // Load the settings from file
            settings = Settings.Load(settingsPath);

            // Load the data sources
            List <ODBCDSN> dsns = new List <ODBCDSN>();

            dsns.AddRange(ODBCManager.GetSystemDSNList());
            dsns.AddRange(ODBCManager.GetUserDSNList());

            mnuDataSource.DropDown.Items.Clear();

            foreach (var dsn in dsns.OrderBy(x => x.GetDSNName()))
            {
                ToolStripMenuItem mnu = new ToolStripMenuItem(string.Format("{0} : {1}", dsn.GetDSNName(), dsn.GetDSNDriverName()));
                mnu.Tag    = dsn;
                mnu.Click += DSNOnClick;
                mnuDataSource.DropDown.Items.Add(mnu);

                if (dsn.GetDSNName() == settings.DSN)
                {
                    mnu.Checked    = true;
                    currentDSN     = dsn;
                    txtStatus.Text = "DSN: " + mnu.Text;
                }
            }

            txtUserName.Text   = settings.UserName;
            txtPassword.Text   = settings.Password;
            txtOutputPath.Text = settings.OutputPath;
            NewEditor();
            myTreeView1.Visible = settings.TreeViewVisible;
            myTreeView1.Width   = settings.TreeViewWidth;

            splitter1.DoubleClick += new EventHandler(splitter1_DoubleClick);
        }
コード例 #5
0
ファイル: ODBCDSN.cs プロジェクト: wmnightwing/odbc-connect
        public static ODBCDSN ParseForODBCDSN(string dsnName, string dsnDriverName,
                                              string [] dsnElements, string[] dsnElmVals)
        {
            ODBCDSN odbcdsn = null;

            if (dsnElements != null && dsnElmVals != null)
            {
                int    i           = 0;
                string description = null;
                string server      = null;
                string driver      = null;

                // For each element defined for a typical DSN get
                // its value.
                foreach (string dsnElement in dsnElements)
                {
                    switch (dsnElement.ToLower())
                    {
                    case "description":
                        description = dsnElmVals[i];
                        break;

                    case "server":
                        server = dsnElmVals[i];
                        break;

                    case "driver":
                        driver = dsnElmVals[i];
                        break;
                    }
                    i++;
                }
                odbcdsn = new ODBCDSN(dsnName, dsnDriverName,
                                      description, server, driver);
            }
            return(odbcdsn);
        }