private void CreateAppointment_Click(object sender, MouseButtonEventArgs e) { // Bring up window to add appointment EditAppointment form = new EditAppointment(); Rectangle r = (Rectangle)sender; DateTime datetime = DateTime.Parse((String)currentDate.Content + " " + (String)r.Tag); Grid g = (Grid)this.Parent; MainWindow mw = (MainWindow)g.Parent; m_appointmentDatabase = mw.NewAppointmentClicked(datetime, (String)((StackPanel)(r.Parent)).Tag); UpdateDayWithAppointments(); }
private void EditAppointment_Clicked(object sender, MouseButtonEventArgs e) { // bring up window to edit appointment EditAppointment form = new EditAppointment(); TextBlock tb = (TextBlock)sender; //Grid g = (Grid)sender; //TextBlock tb = null; //foreach(UIElement c in g.Children) //{ // if (c.GetType() == typeof(TextBlock)) // tb = (TextBlock)c; //} //if (tb == null) //{ // MessageBox.Show("Error: Could not edit appointment.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); //} Grid g = (Grid)tb.Parent; StackPanel sp = (StackPanel)g.Parent; DateTime dt = DateTime.Parse((String)currentDate.Content + " " + (String)tb.Tag); String doc = (String)sp.Tag; foreach (Appointment a in m_appointmentDatabase.m_appointments) { if (a.m_patient.m_firstName + " " + a.m_patient.m_lastName == tb.Text) { form.SetInfo(tb.Text, a.m_patient.m_hcNumber, (String)sp.Tag, dt); break; } } //form.SetInfo(tb.Text, "patient number", (String)sp.Tag, dt); form.ShowDialog(); if (form.m_delete) { // delete appointment bool success = false; foreach (Appointment a in m_appointmentDatabase.m_appointments) { if (a.m_patient.m_firstName + " " + a.m_patient.m_lastName == tb.Text) { if (DateTime.Compare(a.m_startTime, dt) == 0) { m_appointmentDatabase.DeleteAppointment(a); success = true; break; } } } if (!success) { MessageBox.Show("Error: Could not delete appointment.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Appointment deleted.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); UpdateDayWithAppointments(); } } else if (form.m_changed) { // edit appointment Appointment ap = null; foreach (Appointment a in m_appointmentDatabase.m_appointments) { if (a.m_patient.m_firstName + " " + a.m_patient.m_lastName == tb.Text) { if (DateTime.Compare(a.m_startTime, dt) == 0 && a.m_doctor == doc) { ap = a; break; } } } if (ap == null) { MessageBox.Show("Error: Could not edit appointment.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { bool conflict = false; foreach (Appointment a in m_appointmentDatabase.m_appointments) { if (DateTime.Compare(a.m_startTime, form.m_startDate) == 0 && a.m_doctor == form.m_doctor) { conflict = true; break; } } if (conflict) { String msg = "Appointment time conflicts with another appointment, nothing was changed."; MessageBox.Show(msg, "Time Conflict", MessageBoxButton.OK, MessageBoxImage.Error); } else { ap.m_doctor = form.m_doctor; ap.m_startTime = form.m_startDate; MessageBox.Show("Appointment changed.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); UpdateDayWithAppointments(); } } } }