Exemplo n.º 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);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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)));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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)));
        }
Exemplo n.º 10
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)));
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 internal double?CalculateFormula(ICalcEvaluator evaluator, int baseRow, int baseColumn, string formula)
 {
     return(ConditionValueConverter.TryDouble(ValueObject.FromFormula(formula).GetValue(evaluator, baseRow, baseColumn)));
 }