/// <summary> /// Evaluates using the specified evaluator. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <param name="baseRow">The base row.</param> /// <param name="baseColumn">The base column.</param> /// <param name="actualObj">The actual value object.</param> /// <returns><c>true</c> if the result is successful; otherwise, <c>false</c>.</returns> public override bool Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actualObj) { object obj2 = actualObj.GetValue(); if (obj2 == null) { return(this.IgnoreBlank); } if (ConditionValueConverter.IsNumber(obj2)) { obj2 = (double)ConditionValueConverter.TryDouble(obj2).Value; } bool?nullable = base.GetExpectedBoolean(evaluator, baseRow, baseColumn); if (!nullable.HasValue) { return(false); } Worksheet worksheet = evaluator as Worksheet; List <object> list = null; if (worksheet != null) { list = GetDuplicated(actualObj, this.ranges, worksheet.RowCount, worksheet.ColumnCount); } else { list = GetDuplicated(actualObj, this.ranges, 0x7fffffff, 0x7fffffff); } if (list != null) { if (list.Contains(obj2)) { return(nullable.Value); } if (nullable.Value) { return(false); } return(true); } if (nullable.Value) { return(false); } return(true); }
static bool TryConvertToNumber(object value, out double dValue) { dValue = 0.0; if (ConditionValueConverter.IsNumber(value)) { try { dValue = ConditionValueConverter.ToDouble(value); } catch { return(false); } return(true); } return((value is string) && double.TryParse((string)(value as string), (NumberStyles)NumberStyles.Any, (IFormatProvider)CultureInfo.InvariantCulture, out dValue)); }
static List <object> GetDuplicated(IActualValue actualValue, ICellRange[] ranges, int maxRowCount = 0x7fffffff, int maxColumnCount = 0x7fffffff) { Dictionary <object, int> dictionary = new Dictionary <object, int>(); if (ranges != null) { foreach (ICellRange range in ranges) { int num = Math.Min(range.RowCount, maxRowCount); for (int i = 0; i < num; i++) { int row = i + range.Row; int num4 = Math.Min(range.ColumnCount, maxColumnCount); for (int j = 0; j < num4; j++) { int column = j + range.Column; object obj2 = actualValue.GetValue(row, column); if (obj2 != null) { if (ConditionValueConverter.IsNumber(obj2)) { obj2 = (double)ConditionValueConverter.TryDouble(obj2).Value; } int num7 = 0; dictionary.TryGetValue(obj2, out num7); dictionary[obj2] = num7 + 1; } } } } } List <object> list = new List <object>(); foreach (KeyValuePair <object, int> pair in dictionary) { if (pair.Value > 1) { list.Add(pair.Key); } } return(list); }
/// <summary> /// Evaluates using the specified evaluator. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <param name="baseRow">The base row.</param> /// <param name="baseColumn">The base column.</param> /// <param name="actualObj">The actual value object.</param> /// <returns><c>true</c> if the result is successful; otherwise, <c>false</c>.</returns> public override bool Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actualObj) { object obj2 = actualObj.GetValue(); if (this.IgnoreBlank && (obj2 == null)) { return(true); } this.RebuildFormula(evaluator); double?nullable = base.GetExpectedDouble(evaluator, baseRow, baseColumn); double?nullable2 = null; object val = (this.stdValueObject != null) ? this.stdValueObject.GetValue(evaluator, baseRow, baseColumn) : null; if (val != null) { nullable2 = ConditionValueConverter.TryDouble(val); } if (ConditionValueConverter.IsNumber(obj2)) { double num = ConditionValueConverter.ToDouble(obj2); if (nullable.HasValue) { switch (this.type) { case AverageConditionType.Above: return(num > nullable.Value); case AverageConditionType.Below: return(num < nullable.Value); case AverageConditionType.EqualOrAbove: return(num >= nullable.Value); case AverageConditionType.EqualOrBelow: return(num <= nullable.Value); case AverageConditionType.Above1StdDev: { this.stdValueObject.GetValue(evaluator, baseRow, baseColumn); if (!nullable2.HasValue) { return(false); } double num2 = num; double?nullable3 = nullable; double num3 = nullable2.Value; double?nullable5 = nullable3.HasValue ? new double?(((double)nullable3.GetValueOrDefault()) + num3) : null; if (num2 <= ((double)nullable5.GetValueOrDefault())) { return(false); } return(nullable5.HasValue); } case AverageConditionType.Below1StdDev: { if (!nullable2.HasValue) { return(false); } double num4 = num; double?nullable6 = nullable; double num5 = nullable2.Value; double?nullable8 = nullable6.HasValue ? new double?(((double)nullable6.GetValueOrDefault()) - num5) : null; if (num4 >= ((double)nullable8.GetValueOrDefault())) { return(false); } return(nullable8.HasValue); } case AverageConditionType.Above2StdDev: { if (!nullable2.HasValue) { return(false); } double num6 = num; double?nullable9 = nullable; double num7 = 2.0 * nullable2.Value; double?nullable11 = nullable9.HasValue ? new double?(((double)nullable9.GetValueOrDefault()) + num7) : null; if (num6 <= ((double)nullable11.GetValueOrDefault())) { return(false); } return(nullable11.HasValue); } case AverageConditionType.Below2StdDev: { if (!nullable2.HasValue) { return(false); } double num8 = num; double?nullable12 = nullable; double num9 = 2.0 * nullable2.Value; double?nullable14 = nullable12.HasValue ? new double?(((double)nullable12.GetValueOrDefault()) - num9) : null; if (num8 >= ((double)nullable14.GetValueOrDefault())) { return(false); } return(nullable14.HasValue); } case AverageConditionType.Above3StdDev: { if (!nullable2.HasValue) { return(false); } double num10 = num; double?nullable15 = nullable; double num11 = 3.0 * nullable2.Value; double?nullable17 = nullable15.HasValue ? new double?(((double)nullable15.GetValueOrDefault()) + num11) : null; if (num10 <= ((double)nullable17.GetValueOrDefault())) { return(false); } return(nullable17.HasValue); } case AverageConditionType.Below3StdDev: { if (!nullable2.HasValue) { return(false); } double num12 = num; double?nullable18 = nullable; double num13 = 3.0 * nullable2.Value; double?nullable20 = nullable18.HasValue ? new double?(((double)nullable18.GetValueOrDefault()) - num13) : null; if (num12 >= ((double)nullable20.GetValueOrDefault())) { return(false); } return(nullable20.HasValue); } } } } return(false); }
/// <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 satisfies the condition; otherwise, <c>false</c>. /// </returns> bool CheckCondition(object expectedValue, object actualValue) { if (this.IgnoreBlank && ((actualValue == null) || actualValue.Equals(string.Empty))) { return(true); } if (ConditionValueConverter.IsNumber(actualValue)) { double?nullable = null; object obj2 = expectedValue; if (obj2 is string) { return((this.CompareType == GeneralCompareType.NotEqualsTo) && ConditionValueConverter.IsNumber(actualValue)); } if (ConditionValueConverter.IsNumber(obj2)) { nullable = new double?(ConditionValueConverter.ToDouble(obj2)); } if (!nullable.HasValue) { if (this.IgnoreBlank) { return(true); } nullable = 0.0; } double d = 0.0; try { d = ConditionValueConverter.ToDouble(actualValue); } catch (FormatException) { return(false); } if (!this.IntegerValue || ((d - Math.Floor(d)) == 0.0)) { switch (this.CompareType) { case GeneralCompareType.EqualsTo: return(d == nullable.Value); case GeneralCompareType.NotEqualsTo: return(d != nullable.Value); case GeneralCompareType.GreaterThan: return(d > nullable.Value); case GeneralCompareType.GreaterThanOrEqualsTo: return(d >= nullable.Value); case GeneralCompareType.LessThan: return(d < nullable.Value); case GeneralCompareType.LessThanOrEqualsTo: return(d <= nullable.Value); } } } return(false); }