//Populates practices to textboxes
        private void Delete_Existing_Dropdown_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Practice_Database.PracticeSelected(Delete_Existing_Dropdown, Input_1, Input_2, Input_3, Input_4,
                                               Input_5, Input_6, Input_7, Input_8);

            //Allows user to delete record
            Delete.Enabled = true;
        }
        //When a user clicks a selection from the dropdown box all the values of the selected practice will
        //populate the fields.  The program will also know that this is an edit session and not a new Practice
        private void Dropdown_1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Practice_Database.PracticeSelected(Dropdown_1, Input_1, Input_2, Input_3, Input_4,
                                               Input_5, Input_6, Input_7, Input_8);
            AddOrEditFields(true);             //Allows fields to be written in

            //Allows user to save record
            Save.Enabled = true;
        }
        //Saves changes to new patient or existing practice
        private void Save_Click(object sender, EventArgs e)
        {
            bool saveSuccess = Practice_Database.SavePractice(Dropdown_1, Input_1, Input_2, Input_3, Input_4,
                                                              Input_5, Input_6, Input_7, Input_8);

            if (saveSuccess == true)
            {
                AddOrEditFields(false);     //Changes fields to read only.  User needs to select
                //add new patient or edit existing if they want to continue
                Add_Dropdown_1.Focus();
            }
        }
        public static void RefferingGPSelectedAddEdit(ComboBox refGPDropDownList, TextBox id, TextBox firstName, TextBox lastName, TextBox directNumber,
                                                      TextBox email, TextBox notes, ComboBox practiceDropDownList)
        {
            DataTable pracdt;                                                                                              //Will be used to search through the practice names
            string    practiceName      = null;                                                                            //Will Hold the name of the practice
            int       pracSelectedIndex = 0;                                                                               //Will Hold the selected index of the Dropdown2

            string query = "SELECT * FROM [REFFERING GP] WHERE REFGP_ID_Number =" + refGPDropDownList.SelectedValue + ";"; //SQL Query

            //Connect to database and run query
            using (Global.connection = new SQLiteConnection(Global.connectionString))
                using (SQLiteCommand cmd = new SQLiteCommand(query, Global.connection))
                {
                    try
                    {
                        Global.connection.Open();
                        SQLiteDataReader reader = cmd.ExecuteReader();

                        //Populating the fields with the found Reffering GP details
                        while (reader.Read())
                        {
                            id.Text           = reader.GetInt32(0).ToString();
                            firstName.Text    = reader.GetString(1);
                            lastName.Text     = reader.GetString(2);
                            directNumber.Text = reader.GetString(3);
                            email.Text        = reader.GetString(4);
                            practiceName      = reader.GetString(5);            //Sets a local variable to hold the Practice Name
                            notes.Text        = reader.GetString(6);
                        }
                        Global.editingExistingRefferingGP = true; //Creates an edit session

                        Global.connection.Close();
                    }
                    catch (SQLiteException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            pracdt = Practice_Database.populatePracticeDropDown(practiceDropDownList);
            int counter = 0;                //Counter will be used to find pracSelectedIndex

            //Loop through datatable to find the row with the selected Practice Name
            foreach (DataRow row in pracdt.Rows)
            {
                if (row[0].ToString() == practiceName)
                {
                    pracSelectedIndex = counter;
                    break;
                }
                counter++;
            }
            practiceDropDownList.SelectedIndex = pracSelectedIndex;       //Selects the correct Reffering GP from Reffering_GP_Dropdown
        }
 //Deletes Practice
 private void Delete_Click(object sender, EventArgs e)
 {
     Practice_Database.DeletePractice(Delete_Existing_Dropdown, Input_1);
     if (Delete_Existing_Dropdown.DataSource == null)
     {
         Input_1.Clear();
         Input_2.Clear();
         Input_3.Clear();
         Input_4.Clear();
         Input_5.Clear();
         Input_6.Clear();
         Input_7.Clear();
         Input_8.Clear();
     }
 }
        //Views all of the records determined by the dropdown1 selection
        private void View_All_Click(object sender, EventArgs e)
        {
            switch (Global.view)
            {
            case "View Patients":
                Patient_Database.ViewAllRecords(Dropdown_1, Records_Gridview);
                break;

            case "View Consultations":
                Consultation_Database.ViewAllRecords(Dropdown_1, Records_Gridview);
                break;

            case "View Reffering GPs":
                Reffering_GP_Database.ViewAllRecords(Records_Gridview);
                break;

            case "View Practices":
                Practice_Database.ViewAllRecords(Records_Gridview);
                break;
            }
            Total_Records.Text = Records_Gridview.Rows.Count.ToString();
        }
        private void Search_Click(object sender, EventArgs e)
        {
            switch (Global.view)
            {
            case "View Patients":
                Patient_Database.ViewSearchedRecords(Records_Gridview, Input_1, Dropdown_1, Dropdown_2,
                                                     Dropdown_3, Date_1, Date_2);
                break;

            case "View Consultations":
                Consultation_Database.ViewSearchedRecords(Records_Gridview, Input_1, Dropdown_1, Dropdown_2,
                                                          Dropdown_3, Date_1, Date_2);
                break;

            case "View Reffering GPs":
                Reffering_GP_Database.ViewSearchedRecords(Records_Gridview, Input_1, Dropdown_2);
                break;

            case "View Practices":
                Practice_Database.ViewSearchedRecords(Records_Gridview, Input_1, Dropdown_2);
                break;
            }
            Total_Records.Text = Records_Gridview.Rows.Count.ToString();
        }
        //Sets the search input box and labels
        private void Dropdown_2_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Search.Enabled = true;          //Allows user to search once a selection is made
            switch (Global.view)
            {
            case "View Patients":
                Patient_Database.Show_HideSearchOptions(Dropdown_2, Dropdown_3, Input_1, Date_1,
                                                        Date_2, Search_Label, Search_Label2);
                break;

            case "View Consultations":
                Consultation_Database.Show_HideSearchOptions(Dropdown_2, Dropdown_3, Input_1, Date_1,
                                                             Date_2, Search_Label, Search_Label2);
                break;

            case "View Reffering GPs":
                Reffering_GP_Database.Show_HideSearchOptions(Dropdown_2, Input_1, Search_Label);
                break;

            case "View Practices":
                Practice_Database.Show_HideSearchOptions(Dropdown_2, Input_1, Search_Label);
                break;
            }
        }
        //********************Database Event Methods********************

        //Shows list of all existing practices
        private void Dropdown_1_DropDown(object sender, EventArgs e)
        {
            Practice_Database.populatePracticeDropDown(Dropdown_1);
        }
 //Shows list of practices to delete
 private void Delete_Existing_Dropdown_DropDown(object sender, EventArgs e)
 {
     Practice_Database.populatePracticeDropDown(Delete_Existing_Dropdown);
 }