Beispiel #1
0
        object TryValue(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            double?nullable = FormatConverter.TryDouble(obj, false);

            if (nullable.HasValue)
            {
                int    num2;
                long   num3;
                double d = nullable.Value;
                if (Math.Abs((double)(d - Math.Floor(d))) != 0.0)
                {
                    return(obj);
                }
                if (NumberHelper.TryInteger(d, out num2))
                {
                    return((int)num2);
                }
                if (NumberHelper.TryLong(d, out num3))
                {
                    return((long)num3);
                }
            }
            return(obj);
        }
Beispiel #2
0
 internal void UpdateValueAxisMinMax()
 {
     if (base.items.Count != 0)
     {
         double             maxValue = double.MaxValue;
         double             minValue = double.MinValue;
         Dt.Cells.Data.Axis axis     = this.Axis;
         using (IEnumerator <object> enumerator = base.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 double?nullable = FormatConverter.TryDouble(enumerator.Current, true);
                 if (nullable.HasValue)
                 {
                     if (nullable.Value < maxValue)
                     {
                         maxValue = nullable.Value;
                     }
                     if (nullable.Value > minValue)
                     {
                         minValue = nullable.Value;
                     }
                 }
             }
         }
         if (axis.AxisType == AxisType.Value)
         {
             maxValue = AxisUtility.CalculateValidMinimum(maxValue, minValue, false, axis.LogBase, axis.AutoMin, axis.AutoMax);
             minValue = AxisUtility.CalculateValidMaximum(maxValue, minValue, false, axis.LogBase);
             maxValue = AxisUtility.CalculateMinimum(maxValue, minValue, false, axis.LogBase);
             minValue = AxisUtility.CalculateMaximum(maxValue, minValue, false, axis.LogBase);
         }
         if (axis.AutoMin)
         {
             if (axis.AxisType == AxisType.Value)
             {
                 maxValue = AxisUtility.CalculateMinimum(maxValue, minValue, axis.MajorUnit, false, axis.LogBase);
             }
             if (maxValue != double.MaxValue)
             {
                 axis.SetMinInternal(maxValue);
             }
         }
         if (axis.AutoMax)
         {
             if (axis.AxisType == AxisType.Value)
             {
                 minValue = AxisUtility.CalculateMaximum(maxValue, minValue, axis.MajorUnit, false, axis.LogBase, false);
             }
             if (minValue != double.MinValue)
             {
                 axis.SetMaxInternal(minValue);
             }
         }
         if ((axis.AutoMajorUnit || axis.AutoMinorUnit) && ((maxValue != double.MaxValue) && (minValue != double.MinValue)))
         {
             axis.UpdateMajorMinorUnit(maxValue, minValue);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Formats the specified object as a string.
        /// </summary>
        /// <param name="obj">Object with cell data to format.</param>
        /// <returns>Returns the formatted string.</returns>
        public string Format(object obj)
        {
            string str = string.Empty;

            try
            {
                if (obj is IFormattable)
                {
                    return(NumberHelper.Format <IFormattable>(obj as IFormattable, this.formatString, (IFormatProvider)this.FormatProvider));
                }
                double?nullable = FormatConverter.TryDouble(obj, true);
                if (!nullable.HasValue)
                {
                    if (obj is string)
                    {
                        return((string)(obj as string));
                    }
                    return(null);
                }
                return(((double)nullable.Value).ToString(this.formatString, (IFormatProvider)this.FormatProvider));
            }
            catch
            {
                str = FormatConverter.ToString(obj, true);
            }
            return(str);
        }
Beispiel #4
0
        public object GetValue(int index)
        {
            if ((this.Sheet != null) && (this.DataReference != null))
            {
                if (this.cachedData == null)
                {
                    this.cachedData = this.Sheet.EvaluateExpression(this.DataReference, 0, 0, 0, 0, true) as object[, ];
                    for (int i = 0; i < this.cachedData.GetLength(0); i++)
                    {
                        for (int j = 0; j < this.cachedData.GetLength(1); j++)
                        {
                            object val = this.cachedData[i, j];
                            if (val != null)
                            {
                                double?nullable = FormatConverter.TryDouble(val, false);
                                if (!nullable.HasValue)
                                {
                                    this.cachedData[i, j] = null;
                                }
                                else
                                {
                                    this.cachedData[i, j] = (double)nullable.Value;
                                }
                            }
                        }
                    }
                }
                if (!this.ShowHiddenData && !this.IsValueVisible(index))
                {
                    return((double)double.NaN);
                }
                if (this.cachedData != null)
                {
                    switch (this.DataOrientation)
                    {
                    case Dt.Cells.Data.DataOrientation.Vertical:
                        return(this.cachedData[0, index]);

                    case Dt.Cells.Data.DataOrientation.Horizontal:
                        return(this.cachedData[index, 0]);
                    }
                }
            }
            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Converts the value.
        /// </summary>
        /// <param name="valueIndex">Index of the value.</param>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        protected override double ConvertValue(int valueIndex, object obj)
        {
            if (obj == null)
            {
                if (base.DataSeries.EmptyValueStyle == EmptyValueStyle.Zero)
                {
                    return(0.0);
                }
                return(double.NaN);
            }
            double?nullable = FormatConverter.TryDouble(obj, false);

            if (!nullable.HasValue)
            {
                return(double.NaN);
            }
            return(nullable.Value);
        }
Beispiel #6
0
        void AdjustAxisMinMax(Dt.Cells.Data.Axis axis, object value)
        {
            double?nullable = FormatConverter.TryDouble(value, true);

            if (nullable.HasValue)
            {
                if (nullable.Value > axis.Max)
                {
                    if (axis.AutoMax)
                    {
                        if (axis.AxisType == AxisType.Value)
                        {
                            nullable = new double?(AxisUtility.CalculateMaximum(axis.Min, nullable.Value, axis.MajorUnit, false, axis.LogBase, false));
                        }
                        double?nullable2 = nullable;
                        if ((((double)nullable2.GetValueOrDefault()) != double.MinValue) || !nullable2.HasValue)
                        {
                            axis.SetMaxInternal(nullable.Value);
                        }
                        if ((axis.AutoMajorUnit || axis.AutoMinorUnit) && ((nullable.Value != double.MaxValue) && (nullable.Value != double.MinValue)))
                        {
                            axis.UpdateMajorMinorUnit(axis.Min, nullable.Value);
                        }
                    }
                }
                else if ((nullable.Value < axis.Min) && axis.AutoMin)
                {
                    if (axis.AxisType == AxisType.Value)
                    {
                        nullable = new double?(AxisUtility.CalculateMinimum(nullable.Value, axis.Max, axis.MajorUnit, false, axis.LogBase));
                    }
                    if (nullable.Value != double.MaxValue)
                    {
                        axis.SetMinInternal(nullable.Value);
                    }
                    if ((axis.AutoMajorUnit || axis.AutoMinorUnit) && ((nullable.Value != double.MaxValue) && (nullable.Value != double.MinValue)))
                    {
                        axis.UpdateMajorMinorUnit(nullable.Value, axis.Max);
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Formats the specified value.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>
        /// Returns the string of the formatted value.
        /// </returns>
        public override string Format(object obj)
        {
            string str = string.Empty;

            if (FormatConverter.IsNumber(obj))
            {
                bool   flag     = (base.PartLocaleID == null) || base.PartLocaleID.AllowScience;
                double?nullable = FormatConverter.TryDouble(obj, true);
                if (!nullable.HasValue)
                {
                    return("");
                }
                double num = nullable.Value;
                if (((Math.Abs(num) <= 99999999999) || !flag) && ((Math.Abs(num) >= 1E-11) || (num == 0.0)))
                {
                    return(this.DigitalFormat.Format(obj));
                }
                return(this.ExponentialDigitalFormat.Format(obj));
            }
            if (obj is string)
            {
                string newValue = FormatConverter.ToString(obj, true);
                string str3     = DefaultTokens.TrimEscape(this.FormatString.Replace("\"", ""));
                if (str3 != null)
                {
                    newValue = str3.Replace("General", newValue);
                }
                return(newValue);
            }
            if (obj is bool)
            {
                bool flag2 = (bool)((bool)obj);
                str = flag2.ToString().ToUpper();
            }
            return(str);
        }
Beispiel #8
0
        /// <summary>
        /// Formats the specified value.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>Returns the string of the formatted value.</returns>
        public override string Format(object obj)
        {
            if (obj is bool)
            {
                return(FormatConverter.ToString(obj, true));
            }
            double?nullable = FormatConverter.TryDouble(obj, true);

            if (!nullable.HasValue)
            {
                if (obj is string)
                {
                    return((string)(obj as string));
                }
                return(null);
            }
            double num       = nullable.Value;
            string naNSymbol = base.NaNSymbol;

            if ((this.fractionNumeratorFormat != null) && (this.fractionDenominatorFormat != null))
            {
                double num2;
                double num3;
                double num4;
                double num13;
                int    length = this.fractionDenominatorFormat.Length;
                if (!GetFraction(num, length, out num2, out num3, out num4))
                {
                    return(((double)num).ToString((IFormatProvider)this.NumberFormatInfo));
                }
                double mincCommonMultiple = this.GetMincCommonMultiple(num3, num4);
                if (mincCommonMultiple > 1.0)
                {
                    num3 /= mincCommonMultiple;
                    num4 /= mincCommonMultiple;
                }
                if (this.fractionIntegerFormat != null)
                {
                    double        num7;
                    double        num9;
                    StringBuilder builder = new StringBuilder();
                    if (num2 != 0.0)
                    {
                        builder.Append(((double)num2).ToString(this.fractionIntegerFormat, (IFormatProvider)this.NumberFormatInfo));
                    }
                    if (this.constString != null)
                    {
                        builder.Append(this.constString);
                    }
                    if ((num2 == 0.0) && (num < 0.0))
                    {
                        builder.Append(base.NegativeSign);
                    }
                    if (num == 0.0)
                    {
                        builder.Append("0");
                    }
                    string fractionDenominatorFormat = this.fractionDenominatorFormat;
                    if (double.TryParse(fractionDenominatorFormat, out num7) && (num7 > 0.0))
                    {
                        num3 *= num7 / num4;
                        fractionDenominatorFormat = string.Empty;
                        num4 = num7;
                        double num8 = Math.Ceiling(num3) - num3;
                        if ((num8 <= 0.5) && (num8 > 0.0))
                        {
                            num3 = ((int)num3) + 1;
                        }
                        else
                        {
                            num3 = (int)num3;
                        }
                    }
                    string fractionNumeratorFormat = this.fractionNumeratorFormat;
                    if (double.TryParse(fractionNumeratorFormat, out num9) && (num9 == 0.0))
                    {
                        int    num10 = fractionNumeratorFormat.Length;
                        string str4  = ((double)num3).ToString();
                        int    num11 = str4.Length;
                        if (num10 > num11)
                        {
                            fractionNumeratorFormat = fractionNumeratorFormat.Substring(0, fractionNumeratorFormat.Length - (num10 - num11));
                        }
                        else if (num10 < num11)
                        {
                            num3 = int.Parse(str4.Substring(0, num10));
                        }
                    }
                    if (num3 != 0.0)
                    {
                        builder.Append(((double)num3).ToString(fractionNumeratorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' }));
                        builder.Append(DefaultTokens.SolidusSign);
                        builder.Append(((double)num4).ToString(fractionDenominatorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' }));
                    }
                    return(builder.ToString());
                }
                StringBuilder builder2 = new StringBuilder();
                double        a        = (num2 * num4) + num3;
                if (double.TryParse(this.fractionDenominatorFormat, out num13) && (num13 > 0.0))
                {
                    a   *= num13 / num4;
                    num4 = num13;
                    double num14 = Math.Ceiling(a) - a;
                    if ((num14 <= 0.5) && (num14 > 0.0))
                    {
                        a = ((int)a) + 1;
                    }
                    else
                    {
                        a = (int)a;
                    }
                    builder2.Append(string.Format("{0}/{1}", (object[])new object[] { ((double)a), ((double)num4) }));
                }
                else
                {
                    builder2.Append(((double)a).ToString(this.fractionNumeratorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' }));
                    builder2.Append(DefaultTokens.SolidusSign);
                    builder2.Append(((double)num4).ToString(this.fractionDenominatorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' }));
                }
                return(builder2.ToString());
            }
            naNSymbol = ((double)num).ToString(this.EncodeNumberFormat(this.numberFormatString), (IFormatProvider)this.NumberFormatInfo);
            if (this.NumberStringConverter != null)
            {
                naNSymbol = this.NumberStringConverter.ConvertTo(naNSymbol, obj, this.isGeneralNumber, base.PartLocaleID, base.PartDBNumberFormat);
            }
            return(naNSymbol);
        }
Beispiel #9
0
        internal override bool IsConditionEvaluateToTrue(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            if (base.condition == null)
            {
                return(false);
            }
            object obj2 = actual.GetValue(baseRow, baseColumn);

            if (obj2 == null)
            {
                return(false);
            }
            double num = 0.0;

            if (!FormatConverter.IsNumber(obj2))
            {
                return(false);
            }
            double?nullable = FormatConverter.TryDouble(obj2, false);

            if (!nullable.HasValue)
            {
                return(false);
            }
            num = nullable.Value;
            int num2 = 0;

            if ((this.iconSetType >= Dt.Cells.Data.IconSetType.ThreeArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.ThreeSymbolsUncircled))
            {
                num2 = 3;
            }
            else if ((this.iconSetType >= Dt.Cells.Data.IconSetType.FourArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.FourTrafficLights))
            {
                num2 = 4;
            }
            else if ((this.iconSetType >= Dt.Cells.Data.IconSetType.FiveArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.FiveBoxes))
            {
                num2 = 5;
            }
            if (this.iconCriteria != null)
            {
                double maxValue = double.MaxValue;
                for (int i = num2 - 1; i > 0; i--)
                {
                    if (i >= (this.iconCriteria.Length + 1))
                    {
                        return(true);
                    }
                    IconCriterion criterion = this.iconCriteria[i - 1];
                    if ((criterion == null) || (criterion.Value == null))
                    {
                        return(true);
                    }
                    double?nullable2 = this.GetActualValue(evaluator, baseRow, baseColumn, i - 1, actual);
                    if (!nullable2.HasValue)
                    {
                        return(true);
                    }
                    if (criterion.IsGreaterThanOrEqualTo)
                    {
                        if ((num < maxValue) && (num >= nullable2.Value))
                        {
                            return(true);
                        }
                    }
                    else if ((num < maxValue) && (num > nullable2.Value))
                    {
                        return(true);
                    }
                }
            }
            return(true);
        }
Beispiel #10
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 object.</param>
        /// <returns>Returns an icon object.</returns>
        public override object Evaluate(ICalcEvaluator evaluator, int baseRow, int baseColumn, IActualValue actual)
        {
            object obj2 = actual.GetValue(baseRow, baseColumn);

            if (obj2 == null)
            {
                return(null);
            }
            double num = 0.0;

            if (!FormatConverter.IsNumber(obj2))
            {
                return(null);
            }
            double?nullable = FormatConverter.TryDouble(obj2, false);

            if (!nullable.HasValue)
            {
                return(null);
            }
            num = nullable.Value;
            int num2 = 0;

            if ((this.iconSetType >= Dt.Cells.Data.IconSetType.ThreeArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.ThreeSymbolsUncircled))
            {
                num2 = 3;
            }
            else if ((this.iconSetType >= Dt.Cells.Data.IconSetType.FourArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.FourTrafficLights))
            {
                num2 = 4;
            }
            else if ((this.iconSetType >= Dt.Cells.Data.IconSetType.FiveArrowsColored) && (this.iconSetType <= Dt.Cells.Data.IconSetType.FiveBoxes))
            {
                num2 = 5;
            }
            if (this.iconCriteria == null)
            {
                return((int)0);
            }
            double maxValue = double.MaxValue;

            for (int i = num2 - 1; i > 0; i--)
            {
                if (i >= (this.iconCriteria.Length + 1))
                {
                    return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(0), this.showIconOnly));
                }
                IconCriterion criterion = this.iconCriteria[i - 1];
                if ((criterion == null) || (criterion.Value == null))
                {
                    return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(0), this.showIconOnly));
                }
                double?nullable2 = this.GetActualValue(evaluator, baseRow, baseColumn, i - 1, actual);
                if (!nullable2.HasValue)
                {
                    return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(0), this.showIconOnly));
                }
                if (criterion.IsGreaterThanOrEqualTo)
                {
                    if ((num < maxValue) && (num >= nullable2.Value))
                    {
                        return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(i), this.showIconOnly));
                    }
                }
                else if ((num < maxValue) && (num > nullable2.Value))
                {
                    return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(i), this.showIconOnly));
                }
            }
            return(new IconDrawingObject(baseRow, baseColumn, this.iconSetType, this.modifyIconIndex(0), this.showIconOnly));
        }