public static ISummary CreateSummaryMethod(SummaryDescriptor sd, Record record) { object obj = sd.GetValue(record); bool isNull = (obj == null || obj is DBNull); if (isNull) { return(new DistinctInt32CountSummary(new Int32[0])); } else { Int32 val = Convert.ToInt32(obj); return(new DistinctInt32CountSummary(new Int32[] { val })); } }
/// <summary> /// Assign this CreateSummaryDelegate handler method to SummaryDescriptor.CreateSummaryMethod /// </summary> /// <param name="sd"></param> /// <param name="record"></param> /// <returns></returns> public static ISummary CreateSummaryMethod(SummaryDescriptor sd, Record record) { object obj = sd.GetValue(record); bool isNull = (obj == null || obj is DBNull); if (isNull) { return(Empty); } else { double val = Convert.ToDouble(obj); return(new TotalSummary(val)); } }
public static ISummary CreateSummaryMethod(SummaryDescriptor sd, Record record) { object obj = sd.GetValue(record); bool isNull = (obj == null || obj is DBNull) || (obj is double) && double.IsNaN((double)obj); // could also be double.NaN... which is also treated as null if (isNull) { return(new StatisticsSummary(new double[0], 0)); // { double.NaN }, 1); } else { double val = Convert.ToDouble(obj); return(new StatisticsSummary(new double[] { val }, 1)); } }
/// <summary> /// A method that returns the filter values. /// </summary> /// <param name="column">Column in which filter is being applied.</param> /// <returns>Set of filter values.</returns> private object[] GetFilterValues(GridColumnDescriptor column) { var sd = new SummaryDescriptor( column.Name + "FilterBarChoices", column.MappingName, FilterBarChoicesSummary.CreateSummaryMethod) { IgnoreRecordFilterCriteria = true }; if (!_engine.Table.TableDescriptor.Summaries.Contains(sd.Name)) { _engine.Table.TableDescriptor.Summaries.Add(sd); } var summaries = _engine.Table.GetSummaries(); var summaryIndex = _engine.Table.TableDescriptor.Summaries.IndexOf(sd); var filtersummary = (FilterBarChoicesSummary)summaries[summaryIndex]; var values = filtersummary.Values; _engine.Table.TableDescriptor.Summaries.Remove(sd); _engine.Table.SummariesDirty = true; return(values); }
string GetAverageSummary(SummaryDescriptor summaryDescriptor, Group group) { Table table = group.ParentTable; TableDescriptor td = table.TableDescriptor; string summaryText = ""; bool use31Code = true; if (use31Code) { // Option 1: Strong typed access to DoubleAggregateSummary. DoubleAggregateSummary summary1 = (DoubleAggregateSummary)group.GetSummary(summaryDescriptor); summaryText = string.Format("{0:c}", summary1.Average); // or Option 2: Use reflection to get "Average" property of summary summaryText = string.Format("{0:c}", group.GetSummaryProperty(summaryDescriptor, "Average")); // or Option 3: Use reflection to get "Average" property of summary and format it summaryText = group.GetFormattedSummaryProperty(summaryDescriptor, "Average", "{0:c}"); } else { // This is the code you had to use in version 3.0 and earlier (still working but bit more complicate) if (summaryDescriptor != null) { int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(summaryDescriptor); // strong typed - you have to cast to DoubleAggregateSummary. DoubleAggregateSummary summary1 = (DoubleAggregateSummary)group.GetSummaries(table)[indexOfSd1]; summaryText = string.Format("{0:c}", summary1.Average); } } return(summaryText); }
public ChartOversizedDataBindModel(ChartControl chart, DataTable dataSource, string xName, string yName, bool recaliberateOnZoom) : base(dataSource.DefaultView, String.Empty, null) { this.dataSource = dataSource; engine.SetSourceList((IEnumerable)dataSource.DefaultView); this.yName = yName; this.xName = xName; // Create a summary in the engine so that the averages, min and max are calculated for the groups (and the table). SummaryDescriptor sd = new SummaryDescriptor(); sd.Name = "YAverage"; sd.MappingName = yName; sd.SummaryType = SummaryType.DoubleAggregate; engine.TableDescriptor.Summaries.Add(sd); this.chart = chart; this.chart.Resize += new EventHandler(chart_RequiresRecalculation); this.UpdateCategorizer(); }
public Class1() { InitializeComponent(); bool msdeAvailable = false; if (msdeAvailable) { this.sqlDataAdapter1.Fill(this.dataSet11); //this.dataSet11.WriteXml("CustOrders.xml", XmlWriteMode.WriteSchema); } else { // Read from a xml file instead. ReadXml(this.dataSet11, @"Common\Data\CustOrders.xml"); } this.engine1 = new Engine(); // Setup a integrated summary sd0 = new SummaryDescriptor(); sd0.MappingName = "Quantity"; sd0.SummaryType = SummaryType.DoubleAggregate; this.engine1.TableDescriptor.Summaries.Add(sd0); // Setup custom summaries sd1 = new SummaryDescriptor(); sd1.Name = "QuantityTotal"; sd1.MappingName = "Quantity"; sd1.SummaryType = SummaryType.Custom; sd1.CreateSummaryMethod = new CreateSummaryDelegate(TotalSummary.CreateSummaryMethod); this.engine1.TableDescriptor.Summaries.Add(sd1); sd2 = new SummaryDescriptor(); sd2.Name = "QuantityDistinctCount"; sd2.MappingName = "Quantity"; sd2.SummaryType = SummaryType.Custom; sd2.CreateSummaryMethod = new CreateSummaryDelegate(DistinctInt32CountSummary.CreateSummaryMethod); this.engine1.TableDescriptor.Summaries.Add(sd2); sd3 = new SummaryDescriptor(); sd3.Name = "QuantityMedian"; sd3.MappingName = "Quantity"; sd3.SummaryType = SummaryType.Custom; sd3.CreateSummaryMethod = new CreateSummaryDelegate(StatisticsSummary.CreateSummaryMethod); this.engine1.TableDescriptor.Summaries.Add(sd3); // Setup running totals by displaying the value of a custom counter in an unbound field FieldDescriptor unboundField = new FieldDescriptor("QuantityCount", "", false, ""); unboundField.ReadOnly = false; this.engine1.TableDescriptor.UnboundFields.Add(unboundField); this.engine1.TableDescriptor.QueryValue += new FieldValueEventHandler(unboundField_QueryValue); // Routine that queries for the value this.engine1.TableDescriptor.SaveValue += new FieldValueEventHandler(unboundField_SaveValue); FieldDescriptor unboundField2 = new FieldDescriptor("QuantityCount2", "", false, ""); this.engine1.TableDescriptor.UnboundFields.Add(unboundField2); // Setup custom counter this.engine1.Table.QueryCustomCount += new CustomCountEventHandler(Table_QueryCustomCount); this.engine1.CurrentRecordContextChange += new CurrentRecordContextChangeEventHandler(engine1_CurrentRecordContextChange); this.engine1.Table.QueryVisibleCustomCount += new CustomCountEventHandler(Table_QueryVisibleCustomCount); // Assign data source this.engine1.SetSourceList(this.dataSet11.Order_Details.DefaultView); quantityFieldDescriptor = this.engine1.TableDescriptor.Fields["Quantity"]; // Add a filter so that we can check out difference between VisibleCustomCount (only records that meet criteria are counted) // and CustomCount (all records are counted) this.engine1.TableDescriptor.RecordFilters.Add("[UnitPrice] > 20"); }