Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

A Helpful Database Library

, 6 Dec 2006
This article illustrates a helpful database library.
mydatabaselibrary_exe.zip
windb_for_codeproject_source.zip
WinDB for CodeProject
MyDatabaseLibrary
bin
Debug
Interop.ADODB.dll
Interop.MSDASC.dll
MyDatabaseLibrary.dll
Release
ClassDiagram1.cd
obj
Debug
Refactor
TempPE
Release
TempPE
Properties
Settings.settings
WinDB for CodeProject
bin
Debug
Interop.ADODB.dll
Interop.MSDASC.dll
MyDatabaseLibrary.dll
Release
WinDB for CodeProject.vshost.exe
obj
Debug
Refactor
TempPE
Release
TempPE
Properties
Settings.settings
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using MSDASC;
using ADODB;
using Settings = LDC_10.Properties.Settings;

namespace LDC_10
{
    internal partial class Setup : Form
    {
        public Setup()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (Settings.Default.DirMonitor == "" || Settings.Default.ConnString == "")
                {
                    Settings.Default.Stop = true;
                    MessageBox.Show("Application Stoping!\nApplication Parameters are not set.\nRun Application with setup command.", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.Close();
            }
            catch (Exception ebtnCancel)
            {
                MessageBox.Show(ebtnCancel.ToString());
            }
        }

        private void dirBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog _fld = new FolderBrowserDialog();
                _fld.ShowDialog();
                if (_fld.SelectedPath != null)
                {
                    txtDirMon.Text = _fld.SelectedPath;
                    txtDirMon.Refresh();
                }
            }
            catch (Exception edirBrowse)
            {
                MessageBox.Show(edirBrowse.ToString());
            }
        }

        private void dataSel_Click(object sender, EventArgs e)
        {
            try
            {
                DataLinksClass _dl = new DataLinksClass();
                
                _dl.hWnd = this.Handle.ToInt32();
                Connection _con = (Connection)_dl.PromptNew();
                if (_con != null)
                {
                    txtData.Text = _con.ConnectionString;
                    txtData.Refresh();
                }
            }
            catch (Exception edataSel)
            {
                MessageBox.Show(edataSel.ToString());
            }
        }

        private void xmlBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog _fld = new FolderBrowserDialog();
                _fld.ShowDialog();
                if (_fld.SelectedPath != null)
                {
                    txtXML.Text = _fld.SelectedPath;
                    txtXML.Refresh();
                }
            }
            catch (Exception exmlBrowse)
            {
                MessageBox.Show(exmlBrowse.ToString());
            }
        }

        private void rdoYes_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (rdoNo.Checked)
                {
                    rdoNo.Checked = false;
                    rdoYes.Checked = true;
                    txtXML.Enabled = true;
                    txtXML.Refresh();
                    xmlBrowse.Enabled = true;
                    xmlBrowse.Refresh();
                }
            }
            catch (Exception erdoYes)
            {
                MessageBox.Show(erdoYes.ToString());
            }
        }

        private void rdoNo_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (rdoYes.Checked)
                {
                    rdoYes.Checked = false;
                    rdoNo.Checked = true;
                    txtXML.Enabled = false;
                    txtXML.Refresh();
                    xmlBrowse.Enabled = false;
                    xmlBrowse.Refresh();
                }
            }
            catch (Exception erdoNo)
            {
                MessageBox.Show(erdoNo.ToString());
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtData.Text == "" || txtDirMon.Text == "")
                {
                    MessageBox.Show("You must enter a diretory to monitor and a data storage location.", "Setup Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {

                    System.Data.OleDb.OleDbConnection oleConn = new System.Data.OleDb.OleDbConnection(txtData.Text);
                    string newconn = txtData.Text;
                    newconn = newconn.Substring((newconn.IndexOf(";") + 1), (newconn.Length - ((newconn.IndexOf(";") + 1))));
                    Settings.Default.Provider = oleConn.Provider;
                    Settings.Default.DirMonitor = txtDirMon.Text;
                    Settings.Default.ConnString = txtData.Text;
                    Settings.Default.ConnStringSQL = newconn;
                    Settings.Default.XMLDir = txtXML.Text;
                    Settings.Default.CreateXML = rdoYes.Checked;
                    Settings.Default.Stop = false;
                    Settings.Default.Save();
                    this.Close();
                }
            }
            catch (Exception ebtnSave)
            {
                MessageBox.Show(ebtnSave.ToString());
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

lost in transition
Web Developer
United States United States
I am a software, database, and gis developer. I love the challenge of learning new ways to code.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 6 Dec 2006
Article Copyright 2006 by lost in transition
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid