Exemple #1
0
 internal override bool IsConditionEvaluateToTrue(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
 {
     if (base.condition != null)
     {
         this.lastActualValue = actual;
         object val = actual.GetValue(baseRow, baseColumn);
         if (val != null)
         {
             double?nullable = ConditionValueConverter.TryDouble(val);
             if (!nullable.HasValue)
             {
                 return(false);
             }
             double currentValue = nullable.Value;
             double?nullable2    = this.CalcuteMinValue(evaluator, baseRow, baseColumn, 0, actual);
             double?nullable3    = this.CalcuteMaxValue(evaluator, baseRow, baseColumn, 2, actual);
             if (nullable2.HasValue && nullable3.HasValue)
             {
                 double?nullable5 = nullable2;
                 double?nullable6 = nullable3;
                 if ((((double)nullable5.GetValueOrDefault()) > ((double)nullable6.GetValueOrDefault())) && (nullable5.HasValue & nullable6.HasValue))
                 {
                     double?nullable4 = nullable3;
                     nullable3 = nullable2;
                     nullable2 = nullable4;
                 }
                 double axisScale = -1.0;
                 this.EvaluateScale(currentValue, nullable2.Value, nullable3.Value, out axisScale);
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #2
0
        internal override bool IsConditionEvaluateToTrue(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            if (base.condition == null)
            {
                return(false);
            }
            this.lastActualValue = actual;
            object obj2 = actual.GetValue(baseRow, baseColumn);

            if (obj2 != null)
            {
                try
                {
                    ConditionValueConverter.ToDouble(obj2);
                }
                catch (InvalidCastException)
                {
                    return(false);
                }
                double?nullable  = base.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
                double?nullable2 = base.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
                if (nullable.HasValue && nullable2.HasValue)
                {
                    return(true);
                }
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Returns a specified value of the rule if the cell satisfies the condition.
        /// </summary>
        /// <param name="evaluator">The evaluator.</param>
        /// <param name="baseRow">The row index.</param>
        /// <param name="baseColumn">The column index.</param>
        /// <param name="actual">The current value.</param>
        /// <returns>Returns the conditional number value.</returns>
        public override object Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            this.lastActualValue = actual;
            object obj2 = actual.GetValue(baseRow, baseColumn);

            if (obj2 != null)
            {
                double num;
                try
                {
                    num = ConditionValueConverter.ToDouble(obj2);
                }
                catch (InvalidCastException)
                {
                    return(null);
                }
                double?nullable  = base.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
                double?nullable2 = base.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
                if (nullable.HasValue && nullable2.HasValue)
                {
                    return(ScaleRule.EvaluateColor(ScaleRule.Evaluate2Scale(num, nullable.Value, nullable2.Value), this.MinimumColor, this.MaximumColor));
                }
            }
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Returns a drawing object based on a specified parameter.
        /// </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>The data bar object.</returns>
        public override object Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            this.lastActualValue = actual;
            object val = actual.GetValue(baseRow, baseColumn);

            if (val != null)
            {
                double?nullable = ConditionValueConverter.TryDouble(val);
                if (!nullable.HasValue)
                {
                    return(null);
                }
                double currentValue = nullable.Value;
                double?nullable2    = this.CalcuteMinValue(evaluator, baseRow, baseColumn, 0, actual);
                double?nullable3    = this.CalcuteMaxValue(evaluator, baseRow, baseColumn, 2, actual);
                if (nullable2.HasValue && nullable3.HasValue)
                {
                    double?nullable5 = nullable2;
                    double?nullable6 = nullable3;
                    if ((((double)nullable5.GetValueOrDefault()) > ((double)nullable6.GetValueOrDefault())) && (nullable5.HasValue & nullable6.HasValue))
                    {
                        double?nullable4 = nullable3;
                        nullable3 = nullable2;
                        nullable2 = nullable4;
                    }
                    double           axisScale = -1.0;
                    double           scale     = this.EvaluateScale(currentValue, nullable2.Value, nullable3.Value, out axisScale);
                    Windows.UI.Color fillColor = ((currentValue < 0.0) && this.useNegativeFillColor) ? this.negativeFillColor : this.color;
                    return(new DataBarDrawingObject(baseRow, baseColumn, fillColor, ((currentValue < 0.0) && this.useNegativeBorderColor) ? this.negativeBorderColor : this.borderColor, this.showBorder, this.axisColor, this.gradient, this.direction, axisScale, scale, this.showBarOnly));
                }
            }
            return(null);
        }
Exemple #5
0
 internal double?CalculateValue(ICalcEvaluator evaluator, int baseRow, int baseColumn, object value)
 {
     if (IsFormula(value))
     {
         return(this.CalculateFormula(evaluator, baseRow, baseColumn, TrimFormula((string)(value as string))));
     }
     return(ConditionValueConverter.TryDouble(value));
 }
Exemple #6
0
        internal static List <double> GetMinValues(IActualValue actualValue, int rank, ICellRange[] ranges)
        {
            List <double> list = new List <double>();

            if (ranges != null)
            {
                double minValue = double.MinValue;
                int    num2     = 0;
                foreach (ICellRange range in ranges)
                {
                    for (int i = 0; i < range.RowCount; i++)
                    {
                        int row = i + range.Row;
                        for (int j = 0; j < range.ColumnCount; j++)
                        {
                            int    column = j + range.Column;
                            object val    = actualValue.GetValue(row, column);
                            double num7   = 0.0;
                            if (val != null)
                            {
                                double?nullable = ConditionValueConverter.TryDouble(val);
                                if (nullable.HasValue)
                                {
                                    num7 = nullable.Value;
                                    if (num2 < rank)
                                    {
                                        list.Add(num7);
                                        if (num7 > minValue)
                                        {
                                            minValue = num7;
                                        }
                                        num2++;
                                    }
                                    else if (num7 < minValue)
                                    {
                                        list.Remove(minValue);
                                        list.Add(num7);
                                        if (list.IndexOf(minValue) < 0)
                                        {
                                            minValue = num7;
                                            for (int k = 0; k < list.Count; k++)
                                            {
                                                if (list[k] > minValue)
                                                {
                                                    minValue = list[k];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(list);
        }
Exemple #7
0
 /// <summary>
 /// Calculates the number.
 /// </summary>
 /// <param name="value">Value</param>
 /// <returns>Returns the value.</returns>
 internal double?CalculateNumber(object value)
 {
     try
     {
         return(new double?(ConditionValueConverter.ToDouble(value)));
     }
     catch (InvalidCastException)
     {
         return(null);
     }
 }
Exemple #8
0
        /// <summary>
        /// Calculates the formula.
        /// </summary>
        /// <param name="evaluator"></param>
        /// <param name="baseRow"></param>
        /// <param name="baseColumn"></param>
        /// <param name="formula">Formula</param>
        /// <returns>Returns the formula.</returns>
        internal double?CalculateFormula(ICalcEvaluator evaluator, int baseRow, int baseColumn, string formula)
        {
            object obj2 = ValueObject.FromFormula(formula).GetValue(evaluator, baseRow, baseColumn);

            try
            {
                return(new double?(ConditionValueConverter.ToDouble(obj2)));
            }
            catch (InvalidCastException)
            {
                return(null);
            }
        }
Exemple #9
0
 internal override bool IsConditionEvaluateToTrue(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
 {
     if (base.condition != null)
     {
         this.lastActualValue = actual;
         object obj2 = actual.GetValue(baseRow, baseColumn);
         if (obj2 != null)
         {
             double num;
             try
             {
                 num = ConditionValueConverter.ToDouble(obj2);
             }
             catch (InvalidCastException)
             {
                 return(false);
             }
             double?nullable  = base.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
             double?nullable2 = base.GetActualValue(evaluator, baseRow, baseColumn, 1, actual);
             double?nullable3 = base.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
             if ((nullable.HasValue && nullable3.HasValue) && nullable2.HasValue)
             {
                 double?nullable4 = nullable;
                 double?nullable5 = nullable3;
                 if ((((double)nullable4.GetValueOrDefault()) > ((double)nullable5.GetValueOrDefault())) && (nullable4.HasValue & nullable5.HasValue))
                 {
                     return(false);
                 }
                 double num2      = num;
                 double?nullable6 = nullable;
                 if ((num2 >= ((double)nullable6.GetValueOrDefault())) || !nullable6.HasValue)
                 {
                     double num3      = num;
                     double?nullable7 = nullable3;
                     if ((num3 >= ((double)nullable7.GetValueOrDefault())) && nullable7.HasValue)
                     {
                         return(true);
                     }
                     if ((nullable.Value <= num) && (num <= nullable2.Value))
                     {
                         ScaleRule.Evaluate2Scale(num, nullable.Value, nullable2.Value);
                         return(true);
                     }
                     ScaleRule.Evaluate2Scale(num, nullable2.Value, nullable3.Value);
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #10
0
 void CalculateLowestValueAndHighestValue(IActualValue actualValue, out double?min, out double?max, ICellRange[] ranges)
 {
     min = 0;
     max = 0;
     if (ranges != null)
     {
         foreach (ICellRange range in ranges)
         {
             for (int i = 0; i < range.RowCount; i++)
             {
                 int row = i + range.Row;
                 for (int j = 0; j < range.ColumnCount; j++)
                 {
                     int    column = j + range.Column;
                     object val    = actualValue.GetValue(row, column);
                     if (val != null)
                     {
                         double?nullable = ConditionValueConverter.TryDouble(val);
                         if (nullable.HasValue)
                         {
                             double num5 = nullable.Value;
                             if (!min.HasValue)
                             {
                                 min = new double?(num5);
                             }
                             if (!max.HasValue)
                             {
                                 max = new double?(num5);
                             }
                             double num7      = num5;
                             double?nullable2 = min;
                             if ((num7 < ((double)nullable2.GetValueOrDefault())) && nullable2.HasValue)
                             {
                                 min = new double?(num5);
                             }
                             double num8      = num5;
                             double?nullable3 = max;
                             if ((num8 > ((double)nullable3.GetValueOrDefault())) && nullable3.HasValue)
                             {
                                 max = new double?(num5);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #11
0
        /// <summary>
        /// Returns the specified value of the rule if the cell meets the condition.
        /// </summary>
        /// <param name="evaluator">The evaluator.</param>
        /// <param name="baseRow">The row index.</param>
        /// <param name="baseColumn">The column index.</param>
        /// <param name="actual">The current value.</param>
        /// <returns>Returns the conditional number value.</returns>
        public override object Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            this.lastActualValue = actual;
            object obj2 = actual.GetValue(baseRow, baseColumn);

            if (obj2 != null)
            {
                double num;
                try
                {
                    num = ConditionValueConverter.ToDouble(obj2);
                }
                catch (InvalidCastException)
                {
                    return(null);
                }
                double?nullable  = base.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
                double?nullable2 = base.GetActualValue(evaluator, baseRow, baseColumn, 1, actual);
                double?nullable3 = base.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
                if ((nullable.HasValue && nullable3.HasValue) && nullable2.HasValue)
                {
                    double?nullable4 = nullable;
                    double?nullable5 = nullable3;
                    if ((((double)nullable4.GetValueOrDefault()) > ((double)nullable5.GetValueOrDefault())) && (nullable4.HasValue & nullable5.HasValue))
                    {
                        return(null);
                    }
                    double num4      = num;
                    double?nullable6 = nullable;
                    if ((num4 < ((double)nullable6.GetValueOrDefault())) && nullable6.HasValue)
                    {
                        return(this.MinimumColor);
                    }
                    double num5      = num;
                    double?nullable7 = nullable3;
                    if ((num5 >= ((double)nullable7.GetValueOrDefault())) && nullable7.HasValue)
                    {
                        return(this.MaximumColor);
                    }
                    if ((nullable.Value <= num) && (num <= nullable2.Value))
                    {
                        return(ScaleRule.EvaluateColor(ScaleRule.Evaluate2Scale(num, nullable.Value, nullable2.Value), this.MinimumColor, this.MidpointColor));
                    }
                    return(ScaleRule.EvaluateColor(ScaleRule.Evaluate2Scale(num, nullable2.Value, nullable3.Value), this.MidpointColor, this.MaximumColor));
                }
            }
            return(null);
        }
Exemple #12
0
        /// <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);
        }
Exemple #13
0
        /// <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)));
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        internal double?CalculatePercentile(ICalcEvaluator evaluator, int baseRow, int baseColumn, object value)
        {
            double?nullable = this.CalculateValue(evaluator, baseRow, baseColumn, value);

            if ((!nullable.HasValue || (0.0 > nullable.Value)) || (nullable.Value > 100.0))
            {
                return(null);
            }
            double num = 0.0;

            foreach (CellRange range in base.Ranges)
            {
                object expression = evaluator.CreateExpression("CalcPercentileFunction", new object[] { range, (double)(nullable.Value / 100.0) });
                double?nullable2  = ConditionValueConverter.TryDouble(evaluator.EvaluateExpression(expression, 0, 0, baseRow, baseColumn, false));
                if (nullable2.HasValue)
                {
                    num += nullable2.Value;
                }
            }
            return(new double?(num / ((double)base.Ranges.Length)));
        }
Exemple #16
0
        /// <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);
            }
            int?nullable = base.GetExpectedInt(evaluator, baseRow, baseColumn);

            if (nullable.HasValue)
            {
                List <double> list = null;
                if (this.type == Top10ConditionType.Top)
                {
                    list = GetMaxValues(actualObj, nullable.Value, this.ranges);
                }
                else if (this.type == Top10ConditionType.Bottom)
                {
                    list = GetMinValues(actualObj, nullable.Value, this.ranges);
                }
                if (list != null)
                {
                    double num = 0.0;
                    try
                    {
                        num = ConditionValueConverter.ToDouble(obj2);
                    }
                    catch (InvalidCastException)
                    {
                        return(false);
                    }
                    if (list.Contains(num))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #17
0
        /// <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)
        {
            if (this.customValueType == CustomValueType.Formula)
            {
                object val = base.GetExpected(evaluator, baseRow, baseColumn);
                if (this.IgnoreBlank && (val == null))
                {
                    return(true);
                }
                bool?nullable = ConditionValueConverter.TryBool(val);
                if (!nullable.HasValue)
                {
                    return(false);
                }
                return(nullable.Value);
            }
            object objA = actualObj.GetValue();

            switch (this.customValueType)
            {
            case CustomValueType.Empty:
                return((objA == null) || object.Equals(objA, string.Empty));

            case CustomValueType.NonEmpty:
                if (objA == null)
                {
                    return(false);
                }
                return(!object.Equals(objA, string.Empty));

            case CustomValueType.Error:
                return(evaluator.IsCalcError(objA));

            case CustomValueType.NonError:
                return(!evaluator.IsCalcError(objA));
            }
            return(false);
        }
Exemple #18
0
        /// <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);
        }
Exemple #19
0
        /// <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);
        }
Exemple #20
0
 /// <summary>
 /// Evaluates a specified value of the rule if the cell satisfies the condition.
 /// </summary>
 /// <param name="evaluator">The evaluator.</param>
 /// <param name="baseRow">The row index.</param>
 /// <param name="baseColumn">The column index.</param>
 /// <param name="actual">The current value.</param>
 /// <returns>Returns the conditional number value.</returns>
 public override object Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
 {
     this.TryCache(actual);
     if (base.Contains(baseRow, baseColumn))
     {
         object obj2 = actual.GetValue();
         if (obj2 == null)
         {
             return(null);
         }
         try
         {
             double num       = ConditionValueConverter.ToDouble(obj2);
             double?nullable  = this.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
             double?nullable2 = this.GetActualValue(evaluator, baseRow, baseColumn, 1, actual);
             double?nullable3 = this.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
             if (!nullable2.HasValue)
             {
                 if (nullable.HasValue && nullable3.HasValue)
                 {
                     double?nullable4 = nullable;
                     double?nullable5 = nullable3;
                     if ((((double)nullable4.GetValueOrDefault()) > ((double)nullable5.GetValueOrDefault())) && (nullable4.HasValue & nullable5.HasValue))
                     {
                         return(null);
                     }
                     return((double)Evaluate2Scale(num, nullable.Value, nullable3.Value));
                 }
             }
             else if ((nullable.HasValue && nullable3.HasValue) && nullable2.HasValue)
             {
                 double?nullable6 = nullable;
                 double?nullable7 = nullable3;
                 if ((((double)nullable6.GetValueOrDefault()) > ((double)nullable7.GetValueOrDefault())) && (nullable6.HasValue & nullable7.HasValue))
                 {
                     return(null);
                 }
                 double num5      = num;
                 double?nullable8 = nullable;
                 if ((num5 < ((double)nullable8.GetValueOrDefault())) && nullable8.HasValue)
                 {
                     return((double)0.0);
                 }
                 double num6      = num;
                 double?nullable9 = nullable3;
                 if ((num6 >= ((double)nullable9.GetValueOrDefault())) && nullable9.HasValue)
                 {
                     return((double)2.0);
                 }
                 Evaluate2Scale(nullable2.Value, nullable.Value, nullable3.Value);
                 if ((nullable.Value <= num) && (num <= nullable2.Value))
                 {
                     return((double)Evaluate2Scale(num, nullable.Value, nullable2.Value));
                 }
                 double num4 = 1.0 + Evaluate2Scale(num, nullable.Value, nullable3.Value);
                 return((double)num4);
             }
         }
         catch
         {
             return(null);
         }
     }
     return(null);
 }
Exemple #21
0
 internal override bool IsConditionEvaluateToTrue(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
 {
     if (base.condition != null)
     {
         this.TryCache(actual);
         if (base.Contains(baseRow, baseColumn))
         {
             object obj2 = actual.GetValue();
             if (obj2 == null)
             {
                 return(false);
             }
             try
             {
                 double num       = ConditionValueConverter.ToDouble(obj2);
                 double?nullable  = this.GetActualValue(evaluator, baseRow, baseColumn, 0, actual);
                 double?nullable2 = this.GetActualValue(evaluator, baseRow, baseColumn, 1, actual);
                 double?nullable3 = this.GetActualValue(evaluator, baseRow, baseColumn, 2, actual);
                 if (!nullable2.HasValue)
                 {
                     if (nullable.HasValue && nullable3.HasValue)
                     {
                         double?nullable4 = nullable;
                         double?nullable5 = nullable3;
                         if ((((double)nullable4.GetValueOrDefault()) > ((double)nullable5.GetValueOrDefault())) && (nullable4.HasValue & nullable5.HasValue))
                         {
                             return(false);
                         }
                         return(true);
                     }
                 }
                 else if ((nullable.HasValue && nullable3.HasValue) && nullable2.HasValue)
                 {
                     double?nullable6 = nullable;
                     double?nullable7 = nullable3;
                     if ((((double)nullable6.GetValueOrDefault()) > ((double)nullable7.GetValueOrDefault())) && (nullable6.HasValue & nullable7.HasValue))
                     {
                         return(false);
                     }
                     double num2      = num;
                     double?nullable8 = nullable;
                     if ((num2 >= ((double)nullable8.GetValueOrDefault())) || !nullable8.HasValue)
                     {
                         double num3      = num;
                         double?nullable9 = nullable3;
                         if ((num3 >= ((double)nullable9.GetValueOrDefault())) && nullable9.HasValue)
                         {
                             return(true);
                         }
                         Evaluate2Scale(nullable2.Value, nullable.Value, nullable3.Value);
                         if ((nullable.Value <= num) && (num <= nullable2.Value))
                         {
                             return(true);
                         }
                     }
                     return(true);
                 }
             }
             catch
             {
                 return(false);
             }
         }
     }
     return(false);
 }
Exemple #22
0
 /// <summary>
 /// Gets the expected bool value.
 /// </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 bool value.</returns>
 protected bool?GetExpectedBoolean(ICalcEvaluator evaluator, int baseRow, int baseColumn)
 {
     return(ConditionValueConverter.TryBool(this.GetExpected(evaluator, baseRow, baseColumn)));
 }
Exemple #23
0
 internal double?CalculateFormula(ICalcEvaluator evaluator, int baseRow, int baseColumn, string formula)
 {
     return(ConditionValueConverter.TryDouble(ValueObject.FromFormula(formula).GetValue(evaluator, baseRow, baseColumn)));
 }
Exemple #24
0
 /// <summary>
 /// Gets the expected double value.
 /// </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 double value.</returns>
 protected double?GetExpectedDouble(ICalcEvaluator evaluator, int baseRow, int baseColumn)
 {
     return(ConditionValueConverter.TryDouble(this.GetExpected(evaluator, baseRow, baseColumn)));
 }
Exemple #25
0
        /// <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);
        }