分组和明细

统计不同产品的销售额,并列出每一个订单:

Dim doc As New PrintDoc
Dim
rt As New prt.RenderText
Dim
ra As New prt.RenderArea
Dim
Agg As New prt.DataBinding.Aggregate("GroupSum")

ra.Style.Spacing.Bottom =
4
ra.DataBinding.DataSource = BindTables(
"订单") '将容器绑定到订单表
ra.DataBinding.Grouping.Expressions.Add(
"Fields!产品.Value") '增加产品分组

agg.DataBinding = ra.DataBinding
'Agg的DataBinding属性,应该设为打印对象的DataBinding
agg.Running = 1
'分组统计
agg.ExpressionText =
"Fields!数量.Value" '统计字段
doc.DataSchema.Aggregates.Add(agg)
'定义好的统计必须添加到报表的DataSchema中

rt.Text=
"产品:[Fields!产品.Value]"
rt.Style.FontBold =
True
rt.Style.Spacing.Bottom =
1
ra.Children.Add(rt)


'这一个RenderText需要单独设置DataBinding,这样才会针对每一个数据行打印副本

rt = New prt.RenderText
rt.Text =
"日期:[Format(Fields!日期.Value,""yyyy-MM-dd"")] 客户:[Fields!客户.Value] 数量:[Fields!数量.Value]"
rt.DataBinding.DataSource = ra.DataBinding.DataSource '不能漏掉这一行
ra.Children.Add(rt)

rt = New prt.RenderText
rt.Text=
"合计:[Aggregates!GroupSum.Value]"
rt.Style.FontBold =
True
rt.Style.Spacing.Top =
1
ra.Children.Add(rt)

doc.body.Children.Add(ra)
doc.Preview()

执行结果:

 


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