private void generateButton_Click(object sender, EventArgs e)
        {
            List<DatabaseTable> databaseTables = new List<DatabaseTable>();

            //Retrieve Tables in generation listbox
            for(int index = 0; index < generationTablesListBox.Items.Count; index++ )
            {
                DatabaseTable table = new DatabaseTable();
                table.Name = Convert.ToString(generationTablesListBox.Items[index]);
                databaseTables.Add(table);
            }

            //Retrieve the columns in the selected tables
            DatabaseHelper helper = new DatabaseHelper(User.Default.DatabaseConnectionString);
            foreach (DatabaseTable table in databaseTables)
            {
                table.Columns = helper.RetrieveColumns(databasesComboBox.Text, table.Name);
            }

            //populate Settings class
            CodeGenSettings settings = new CodeGenSettings();
            settings.SolutionNamespace = User.Default.SolutionNamespace;
            settings.CodeGenerationDirectory = User.Default.CodeGenerationDirectory;
            settings.DatabaseConnectionString = User.Default.DatabaseConnectionString;
            settings.CompiledTemplateLocation = User.Default.CompiledTemplateLocation;
            settings.ReturnIdentityFromInserts = returnIdentityFromInserts.Checked;
            settings.UseDynamicParameters = useDynamicParameters.Checked;

            if (!string.IsNullOrEmpty(settings.CodeGenerationDirectory))
            {
                //Check that items have been added to the Generation Queue
                if (generationTablesListBox.Items.Count > 0)
                {
                    try
                    {
                        Cursor = Cursors.WaitCursor;
                        SolutionLogic.Generate(settings, databaseTables);

                        MessageBox.Show(this, "Generation Completed!", "Generation Completed!", MessageBoxButtons.OK,MessageBoxIcon.Information);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        Cursor = Cursors.Arrow;
                    }
                }
                else
                {
                    MessageBox.Show(this, "Add tables to the generation queue", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show(this, "A location to save the generated files is required. Please use the settings dialog to set the code generation path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void testConnectionButton_Click(object sender, EventArgs e)
        {
            string message = "Connection Successful!";

            try
            {
                DatabaseHelper helper = new DatabaseHelper(connectionStringTextBox.Text);
                helper.IsValidConnectionString();

            }
            catch (Exception ex)
            {
                message = ex.Message;
                MessageBox.Show(this, message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            MessageBox.Show(this, message, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        /// <summary>
        /// Reloads the Listbox with the list of tables
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void databasesComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            DatabaseHelper helper = new DatabaseHelper(User.Default.DatabaseConnectionString);

            LoadListBox(helper);
        }
        private void LoadListBox(DatabaseHelper helper)
        {
            //Clear items from the ListBox
            databaseTablesListBox.Items.Clear();

            generationTablesListBox.Items.Clear();

            //Retrieve table names from Database and manually add them to the ListBox. DataBinding creates and error when the collection
            //is motified.
            List<string> tableNames = helper.RetrieveTables(databasesComboBox.Text);
            AddTableNamesToListBox(tableNames);
        }
 private void LoadDropdownAndListBox(DatabaseHelper helper)
 {
     databasesComboBox.DataSource = helper.RetrieveDatabaseNames();
     LoadListBox(helper);
 }
        private void loadDatabaseDropDown_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            DatabaseHelper helper = new DatabaseHelper(User.Default.DatabaseConnectionString);
            LoadDropdownAndListBox(helper);

            Cursor = Cursors.Arrow;

            loadDatabaseDropDown.Text = "Refresh";
        }