private double ConvertValue(object value) { if (value == null) { return(0.0); } if (value is double) { return((double)value); } if (value is float) { return((double)(float)value); } if (value is decimal) { return((double)(decimal)value); } if (value is int) { return((double)(int)value); } if (value is uint) { return((double)(uint)value); } if (value is long) { return((double)(long)value); } if (value is ulong) { return((double)(ulong)value); } if (value is byte) { return((double)(int)(byte)value); } if (value is sbyte) { return((double)(sbyte)value); } if (value is bool) { if (!(bool)value) { return(0.0); } return(1.0); } string text = ""; text = value.ToString(); return(CommonElements.ParseDouble(text)); }
public DataPoint(double xValue, string yValues) : base(null, true) { string[] array = yValues.Split(','); this.yValue = new double[array.Length]; for (int i = 0; i < array.Length; i++) { this.yValue[i] = CommonElements.ParseDouble(array[i]); } this.xValue = xValue; }
public void SetValueY(params object[] yValue) { if (yValue.Length != 0 && (base.series == null || yValue.Length <= base.series.YValuesPerPoint)) { for (int i = 0; i < yValue.Length; i++) { if (yValue[i] == null || yValue[i] is DBNull) { yValue[i] = 0.0; if (i == 0) { this.Empty = true; } } } Type type = yValue[0].GetType(); if (base.series != null) { base.series.CheckSupportedTypes(type); } if (this.yValue.Length < yValue.Length) { this.yValue = new double[yValue.Length]; } if (type == typeof(string)) { try { for (int j = 0; j < yValue.Length; j++) { this.yValue[j] = CommonElements.ParseDouble((string)yValue[j]); } } catch { if (base.series != null && base.series.chart == null && base.series.serviceContainer != null) { base.series.chart = (Chart)base.series.serviceContainer.GetService(typeof(Chart)); } if (base.series != null && base.series.chart != null && base.series.chart.chartPicture.SuppressExceptions) { this.Empty = true; for (int k = 0; k < yValue.Length; k++) { yValue[k] = 0.0; } goto end_IL_00ee; } throw new ArgumentException(SR.ExceptionDataPointYValueStringFormat); end_IL_00ee :; } } else if (type == typeof(DateTime)) { for (int l = 0; l < yValue.Length; l++) { if (yValue[l] == null || (yValue[l] is double && (double)yValue[l] == 0.0)) { this.yValue[l] = DateTime.Now.ToOADate(); } else { this.yValue[l] = ((DateTime)yValue[l]).ToOADate(); } } } else { for (int m = 0; m < yValue.Length; m++) { this.yValue[m] = this.ConvertValue(yValue[m]); } } if (base.series != null) { for (int n = 0; n < yValue.Length; n++) { if (yValue[n] == null || (yValue[n] is double && (double)yValue[n] == 0.0)) { if (base.series.YValueType == ChartValueTypes.Date) { this.yValue[n] = Math.Floor(this.yValue[n]); } else if (base.series.YValueType == ChartValueTypes.Time) { this.yValue[n] = this.xValue - Math.Floor(this.yValue[n]); } } else if (base.series.YValueType == ChartValueTypes.Date) { DateTime dateTime = (!(yValue[n] is DateTime)) ? ((!(yValue[n] is double)) ? Convert.ToDateTime(yValue[n], CultureInfo.InvariantCulture) : DateTime.FromOADate((double)yValue[n])) : ((DateTime)yValue[n]); DateTime dateTime2 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0); this.yValue[n] = dateTime2.ToOADate(); } else if (base.series.YValueType == ChartValueTypes.Time) { DateTime dateTime3; if (yValue[n] is DateTime) { dateTime3 = (DateTime)yValue[n]; } dateTime3 = ((!(yValue[n] is double)) ? Convert.ToDateTime(yValue[n], CultureInfo.InvariantCulture) : DateTime.FromOADate((double)yValue[n])); DateTime dateTime4 = new DateTime(1899, 12, 30, dateTime3.Hour, dateTime3.Minute, dateTime3.Second, dateTime3.Millisecond); this.yValue[n] = dateTime4.ToOADate(); } } } return; } throw new ArgumentOutOfRangeException("yValue", SR.ExceptionDataPointYValuesSettingCountMismatch(base.series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture))); }