Beispiel #1
0
        private void NewRecurringAppointment()
        {
            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;
            }
            RecurringAppointmentFrontEnd form = new RecurringAppointmentFrontEnd(monthCalendar.SelectionRange.Start.Date);

            form.ShowDialog();
            if (form.RecurringAppointment == null)
            {
                return;
            }
            if (_Appointments.Count > 0)
            {
                foreach (IAppointment app in _Appointments)
                {
                    if (form.RecurringAppointment.OccursOnTime(app.Start, app.Length))
                    {
                        MessageBox.Show("Date and Time already used at " + app.Start.ToLongDateString(),
                                        "Cannot add current recurring appointment",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            // Saving the recurring appointment
            // via StreamReader in a .txt file
            _Appointments.Add(form.RecurringAppointment);
            if (_Appointments.Save())
            {
                _TodaysAppointments.Add(form.RecurringAppointment);
                panelDailyView.Invalidate();
            }
        }
Beispiel #2
0
 // EDIT option of an appointment already booked in calendar
 // preventing from all datetime exceptions
 private void editToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_SelectedAppointment is RecurringAppointment)
     {
         RecurringAppointment         app  = _SelectedAppointment as RecurringAppointment;
         RecurringAppointmentFrontEnd form = new RecurringAppointmentFrontEnd(monthCalendar.SelectionRange.Start, app);
         form.ShowDialog();
         _Appointments.Remove(app);
         _TodaysAppointments.Remove(app);
         if (form.RecurringAppointment == null || form.RecurringAppointment == app)
         {
             return;
         }
         if (_Appointments.Count > 0)
         {
             foreach (IAppointment appointment in _Appointments)
             {
                 if (form.RecurringAppointment.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.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 appointment in _Appointments)
             {
                 if (form.Appointment.TimeConflict(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.Appointment);
         if (_Appointments.Save())
         {
             _TodaysAppointments.Add(form.Appointment);
             panelDailyView.Invalidate();
         }
     }
 }