ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Data Binding > Data Aggregates

Data Aggregates

In the 2010 v1 release, new aggregates were added to Reports for WinForms. These aggregate types can be used in data-bound C1PrintDocuments without the need to declare them in the document's aggregates collection (Aggregates).

For instance, if "Balance" is a data field in a data-bound document, the following RenderText can be used to print the total balance for the dataset:

      Visual Basic

Dim rt As New RenderText("[Sum(""Fields!Balance.Value"")]")

      C#

RenderText rt = new RenderText("[Sum(\"Fields!Balance.Value\")]");

The following new properties and methods were added to the DataSet and C1DataBinding types to support this feature:

 

Class

Member

Description

C1DataBinding

Name property

Gets or sets the name of the current C1DataBinding. That name can be used in aggregate functions to indicate which data binding the aggregate refers to.

DataSet

Name property

Gets or sets the name of the current DataSet. That name can be used in aggregate functions to indicate which data set the aggregate refers to.

 

All aggregate functions have the follwing format:

AggFunc(expression, scope)

where:

      expression is a string defining an expression calculated for each row group or dataset row.

      scope is a string identifying the set of data for which the aggregate is calculated. If omitted, the aggregate is calculated for the current set of data (such as for the current group, dataset, and so on). If specified, should be the name of the target group or dataset.

For example, if a dataset has the following fields, ID, GroupID, SubGroupID, NAME, Q, and records are grouped by GroupID and SubGroupID, the following document can be created:

      Visual Basic

Dim doc As New C1PrintDocument()

Dim raGroupId As New RenderArea()

' ...set up raGroupId properties as desired...

raGroupID.DataBinding.DataSource = dataSet

raGroupID.DataBinding.Name = "GroupID"

raGroupID.DataBinding.Grouping.Expressions.Add("Fields!GroupID.Value")

 

Dim raSubGroupID As New RenderArea()

' ...set up raSubGroupID properties as desired...

raSubGroupID.DataBinding.DataSource = dataSet

raSubGroupID.DataBinding.Grouping.Expressions.Add("Fields!SubGroupID.Value")

raGroupID.Children.Add(raSubGroupID)

 

Dim raDetail As New RenderArea()

' ...set up raDetail properties as desired...

raDetail.DataBinding.DataSource = dataSet

raSubGroupID.Children.Add(raDetail)

 

' show value of Q field:

Dim rtQ As New RenderText()

rtQ.Text = "[Fields!Q.Value]"

raDetail.Children.Add(rtQ)

 

' show sum of Q field for nested group (SubGroupID):

Dim rtSumQ1 As New RenderText()

rtSumQ1.Text = "[Sum(""Fields!Q.Value"")]"

raDetail.Children.Add(rtSumQ1)

' show sum of Q field for GroupID:

Dim rtSumQ2 As New RenderText()

rtSumQ2.Text = "[Sum(\"Fields!Q.Value\", "\"GroupID\"")]"

raDetail.Children.Add(rtSumQ2)

' show TOTAL sum of Q field for the entire dataset:

Dim rtSumQ3 As New RenderText()

rtSumQ3.Text = "[Sum(\"Fields!Q.Value\", "\"DataSet\"")]"

raDetail.Children.Add(rtSumQ3)

doc.Body.Children.Add(raGroupId)

      C#

C1PrintDocument doc = new C1PrintDocument();

RenderArea raGroupId = new RenderArea();

// ...set up raGroupId properties as desired...

raGroupID.DataBinding.DataSource = dataSet;

raGroupID.DataBinding.Name = "GroupID";

raGroupID.DataBinding.Grouping.Expressions.Add("Fields!GroupID.Value");

 

RenderArea raSubGroupID = new RenderArea();

// ...set up raSubGroupID properties as desired...

raSubGroupID.DataBinding.DataSource = dataSet;

raSubGroupID.DataBinding.Grouping.Expressions.Add("Fields!SubGroupID.Value");

raGroupID.Children.Add(raSubGroupID);

 

RenderArea raDetail = new RenderArea();

// ...set up raDetail properties as desired...

raDetail.DataBinding.DataSource = dataSet;

raSubGroupID.Children.Add(raDetail);

 

// show value of Q field:

RenderText rtQ = new RenderText();

rtQ.Text = "[Fields!Q.Value]";

raDetail.Children.Add(rtQ);

// show sum of Q field for nested group (SubGroupID):

RenderText rtSumQ1 = new RenderText();

rtSumQ1.Text = "[Sum(\"Fields!Q.Value\")]";

raDetail.Children.Add(rtSumQ1);

// show sum of Q field for GroupID:

RenderText rtSumQ2 = new RenderText();

rtSumQ2.Text = "[Sum(\"Fields!Q.Value\", "\"GroupID\"")]";

raDetail.Children.Add(rtSumQ2);

// show TOTAL sum of Q field for the entire dataset:

RenderText rtSumQ3 = new RenderText();

rtSumQ3.Text = "[Sum(\"Fields!Q.Value\", "\"DataSet\"")]";

raDetail.Children.Add(rtSumQ3);

 

doc.Body.Children.Add(raGroupId);

When the above document is generated, each instance of the raDetail group will show four values as follows:

      the current value of "Q" field

      the sum of the "Q" field over the current SubGroupID

      the sum of the "Q" field over the current GroupID

      the sum of the "Q" field over the whole document


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.