多个统计

统计不同产品的订单数、订购数量:

Dim doc As New PrintDoc
Dim
rt As New prt.RenderText
Dim
ra As New prt.RenderArea
Dim
Agg1 As New prt.DataBinding.Aggregate("Sum")
Dim
Agg2 As New prt.DataBinding.Aggregate("Count")

ra.DataBinding.DataSource = BindTables(
"订单") '将容器绑定到订单表
ra.DataBinding.Grouping.Expressions.Add(
"Fields!产品.Value") '根据产品进行分组
ra.Style.Spacing.Bottom =
2
doc.body.Children.Add(ra)

rt.Text=
"[Fields!产品.Value]"
ra.Children.Add(rt)

rt = New prt.RenderText
rt.Text=
" 订单数: [Aggregates!Count.Value]"
ra.Children.Add(rt)

rt = New prt.RenderText
rt.Text=
" 订购数: [Aggregates!Sum.Value]"
ra.Children.Add(rt)

agg1.DataBinding = ra.DataBinding
'这个一定要设置为ra的DataBinding,因为agg1统计的分组来自于ra定义的分组
agg1.Running = 1
'分组统计
agg1.ExpressionText =
"Fields!数量.Value" '统计字段
doc.DataSchema.Aggregates.Add(agg1)
'定义好的统计必须添加到报表的DataSchema中

agg2.DataBinding = ra.DataBinding
'这个一定要设置为rt的DataBinding,因为agg1统计的分组来自于rt定义的分组
agg2.Running = 1
'分组统计
agg2
.ExpressionText = "Fields!产品.Value" '统计字段
agg2.Func = 2
'统计订单数
doc.DataSchema.Aggregates.Add(agg2)
'定义好的统计必须添加到报表的DataSchema中


doc.Preview()

执行结果:

 


本页地址:http://www.foxtable.com/webhelp/topics/1264.htm