Ejemplo n.º 1
0
        /// <summary>
        /// 验证时间是否在有效值的范围内
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        internal bool DateItemIsInValidRange(DateTime item)
        {
            bool returnResult = true;

            if (DateRuleObjects.IsNotNull())
            {
                if (!DateRuleObjects.minDate.IsNullAndTrimAndEmpty())
                {
                    //是否含有#F{ }
                    if (DateRuleObjects.minDate.IndexOf(@"#F{") == 0)
                    {
                        List <DateTime?> _4 = null;
                        if (DateRuleObjects.minDate.IndexOf("ay") > -1) //使用了绑定
                        {
                            if (MinDateReferToElement.IsNotNull())
                            {
                                string _text     = MinDateReferToElement.Text;
                                string _dateRule = MinDateReferToElement.DateRule;
                                var    ddo       = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(_dateRule);

                                if (ddo.IsNotNull())
                                {
                                    _4 = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.minDate, ddo.dateFmt);
                                }
                                else
                                {
                                    _4 = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.minDate, "yyyy-MM-dd");
                                }
                            }
                        }
                        else
                        {
                            _4 = AyDateStrictExpression.ConvertDDVF(null, DateRuleObjects.minDate, null);
                        }
                        bool ret = true;

                        foreach (var subtime in _4)
                        {
                            if (subtime.IsNotNull() && item < subtime.Value)
                            {
                                ret = false;
                                break;
                            }
                        }

                        return(ret);
                    }
                    else
                    {
                        //单控制
                        DateTime MinDateCopy = AyDateStrictExpression.Convert(DateRuleObjects.minDate);
                        if (item < MinDateCopy)
                        {
                            returnResult = false;
                        }
                    }
                }
                if (!DateRuleObjects.maxDate.IsNullAndTrimAndEmpty())
                {
                    //是否含有#F{ }
                    if (DateRuleObjects.maxDate.IndexOf(@"#F{") == 0)
                    {
                        List <DateTime?> _4 = null;
                        if (DateRuleObjects.maxDate.IndexOf("ay") > -1) //使用了绑定
                        {
                            if (MaxDateReferToElement.IsNotNull())
                            {
                                string _text     = MaxDateReferToElement.Text;
                                string _dateRule = MaxDateReferToElement.DateRule;
                                var    ddo       = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(_dateRule);

                                if (ddo.IsNotNull())
                                {
                                    _4 = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.maxDate, ddo.dateFmt);
                                }
                                else
                                {
                                    _4 = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.maxDate, "yyyy-MM-dd");
                                }
                            }
                        }
                        else
                        {
                            _4 = AyDateStrictExpression.ConvertDDVF(null, DateRuleObjects.maxDate, null);
                        }
                        bool ret = true;

                        foreach (var subtime in _4)
                        {
                            if (subtime.IsNotNull() && item > subtime.Value)
                            {
                                ret = false;
                                break;
                            }
                        }

                        return(ret);
                    }
                    else
                    {
                        //单控制
                        DateTime MaxDateCopy = AyDateStrictExpression.Convert(DateRuleObjects.maxDate);
                        if (item > MaxDateCopy)
                        {
                            returnResult = false;
                        }
                    }
                }


                if (DateRuleObjects.disabledDays.IsNotNull() && DateRuleObjects.disabledDays.Count > 0)
                {
                    var _1 = item.DayOfWeek.GetHashCode();
                    foreach (var disabledDay in DateRuleObjects.disabledDays)
                    {
                        if (_1 == disabledDay)
                        {
                            returnResult = false;
                            break;
                        }
                    }
                }
                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(disabledDate))
                            {
                                DisabledDatesStrings.Add(disabledDate);
                            }
                        }
                        //正则处理
                        if (_2.IndexOf(":") < 0)
                        {
                            bool d = Regex.IsMatch(item.ToString("yyyy-MM-dd"), _2);
                            if (d)
                            {
                                returnResult = false;
                            }
                        }
                        else
                        {
                            bool d = Regex.IsMatch(item.ToString("yyyy-MM-dd HH:mm:ss"), _2);
                            if (d)
                            {
                                returnResult = false;
                            }
                        }
                        if (DateRuleObjects.opposite)
                        {
                            returnResult = !returnResult;
                        }
                    }
                }
                else
                {
                    DisabledDatesStrings = null;
                }
            }
            return(returnResult);
        }
Ejemplo n.º 2
0
        internal void UseValidate()
        {
            bool hasTan = false;

            try
            {
                DateRuleObjects = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(DateRule);

                if (DateRuleObjects.IsNotNull())
                {
                    string[] expectedFormats = { DateRuleObjects.dateFmt };
                    DateTime dt = DateTime.ParseExact(Text, expectedFormats, AyDatePickerHelper.culture, DateTimeStyles.AllowInnerWhite);
                    if (dt.Year < YearStrick.MINYEAR)
                    {
                        if (!hasTan)
                        {
                            HasWrongShowTip();
                            hasTan = true;
                        }

                        return;
                    }
                    else if (dt.Year > YearStrick.MAXYEAR)
                    {
                        if (!hasTan)
                        {
                            HasWrongShowTip();
                            hasTan = true;
                        }
                    }
                    if (!DateItemIsInValidRange(dt))
                    {
                        if (!hasTan)
                        {
                            HasWrongShowTip();
                            hasTan = true;
                        }
                    }
                    if (!hasTan)
                    {
                        PickedDate = dt;
                        if (DateRuleObjects.IsNotNull())
                        {
                            Week = AyCalendarService.GetWeekOfYear(PickedDate.Value, DateRuleObjects.firstDayOfWeek).ToObjectString();
                        }
                        else
                        {
                            Week = "0";
                        }
                    }

                    //}
                }
            }
            catch
            {
                if (!hasTan)
                {
                    hasTan = true;

                    ErrorInfo             = AyCalendarService.WRONGTIP;
                    apErrorToolTip.IsOpen = true;
                    IsError = true;
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        internal void FilterDatePickerItem(AyDatePickerItem item)
        {
            if (firstInitMinMax)
            {
                var _1 = AyCalendarService.FilterDatePickerItem(DateRuleObjects, MinDateReferToElement, MaxDateReferToElement);
                MinDateCopy     = _1.Item1;
                MaxDateCopy     = _1.Item2;
                firstInitMinMax = false;
            }
            if (item.IsNotNull())
            {
                if (MinDateCopy.Count > 0)
                {
                    foreach (var subitem in MinDateCopy)
                    {
                        if (subitem.HasValue && item.Date < subitem.Value.Date)
                        {
                            item.IsEnabled = false;
                            break;
                        }
                    }
                }
                if (MaxDateCopy.Count > 0)
                {
                    foreach (var subitem in MaxDateCopy)
                    {
                        if (subitem.HasValue && item.Date > subitem.Value.Date)
                        {
                            item.IsEnabled = false;
                            break;
                        }
                    }
                }

                //周几限制
                if (DateRuleObjects.IsNotNull())
                {
                    if (DateRuleObjects.disabledDays.IsNotNull() && DateRuleObjects.disabledDays.Count > 0)
                    {
                        var _1 = item.Date.DayOfWeek.GetHashCode();
                        foreach (var disabledDay in DateRuleObjects.disabledDays)
                        {
                            if (_1 == disabledDay)
                            {
                                item.IsEnabled = false;
                                break;
                            }
                        }
                    }

                    //限制disabledDate
                    var _validateItemResult = AyCalendarService.ValidateRegexDate(item.Date, this.DisabledDatesStrings, DateRuleObjects.opposite);
                    if (!_validateItemResult)
                    {
                        item.IsEnabled = false;
                    }


                    //高亮日和高亮日期
                    if (DateRuleObjects.specialDays.IsNotNull() && DateRuleObjects.specialDays.Count > 0)
                    {
                        var _1 = item.Date.DayOfWeek.GetHashCode();
                        foreach (var specialDay in DateRuleObjects.specialDays)
                        {
                            if (_1 == specialDay)
                            {
                                item.IsHighlight = true;
                                break;
                            }
                        }
                    }

                    if (SpecialDatesStrings.IsNotNull() && SpecialDatesStrings.Count > 0)
                    {
                        foreach (var SpecialDates in SpecialDatesStrings)
                        {
                            bool vaResult = false;
                            if (SpecialDates.IndexOf(":") > -1)
                            {
                                string[] _01 = item.Date.ToString("yyyy-MM-dd HH:mm:ss").Split(' ');
                                string[] _02 = SpecialDates.Split(' ');
                                vaResult = System.Text.RegularExpressions.Regex.IsMatch(_01[0] + " " + _02[1], SpecialDates);
                            }
                            else
                            {
                                vaResult = System.Text.RegularExpressions.Regex.IsMatch(item.Date.ToString("yyyy-MM-dd"), SpecialDates);
                            }
                            if (vaResult)
                            {
                                item.IsHighlight = true;
                                break;
                            }
                        }
                    }
                }
            }
        }