private void ApptDeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create an object called CurrentAppt of type Appt1
            Appointment1 CurrentAppt = new Appointment1();

            //CurrentAppt holds the values of the selectedItem by casting the ApptDataGrid as type Appt1. This makes it possible to grab these values
            CurrentAppt = (Appointment1)ApptDataGrid.SelectedItem;
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Delete Appointment for " + CurrentAppt.Client + "?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                AppointmentID = CurrentAppt.AppointmentID.ToString();

                //Execute the following query to delete the record from the Appt table using the ApptID
                dbContext.Database.ExecuteSqlCommand("Delete from Appointment where AppointmentID = @ApptID",
                                                     //assign parameters values
                                                     new SqlParameter("ApptID", this.AppointmentID));

                //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.AppointmentID));
                var Appt = dbContext.Appointments1.SqlQuery("select * from Appointments").ToList();
                ApptDataGrid.ItemsSource = Appt;

                MessageBox.Show("An Appointment for " + CurrentAppt.Client.ToString() + " was deleted");

                //Populated the datagrid so that it no longer contains the deleted record

                ApptDataGrid.SelectedIndex = 0;

                //Resets the text fields
                ApptDate.Text               = null;
                TimeCB.SelectedIndex        = -1;
                DurationCB.SelectedIndex    = -1;
                CounselorCB.SelectedIndex   = -1;
                ScheduledByCB.SelectedIndex = -1;
                RoomCB.SelectedIndex        = -1;
                NotesTxt.Text               = null;
                ClientCB.SelectedIndex      = -1;
                AppointmentID               = null;

                ApptAddBtn.IsEnabled  = true;
                ApptEditBtn.IsEnabled = true;
            }
        }
        private void ApptEditBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create an object called CurrentAppointment of type Appointment1
            Appointment1 CurrentAppointment = new Appointment1();

            //CurrentAppointment holds the values of the selectedItem by casting the AppointmentDataGrid as type Appointment1. This makes it possible to grab these values
            CurrentAppointment = (Appointment1)ApptDataGrid.SelectedItem;
            Index = ApptDataGrid.SelectedIndex;

            //ScheduledFor CurrentClient = new ScheduledFor();

            CounselorCB.SelectedValue = CurrentAppointment.Counselor;

            ClientCB.SelectedValue = CurrentAppointment.Client;
//this separates the first name from the last name so that I can use it to select the value in the combo box

            ScheduledByCB.SelectedValue = CurrentAppointment.ScheduledBy;

            string DateTime = CurrentAppointment.StartTime.ToString();
            //Ex: ger = Holly White

            //spits the time
            var DTime = DateTime.Split(' ');
            //Ex: [1] = White   [0] = Holly
            string Time = DTime[1].ToString();
            string AMPM = DTime[2].ToString();
            string Date = DTime[0].ToString();

            String FinalTime = Time + " " + AMPM;


            //Populate the text fields with their respective data from the datagrid
            ApptDate.Text   = Date;
            TimeCB.Text     = FinalTime;
            RoomCB.Text     = CurrentAppointment.RoomName;
            NotesTxt.Text   = CurrentAppointment.Notes;
            DurationCB.Text = CurrentAppointment.Duration.ToString();

            //AppointmentID holds the AppointmentID of the record that is being updated
            this.AppointmentID = CurrentAppointment.AppointmentID.ToString();

            ApptEditBtn.IsEnabled = false;
            ApptAddBtn.IsEnabled  = false;
        }
        private void ApptAddBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //iMatch holds the value to know if the appointment 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 < ApptDataGrid.Items.Count - 1; iCount++)
                {
                    //create an object of type appointment1 to access appointment information from datagrid
                    Appointment1 CurrentAppt = new Appointment1();
                    ApptDataGrid.SelectedIndex = iCount;// set the index to that of the iCount
                    CurrentAppt = (Appointment1)ApptDataGrid.SelectedItem;
                    String Date = ApptDate.SelectedDate.Value.ToShortDateString();
                    String Time = (String)TimeCB.SelectionBoxItem;

                    String DateTime = Date + " " + Time;
                    //if the new name matches a record, one is added to iMatch
                    if (DateTime == CurrentAppt.StartTime.ToString() &&
                        ClientCB.SelectionBoxItem.ToString() == CurrentAppt.Client &&
                        RoomCB.SelectionBoxItem.ToString() == CurrentAppt.RoomName &&
                        CounselorCB.SelectionBoxItem.ToString() == CurrentAppt.Counselor)
                    {
                        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("An Appointment already exists with this name, add anyway?", "Add Confirmation", System.Windows.MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        string Counselor = CounselorCB.SelectionBoxItem.ToString();
                        //Ex: ger = Holly White

                        var CounselorName = Counselor.Split(' ');
                        //Ex: [1] = White   [0] = Holly
                        string CounselorLastName  = CounselorName[1].ToString();
                        string CounselorFirstName = CounselorName[0].ToString();

                        //runs query
                        int query_super_ID = (from Person in dbContext.People
                                              where Person.FirstName == CounselorFirstName &&
                                              Person.LastName == CounselorLastName
                                              select Person).First <Person>().personID;
                        int CLRID = Convert.ToInt32(query_super_ID);

                        //Separate Employee First Name and Last Name
                        string Employee = ScheduledByCB.SelectionBoxItem.ToString();
                        //Ex: ger = Holly White

                        var EmployeeName = Employee.Split(' ');
                        //Ex: [1] = White   [0] = Holly
                        string EmployeeLastName  = EmployeeName[1].ToString();
                        string EmployeeFirstName = EmployeeName[0].ToString();

                        //runs query
                        int query_Emp_ID = (from Person in dbContext.People
                                            where Person.FirstName == EmployeeFirstName &&
                                            Person.LastName == EmployeeLastName
                                            select Person).First <Person>().personID;
                        int EmpID = Convert.ToInt32(query_Emp_ID);

                        //Client
                        string Client = ClientCB.SelectionBoxItem.ToString();
                        //Ex: ger = Holly White

                        var ClientName = Client.Split(' ');
                        //Ex: [1] = White   [0] = Holly
                        string ClientLastName  = ClientName[1].ToString();
                        string ClientFirstName = ClientName[0].ToString();

                        int query_Client_ID = (from Person in dbContext.People
                                               where Person.FirstName == ClientFirstName &&
                                               Person.LastName == ClientLastName
                                               select Person).First <Person>().personID;
                        int CID = Convert.ToInt32(query_Client_ID);
                        //concatenates the Date and TIme combobox
                        String Date = ApptDate.SelectedDate.Value.ToShortDateString();
                        String Time = (String)TimeCB.SelectionBoxItem;

                        String DateTime = Date + " " + Time;
                        //runs query
                        dbContext.Database.ExecuteSqlCommand("Insert into Appointment(StartTime, Duration, CounselorID, EmployeeID, RoomNumber, Notes) values (@StartTime, @Duration, @Counselor,@Employee, (Select RoomNumber from Room where RoomName =@RoomName), @Notes)",
                                                             new SqlParameter("StartTime", DateTime),
                                                             new SqlParameter("Duration", DurationCB.SelectionBoxItem),
                                                             new SqlParameter("Counselor", CLRID),
                                                             new SqlParameter("Employee", EmpID),
                                                             new SqlParameter("RoomName", RoomCB.SelectionBoxItem),
                                                             new SqlParameter("Notes", NotesTxt.Text));
                        dbContext.Database.ExecuteSqlCommand("Insert into ScheduledFor (AppointmentID, ClientID) values((Select max(AppointmentID) from appointment),  @Client)",
                                                             new SqlParameter("Client", CID));

                        //populates the datagrid with the Employee1 view information
                        var Appointment = dbContext.Appointments1.SqlQuery("select * from Appointments").ToList();
                        ApptDataGrid.ItemsSource   = Appointment;
                        ApptDataGrid.SelectedIndex = 0;

                        MessageBox.Show("An Appointment was added for " + ClientCB.SelectionBoxItem.ToString());

                        //Resets the text fields
                        ApptDate.Text               = null;
                        TimeCB.SelectedIndex        = -1;
                        DurationCB.SelectedIndex    = -1;
                        CounselorCB.SelectedIndex   = -1;
                        ScheduledByCB.SelectedIndex = -1;
                        RoomCB.SelectedIndex        = -1;
                        NotesTxt.Text               = null;
                        ClientCB.SelectedIndex      = -1;
                        AppointmentID               = null;
                    }
                    else
                    {
                        //resets the fields
                        ApptDate.Text               = null;
                        TimeCB.SelectedIndex        = -1;
                        DurationCB.SelectedIndex    = -1;
                        CounselorCB.SelectedIndex   = -1;
                        ScheduledByCB.SelectedIndex = -1;
                        RoomCB.SelectedIndex        = -1;
                        NotesTxt.Text               = null;
                        ClientCB.SelectedIndex      = -1;
                        AppointmentID               = null;
                    }
                }
                else
                {
                    string Counselor = CounselorCB.SelectionBoxItem.ToString();
                    //Ex: ger = Holly White

                    var CounselorName = Counselor.Split(' ');
                    //Ex: [1] = White   [0] = Holly
                    string CounselorLastName  = CounselorName[1].ToString();
                    string CounselorFirstName = CounselorName[0].ToString();


                    int query_super_ID = (from Person in dbContext.People
                                          where Person.FirstName == CounselorFirstName &&
                                          Person.LastName == CounselorLastName
                                          select Person).First <Person>().personID;
                    int CLRID = Convert.ToInt32(query_super_ID);

                    //Separate Employee First Name and Last Name
                    string Employee = ScheduledByCB.SelectionBoxItem.ToString();
                    //Ex: ger = Holly White

                    var EmployeeName = Employee.Split(' ');
                    //Ex: [1] = White   [0] = Holly
                    string EmployeeLastName  = EmployeeName[1].ToString();
                    string EmployeeFirstName = EmployeeName[0].ToString();


                    int query_Emp_ID = (from Person in dbContext.People
                                        where Person.FirstName == EmployeeFirstName &&
                                        Person.LastName == EmployeeLastName
                                        select Person).First <Person>().personID;
                    int EmpID = Convert.ToInt32(query_Emp_ID);

                    //Client
                    string Client = ClientCB.SelectionBoxItem.ToString();
                    //Ex: ger = Holly White

                    var ClientName = Client.Split(' ');
                    //Ex: [1] = White   [0] = Holly
                    string ClientLastName  = ClientName[1].ToString();
                    string ClientFirstName = ClientName[0].ToString();

                    int query_Client_ID = (from Person in dbContext.People
                                           where Person.FirstName == ClientFirstName &&
                                           Person.LastName == ClientLastName
                                           select Person).First <Person>().personID;
                    int CID = Convert.ToInt32(query_Client_ID);

                    String Date = ApptDate.SelectedDate.Value.ToShortDateString();
                    String Time = (String)TimeCB.SelectionBoxItem;

                    String DateTime = Date + " " + Time;

                    dbContext.Database.ExecuteSqlCommand("Insert into Appointment(StartTime, Duration, CounselorID, EmployeeID, RoomNumber, Notes) values (@StartTime, @Duration, @Counselor,@Employee, (Select RoomNumber from Room where RoomName =@RoomName), @Notes)",
                                                         new SqlParameter("StartTime", DateTime),
                                                         new SqlParameter("Duration", DurationCB.SelectionBoxItem),
                                                         new SqlParameter("Counselor", CLRID),
                                                         new SqlParameter("Employee", EmpID),
                                                         new SqlParameter("RoomName", RoomCB.SelectionBoxItem),
                                                         new SqlParameter("Notes", NotesTxt.Text));
                    dbContext.Database.ExecuteSqlCommand("Insert into ScheduledFor (AppointmentID, ClientID) values((Select max(AppointmentID) from appointment),  @Client)",
                                                         new SqlParameter("Client", CID));

                    //populates the datagrid with the Employee1 view information
                    var Appointment = dbContext.Appointments1.SqlQuery("select * from Appointments").ToList();
                    ApptDataGrid.ItemsSource   = Appointment;
                    ApptDataGrid.SelectedIndex = 0;

                    MessageBox.Show("An Appointment was added for " + ClientCB.SelectionBoxItem.ToString());

                    //Resets the text fields
                    ApptDate.Text               = null;
                    TimeCB.SelectedIndex        = -1;
                    DurationCB.SelectedIndex    = -1;
                    CounselorCB.SelectedIndex   = -1;
                    ScheduledByCB.SelectedIndex = -1;
                    RoomCB.SelectedIndex        = -1;
                    NotesTxt.Text               = null;
                    ClientCB.SelectedIndex      = -1;
                    AppointmentID               = null;
                }
            }
            catch
            {
                MessageBox.Show("Please Enter All information");
            }
        }