/// <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); }
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); }
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)); }