Beispiel #1
0
        private List <RehearsalPart> ScheduleDay(DateTime start, Duration length, GetDAL get)
        {
            List <RehearsalPart> retval = new List <RehearsalPart>();
            //DateTime end = start.AddMinutes(length.TotalMinutes);
            Duration totalRehearsalTimeForDay = Duration.Zero;

            DateTime rehearsalPartStart = start;
            DateTime rehearsalPartEnd   = rehearsalPartStart;

            foreach (RehearsalPart rp in UnscheduledRehearsalParts.ToArray())
            {
                double minutesRehearsalPartLength = rp.DurLength.ToDuration().TotalMinutes;
                rehearsalPartEnd = rehearsalPartEnd.AddMinutes(minutesRehearsalPartLength);
                // if the list of needed members do not have conflicts between start and end
                // AND the duration of the rehearsal part plus total time so far is less than the max length of the rehearsal
                bool hasConflicts        = HasConflicts(rp.LstMembers, rehearsalPartStart, rehearsalPartEnd, get);
                bool rehearsalLengthFits = rp.DurLength.ToDuration().Plus(totalRehearsalTimeForDay) <= length;
                if (!hasConflicts && rehearsalLengthFits)
                {
                    // start rehearsal part at given time
                    rp.DtmStartDateTime = rehearsalPartStart;
                    // end rehearsal part at given time
                    rp.DtmEndDateTime = rehearsalPartStart.AddMinutes(minutesRehearsalPartLength);
                    // move new rehearsal part start time to end
                    rehearsalPartStart = (DateTime)rp.DtmEndDateTime;
                    // reset rehearsal part end time to new start time
                    rehearsalPartEnd = rehearsalPartStart;
                    // add to total rehearsal time for day
                    totalRehearsalTimeForDay = totalRehearsalTimeForDay.Plus(Duration.FromMinutes(minutesRehearsalPartLength));


                    // remove from unschedule rehearsal parts list
                    UnscheduledRehearsalParts.Remove(rp);

                    // add this rehearsal part to the list of scheduled parts
                    retval.Add(rp);
                }
            }
            return(retval);
        }
Beispiel #2
0
        public FinalSchedule CreateSchedule(DateTime startDate, DateTime eventDate, GetDAL get)
        {
            // starting at the rehearsal start date
            List <DateTime> rehearsalDates = Enumerable.Range(0, 1 + eventDate.Subtract(startDate).Days)
                                             .Select(offset => startDate.AddDays(offset))
                                             .ToList();

            List <RehearsalPart> scheduledRehearsalParts = new List <RehearsalPart>();

            foreach (var day in rehearsalDates)
            {
                if (UnscheduledRehearsalParts.Any())
                {
                    switch (day.DayOfWeek)
                    {
                    case DayOfWeek.Monday:
                        DateTime monday = new DateTime(day.Year, day.Month, day.Day,
                                                       EventSchedule.TmeMondayStart.Hour,
                                                       EventSchedule.TmeMondayStart.Minute,
                                                       EventSchedule.TmeMondayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(monday, EventSchedule.PerWeekdayDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Tuesday:
                        DateTime tuesday = new DateTime(day.Year, day.Month, day.Day,
                                                        EventSchedule.TmeTuesdayStart.Hour,
                                                        EventSchedule.TmeTuesdayStart.Minute,
                                                        EventSchedule.TmeTuesdayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(tuesday, EventSchedule.PerWeekdayDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Wednesday:
                        DateTime wednesday = new DateTime(day.Year, day.Month, day.Day,
                                                          EventSchedule.TmeWednesdayStart.Hour,
                                                          EventSchedule.TmeWednesdayStart.Minute,
                                                          EventSchedule.TmeWednesdayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(wednesday, EventSchedule.PerWeekdayDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Thursday:
                        DateTime thursday = new DateTime(day.Year, day.Month, day.Day,
                                                         EventSchedule.TmeThursdayStart.Hour,
                                                         EventSchedule.TmeThursdayStart.Minute,
                                                         EventSchedule.TmeThursdayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(thursday, EventSchedule.PerWeekdayDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Friday:
                        DateTime friday = new DateTime(day.Year, day.Month, day.Day,
                                                       EventSchedule.TmeFridayStart.Hour,
                                                       EventSchedule.TmeFridayStart.Minute,
                                                       EventSchedule.TmeFridayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(friday, EventSchedule.PerWeekdayDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Saturday:
                        DateTime saturday = new DateTime(day.Year, day.Month, day.Day,
                                                         EventSchedule.TmeSaturdayStart.Hour,
                                                         EventSchedule.TmeSaturdayStart.Minute,
                                                         EventSchedule.TmeSaturdayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(saturday, EventSchedule.PerWeekendDuration.ToDuration(), get)).ToList();
                        break;

                    case DayOfWeek.Sunday:
                        DateTime sunday = new DateTime(day.Year, day.Month, day.Day,
                                                       EventSchedule.TmeSundayStart.Hour,
                                                       EventSchedule.TmeSundayStart.Minute,
                                                       EventSchedule.TmeSundayStart.Second);
                        scheduledRehearsalParts = scheduledRehearsalParts.Concat(ScheduleDay(sunday, EventSchedule.PerWeekendDuration.ToDuration(), get)).ToList();
                        break;
                    }
                }
            }

            FinalSchedule = new FinalSchedule(scheduledRehearsalParts, UnscheduledRehearsalParts);
            get.CloseConnection();

            return(FinalSchedule);
        }