Esempio n. 1
0
 private void ChangeWeekSchedule(object sender, WeekScheduleChangedEventArgs weekScheduleChangeData)
 {
     try
     {
         model.ChangeWeekSchedule(weekScheduleChangeData);
     }
     catch (InvalidTimePeriodException ex)
     {
         MessageBox.Show("Proszę wybrać poprawny przedział czasu!");
     }
     finally
     {
         view.DisplayContent();
     }
 }
Esempio n. 2
0
        public void ChangeWeekSchedule(WeekScheduleChangedEventArgs eventArgs)
        {
            var   weekSchedule = new Dictionary <DayOfWeek, Tuple <DateTime, DateTime> >();
            Array daysOfWeek   = Enum.GetValues(typeof(DayOfWeek));

            IEnumerable <WeekDayCheckBox>   weekDayCheckBoxCollection = eventArgs.WeekDayPanel.Cast <WeekDayCheckBox>();
            IEnumerable <WeekDayHourPicker> startTimePickerCollection = eventArgs.StartTimePanel.Cast <WeekDayHourPicker>();
            IEnumerable <WeekDayHourPicker> endTimePickerCollection   = eventArgs.EndTimePanel.Cast <WeekDayHourPicker>();

            for (int i = 0; i < daysOfWeek.Length; i++)
            {
                Tuple <DateTime, DateTime> timePeriod;
                var weekDayCheckBox = weekDayCheckBoxCollection.Where(item => item.AssociatedDay == (DayOfWeek)daysOfWeek.GetValue(i)).FirstOrDefault();
                if (weekDayCheckBox != null)
                {
                    if (weekDayCheckBox.Checked)
                    {
                        DateTime start = DateTime.Now.Date;
                        DateTime end   = DateTime.Now.Date;

                        var datePicker = startTimePickerCollection.Where(item => item.AssociatedDay == (DayOfWeek)daysOfWeek.GetValue(i)).FirstOrDefault();
                        if (datePicker != null)
                        {
                            start = datePicker.Value;
                        }
                        datePicker = endTimePickerCollection.Where(item => item.AssociatedDay == (DayOfWeek)daysOfWeek.GetValue(i)).FirstOrDefault();
                        if (datePicker != null)
                        {
                            end = datePicker.Value;
                        }

                        if (end < start)
                        {
                            throw new InvalidTimePeriodException();
                        }

                        timePeriod = new Tuple <DateTime, DateTime>(start, end);
                        weekSchedule.Add(weekDayCheckBox.AssociatedDay, timePeriod);
                    }
                }
            }
            WeekSchedule = weekSchedule;
        }