예제 #1
0
        private bool SelectDayView(PointF p)
        {
            int index = ((int)p.Y / calendarMonthView.BoxHeight) * 7 + ((int)p.X / calendarMonthView.BoxWidth);

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

            CalendarDayView newSelectedDayView = dayTiles[index];

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

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

            if (SelectedDayView != null)
            {
                SelectedDayView.Selected = false;
            }

            BringSubviewToFront(newSelectedDayView);
            newSelectedDayView.Selected = true;

            SelectedDayView = newSelectedDayView;
            calendarMonthView.CurrentSelectedDate = SelectedDayView.Date;
            SetNeedsDisplay();
            return(true);
        }
        private bool SelectDayView( PointF p )
        {
            int index = ((int) p.Y/calendarMonthView.BoxHeight)*7 + ((int) p.X/calendarMonthView.BoxWidth);
            if (index < 0 || index >= dayTiles.Count)
                return false;

            CalendarDayView newSelectedDayView = dayTiles[index];
            if (newSelectedDayView == SelectedDayView)
                return false;

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

            if (SelectedDayView != null)
                SelectedDayView.Selected = false;

            BringSubviewToFront(newSelectedDayView);
            newSelectedDayView.Selected = true;

            SelectedDayView = newSelectedDayView;
            calendarMonthView.CurrentSelectedDate = SelectedDayView.Date;
            SetNeedsDisplay();
            return true;
        }
 public void UpdateDayView( CalendarDayView dayView )
 {
     dayView.Marked = calendarMonthView.IsDayMarkedDelegate != null && calendarMonthView.IsDayMarkedDelegate(dayView.Date);
     dayView.Available = calendarMonthView.IsDateAvailable == null || calendarMonthView.IsDateAvailable(dayView.Date);
 }
        public void DeselectDayView()
        {
            if (SelectedDayView == null)
                return;

            SelectedDayView.Selected = false;
            SelectedDayView = null;
            SetNeedsDisplay();
        }
        /// <summary>
        ///    Build month grid.
        /// </summary>
        public void BuildGrid()
        {
            DateTime previousMonth = currentMonth.AddMonths(-1);
            int daysInPreviousMonth = DateTime.DaysInMonth(previousMonth.Year, previousMonth.Month);

            int daysInMonth = DateTime.DaysInMonth(currentMonth.Year, currentMonth.Month);
            WeekdayOfFirst = (int) currentMonth.DayOfWeek;

            int lead = daysInPreviousMonth - (WeekdayOfFirst - 1);

            int boxWidth = calendarMonthView.BoxWidth;
            int boxHeight = calendarMonthView.BoxHeight;

            // Build previous month's days.
            for (int i = 1; i <= WeekdayOfFirst; i++) {
                var viewDay = new DateTime(currentMonth.Year, currentMonth.Month, i);
                var dayView = new CalendarDayView(calendarMonthView) {
                    Frame = new RectangleF((i - 1)*boxWidth - 1, 0, boxWidth, boxHeight),
                    Date = viewDay,
                    Text = lead.ToString()
                };

                AddSubview(dayView);
                dayTiles.Add(dayView);
                lead++;
            }

            int position = WeekdayOfFirst + 1;
            int 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 RectangleF((position - 1)*boxWidth - 1, line*boxHeight, boxWidth, boxHeight),
                    Today = (CurrentDate.Date == viewDay.Date),
                    Text = i.ToString(),
                    Active = true,
                    Tag = i,
                    Selected = (viewDay.Date == calendarMonthView.CurrentSelectedDate.Date),
                    Date = viewDay
                };

                UpdateDayView(dayView);

                if (dayView.Selected)
                    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(currentMonth.Year, currentMonth.Month, i);
                    var dayView = new CalendarDayView(calendarMonthView) {
                        Frame = new RectangleF((i - 1)*boxWidth - 1, line*boxHeight, boxWidth, boxHeight),
                        Text = dayCounter.ToString(),
                        Date = viewDay,
                    };
                    UpdateDayView(dayView);

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

            while (line < calendarMonthView.LinesCount - 1) {
                line++;
                for (int i = 1; i < 8; i++) {
                    var viewDay = new DateTime(currentMonth.Year, currentMonth.Month, i);
                    var dayView = new CalendarDayView(calendarMonthView) {
                        Frame = new RectangleF((i - 1)*boxWidth - 1, line*boxHeight, boxWidth, boxHeight),
                        Text = dayCounter.ToString(),
                        Date = viewDay,
                    };
                    UpdateDayView(dayView);

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

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

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

            if (SelectedDayView != null)
                BringSubviewToFront(SelectedDayView);
        }
예제 #6
0
        /// <summary>
        ///    Build month grid.
        /// </summary>
        public void BuildGrid()
        {
            DateTime previousMonth       = currentMonth.AddMonths(-1);
            int      daysInPreviousMonth = DateTime.DaysInMonth(previousMonth.Year, previousMonth.Month);

            int daysInMonth = DateTime.DaysInMonth(currentMonth.Year, currentMonth.Month);

            WeekdayOfFirst = (int)currentMonth.DayOfWeek;

            int lead = daysInPreviousMonth - (WeekdayOfFirst - 1);

            int boxWidth  = calendarMonthView.BoxWidth;
            int boxHeight = calendarMonthView.BoxHeight;

            // Build previous month's days.
            for (int i = 1; i <= WeekdayOfFirst; i++)
            {
                var viewDay = new DateTime(currentMonth.Year, currentMonth.Month, i);
                var dayView = new CalendarDayView(calendarMonthView)
                {
                    Frame = new RectangleF((i - 1) * boxWidth - 1, 0, boxWidth, boxHeight),
                    Date  = viewDay,
                    Text  = lead.ToString()
                };

                AddSubview(dayView);
                dayTiles.Add(dayView);
                lead++;
            }

            int position = WeekdayOfFirst + 1;
            int 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 RectangleF((position - 1) * boxWidth - 1, line * boxHeight, boxWidth, boxHeight),
                    Today    = (CurrentDate.Date == viewDay.Date),
                    Text     = i.ToString(),
                    Active   = true,
                    Tag      = i,
                    Selected = (viewDay.Date == calendarMonthView.CurrentSelectedDate.Date),
                    Date     = viewDay
                };

                UpdateDayView(dayView);

                if (dayView.Selected)
                {
                    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(currentMonth.Year, currentMonth.Month, i);
                    var dayView = new CalendarDayView(calendarMonthView)
                    {
                        Frame = new RectangleF((i - 1) * boxWidth - 1, line * boxHeight, boxWidth, boxHeight),
                        Text  = dayCounter.ToString(),
                        Date  = viewDay,
                    };
                    UpdateDayView(dayView);

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

            while (line < calendarMonthView.LinesCount - 1)
            {
                line++;
                for (int i = 1; i < 8; i++)
                {
                    var viewDay = new DateTime(currentMonth.Year, currentMonth.Month, i);
                    var dayView = new CalendarDayView(calendarMonthView)
                    {
                        Frame = new RectangleF((i - 1) * boxWidth - 1, line * boxHeight, boxWidth, boxHeight),
                        Text  = dayCounter.ToString(),
                        Date  = viewDay,
                    };
                    UpdateDayView(dayView);

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

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

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

            if (SelectedDayView != null)
            {
                BringSubviewToFront(SelectedDayView);
            }
        }
예제 #7
0
 public void UpdateDayView(CalendarDayView dayView)
 {
     dayView.Marked    = calendarMonthView.IsDayMarkedDelegate != null && calendarMonthView.IsDayMarkedDelegate(dayView.Date);
     dayView.Available = calendarMonthView.IsDateAvailable == null || calendarMonthView.IsDateAvailable(dayView.Date);
 }