private void Function_Click(object sender, EventArgs e) { MatrixAggregateFunction function = (MatrixAggregateFunction)(sender as ButtonItem).Tag; (Descriptor as MatrixCellDescriptor).Function = function; Change(); }
/// <summary> /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class /// with specified expression, aggregate function, and a percent. /// </summary> /// <param name="expression">The descriptor's expression.</param> /// <param name="function">The aggregate function.</param> /// <param name="percent">The percent setting.</param> public MatrixCellDescriptor(string expression, MatrixAggregateFunction function, MatrixPercent percent) { Expression = expression; this.function = function; this.percent = percent; }
/// <summary> /// Initializes a new instance of the <see cref="MatrixCellDescriptor"/> class /// with specified expression and aggregate function. /// </summary> /// <param name="expression">The descriptor's expression.</param> /// <param name="function">The aggregate function.</param> public MatrixCellDescriptor(string expression, MatrixAggregateFunction function) : this(expression, function, MatrixPercent.None) { }
public MatrixCellMenu(MatrixObject matrix, MatrixElement element, MatrixDescriptor descriptor) : base(matrix, element, descriptor) { MyRes res = new MyRes("Forms,TotalEditor"); miFunction = CreateMenuItem(Res.GetImage(132), Res.Get("ComponentMenu,MatrixCell,Function"), null); miFunctionNone = CreateMenuItem(null, Res.Get("Misc,None"), new EventHandler(Function_Click)); miFunctionNone.AutoCheckOnClick = true; miFunctionNone.Tag = MatrixAggregateFunction.None; miFunctionSum = CreateMenuItem(null, res.Get("Sum"), new EventHandler(Function_Click)); miFunctionSum.AutoCheckOnClick = true; miFunctionSum.Tag = MatrixAggregateFunction.Sum; miFunctionMin = CreateMenuItem(null, res.Get("Min"), new EventHandler(Function_Click)); miFunctionMin.AutoCheckOnClick = true; miFunctionMin.Tag = MatrixAggregateFunction.Min; miFunctionMax = CreateMenuItem(null, res.Get("Max"), new EventHandler(Function_Click)); miFunctionMax.AutoCheckOnClick = true; miFunctionMax.Tag = MatrixAggregateFunction.Max; miFunctionAvg = CreateMenuItem(null, res.Get("Avg"), new EventHandler(Function_Click)); miFunctionAvg.AutoCheckOnClick = true; miFunctionAvg.Tag = MatrixAggregateFunction.Avg; miFunctionCount = CreateMenuItem(null, res.Get("Count"), new EventHandler(Function_Click)); miFunctionCount.AutoCheckOnClick = true; miFunctionCount.Tag = MatrixAggregateFunction.Count; miFunctionCustom = CreateMenuItem(null, res.Get("Custom"), new EventHandler(Function_Click)); miFunctionCustom.AutoCheckOnClick = true; miFunctionCustom.Tag = MatrixAggregateFunction.Custom; miFunction.SubItems.AddRange(new BaseItem[] { miFunctionNone, miFunctionSum, miFunctionMin, miFunctionMax, miFunctionAvg, miFunctionCount, miFunctionCustom }); res = new MyRes("ComponentMenu,MatrixCell"); miPercent = CreateMenuItem(null, res.Get("Percent"), null); miPercentNone = CreateMenuItem(null, Res.Get("Misc,None"), new EventHandler(Percent_Click)); miPercentNone.AutoCheckOnClick = true; miPercentNone.Tag = MatrixPercent.None; miPercentColumnTotal = CreateMenuItem(null, res.Get("PercentColumnTotal"), new EventHandler(Percent_Click)); miPercentColumnTotal.AutoCheckOnClick = true; miPercentColumnTotal.Tag = MatrixPercent.ColumnTotal; miPercentRowTotal = CreateMenuItem(null, res.Get("PercentRowTotal"), new EventHandler(Percent_Click)); miPercentRowTotal.AutoCheckOnClick = true; miPercentRowTotal.Tag = MatrixPercent.RowTotal; miPercentGrandTotal = CreateMenuItem(null, res.Get("PercentGrandTotal"), new EventHandler(Percent_Click)); miPercentGrandTotal.AutoCheckOnClick = true; miPercentGrandTotal.Tag = MatrixPercent.GrandTotal; miPercent.SubItems.AddRange(new BaseItem[] { miPercentNone, miPercentColumnTotal, miPercentRowTotal, miPercentGrandTotal }); int insertIndex = Items.IndexOf(miDelete); Items.Insert(insertIndex, miFunction); Items.Insert(insertIndex + 1, miPercent); MatrixAggregateFunction function = (Descriptor as MatrixCellDescriptor).Function; foreach (BaseItem item in miFunction.SubItems) { if ((MatrixAggregateFunction)item.Tag == function) { (item as ButtonItem).Checked = true; break; } } MatrixPercent percent = (Descriptor as MatrixCellDescriptor).Percent; foreach (BaseItem item in miPercent.SubItems) { if ((MatrixPercent)item.Tag == percent) { (item as ButtonItem).Checked = true; break; } } }
private object GetAggregatedValue(ArrayList list, int cellIndex) { if (list == null || list.Count == 0) { return(null); } MatrixAggregateFunction function = Matrix.Data.Cells[cellIndex].Function; // custom function - just calculate the expression if (function == MatrixAggregateFunction.Custom) { return(Report.Calc(Matrix.Data.Cells[cellIndex].Expression)); } // Count function - just return the number of values if (function == MatrixAggregateFunction.Count) { return(list.Count); } // aggregated value Variant aggrValue = new Variant(); for (int i = 0; i < list.Count; i++) { object value = list[i]; if (i == 0) { // assign the first value to aggrValue aggrValue = new Variant(value); } else { // handle other values switch (function) { case MatrixAggregateFunction.Sum: case MatrixAggregateFunction.Avg: aggrValue += new Variant(value); break; case MatrixAggregateFunction.Min: if (new Variant(value) < aggrValue) { aggrValue = new Variant(value); } break; case MatrixAggregateFunction.Max: if (new Variant(value) > aggrValue) { aggrValue = new Variant(value); } break; } } } // finish Avg calculation if (function == MatrixAggregateFunction.Avg) { aggrValue = aggrValue / list.Count; } return(aggrValue.Value); }