Esempio n. 1
0
        private void AddToGroup(IEnumerable <CalendarEvent> calendarEvents)
        {
            var           anyHolidayAdd          = false;
            CalendarEvent lastAddedCalendarEvent = null;

            foreach (var calendarEvent in calendarEvents)
            {
                var start = calendarEvent.Start.Date;
                while (start < calendarEvent.End.Date)
                {
                    if (!_dayItemsSource.ContainsKey(start))
                    {
                        _dayItemsSource[start] = new DayItemModel(start);
                    }

                    if (calendarEvent.Is <DaylightSavingTime>())
                    {
                        _dayItemsSource[start].Insert(0, calendarEvent);
                    }
                    else
                    {
                        _dayItemsSource[start].Add(calendarEvent);
                    }

                    _dayItemsSource[start].Refresh();
                    //CollectionViewSource.GetDefaultView(_dayItemsSource[start])
                    //    .Self(v =>
                    //    {   //可防止删除calendarEvent的时候未选中项
                    //        v.MoveCurrentToFirst();
                    //    });
                    start = start.AddDays(1);
                }
                _allEvents.Add(calendarEvent);
                if (calendarEvent.Is <Holiday>())
                {
                    anyHolidayAdd = true;
                }

                lastAddedCalendarEvent = calendarEvent;
            }

            AllEventsView.Refresh();
            if (lastAddedCalendarEvent != null)
            {
                AllEventsView.MoveCurrentTo(lastAddedCalendarEvent);
            }

            if (anyHolidayAdd)
            {
                SummarizeActiveMonth();
            }
        }
Esempio n. 2
0
        public object GetItem(object index, Type indexType)
        {
            if (indexType == typeof(DateTime))
            {
                var dateKey = Convert.ToDateTime(index);
                if (DayItemsSource != null)
                {
                    if (!DayItemsSource.ContainsKey(dateKey))
                    {
                        DayItemsSource[dateKey] = new DayItemModel(dateKey);
                    }

                    return(DayItemsSource[dateKey]);
                }
            }
            return(null);
        }
Esempio n. 3
0
        private void SetDayItemsSource(IList <CalendarEvent> value)
        {
            _allEvents = value;
            // convert to dayItemsSource
            _dayItemsSource = new Dictionary <DateTime, DayItemModel>();
            foreach (var calendarEvent in _allEvents)
            {
                var start = calendarEvent.Start.Date;
                while (start < calendarEvent.End.Date)
                {
                    if (!_dayItemsSource.ContainsKey(start))
                    {
                        _dayItemsSource[start] = new DayItemModel(start);
                    }

                    _dayItemsSource[start].Add(calendarEvent);

                    start = start.AddDays(1);
                }
            }
            _workingDays -= Holidays;

            NotifyOfPropertyChange(() => DayItemsSource);
        }