Exemple #1
0
        private void NewAppointment()
        {
            // Case handler exception for adding an appointment
            // on a datetime passed
            if (monthCalendar.SelectionRange.Start.Date < System.DateTime.Now.Date)
            {
                MessageBox.Show("Error adding past appointments to the callendar", "Invalid date", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            AppointmentFrontEnd form = new AppointmentFrontEnd(monthCalendar.SelectionRange.Start);

            form.ShowDialog();
            if (form.Appointment == null)
            {
                return;
            }
            if (_Appointments.Count > 0)
            {
                foreach (IAppointment s_appointment in _Appointments)
                {
                    // Case handler for overriding appointments
                    // that have the same time or date
                    // even a passed appointment
                    if (form.Appointment.ConflictExceptionHandler(s_appointment.Start, s_appointment.Length))
                    {
                        MessageBox.Show("There is an another appointment at current time ",
                                        "Error adding current appointment",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            // Saving the appointment via StreamReader
            // in a txt file
            _Appointments.Add(form.Appointment);
            if (_Appointments.Save())
            {
                _TodaysAppointments.Add(form.Appointment);
                panelDailyView.Invalidate();
            }
        }
Exemple #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();
         }
     }
 }