示例#1
0
        private static void OnDateRuleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var _1 = d as AyDateBoxCalendar;

            if (_1.IsNotNull())
            {
                var oldStr = e.OldValue.ToObjectString();
                var newStr = e.NewValue.ToObjectString();
                try
                {
                    _1.RootGrid.Children.Clear();
                    _1._PopupContent.Child = null;
                    _1._PopupContent       = null;
                    var _oldRule = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(oldStr);
                    if (_oldRule.IsNotNull())
                    {
                        //if (_oldRule.dateFmt.IsNullAndTrimAndEmpty())
                        //{
                        //    _oldRule.dateFmt = "yyyy-MM-dd";
                        //}
                        string[] expectedFormats = { _oldRule.dateFmt };
                        DateTime dt =
                            DateTime.ParseExact(_1.Text,
                                                expectedFormats,
                                                AyDatePickerHelper.culture,
                                                DateTimeStyles.AllowInnerWhite);

                        var _newRule = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(newStr);
                        if (_newRule.IsNotNull())
                        {
                            //if (_newRule.dateFmt.IsNullAndTrimAndEmpty())
                            //{
                            //    _newRule.dateFmt = "yyyy-MM-dd";
                            //}
                            _1.Text = dt.ToString(_newRule.dateFmt);
                        }
                    }
                }
                catch
                {
                }
            }
        }
示例#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
 public override void UpdateTextWhenDateChange()
 {
     //数据第一次赋值的时候一定要验证一下
     //ValidateDateTimeIsUsefulLoadedUse();
     if (Text.IsNullAndTrimAndEmpty() && PickedDate.HasValue)
     {
         if (DateRuleObjects.IsNull())
         {
             DateRuleObjects = AyJsonUtility.DecodeObject2 <AyDateRuleJsonToObjects>(DateRule);
         }
         string t = PickedDate.Value.ToString(DateRuleObjects.dateFmt);
         if (t.Contains("0001") || t.Contains("9999"))
         {
             t = "";
         }
         else
         {
             Text = t;
         }
     }
 }
示例#4
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;
                }
            }
        }
示例#5
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);
        }
        internal static Tuple <List <DateTime?>, List <DateTime?> > FilterDatePickerItem(AyDateRuleJsonToObjects DateRuleObjects, AyDateBoxCalendar MinDateReferToElement, AyDateBoxCalendar MaxDateReferToElement)
        {
            List <DateTime?> MinDateCopy = new List <DateTime?>();
            List <DateTime?> MaxDateCopy = new List <DateTime?>();

            if (DateRuleObjects.IsNotNull())
            {
                //AyCalendarFMT _fmt = GetAyCalendarFMT(DateRuleObjects.dateFmt);
                if (!DateRuleObjects.minDate.IsNullAndTrimAndEmpty())
                {
                    //是否含有#F{ }
                    if (DateRuleObjects.minDate.IndexOf(@"#F{") == 0)
                    {
                        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())
                                {
                                    MinDateCopy = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.minDate, ddo.dateFmt);
                                }
                                else
                                {
                                    MinDateCopy = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.minDate, "yyyy-MM-dd");
                                }
                            }
                        }
                        else
                        {
                            MinDateCopy = AyDateStrictExpression.ConvertDDVF(null, DateRuleObjects.minDate, null);
                        }
                    }
                    else
                    {
                        MinDateCopy.Add(AyDateStrictExpression.Convert(DateRuleObjects.minDate));
                    }
                }
                if (!DateRuleObjects.maxDate.IsNullAndTrimAndEmpty())
                {
                    //是否含有#F{ }
                    if (DateRuleObjects.maxDate.IndexOf(@"#F{") == 0)
                    {
                        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())
                                {
                                    MaxDateCopy = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.maxDate, ddo.dateFmt);
                                }
                                else
                                {
                                    MaxDateCopy = AyDateStrictExpression.ConvertDDVF(_text, DateRuleObjects.maxDate, "yyyy-MM-dd");
                                }
                            }
                        }
                        else
                        {
                            MaxDateCopy = AyDateStrictExpression.ConvertDDVF(null, DateRuleObjects.maxDate, null);
                        }
                    }
                    else
                    {
                        MaxDateCopy.Add(AyDateStrictExpression.Convert(DateRuleObjects.maxDate));
                    }
                }
            }
            return(Tuple.Create <List <DateTime?>, List <DateTime?> >(MinDateCopy, MaxDateCopy));
        }
        public static DateTime?ConvertDV(string expression)
        {
            DateTime?dtReturn = null;
            string   str1     = null;
            string   str2     = null;

            if (expression.IndexOf(",{") > 0)
            {
                MatchCollection matches = Regex.Matches(expression, @"#DV\((?<c>.*?),{(?<h>.*?)}");
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    string          _1     = groups["c"].Value;
                    if (_1 != null)
                    {
                        str1 = groups["c"].Value;
                    }
                    string _2 = groups["h"].Value;
                    if (_2 != null)
                    {
                        str2 = groups["h"].Value;
                    }
                }
            }
            else
            {
                MatchCollection matches = Regex.Matches(expression, @"#DV\((?<c>.*?)\)");
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    string          _1     = groups["c"].Value;
                    if (_1 != null)
                    {
                        str1 = groups["c"].Value;
                    }
                }
            }
            try
            {
                if (str1 == null)
                {
                    throw new Exception("AY日期表达式中DV片段有错误");
                }
                dtReturn = Convert(str1);

                if (str2 != null)
                {
                    AyDCDateExpression _ewai = AyJsonUtility.DecodeObject2 <AyDCDateExpression>(str2);
                    //开始处理
                    if (_ewai.y != 0)
                    {
                        dtReturn = dtReturn.Value.AddYears(_ewai.y);
                    }
                    if (_ewai.M != 0)
                    {
                        dtReturn = dtReturn.Value.AddMonths(_ewai.M);
                    }
                    if (_ewai.d != 0)
                    {
                        dtReturn = dtReturn.Value.AddDays(_ewai.d);
                    }
                    if (_ewai.H != 0)
                    {
                        dtReturn = dtReturn.Value.AddHours(_ewai.H);
                    }
                    if (_ewai.m != 0)
                    {
                        dtReturn = dtReturn.Value.AddMinutes(_ewai.m);
                    }
                    if (_ewai.s != 0)
                    {
                        dtReturn = dtReturn.Value.AddSeconds(_ewai.s);
                    }
                }
            }
            catch
            {
                throw new Exception("AY日期表达式中DV片段中的时间部分不能转换成有效的DateTime");
            }



            return(dtReturn);
        }
        public static DateTime?ConvertD(string dt, string expression, string fmt)
        {
            DateTime?dtReturn = null;

            //读取文本框的值
            if (dt.IsNullAndTrimAndEmpty())
            {
                return(dtReturn);
            }
            else
            {
                MatchCollection matches = Regex.Matches(expression, @"#D\(ay,{(?<c>.*?)}\)");
                List <string>   strs    = new List <string>();
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    string          _1     = groups["c"].Value;
                    if (_1 != null)
                    {
                        strs.Add(groups["c"].Value);
                    }
                }
                if (strs.Count > 0)
                {
                    AyDCDateExpression _ewai = AyJsonUtility.DecodeObject2 <AyDCDateExpression>(strs[0]);
                    try
                    {
                        string[] expectedFormats = { fmt };
                        dtReturn = DateTime.ParseExact(dt, expectedFormats, AyDatePickerHelper.culture, DateTimeStyles.None);
                    }
                    catch
                    {
                        throw new Exception("AY日期表达式 D函数表达式发生问题");
                    }

                    //dtReturn = dt.ToDateTime();
                    //开始处理
                    if (_ewai.y != 0)
                    {
                        dtReturn = dtReturn.Value.AddYears(_ewai.y);
                    }
                    if (_ewai.M != 0)
                    {
                        dtReturn = dtReturn.Value.AddMonths(_ewai.M);
                    }
                    if (_ewai.d != 0)
                    {
                        dtReturn = dtReturn.Value.AddDays(_ewai.d);
                    }
                    if (_ewai.H != 0)
                    {
                        dtReturn = dtReturn.Value.AddHours(_ewai.H);
                    }
                    if (_ewai.m != 0)
                    {
                        dtReturn = dtReturn.Value.AddMinutes(_ewai.m);
                    }
                    if (_ewai.s != 0)
                    {
                        dtReturn = dtReturn.Value.AddSeconds(_ewai.s);
                    }
                    return(dtReturn);
                }
                else
                {
                    //这里要换成 tryparseextra方式的时间,如果转换失败就当空白处理
                    dtReturn = dt.ToDateTime();

                    return(dtReturn);
                }
            }
        }