汇总模式
我们可以完全用绑定来生成一个汇总模式:
Dim
doc
As New PrintDoc
Dim rt As
New prt.RenderTable
Dim tb as
Table =
Tables("订单")
Dim ColNames As
String() = New
String(){"产品",
"客户","单价",
"数量",
"金额"}
rt.Style.GridLines.All
= New
prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All
= 1
For c
As
integer
= 0
To
ColNames.Length
-1
rt.Cells(0,c).Text
= ColNames(c)
rt.Cols(c).Width
= tb.Cols(ColNames(c)).PrintWidth
rt.Cells(1,
c).Text
= "[Fields!" & ColNames(c) &
".Value]"
Next
rt.Cells(2,0).Text
="小计"
rt.Cells(2,0).SpanCols
= 3
rt.Cells(2,3).Text
= "[Aggregates!数量小计.Value]"
rt.Cells(2,4).Text
= "[Aggregates!金额小计.Value]"
rt.Cells(3,0).Text
="总计"
rt.Cells(3,0).SpanCols
= 3
rt.Cells(3,3).Text
= "[Aggregates!数量总计.Value]"
rt.Cells(3,4).Text
= "[Aggregates!金额总计.Value]"
rt.Rows(0).Style.TextAlignVert
= prt.AlignVertEnum.Center
rt.RowGroups(0,1).Header
= prt.TableHeaderEnum.All
With rt.RowGroups(1,2)
.DataBinding.DataSource = BindTables("订单")
.DataBinding.Grouping.Expressions.Add("Fields!产品.Value")
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("数量小计",
"Fields!数量.Value", .DataBinding,
1,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("金额小计",
"Fields!金额.Value", .DataBinding,
1,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("数量总计",
"Fields!数量.Value", .DataBinding,
0,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("金额总计",
"Fields!金额.Value", .DataBinding,
0,
0))
End With
rt.RowGroups(1,1).DataBinding.DataSource
= BindTables("订单")
doc.Body.Children.Add(rt)
doc.Preview()
执行结果:
下面的代码根据产品和客户分组,对数量和金额进行统计,代码比较繁琐,得有点钻研精神,才可以看明白的:
Dim
doc
As New
PrintDoc
Dim rt
As New
prt.RenderTable
Dim tb
as
Table =
Tables("订单")
Dim ColNames
As
String() = New
String(){"产品",
"客户","单价",
"数量",
"金额"}
rt.Style.GridLines.All
= New
prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All
= 1
For
c As
integer
= 0
To
ColNames.Length
-1
rt.Cells(0,c).Text
= ColNames(c)
rt.Cols(c).Width
= tb.Cols(ColNames(c)).PrintWidth
rt.Cells(1, c).Text = "[Fields!"
& ColNames(c) & ".Value]"
Next
rt.Cells(2,0).Text
="[Fields!客户.Value]小计"
rt.Cells(2,0).SpanCols
= 3
rt.Cells(2,3).Text
=
"[Aggregates!数量小计2.Value]"
rt.Cells(2,4).Text
=
"[Aggregates!金额小计2.Value]"
rt.Cells(3,0).Text
="[Fields!产品.Value]小计"
rt.Cells(3,0).SpanCols
= 3
rt.Cells(3,3).Text
=
"[Aggregates!数量小计1.Value]"
rt.Cells(3,4).Text
=
"[Aggregates!金额小计1.Value]"
rt.Cells(4,0).Text
="总计"
rt.Cells(4,0).SpanCols
= 3
rt.Cells(4,3).Text
=
"[Aggregates!数量总计.Value]"
rt.Cells(4,4).Text
=
"[Aggregates!金额总计.Value]"
rt.Rows(0).Style.TextAlignVert
= prt.AlignVertEnum.Center
rt.RowGroups(0,1).Header
= prt.TableHeaderEnum.All
With rt.RowGroups(1,3)
.DataBinding.DataSource = BindTables("订单")
.DataBinding.Grouping.Expressions.Add("Fields!产品.Value")
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("数量小计1",
"Fields!数量.Value", .DataBinding,
1,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("金额小计1",
"Fields!金额.Value", .DataBinding,
1,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("数量总计",
"Fields!数量.Value", .DataBinding,
0,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("金额总计",
"Fields!金额.Value", .DataBinding,
0,
0))
End
With
With rt.RowGroups(1,2)
.DataBinding.DataSource = BindTables("订单")
.DataBinding.Grouping.Expressions.Add("Fields!客户.Value")
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("数量小计2",
"Fields!数量.Value", .DataBinding,
1,
0))
doc.DataSchema.Aggregates.Add(New prt.DataBinding.Aggregate("金额小计2",
"Fields!金额.Value", .DataBinding,
1,
0))
End
With
rt.RowGroups(1,1).DataBinding.DataSource
= BindTables("订单")
doc.Body.Children.Add(rt)
doc.Preview()