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(); } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { // Raised by selecting Delete on the content menu _Appointments.Remove(_SelectedAppointment); RefreshAppointments(); _Appointments.Save(); }
// 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; RecurringAppointmentFrontEnd form = new RecurringAppointmentFrontEnd(monthCalendar.SelectionRange.Start, app); form.ShowDialog(); _Appointments.Remove(_SelectedAppointment); _TodaysAppointments.Remove(_SelectedAppointment); if (form.RecurringAppointment == null || form.RecurringAppointment == app) { return; } if (_Appointments.Count > 0) { foreach (IAppointment otherappointment in _Appointments) { if (form.RecurringAppointment.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.Remove(app); _TodaysAppointments.Remove(app); _Appointments.Add(form.RecurringAppointment); if (_Appointments.Save()) { _TodaysAppointments.Add(form.RecurringAppointment); panelDailyView.Invalidate(); } } if (_SelectedAppointment is Appointment) { Appointment app = _SelectedAppointment as Appointment; AppointmentFrontEnd form = new AppointmentFrontEnd(monthCalendar.SelectionRange.Start, app); form.ShowDialog(); if (form.Appointment == null || form.Appointment == app) { return; } if (_Appointments.Count > 0) { foreach (IAppointment otherappointment in _Appointments) { if (form.Appointment.TimeConflict(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.Appointment); if (_Appointments.Save()) { _TodaysAppointments.Add(form.Appointment); panelDailyView.Invalidate(); } } } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { _Appointments.Save(); }