示例#1
0
        private DayScheduleItemsArranger(AccountDataItem account, SemesterItemsViewGroup semesterItems, ScheduleViewItemsGroup scheduleGroup, DateTime date, double heightOfHour, double spacingWhenNoAdditionalItems, double spacingWithAdditionalItems, double widthOfCollapsed, bool includeHomeworkAndHolidays)
        {
            if (semesterItems.Semester == null)
            {
                throw new NullReferenceException("Semester was null");
            }

            _semesterItems = semesterItems;
            semesterItems.OnItemsChanged    += new WeakEventHandler <EventArgs>(SemesterGroup_OnItemsChanged).Handler;
            scheduleGroup.OnChangesOccurred += new WeakEventHandler <DataChangedEvent>(ScheduleViewItemsGroup_OnChangesOccurred).Handler;

            Date = date;
            _spacingWhenNoAdditionalItems = spacingWhenNoAdditionalItems;
            _spacingWithAdditionalItems   = spacingWithAdditionalItems;
            _widthOfCollapsed             = widthOfCollapsed;
            Account         = account;
            _schoolTimeZone = account.SchoolTimeZone;
            HeightOfHour    = heightOfHour;
            MinDuration     = TimeSpan.FromHours(widthOfCollapsed / HeightOfHour);

            IsDifferentSemester = !semesterItems.Semester.IsDateDuringThisSemester(date);

            SchedulesOnDay schedules = null;

            if (!IsDifferentSemester)
            {
                schedules = SchedulesOnDay.Get(semesterItems.Classes, date, account.GetWeekOnDifferentDate(date), trackChanges: true);
                schedules.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(Schedules_CollectionChanged).Handler;
            }

            _schedules = schedules;

            if (includeHomeworkAndHolidays)
            {
                _events = HomeworksOnDay.Get(semesterItems.Items, date);
                _events.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(Events_CollectionChanged).Handler;
            }
            else
            {
                _events = new MyObservableList <BaseViewItemHomeworkExamGrade>();
            }

            if (includeHomeworkAndHolidays)
            {
                _holidays = HolidaysOnDay.Create(semesterItems.Items, date);
                _holidays.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(_holidays_CollectionChanged).Handler;
            }
            else
            {
                _holidays = new MyObservableList <ViewItemHoliday>();
            }

            Initialize(schedules, _events, _holidays);
        }
        public static HomeworksOnDay Get(MyObservableList <BaseViewItemHomeworkExamGrade> mainList, DateTime date)
        {
            HomeworksOnDay answer;

            for (int i = 0; i < _cached.Count; i++)
            {
                if (_cached[i].TryGetTarget(out answer))
                {
                    if (answer.Date == date.Date && answer.MainList == mainList)
                    {
                        return(answer);
                    }
                }
                else
                {
                    _cached.RemoveAt(i);
                    i--;
                }
            }

            answer = new HomeworksOnDay(mainList, date);
            _cached.Add(new WeakReference <HomeworksOnDay>(answer));
            return(answer);
        }