private void CounselorEditBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create an object called CurrentCounselor of type Counselor1
            Counselor1 CurrentCounselor = new Counselor1();

            //CurrentCounselor holds the values of the selectedItem by casting the CounselorDataGrid as type Counselor1. This makes it possible to grab these values
            CurrentCounselor = (Counselor1)CounselorDataGrid.SelectedItem;
            Index            = CounselorDataGrid.SelectedIndex;

            //Populate the text fields with their respective data from the datagrid
            CounselorFNameTxt.Text   = CurrentCounselor.FirstName;
            CounselorLNameTxt.Text   = CurrentCounselor.LastName;
            DegreeCB.Text            = CurrentCounselor.DegreeSuffix;
            CounselorAddressTxt.Text = CurrentCounselor.Address;
            CounselorCityTxt.Text    = CurrentCounselor.City;
            cbState.Text             = CurrentCounselor.State;
            CounselorZipTxt.Text     = CurrentCounselor.ZIP;
            CounselorPhoneTxt.Text   = CurrentCounselor.Phone;
            CounselorEmailTxt.Text   = CurrentCounselor.Email;

            //CounselorID holds the counselorID of the record that is being updated
            this.CounselorID = CurrentCounselor.CounselorID.ToString();

            CounselorAddBtn.IsEnabled  = false;
            CounselorEditBtn.IsEnabled = false;
        }
        private void CounselorDeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create an object called CurrentCounselor of type Counselor1
            Counselor1 CurrentCounselor = new Counselor1();

            //CurrentCounselor holds the values of the selectedItem by casting the CounselorDataGrid as type Counselor1. This makes it possible to grab these values
            CurrentCounselor = (Counselor1)CounselorDataGrid.SelectedItem;
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Delete " + CurrentCounselor.FirstName + " " + CurrentCounselor.LastName + "?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                //Execute the following query to delete the record from the counselor table using the CounselorID
                this.CounselorID = CurrentCounselor.CounselorID.ToString();
                dbContext.Database.ExecuteSqlCommand("Delete from Counselor where CounselorID = @CounselorID",
                                                     //assign parameters values
                                                     new SqlParameter("CounselorID", this.CounselorID));

                //Execute the following query to delete the record from the person table using the person ID
                dbContext.Database.ExecuteSqlCommand("Delete from Person where PersonID = @PersonID",
                                                     new SqlParameter("PersonID", this.CounselorID));

                String DeleteName = CurrentCounselor.FirstName + " " + CurrentCounselor.LastName;
                MessageBox.Show(DeleteName + " deleted from Current Counselors");

                //Populated the datagrid so that it no longer contains the deleted record
                var Counselor = dbContext.Counselor1.SqlQuery("select * from Counselor1").ToList();
                CounselorDataGrid.ItemsSource   = Counselor;
                CounselorDataGrid.SelectedIndex = 0;

                //Reset the values in the fields
                CounselorFNameTxt.Text   = null;
                CounselorLNameTxt.Text   = null;
                DegreeCB.SelectedIndex   = -1;
                CounselorAddressTxt.Text = null;
                CounselorCityTxt.Text    = null;
                cbState.SelectedIndex    = -1;
                CounselorZipTxt.Text     = null;
                CounselorPhoneTxt.Text   = null;
                CounselorEmailTxt.Text   = null;
                CounselorID = null;

                CounselorEditBtn.IsEnabled = true;
                CounselorAddBtn.IsEnabled  = true;
            }
        }
        private void CounselorAddBtn_Click(object sender, RoutedEventArgs e)
        {
            //checks to see if the fields are empty. if any are empty it prompts the user to fill in all the fields
            if (CounselorFNameTxt.Text == null || DegreeCB.SelectedIndex == -1 || cbState.SelectedIndex == -1 || CounselorLNameTxt.Text == null ||
                CounselorAddressTxt.Text == null | CounselorCityTxt.Text == null ||
                CounselorEmailTxt.Text == null || CounselorZipTxt.Text == null ||
                CounselorPhoneTxt.Text == null)
            {
                MessageBox.Show("Please Enter Counselor Information into ALL fields");
            }

            else
            {
                //iMatch holds the value to know if the room name matches any name in current room
                int iMatch = 0;
                //the for loop goes through all the records to check if there are any matches
                for (int iCount = 0; iCount < CounselorDataGrid.Items.Count - 1; iCount++)
                {
                    Counselor1 CurrentCounselor = new Counselor1();
                    CounselorDataGrid.SelectedIndex = iCount;// set the index to that of the iCount
                    CurrentCounselor = (Counselor1)CounselorDataGrid.SelectedItem;

                    //if the new name matches a record, one is added to iMatch
                    if (CounselorFNameTxt.Text.ToLowerInvariant() == CurrentCounselor.FirstName.ToLowerInvariant() &&
                        CounselorLNameTxt.Text.ToLowerInvariant() == CurrentCounselor.LastName.ToLowerInvariant() &&
                        CounselorAddressTxt.Text.ToLowerInvariant() == CurrentCounselor.Address.ToLowerInvariant())
                    {
                        iMatch++;
                    }
                }
                if (iMatch > 0)
                {
                    //asks the user if they want to add the name even tho it already exists
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Counselor already exists with this name, add anyway?", "Add Confirmation", System.Windows.MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        //Execute the following query to add new record to the person table.
                        //make variables that capture the values
                        dbContext.Database.ExecuteSqlCommand("Insert into Person(FirstName, LastName, Address, City, State, Zip, Phone, Email) Values (@FirstName, @LastName, @Address, @City, @State, @Zip, @Phone, @Email)",
                                                             //assign the parameters values
                                                             new SqlParameter("FirstName", CounselorFNameTxt.Text),
                                                             new SqlParameter("LastName", CounselorLNameTxt.Text),
                                                             new SqlParameter("Address", CounselorAddressTxt.Text),
                                                             new SqlParameter("City", CounselorCityTxt.Text),
                                                             new SqlParameter("State", cbState.SelectionBoxItem),
                                                             new SqlParameter("Zip", CounselorZipTxt.Text),
                                                             new SqlParameter("Phone", CounselorPhoneTxt.Text),
                                                             new SqlParameter("Email", CounselorEmailTxt.Text));

                        //Execute the follwoing query to add new record to the counselor table
                        dbContext.Database.ExecuteSqlCommand("insert into counselor values((select max(personid) from person),@Degree)",
                                                             new SqlParameter("Degree", DegreeCB.SelectionBoxItem));

                        //Populate the datagrid with the new records
                        var Counselor = dbContext.Counselor1.SqlQuery("select * from Counselor1").ToList();
                        CounselorDataGrid.ItemsSource = Counselor;
                        //select the first record in the datagrid
                        CounselorDataGrid.SelectedIndex = 0;

                        String AddName = CounselorFNameTxt.Text + " " + CounselorLNameTxt.Text;
                        MessageBox.Show(AddName + " added to Current Counselor");

                        //Reset the values in the fields
                        CounselorFNameTxt.Text   = null;
                        CounselorLNameTxt.Text   = null;
                        DegreeCB.SelectedIndex   = -1;
                        CounselorAddressTxt.Text = null;
                        CounselorCityTxt.Text    = null;
                        cbState.SelectedIndex    = -1;
                        CounselorZipTxt.Text     = null;
                        CounselorPhoneTxt.Text   = null;
                        CounselorEmailTxt.Text   = null;
                        CounselorID = null;
                    }
                    else
                    {
                        CounselorFNameTxt.Text   = null;
                        CounselorLNameTxt.Text   = null;
                        DegreeCB.SelectedIndex   = -1;
                        CounselorAddressTxt.Text = null;
                        CounselorCityTxt.Text    = null;
                        cbState.SelectedIndex    = -1;
                        CounselorZipTxt.Text     = null;
                        CounselorPhoneTxt.Text   = null;
                        CounselorEmailTxt.Text   = null;
                        CounselorID = null;
                    }
                }
                else
                {
                    //Execute the following query to add new record to the person table.
                    //make variables that capture the values
                    dbContext.Database.ExecuteSqlCommand("Insert into Person(FirstName, LastName, Address, City, State, Zip, Phone, Email) Values (@FirstName, @LastName, @Address, @City, @State, @Zip, @Phone, @Email)",
                                                         //assign the parameters values
                                                         new SqlParameter("FirstName", CounselorFNameTxt.Text),
                                                         new SqlParameter("LastName", CounselorLNameTxt.Text),
                                                         new SqlParameter("Address", CounselorAddressTxt.Text),
                                                         new SqlParameter("City", CounselorCityTxt.Text),
                                                         new SqlParameter("State", cbState.SelectionBoxItem),
                                                         new SqlParameter("Zip", CounselorZipTxt.Text),
                                                         new SqlParameter("Phone", CounselorPhoneTxt.Text),
                                                         new SqlParameter("Email", CounselorEmailTxt.Text));

                    //Execute the follwoing query to add new record to the counselor table
                    dbContext.Database.ExecuteSqlCommand("insert into counselor values((select max(personid) from person),@Degree)",
                                                         new SqlParameter("Degree", DegreeCB.SelectionBoxItem));

                    //Populate the datagrid with the new records
                    var Counselor = dbContext.Counselor1.SqlQuery("select * from Counselor1").ToList();
                    CounselorDataGrid.ItemsSource = Counselor;
                    //select the first record in the datagrid
                    CounselorDataGrid.SelectedIndex = 0;

                    String AddName = CounselorFNameTxt.Text + " " + CounselorLNameTxt.Text;
                    MessageBox.Show(AddName + " added to Current Counselor");

                    //Reset the values in the fields
                    CounselorFNameTxt.Text   = null;
                    CounselorLNameTxt.Text   = null;
                    DegreeCB.SelectedIndex   = -1;
                    CounselorAddressTxt.Text = null;
                    CounselorCityTxt.Text    = null;
                    cbState.SelectedIndex    = -1;
                    CounselorZipTxt.Text     = null;
                    CounselorPhoneTxt.Text   = null;
                    CounselorEmailTxt.Text   = null;
                    CounselorID = null;
                }
            }
        }