Report Scripting Patterns
This document will keep track of some of the patterns and solutions we have developed for scripting report calculations.
|
|
"Summary of Summaries" - Using an Array List to Sum One Instance of a Value Only Once. | |
Some fields in the report data sets do not represent a period value- they represent the grand total to date, or for the entire period. For one situation, we needed to create a report that got the grand total for the flock, using the expense summary dataset. The FC_LbsFeedConsumed_LTD field repeated the summary total of pounds consumed for each record of the flock, at the house level. Creating a simplle summary field would mean the total would add up and that would be incorrect. What we needed was a way to get the total only once for each house, and then summarize it at the group-level.
That's where this pattern comes into play. We created a total variable and an array list. We loop through the expenses for each flock. If the house's total has been accounted for, we skip it. If it has not, we sum it to the total and add the house id to the list of houses. For the duration of the loop, for the current flock, that house will be skipped.
| Dim total as Decimal
Dim housecodes as ArrayList = new ArrayList()
Private Sub label34_SummaryRowChanged(ByVal sender As Object,ByVal e As System.EventArgs)
Dim id as integer= GetCurrentColumnValue("General_HouseID")
if housecodes.Contains(id) then return
Dim amount as decimal =
GetCurrentColumnValue("FC_LbsFeedConsumed_LTD")
total += amount
housecodes.add(id)
End Sub
Private Sub label34_SummaryReset(ByVal sender As Object, ByVal e As System.EventArgs)
total = 0
housecodes = new ArrayList()
End Sub
Private Sub label34_SummaryGetResult(ByVal sender As Object,
ByVal e As DevExpress.XtraReports.UI.SummaryGetResultEventArgs)
e.result = total
e.handled = true
End Sub |
|
|
|
|
|
|
|
|
|
|
|
|