/// <summary> /// Raises the <see cref="E:C1.WPF.FlexGrid.C1FlexGrid.CustomAggregate" /> event. /// </summary> /// <param name="e"> /// <see cref="T:C1.WPF.FlexGrid.CustomAggregateEventArgs" /> that contains the event data. /// </param> protected internal virtual void OnCustomAggregate(CustomAggregateEventArgs e) { if (CustomAggregate != null) { CustomAggregate(this, e); } }
internal static decimal GetValue(C1FlexGrid grid, Aggregate agg, CellRange rng) { if (agg == Aggregate.Custom) { CustomAggregateEventArgs customAggregateEventArg = new CustomAggregateEventArgs(grid.Cells, rng); grid.OnCustomAggregate(customAggregateEventArg); return customAggregateEventArg.Result; } decimal num = new decimal(0); decimal num1 = num; decimal num2 = num; decimal num3 = num; decimal num4 = num; decimal num5 = num; bool flag = false; switch (agg) { case Aggregate.Std: case Aggregate.Var: case Aggregate.StdPop: case Aggregate.VarPop: { flag = true; break; } } foreach (CellRange cell in rng.Cells) { if (!grid.IsRangeValid(cell)) { continue; } Row item = grid.Rows[cell.Row]; Column column = grid.Columns[cell.Column]; if (!grid.IncludeInAggregate(item, column)) { continue; } object dataRaw = item.GetDataRaw(column); if (Equals(dataRaw, string.Empty)) { dataRaw = null; } if (dataRaw is bool) { dataRaw = ((bool) dataRaw ? 1 : 0); } if (dataRaw is DateTime) { dataRaw = null; } if (dataRaw != null && grid.TryChangeType(ref dataRaw, typeof (decimal))) { decimal num6 = (decimal) dataRaw; if (num5 == new decimal(0)) { decimal num7 = num6; num1 = num7; num2 = num7; } if (num6 < num1) { num1 = num6; } if (num6 > num2) { num2 = num6; } num4 = num4 + num6; if (flag) { num3 = num3 + (num6*num6); } } num5 = num5++; } decimal num8 = (num5 == new decimal(0) ? new decimal(0) : num4/num5); switch (agg) { case Aggregate.Sum: { return num4; } case Aggregate.Count: { return num5; } case Aggregate.Average: { return num8; } case Aggregate.Maximum: { return num2; } case Aggregate.Minimum: { return num1; } case Aggregate.Range: { return num2 - num1; } case Aggregate.Std: { if (num5 <= new decimal(1)) { return new decimal(0); } return (decimal) Math.Sqrt((double) ((((num3/num5) - (num8*num8))*num5)/num5--)); } case Aggregate.Var: { if (num5 <= new decimal(1)) { return new decimal(0); } return (((num3/num5) - (num8*num8))*num5)/num5--; } case Aggregate.StdPop: { if (num5 <= new decimal(1)) { return new decimal(0); } return (decimal) Math.Sqrt((double) ((num3/num5) - (num8*num8))); } case Aggregate.VarPop: { if (num5 <= new decimal(1)) { return new decimal(0); } return (num3/num5) - (num8*num8); } } return new decimal(0); }