Пример #1
0
 public void updateDayView(CalendarDayView dayView)
 {
     dayView.Marked = _calendarMonthView.IsDayMarkedDelegate == null ?
                      false : _calendarMonthView.IsDayMarkedDelegate(dayView.Date);
     dayView.Available = _calendarMonthView.IsDateAvailable == null ?
                         true : _calendarMonthView.IsDateAvailable(dayView.Date);
 }
Пример #2
0
        public void BuildGrid()
        {
            DateTime previousMonth       = _currentMonth.AddMonths(-1);
            var      daysInPreviousMonth = DateTime.DaysInMonth(previousMonth.Year, previousMonth.Month);
            var      daysInMonth         = DateTime.DaysInMonth(_currentMonth.Year, _currentMonth.Month);

            weekdayOfFirst = (int)_currentMonth.DayOfWeek;
            var lead = daysInPreviousMonth - (weekdayOfFirst - 1);

            // build last month's days
            for (int i = 1; i <= weekdayOfFirst; i++)
            {
                var viewDay = new DateTime(_currentMonth.Year, _currentMonth.Month, i);
                var dayView = new CalendarDayView();
                dayView.Frame = new RectangleF((i - 1) * 46 - 1, 0, 47, 45);
                dayView.Date  = viewDay;
                dayView.Text  = lead.ToString();
                AddSubview(dayView);
                _dayTiles.Add(dayView);
                lead++;
            }

            var position = weekdayOfFirst + 1;
            var line     = 0;

            // current month
            for (int i = 1; i <= daysInMonth; i++)
            {
                var viewDay = new DateTime(_currentMonth.Year, _currentMonth.Month, i);
                var dayView = new CalendarDayView
                {
                    Frame    = new RectangleF((position - 1) * 46 - 1, line * 44, 47, 45),
                    Today    = (CurrentDate.Date == viewDay.Date),
                    Text     = i.ToString(),
                    m_phase  = _calendarMonthView.stageForDayDelegate == null ? 0 : _calendarMonthView.stageForDayDelegate((DateTime)viewDay),
                    Active   = true,
                    Tag      = i,
                    Selected = (i == CurrentDate.AddDays(1).Day)
                };
                dayView.Date = viewDay;
                updateDayView(dayView);

                if (dayView.Selected)
                {
                    SelectedDayView = dayView;
                }

                AddSubview(dayView);
                _dayTiles.Add(dayView);

                position++;
                if (position > 7)
                {
                    position = 1;
                    line++;
                }
            }

            //next month
            if (position != 1)
            {
                int dayCounter = 1;
                for (int i = position; i < 8; i++)
                {
                    var viewDay = new DateTime(_currentMonth.Year, _currentMonth.Month, i);
                    var dayView = new CalendarDayView
                    {
                        Frame = new RectangleF((i - 1) * 46 - 1, line * 44, 47, 45),
                        Text  = dayCounter.ToString(),
                    };
                    dayView.Date = viewDay;
                    updateDayView(dayView);

                    AddSubview(dayView);
                    _dayTiles.Add(dayView);
                    dayCounter++;
                }
            }

            Frame = new RectangleF(Frame.Location, new SizeF(Frame.Width, (line + 1) * 44));

            Lines = (position == 1 ? line - 1 : line);

            if (SelectedDayView != null)
            {
                this.BringSubviewToFront(SelectedDayView);
            }
        }