private void NewAppointment() { // handles the addition of a new appointment, gets values from the // form and then sets them to be the values of the new appointment DateTime selectedDate = monthCalendar.SelectionRange.Start; int selectedDateIndex = _SelectedRow; if (!Outdated(selectedDate)) { AppointmentForm appointment = new AppointmentForm(selectedDate, selectedDateIndex, false); DialogResult dr = appointment.ShowDialog(); { if (dr == DialogResult.OK && !Outdated(selectedDate)) { // if the user clicks "save", the values passed through from // the form get implemented into the appointment and then added // to the list string desc = appointment.GetDesc; DateTime start = appointment.GetStart; int len = appointment.GetLen; bool rec = appointment.GetRecurs; int occ = appointment.GetOcc; // this section it adds the new appointment to the list, then // saves the new list. Appointment a = new Appointment(start, len, desc, rec, occ); if (!CheckOverlapping(a)) { _Appointments.Add(a); if (!_Appointments.Save()) { MessageBox.Show("The appointment Could not be saved, " + "Please ensure that all fields are filled", "Saving To File", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("There is already an appointment " + "at selected date and time, please try a different date", "Saving To File", MessageBoxButtons.OK, MessageBoxIcon.Error); } ResetView(); } } } }
private void NewAppointment() { // TODO - You need to complete this method AppointmentSingle eappForm = new AppointmentSingle(_SelectedAppointment, 1, monthCalendar.SelectionStart); eappForm.ShowDialog(); // Single Appointment if (eappForm.saved) { _Appointments.Add(eappForm._SelectedAppointment); GetAppointmentsOnSelectedDate(monthCalendar.SelectionRange.Start); // Force repaint of daily view panel panelDailyView.Invalidate(); _Appointments.Save(); } }
// Replace the contents of mTodaysAppointments with // the appointments for the specified date. private void GetAppointmentsOnSelectedDate(DateTime date) { _TodaysAppointments.Clear(); foreach (IAppointment appointment in _Appointments.GetAppointmentsOnDate(date)) { _TodaysAppointments.Add(appointment); } }
private void NewAppointment() { Appointment newAppointment = new Appointment(Utility.ConvertRowToDateTime(monthCalendar.SelectionRange.Start, _SelectedRow)); if (AddEdit(newAppointment)) { try { _Appointments.Add(newAppointment); } catch (ItemsException e) { MessageBox.Show(this, e.Message, "Error adding Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } GetAppointmentsOnSelectedDate(monthCalendar.SelectionRange.Start); panelDailyView.Invalidate(); }
private void panelDailyView_MouseDoubleClick(object sender, MouseEventArgs e) { IAppointment appointment = CheckForAppointment(e); if (appointment != null) { _SelectedAppointment = appointment; if (_SelectedAppointment is RecurringAppointment) { RecurringAppointment app = _SelectedAppointment as RecurringAppointment; RecurringAppointmentForm form = new RecurringAppointmentForm(monthCalendar.SelectionRange.Start, app); form.ShowDialog(); _Appointments.Remove(_SelectedAppointment); _TodaysAppointments.Remove(_SelectedAppointment); if (form.ReccuringApp == null) { return; } if (_Appointments.Count > 0) { foreach (IAppointment otherappointment in _Appointments) { if (form.ReccuringApp.OccursOnTime(otherappointment.Start, otherappointment.Length)) { MessageBox.Show("Date and Time already used at " + app.Start.ToLongDateString(), "Cannot add current recurring appointment", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } ; _Appointments.Add(form.ReccuringApp); _TodaysAppointments.Add(form.ReccuringApp); panelDailyView.Invalidate(); return; } if (_SelectedAppointment is Appointment) { Appointment app = _SelectedAppointment as Appointment; AppointmentForm form = new AppointmentForm(monthCalendar.SelectionRange.Start, app); form.ShowDialog(); if (form.App == null) { return; } if (_Appointments.Count > 0) { foreach (IAppointment otherappointment in _Appointments) { if (form.App.OccursOnTime(otherappointment.Start, otherappointment.Length)) { MessageBox.Show("Date and Time already used", "Cannot add current appointment", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } _Appointments.Remove(app); _TodaysAppointments.Remove(app); _Appointments.Add(form.App); _TodaysAppointments.Add(form.App); panelDailyView.Invalidate(); return; } } }