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); }
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); } } }
/// <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); }
/// <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) { DateTime time = DateTime.Now; DateTime?nullable = FormatConverter.TryDateTime(obj, true); if (!nullable.HasValue) { return(FormatConverter.ToString(obj, true)); } return(nullable.Value.ToString(this.formatString, (IFormatProvider)this.FormatProvider)); }
/// <summary> /// Formats the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>Returns the formatted value.</returns> public override string Format(object value) { try { string newValue = FormatConverter.ToString(value, true); string str2 = this.formatString.Replace("\"", ""); if (str2 != null) { newValue = str2.Replace(CommercialAt, newValue); } return(newValue); } catch { } return(string.Empty); }
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); }
/// <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); }
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); } } } }
/// <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); }
/// <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); }
/// <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)); } string number = string.Empty; DateTime time = DateTime.Now; DateTime?nullable = FormatConverter.TryDateTime(obj, true); if (nullable.HasValue) { time = nullable.Value; if ((((this.validDateTimeFormatString == "H") || (this.validDateTimeFormatString == "h")) || ((this.validDateTimeFormatString == "m") || (this.validDateTimeFormatString == "M"))) || (((this.validDateTimeFormatString == "d") || (this.validDateTimeFormatString == "s")) || (this.validDateTimeFormatString == "y"))) { this.validDateTimeFormatString = "%" + this.validDateTimeFormatString; } number = time.ToString(this.validDateTimeFormatString, (IFormatProvider)this.DateTimeFormatInfo); if (this.hasJD) { string monthName = DefaultTokens.DateTimeFormatInfo.GetMonthName(time.Month); number = number.Replace(PlaceholderMonthJD, monthName.Substring(0, 1)); } if (this.absTimeParts != null) { TimeSpan span = (TimeSpan)(time - this.AbsoluteTime); foreach (ABSTimeFormatPart part in this.absTimeParts) { string newValue = null; switch (part.TimePartType) { case TimePart.Hour: newValue = ((double)Math.Floor(span.TotalHours)).ToString(part.FormatString); break; case TimePart.Minute: newValue = ((double)Math.Floor(span.TotalMinutes)).ToString(part.FormatString); break; case TimePart.Second: newValue = ((double)Math.Floor(span.TotalSeconds)).ToString(part.FormatString); break; } if (newValue != null) { number = number.Replace(DefaultTokens.ReplacePlaceholder + part.Token, newValue); } } } } else { number = FormatConverter.ToString(obj, true); } if (this.NumberStringConverter is DefaultDateTimeNumberStringConverter) { if (this.NumberStringConverter != null) { number = this.NumberStringConverter.ConvertTo(number, obj, false, base.PartLocaleID, base.PartDBNumberFormat); } return(number); } if (this.NumberStringConverter == null) { return(number); } if (this.hasYearDelay) { number = number.Replace(DefaultTokens.ReplacePlaceholder + YearFourDigit, time.ToString(YearFourDigit)).Replace(DefaultTokens.ReplacePlaceholder + YearTwoDigit, time.ToString(YearTwoDigit)); } return(this.NumberStringConverter.ConvertTo(number, obj, true, base.PartLocaleID, base.PartDBNumberFormat)); }
internal virtual void UpdateCollection() { List <T> list = new List <T>(); if ((this._dataProviders != null) && (this._dataProviders.Count > 0)) { bool flag = true; foreach (ISeriesDataProvider provider in this._dataProviders) { int valuesCount = provider.ValuesCount; int seriesCount = provider.SeriesCount; for (int i = 0; i < valuesCount; i++) { object obj2 = null; string str = null; bool flag2 = true; for (int j = 0; j < seriesCount; j++) { flag2 = this.DataSeries.DisplayHiddenData || provider.IsValueVisible(j, i); if (flag2) { object obj3 = provider.GetValue(j, i); string text = provider.GetText(j, i); if (j == 0) { obj2 = obj3; str = text; } else { string str3 = (obj2 != null) ? obj2.ToString() : ""; string str4 = (obj3 != null) ? obj3.ToString() : ""; if (!string.IsNullOrEmpty(str4)) { obj2 = str3 + this.ValuesSeperator + str4; } else { obj2 = str3; } flag = false; } } } if (flag2) { if (!(obj2 is DateTime)) { if (FormatConverter.IsNumber(obj2)) { DateTime time; if (!string.IsNullOrEmpty(str) && !DateTime.TryParse(str, (IFormatProvider)CultureInfo.CurrentCulture, (DateTimeStyles)DateTimeStyles.None, out time)) { flag = false; } } else { flag = false; } } T local = this.ConvertValue(i, obj2); list.Add(local); } } } base.items.Clear(); base.items.AddRange((IEnumerable <T>)list); if ((flag != this.IsDateTimeSeries) && (base.items.Count > 0)) { this.IsDateTimeSeries = flag; } } else if ((this.DataSeries != null) && (this.DataSeries.DataReference is CalcArrayExpression)) { bool flag3 = true; CalcArrayExpression dataReference = this.DataSeries.DataReference as CalcArrayExpression; if (dataReference.ArrayValue != null) { int length = dataReference.ArrayValue.Length; for (int k = 0; k < length; k++) { T local2 = this.ConvertValue(k, dataReference.ArrayValue.GetValue(k)); if (flag3 && !(local2 is DateTime)) { flag3 = false; } list.Add(local2); } } base.items.Clear(); base.items.AddRange((IEnumerable <T>)list); if ((flag3 != this.IsDateTimeSeries) && (base.items.Count > 0)) { this.IsDateTimeSeries = flag3; } } else if ((this.DataSeries != null) && (this.DataSeries.DataReference is CalcConstantExpression)) { CalcConstantExpression expression2 = this.DataSeries.DataReference as CalcConstantExpression; T local3 = this.ConvertValue(0, expression2.Value); base.items.Clear(); base.items.Add(local3); bool flag4 = local3 is DateTime; if (flag4 != this.IsDateTimeSeries) { this.IsDateTimeSeries = flag4; } } else { base.items.Clear(); this.IsDateTimeSeries = false; } }
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); }
/// <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)); }