private void NewAppointment() { if (monthCalendar.SelectionRange.Start.Date < System.DateTime.Now.Date) { MessageBox.Show("Cannot add past appointments to the callendar", "Invalid date", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } AppointmentForm form = new AppointmentForm(monthCalendar.SelectionRange.Start); form.ShowDialog(); if (form.App == null) { return; } if (_Appointments.Count > 0) { foreach (IAppointment app in _Appointments) { if (form.App.OccursOnTime(app.Start, app.Length)) { MessageBox.Show("Date and Time already used", "Cannot add current appointment", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } _Appointments.Add(form.App); _TodaysAppointments.Add(form.App); panelDailyView.Invalidate(); }
private void EditApp(IAppointment app) { // this is also somewhat familiar... The difference here is that // the appointment has already been created, I just want to change // the values a little string[] description = app.DisplayableDescription.Split('-'); bool recuring = false; if (description.Length == 3) { recuring = true; } Appointment appoint = ConvertCurrent(app); int _occ = appoint.Occurances; if (!Outdated(app.Start)) { AppointmentForm appointment = new AppointmentForm(recuring, app, _occ); DialogResult dr = appointment.ShowDialog(); { if (dr == DialogResult.OK) { string desc = appointment.GetDesc; DateTime start = appointment.GetStart; int len = appointment.GetLen; bool rec = CheckRecurs(desc); int occ = 1; if (rec) { occ = appointment.GetOcc; } Appointment newApp = new Appointment(start, len, desc, rec, occ); // the difference here is that it goes out with the old and in with the new _Appointments.Remove(app); _Appointments.Add(newApp); 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); } ResetView(); } } } }
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 NewRecurringAppointment() { // this looks familiar... This section creates a new appointment, // like the above example, but this one allows me to add a // recursion to it. DateTime selectedDate = monthCalendar.SelectionRange.Start; int selectedDateIndex = _SelectedRow; if (!Outdated(selectedDate)) { // the main difference here is that the recurs value is set to true AppointmentForm appointment = new AppointmentForm(selectedDate, selectedDateIndex, true); DialogResult dr = appointment.ShowDialog(); { if (dr == DialogResult.OK) { // assuming the date isn't before date.today, and the user clicked "save" again, // the new appointment is added to the list string desc = appointment.GetDesc; DateTime start = appointment.GetStart; int len = appointment.GetLen; bool rec = CheckRecurs(desc); int occ = 1; if (rec) { occ = appointment.GetOcc; } Appointment a = new Appointment(start, len, desc, rec, occ); _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); } ResetView(); } } } }
//A lot of this would have been copied, so I thought it prudent to put it in it's own method. private bool AddEdit(IAppointment apt) { //We have to ensure that it's a new appointment before changing the start time. if (apt.Start < DateTime.Now && !_Appointments.Contains(apt)) { //Set the Datetime as Now (This will be fixed in the class to be a 30min interval). ((Appointment)apt).Start = DateTime.Now; //Alert User that you can't add an appointment before the selected date //Alternately } AppointmentForm editForm; if (apt.GetType() == typeof(RecurringAppointment)) { editForm = new RecurringForm(); } else { editForm = new AppointmentForm(); } //Necessary to determine the appropriate times that aren't overlapped. //Used to edit the Datasource of Length and StartTime //editForm.Apts = _Appointments; editForm.Apt = apt; if (editForm.ShowDialog() == DialogResult.OK) { editForm.Close(); return(true); } else { editForm.Close(); return(false); } }
private void editToolStripMenuItem_Click(object sender, EventArgs e) { if (_SelectedAppointment is RecurringAppointment) { RecurringAppointment app = _SelectedAppointment as RecurringAppointment; RecurringAppointmentForm form = new RecurringAppointmentForm(monthCalendar.SelectionRange.Start, app); form.ShowDialog(); _Appointments.Remove(app); _TodaysAppointments.Remove(app); if (form.ReccuringApp == null) { return; } if (_Appointments.Count > 0) { foreach (IAppointment appointment in _Appointments) { if (form.ReccuringApp.OccursOnTime(appointment.Start, appointment.Length)) { MessageBox.Show("Date and Time already used at" + appointment.Start.ToLongDateString(), "Cannot add current 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 appointment in _Appointments) { if (form.App.OccursOnTime(appointment.Start, appointment.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; } }