コード例 #1
0
 /// <summary>
 /// Updates the day view.
 /// </summary>
 /// <param name="dayView">The day view.</param>
 public void UpdateDayView(CalendarDayView dayView)
 {
     dayView.Marked              = _calendarMonthView.IsDayMarkedDelegate != null && _calendarMonthView.IsDayMarkedDelegate(dayView.Date);
     dayView.Available           = _calendarMonthView.IsDateAvailable == null || _calendarMonthView.IsDateAvailable(dayView.Date);
     dayView.Highlighted         = _calendarMonthView.HighlightedDaysOfWeek[(int)dayView.Date.DayOfWeek];
     dayView.SelectedDatesMarked = SelectedDatesItems.Any(x => x.Equals(dayView.Date));
 }
コード例 #2
0
        /// <summary>
        /// Selects the day view.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool SelectDayView(CGPoint p)
        {
            int index = ((int)p.Y / _calendarMonthView.BoxHeight) * 7 + ((int)p.X / _calendarMonthView.BoxWidth);

            if (index < 0 || index >= DayTiles.Count)
            {
                return(false);
            }

            var newSelectedDayView = DayTiles[index];

            if (newSelectedDayView == SelectedDayView)
            {
                return(false);
            }

            if (!newSelectedDayView.Active)
            {
                var day = int.Parse(newSelectedDayView.Text);
                _calendarMonthView.MoveCalendarMonths(day <= 15, true);
                return(false);
            }
            else if ((!newSelectedDayView.Active && !newSelectedDayView.Available))
            {
                return(false);
            }

            if (SelectedDayView != null)
            {
                if (!SelectedDatesItems.Any(x => x.Date.Equals(SelectedDayView.Date)))
                {
                    SelectedDayView.Selected = false;
                }

                if (SelectedDatesItems.Any(x => x.Date.Equals(SelectedDayView.Date)))
                {
                    SelectedDayView.SelectedDatesMarked = true;
                    SelectedDayView.Selected            = false;
                }
            }

            BringSubviewToFront(newSelectedDayView);
            newSelectedDayView.Selected = true;

            SelectedDayView = newSelectedDayView;
            _calendarMonthView.CurrentSelectedDate = SelectedDayView.Date;
            SetNeedsDisplay();
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Builds the grid.
        /// </summary>
        public void BuildGrid()
        {
            var previousMonth       = _currentMonth.AddMonths(-1);
            var nextMonth           = _currentMonth.AddMonths(1);
            var daysInPreviousMonth = DateTime.DaysInMonth(previousMonth.Year, previousMonth.Month);
            var daysInMonth         = DateTime.DaysInMonth(_currentMonth.Year, _currentMonth.Month);
            var firstDayOfWeek      = (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;

            WeekdayOfFirst = (int)_currentMonth.DayOfWeek;

            var boxWidth  = _calendarMonthView.BoxWidth;
            var boxHeight = _calendarMonthView.BoxHeight;

            var numberOfLastMonthDays = (WeekdayOfFirst - firstDayOfWeek);

            if (numberOfLastMonthDays < 0)
            {
                numberOfLastMonthDays = 7 - (WeekdayOfFirst + firstDayOfWeek);
            }
            var lead = daysInPreviousMonth - numberOfLastMonthDays + 1;

            // build last month's days
            for (var i = 1; i <= numberOfLastMonthDays; i++)
            {
                var viewDay = new DateTime(previousMonth.Year, previousMonth.Month, lead);
                var dayView = new CalendarDayView(_calendarMonthView)
                {
                    Frame = new CGRect((i - 1) * boxWidth, 0, boxWidth, boxHeight),
                    Date  = viewDay,
                    Text  = lead.ToString()
                };

                UpdateDayView(dayView);
                AddSubview(dayView);
                DayTiles.Add(dayView);
                lead++;
            }

            var position = WeekdayOfFirst - firstDayOfWeek + 1;

            if (position == 0)
            {
                position = 7;
            }
            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(_calendarMonthView)
                {
                    Frame =
                        new CGRect(
                            (position - 1) * boxWidth,
                            line * boxHeight,
                            boxWidth,
                            boxHeight),
                    Today               = (CurrentDate.Date == viewDay.Date),
                    Text                = i.ToString(),
                    Active              = true,
                    Tag                 = i,
                    Selected            = (viewDay.Date == _calendarMonthView.CurrentSelectedDate.Date),
                    SelectedDatesMarked = SelectedDatesItems.Any(x => x.Equals(viewDay.Date)),
                    Date                = viewDay
                };

                UpdateDayView(dayView);

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

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

                AddSubview(dayView);
                DayTiles.Add(dayView);

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

            //next month
            int dayCounter = 1;

            if (position != 1)
            {
                for (int i = position; i < 8; i++)
                {
                    var viewDay = new DateTime(nextMonth.Year, nextMonth.Month, dayCounter);
                    var dayView = new CalendarDayView(_calendarMonthView)
                    {
                        Frame = new CGRect((i - 1) * boxWidth, line * boxHeight, boxWidth, boxHeight),
                        Text  = dayCounter.ToString(),
                    };

                    dayView.Date = viewDay;
                    UpdateDayView(dayView);

                    AddSubview(dayView);
                    DayTiles.Add(dayView);
                    dayCounter++;
                }
                line++;
            }

            if (line <= 4)
            {
                while (line <= 4)
                {
                    for (int i = 1; i < 8; i++)
                    {
                        var viewDay = new DateTime(nextMonth.Year, nextMonth.Month, dayCounter);
                        var dayView = new CalendarDayView(_calendarMonthView)
                        {
                            Frame = new CGRect((i - 1) * boxWidth, line * boxHeight, boxWidth, boxHeight),
                            Text  = dayCounter.ToString(),
                        };
                        dayView.Date = viewDay;
                        UpdateDayView(dayView);

                        AddSubview(dayView);
                        DayTiles.Add(dayView);
                        dayCounter++;
                    }
                    line++;
                }
            }

            Frame = new CGRect(Frame.Location, new CGSize(Frame.Width, (line + 1) * boxHeight));

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

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