示例#1
0
        public void CreatePopupList()
        {
            if (DateRule == "")            //如果是空白,默认选中今天,啥也不限制
            {
                AyCalendar ac = new AyCalendar();
                ac.BorderBrush           = Brushes.Transparent;
                ac.MinDateReferToElement = this.MinDateReferToElement;
                ac.MaxDateReferToElement = this.MaxDateReferToElement;
                ac.DateBoxInput          = this;
                //ac.DisabledDatesStrings = this.DisabledDatesStrings;
                ac.HorizontalAlignment = HorizontalAlignment.Center;
                ac.VerticalAlignment   = VerticalAlignment.Center;
                ac.SelectMode          = AyDatePickerSelectMode.OnlySelectDate;
                if (!this.Text.IsNullAndTrimAndEmpty())
                {
                    DateTime?date = ReverseDateTimeFromText(ac);
                    if (date.HasValue)
                    {
                        ac.SelectedDateTime = date;
                    }
                }
                RootGrid.Children.Add(ac);
            }
            else
            {
                if (DateRuleObjects.IsNotNull())
                {
                    _fmt = AyCalendarService.GetAyCalendarFMT(DateRuleObjects.dateFmt);
                    switch (_fmt)
                    {
                    case AyCalendarFMT.None:
                        break;

                    default:
                        AyCalendar ac = CreateAyCalendar();
                        RootGrid.Children.Add(ac);
                        break;
                    }
                }
            }
        }
示例#2
0
        public DateTime?ReverseDateTimeFromText(AyCalendar ca = null)
        {
            var _oldRule = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(DateRule);

            if (ca.IsNotNull())
            {
                ca.IsShowClear  = _oldRule.isShowClear ? Visibility.Visible : Visibility.Collapsed;
                ca.IsShowToday  = _oldRule.isShowToday ? Visibility.Visible : Visibility.Collapsed;
                this.IsReadOnly = _oldRule.readOnly;
            }
            if (Text.IsNullAndTrimAndEmpty())
            {
                return(null);
            }



            if (_oldRule.IsNotNull())
            {
                //if (_oldRule.dateFmt.IsNullAndTrimAndEmpty())
                //{
                //    _oldRule.dateFmt = "yyyy-MM-dd";
                //}
                string[] expectedFormats = { _oldRule.dateFmt };

                try
                {
                    DateTime dt =
                        DateTime.ParseExact(Text,
                                            expectedFormats,
                                            AyDatePickerHelper.culture,
                                            DateTimeStyles.AllowInnerWhite);
                    return(dt);
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
示例#3
0
        private AyCalendar CreateAyCalendar()
        {
            if (DateRuleObjects.disabledDates.IsNotNull() && DateRuleObjects.disabledDates.Count > 0)
            {
                if (DisabledDatesStrings == null)
                {
                    DisabledDatesStrings = new List <string>();
                }
                else
                {
                    DisabledDatesStrings.Clear();
                }

                foreach (var disabledDate in DateRuleObjects.disabledDates)
                {
                    var    _ti = AyCalendarService.hasTeShu(disabledDate);
                    string _2  = disabledDate;
                    if (_ti)
                    {
                        _2 = AyDateStrictExpression.ConvertDynamicAyDateExpression(disabledDate);
                        if (!DisabledDatesStrings.Contains(_2))
                        {
                            DisabledDatesStrings.Add(_2);
                        }
                    }
                    else
                    {
                        if (!DisabledDatesStrings.Contains(_2))
                        {
                            DisabledDatesStrings.Add(_2);
                        }
                    }
                }
            }
            else
            {
                DisabledDatesStrings = null;
            }
            List <string> SpecialDatesStrings = null;

            if (DateRuleObjects.specialDates.IsNotNull() && DateRuleObjects.specialDates.Count > 0)
            {
                if (SpecialDatesStrings == null)
                {
                    SpecialDatesStrings = new List <string>();
                }
                foreach (var specialDates in DateRuleObjects.specialDates)
                {
                    var    _ti = AyCalendarService.hasTeShu(specialDates);
                    string _2  = specialDates;
                    if (_ti)
                    {
                        _2 = AyDateStrictExpression.ConvertDynamicAyDateExpression(specialDates);
                        if (!SpecialDatesStrings.Contains(_2))
                        {
                            SpecialDatesStrings.Add(_2);
                        }
                    }
                    else
                    {
                        if (!SpecialDatesStrings.Contains(_2))
                        {
                            SpecialDatesStrings.Add(_2);
                        }
                    }
                }
            }


            AyCalendar ac = new AyCalendar(DateRule);

            ac.BorderBrush           = Brushes.Transparent;
            ac.MinDateReferToElement = this.MinDateReferToElement;
            ac.MaxDateReferToElement = this.MaxDateReferToElement;
            ac.DisabledDatesStrings  = this.DisabledDatesStrings;
            ac.SpecialDatesStrings   = SpecialDatesStrings;
            ac.DateBoxInput          = this;
            ac.HorizontalAlignment   = HorizontalAlignment.Center;
            ac.VerticalAlignment     = VerticalAlignment.Center;
            DateTime?date = ReverseDateTimeFromText(ac);

            if (date.HasValue)
            {
                ac.SelectedDateTime = date;
            }
            return(ac);
        }