关联表和报表

在示例文件“专业报表.Table”中,类别表和产品表通过类别ID建立了关联,每一个类别下有多个产品。
现在希望按类别打印所有产品,代码如下:

Dim doc As New Printdoc
Dim
rx As prt.RenderText
Dim
rt As prt.RenderTable

rx = New prt.RenderText
rx.Style.FontSize =
14
rx.Style.FontBold =
True
rx.Style.Spacing.Bottom =
5
rx.Text =
"类别: " & Tables("类别").Current("类别名称")
doc.Body.Children.Add(rx)

rt = New prt.RenderTable
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.Borders.Bottom = New prt.LineDef(
0.3,Color.LightGray)
rt.CellStyle.Spacing.All =
1
rt.Cols.Count =
4
rt.Cells(
0,0).Text = "产品名称"
rt.Cells(
0,1).Text = "单价"
rt.Cells(
0,2).Text = "库存量"
rt.Cells(
0,3).Text = "订购量"
rt.Cells(
0,4).Text = "再订购量"
rt.Cells(
0,5).Text = "中止"
rt.rows(
0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray)
rt.rows(
0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray)
With
Tables("类别.产品")
    For
r As integer = 0 To .Rows.Count - 1 '遍历关联表每一行
        rt.Cells(r+
1,0).Text = .rows(r)("产品名称")
        rt.Cells(r+
1,1).Text = .rows(r)("单价")
        rt.Cells(r+
1,2).Text = .rows(r)("库存量")
        rt.Cells(r+
1,3).Text = .rows(r)("订购量")
        rt.Cells(r+
1,4).Text = .rows(r)("再订购量")
        If
.rows(r)("中止") = True Then
            Dim
rm As New prt.RenderImage
            rm.Image = getImage(
"Check.Ico")
            rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center
            rm.Style.ImageAlign.StretchHorz =
False
            rm.Style.ImageAlign.StretchVert =
False
            rt.Cells(r+
1,5).RenderObject = rm
        End
If
    Next
End
With
doc.Body.Children.Add(rt)

rx = New prt.RenderText
rx.Style.FontBold =
True
rx.Style.Spacing.Top =
3
rx.Text =
"产品数目: " & Tables("类别.产品").Rows.Count
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
doc.Body.Children.Add(rx)

doc.Preview

下图是执行结果:

请留意上面的代码中,我们是如何打印逻辑列的。


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