public object GetValue(NumberFormatType type) { object val = this.GetValue(); if (type != NumberFormatType.DateTime) { return(val); } DateTime?nullable = ConditionValueConverter.TryDateTime(val); if (!nullable.HasValue) { return(null); } return(nullable.Value); }
/// <summary> /// Determines whether the current value is valid. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <param name="baseRow">The base row.</param> /// <param name="baseColumn">The base column.</param> /// <param name="actual">The current value.</param> /// <returns> /// <c>true</c> The value is valid; otherwise, <c>false</c>. /// </returns> public virtual bool IsValid(ICalcEvaluator evaluator, int baseRow, int baseColumn, object actual) { if (this.condition == null) { return(true); } if (this.condition.IgnoreBlank && ((actual == null) || ((actual != null) && string.IsNullOrEmpty(actual.ToString())))) { return(true); } object obj2 = actual; if (actual != null) { switch (this.type) { case CriteriaType.AnyValue: return(true); case CriteriaType.WholeNumber: case CriteriaType.DecimalValues: { double?nullable = ConditionValueConverter.TryDouble(actual); if (nullable.HasValue) { obj2 = nullable; } break; } case CriteriaType.Date: case CriteriaType.Time: { DateTime?nullable2 = ConditionValueConverter.TryDateTime(actual); if (nullable2.HasValue) { obj2 = nullable2; } break; } } } return(this.condition.Evaluate(evaluator, baseRow, baseColumn, new ActualValue(obj2))); }
/// <summary> /// Gets the expected date and time string. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <param name="baseRow">The base row index.</param> /// <param name="baseColumn">The base column index.</param> /// <returns>Returns the expected date and time string.</returns> protected DateTime?GetExpectedDateTime(ICalcEvaluator evaluator, int baseRow, int baseColumn) { return(ConditionValueConverter.TryDateTime(this.GetExpected(evaluator, baseRow, baseColumn))); }
/// <summary> /// Checks the condition. /// </summary> /// <param name="expectedValue">Expected value for the condition</param> /// <param name="actualValue">Actual value for the condition</param> /// <returns> /// <c>true</c> if the value satisfy the condition; otherwise, <c>false</c>. /// </returns> bool CheckCondition(object expectedValue, object actualValue) { TimeSpan?nullable = null; if (actualValue is DateTime) { DateTime time = (DateTime)actualValue; DateTime time2 = (DateTime)actualValue; DateTime time3 = (DateTime)actualValue; DateTime time4 = (DateTime)actualValue; nullable = new TimeSpan(0, time.Hour, time2.Minute, time3.Second, time4.Millisecond); } else if (actualValue is TimeSpan) { nullable = new TimeSpan?((TimeSpan)actualValue); } if ((actualValue == null) || actualValue.Equals(string.Empty)) { return(this.IgnoreBlank); } if (actualValue is string) { try { nullable = new TimeSpan?(ConditionValueConverter.ToTimeSpan(actualValue)); } catch (InvalidCastException) { return(false); } } if (nullable.HasValue) { if (!nullable.HasValue && (expectedValue != null)) { return(false); } try { if (nullable.HasValue) { TimeSpan span; if (expectedValue is TimeSpan) { span = (TimeSpan)expectedValue; } else { DateTime?nullable2 = ConditionValueConverter.TryDateTime(expectedValue); if (!nullable2.HasValue) { return(false); } span = new TimeSpan(0, nullable2.Value.Hour, nullable2.Value.Minute, nullable2.Value.Second, nullable2.Value.Millisecond); } switch (this.CompareType) { case DateCompareType.EqualsTo: return(this.IsEquals(span, nullable.Value)); case DateCompareType.NotEqualsTo: return(!this.IsEquals(span, nullable.Value)); case DateCompareType.Before: return(this.IsBefore(span, nullable.Value)); case DateCompareType.BeforeEqualsTo: return(this.IsBefore(span, nullable.Value) || this.IsEquals(span, nullable.Value)); case DateCompareType.After: return(this.IsAfter(span, nullable.Value)); case DateCompareType.AfterEqualsTo: return(this.IsAfter(span, nullable.Value) || this.IsEquals(span, nullable.Value)); } } } catch { } } return(false); }