protected void ChangeCalendar(CalandarChanges changes)
        {
            if (changes.HasFlag(CalandarChanges.StartDate))
            {
                Device.BeginInvokeOnMainThread(() => CenterLabel.Text = StartDate.ToString(TitleLabelFormat));
            }

            var start        = CalendarStartDate;
            var beginOfMonth = false;
            var endOfMonth   = false;

            for (int i = 0; i < buttons.Count; i++)
            {
                endOfMonth   |= beginOfMonth && start.Day == 1;
                beginOfMonth |= start.Day == 1;

                if (i < 7 && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                {
                    labels[i].Text = start.ToString(WeekdaysFormat);
                }

                if (changes.HasFlag(CalandarChanges.All))
                {
                    buttons[i].Text = string.Format("{0}", start.Day);
                }
                else
                {
                    buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                }
                buttons[i].Date = start;

                var         isInsideMonth = beginOfMonth && !endOfMonth;
                SpecialDate sd            = null;
                if (SpecialDates != null)
                {
                    sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                }

                if ((MinDate.HasValue && start < MinDate) || (MaxDate.HasValue && start > MaxDate))
                {
                    SetButtonDisabled(buttons[i]);
                }
                else if (SelectedDate.HasValue && start.Date == SelectedDate.Value.Date)
                {
                    SetButtonSelected(buttons[i], isInsideMonth);
                }
                else if (sd != null)
                {
                    SetButtonSpecial(buttons[i], sd);
                }
                else
                {
                    SetButtonNormal(buttons[i], isInsideMonth);
                }
                start = start.AddDays(1);
            }
        }
예제 #2
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                if (changes.HasFlag(CalandarChanges.StartDate))
                {
                    TitleLabel.Text = StartDate.ToString(TitleLabelFormat);
                    if (TitleLabels != null)
                    {
                        var tls = StartDate.AddMonths(1);
                        foreach (var tl in TitleLabels)
                        {
                            (tl as Label).Text = tls.ToString(TitleLabelFormat);
                            tls = tls.AddMonths(1);
                        }
                    }
                }

                var start        = CalendarStartDate(StartDate).Date;
                var beginOfMonth = false;
                var endOfMonth   = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= beginOfMonth && start.Day == 1;
                    beginOfMonth |= start.Day == 1;

                    if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                    {
                        var day           = start.ToString(WeekdaysFormat);
                        string showDay    = char.ToUpper(day.First()) + day.Substring(1).ToLower();
                        dayLabels[i].Text = showDay;
                    }

                    ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalandarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }
                    buttons[i].Date = start;

                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    SpecialDate sd = null;
                    if (SpecialDates != null)
                    {
                        sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    }

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && start.Date < MinDate) || (MaxDate.HasValue && start.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(start.Date) ?? false))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start = start.AddDays(1);
                    if (i != 0 && (i + 1) % 42 == 0)
                    {
                        beginOfMonth = false;
                        endOfMonth   = false;
                        start        = CalendarStartDate(start);
                    }
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate);
                }
                Content = MainView;
            });
        }
예제 #3
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                if (changes.HasFlag(CalandarChanges.StartDate))
                {
                    TitleLabel.Text = PersianDateInfo.MonthDic[StartDate.ToPersianDateTime().Month];
                    //if (TitleLabels != null)
                    //{
                    //    var tls = StartDate.AddMonths(1);
                    //    foreach (var tl in TitleLabels)
                    //    {
                    //        (tl as Label).Text = PersianDateInfo.MonthDic[tls.Month];
                    //        tls = tls.AddMonths(1);
                    //    }
                    //}
                }

                var pc           = new PersianCalendar();
                var start        = CalendarStartDate(StartDate.ToPersianDateTime());
                var end          = pc.GetDaysInMonth(start.Year, start.Month);
                var startEn      = start.ToDateTime();
                var beginOfMonth = false;
                var endOfMonth   = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= i == end;
                    beginOfMonth |= start.Day == 1;
                    var ddd       = changes.HasFlag(CalandarChanges.StartDay);
                    //if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                    if (i < dayLabels.Count && WeekdaysShow)
                    {
                        var day           = startEn.ToString(WeekdaysFormat);
                        string showDay    = PersianDateInfo.WeekDays[char.ToUpper(day.First()) + day.Substring(1).ToLower()];
                        dayLabels[i].Text = showDay;
                    }

                    //ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalandarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }

                    buttons[i].Date         = startEn;
                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    SpecialDate sd = null;
                    //if (SpecialDates != null)
                    //{
                    //	sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    //}

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && startEn.Date < MinDate) || (MaxDate.HasValue && startEn.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(startEn.Date) ?? false))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start.AddDay(1, end);
                    startEn = start.ToDateTime();
                    //               if (i != 0 && (i+1) % 42 == 0)
                    //{
                    //	beginOfMonth = false;
                    //	endOfMonth = false;
                    //	start = CalendarStartDate(start);
                    //}
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate.ToPersianDateTime()).ToDateTime() < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start.ToDateTime() > MaxDate);
                }
                Content = MainView;
            });
        }