private void Refresh()
        {
            _patientList = new ObservableCollection<Patient>(App.amApp.Patients);
            _practitionerList = new ObservableCollection<Practitioner>(App.amApp.Practitioners);
            _appointmentList = new ObservableCollection<Appointment>(App.amApp.Appointments);
            _queueList = new ObservableCollection<Queue>(App.amApp.Queues);
            appointmentcount.Content = "Appointments:" + _appointmentList.Where(k => k.Dated == selectdate.Text).Count().ToString();
            queuecount.Content = "People in queue :" + _queueList.Where(k => Convert.ToDateTime(k.Day).Date == Convert.ToDateTime(selectdate.Text).Date).Count().ToString();
            QueuelistView.ItemsSource = null;
            AppointmentlistView.ItemsSource = null;
            _appointment = new Appointment(null);

            ListQueue.Clear();
            ListAppoint.Clear();


            foreach (Queue Q in _queueList.Where(m => Convert.ToDateTime(m.Day).Date == Convert.ToDateTime(selectdate.Text).Date && m.Seen=="F"))
            {
                _queue = new Queue(null);
                _queue.Id = Q.Id;
                _queue.Org = Q.Org;
                _queue.Details = "PATIENT : \t" + _patientList.First(x => x.Id.Equals(Q.Patient)).Fname + " " + _patientList.First(x => x.Id.Equals(Q.Patient)).Lname + Environment.NewLine + "PRACTITIONER : \t" + _practitionerList.First(x => x.Id.Equals(Q.Practitioner)).Name + " " + Environment.NewLine + "TIME :" + Q.Checked + Environment.NewLine + "REASON: \t" + Q.Reason + " " + Environment.NewLine + "State:" + Q.Seen + " Amount paid:" + Q.Amount; ;
                _queue.Practitioner = Q.Practitioner;               
                _queue.Patient = Q.Patient;
                _queue.Patientimage = _patientList.First(x => x.Id.Equals(Q.Patient)).Image;
                _queue.Payment = Q.Payment;
                _queue.Amount = Q.Amount;
                _queue.Checked = Convert.ToDateTime(Q.Checked).ToString("T");
                _queue.Reason = Q.Reason;

                ListQueue.Add(_queue);
            }
            //apointment list view 
            QueuelistView.ItemsSource = ListQueue;


            foreach (Appointment T in _appointmentList.Where(i => i.Dated == selectdate.Text))
            {
                _appointment = new Appointment(null);
                _appointment.Id = T.Id;
                _appointment.Org = T.Org;
                _appointment.Details = "PATIENT : \t" + _patientList.First(x => x.Id.Equals(T.Patient)).Fname + " " + _patientList.First(x => x.Id.Equals(T.Patient)).Lname + Environment.NewLine + "PRACTITIONER : \t" + _practitionerList.First(x => x.Id.Equals(T.Practitioner)).Name + " " + Environment.NewLine + "PERIOD: \t \t " + T.Meet + "-" + T.EndTime +" "+ Environment.NewLine + " REASON : \t" + T.Reason;
                _appointment.Practitioner = T.Practitioner;
                _appointment.Patient = T.Patient;
                _appointment.Dated = T.Dated;
                _appointment.StartTime = T.StartTime;
                _appointment.EndTime = T.EndTime;
                _appointment.Patientimage = _patientList.First(x => x.Id.Equals(T.Patient)).Image;
                _appointment.Reason = T.Reason;
                ListAppoint.Add(_appointment);
            }

            AppointmentlistView.ItemsSource = ListAppoint;


        }
        private void QueueButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
            Appointment user = button.DataContext as Appointment;

            if (System.Windows.MessageBox.Show("Are you sure you want queue this appointment" + " " + " ?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                _queue = App.amApp.Queues.Add();
                _queue.Patient = user.Patient.ToString();
                _queue.Practitioner = user.Practitioner;
                _queue.Payment = " ";
                _queue.Amount = " ";
                _queue.Checked = DateTime.Now.ToString("hh:mm:ss");
                _queue.Day = DateTime.Now.ToString();
                _queue.Reason = " ";
                _queue.Sync = "F";
                _queue.Org = "test";
                _queue.Seen = "F";
                _queue.Save();

                Refresh();

            }
            else
            {

                return;
            }
        }
        private void SaveQueue()
        {
          
            _queue = App.amApp.Queues.Add();
            _queue.Patient = patient.Content.ToString();
            _queue.Practitioner = selectedPrac;
            _queue.Payment = payment.Text;
            _queue.Amount = amount.Text;
            _queue.Checked = DateTime.Now.ToString("hh:mm:ss");
            _queue.Day = DateTime.Now.ToString();
            _queue.Reason = reason.Text;
            _queue.Sync = "F";
            _queue.Org = "test";
            _queue.Seen = "F";
            _queue.Save();

           // Messenger.Send("You have `scheduled an appointment with" + _practitionerList.First(x => x.Id == selectedPrac).Practice + "  on:" + startDate.Text + " at:" + endHour.Text + ":" + endMin.Text + "  ", _patientList.First(x => x.Id == patient.Content.ToString()).Phone);    
          


            System.Windows.MessageBox.Show("Queue created ");
            this.DialogResult = true;

        }