--
If Tables("Voucher.VoucherDetails").Current Is Nothing Then
Return
End If
Dim doc As New PrintDoc \'定義一個報表
\'設置Header
Dim rtHeader = New prt.RenderText \'設置文本對象的內容
rtHeader.Text = "第[PageNo]頁, 共[PageCount]頁" \'設置文本內容
rtHeader.Style.TextAlignHorz = prt.AlignHorzEnum.Right \'靠右對齊
rtHeader.Style.Borders.Bottom = New prt.LineDef(0.3, Color.Gray) \'設置底邊框
rtHeader.Style.Padding.Bottom = 1 \'底端內容縮進1毫米
rtHeader.Style.FontSize = 8 \'字體大小為8磅
Doc.PageHeader = rtHeader \'作為頁眉使用
\'設置表格
Dim rt As New prt.RenderTable() \'定義一個表格對象
doc.Body.Children.Add(rt) \'將表格對象加入到報表中
rt.Style.GridLines.All = New prt.Linedef(0.5, Color.Black) \'設置網格線
rt.CellStyle.Spacing.All = 1 \'內容距離網格線1毫米
\'設置表格主標題
rt.Cells(0,0).text = "傳票"
rt.Cells(0,0).SpanCols = 8 \'合併第一行全部單元格,用於顯示主標題
rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'主標題居中
rt.Cells(0,0).Style.Font = New Font("宋體", 18, FontStyle.Bold) \'設置主標題字體
rt.Rows(0).Style.Borders.All = New prt.LineDef(0, Color.White) \'去掉第一行的網格線
\'設置表格副標題
rt.Cells(1,0).SpanCols = 6 \'合併第二行全部單元格,用於顯示副標題
rt.Cells(1,6).SpanCols = 2
rt.Cells(1,0).text = "傳票號碼 : " & e.Form.Controls("VoucherNo").Value \'副標題
rt.Cells(1,6).text = "傳票日期 : " & e.Form.Controls("VoucherDate").Value \'副標題
rt.Cells(1,6).Style.Borders.Left = New prt.LineDef(0, Color.White) \'去掉第二行的網格線
rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Left \'副標題內容居右
rt.Cells(1,6).Style.TextAlignHorz = prt.AlignHorzEnum.Right \'副標題內容居右
rt.Rows(1).Style.Borders.All = New prt.LineDef(0, Color.White) \'去掉第二行的網格線
rt.Rows(1).Style.Borders.Bottom = New prt.Linedef \'恢復第二行底端的網格線
rt.Rows(1).Height = 8 \'設置第二行的高度,拉和表格主體的距離.
rt.RowGroups(0,3).Header = prt.TableHeaderEnum.All \'前三行作為表頭
\'設置表格內容
Dim ColNames As String() = New String(){"ItemName", "Particular", "CenterName", "CaseName", "CurrencyName", "Adjustment", "DebitInitial", "CreditInitial"}
Dim ColCaptions As String() = New String(){"科目名稱", "摘要說明", "部門", "專案", "幣別", "沖帳", "原幣借方金額", "原幣貸方金額"}
For c As Integer = 0 To ColNames.Length -1
rt.Cells(2, c).Text = ColCaptions(c)
If c = 6 OrElse c = 7 Then
rt.Cells(3, c).Text = "[Format(Fields!" & ColNames(c) & ".Value, ""#,##0.00"")]" \'設置綁定表達式
rt.Cells(3, c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
Else
rt.Cells(3, c).Text = "[Fields!" & ColNames(c) & ".Value]" \'設置綁定表達式
End If
Next
rt.RowGroups(3,1).DataBinding.DataSource = BindTables("Voucher.VoucherDetails") \'綁定到表
\'設置表格樣式
rt.RowGroups(2,1).Style.FontSize = 9
rt.RowGroups(2,1).Style.BackColor = Color.LightGray
rt.RowGroups(2,1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Cols(0).Width = 20
rt.Cols(1).Width = 20
rt.Cols(2).Width = 20
rt.Cols(3).Width = 20
rt.Cols(4).Width = 12
rt.Cols(5).Width = 10
rt.Cols(6).Width = 25
rt.Cols(7).Width = 25
\'設置統計欄位
Dim sumDebitInitial As String
Dim sumCreditInitial As String
If Tables("Voucher.VoucherDetails").Rows.Count > 0 Then
Tables("Voucher.VoucherDetails").Cols("DebitInitial").Visible = True
Tables("Voucher.VoucherDetails").Cols("CreditInitial").Visible = True
Dim c As Integer
Dim r As Integer = Tables("Voucher.VoucherDetails").Rows.Count - 1
c = Tables("Voucher.VoucherDetails").Cols("DebitInitial").Index
sumDebitInitial = Format(Tables("Voucher.VoucherDetails").Aggregate(AggregateEnum.Sum, 0, c, r, c), "#,##0.00")
c = Tables("Voucher.VoucherDetails").Cols("CreditInitial").Index
sumCreditInitial = Format(Tables("Voucher.VoucherDetails").Aggregate(AggregateEnum.Sum, 0, c, r, c), "#,##0.00")
End If
Dim rc As Integer = rt.Rows.Count
rt.Cells(rc, 0).Text = "總計 : "
rt.RowGroups(rc, 1).Style.TextAlignHorz = prt.AlignHorzEnum.Right
rt.Cells(rc, 0).SpanCols = 6
rt.Cells(rc, 6).Text = sumDebitInitial
rt.Cells(rc, 7).Text = sumCreditInitial
rt.Cells(rc, 6).Style.Borders.Left = New prt.LineDef(0, Color.White)
rt.Cells(rc, 6).Style.Borders.Right = New prt.LineDef(0, Color.White)
rt.Rows(rc).Style.FontBold = True
rt.Rows(rc).Style.Borders.Left = New prt.LineDef(0, Color.White)
rt.Rows(rc).Style.Borders.Right = New prt.LineDef(0, Color.White)
rt.Rows(rc).Style.Borders.Bottom = New prt.LineDef(0, Color.White)
\'設置底端文本
Dim rtFooter As New prt.RenderText
rtFooter.Style.FontSize = 11
rtFooter.Style.Borders.Top = New prt.LineDef(1, Color.Gray)
rtFooter.Style.Padding.Top = 2
rtFooter.Text = "董事會代表 : " & " " & "執行長 : " & vbcrlf & vbcrlf & "主管 : " & " " & "覆核 : " & " " & _
"會計 : " & " " & "出納 : " & " " & "製票 : " & User.Name & " 簽收 : "
Doc.PageFooter = rtFooter
\'紙張設定
Doc.PageSetting.PaperKind = 11 \'A5紙張
Doc.PageSetting.Landscape = True
Doc.PageSetting.LeftMargin = 5
Doc.PageSetting.RightMargin = 5
Doc.PageSetting.TopMargin = 10
Doc.PageSetting.BottomMargin = 10
Doc.Preview() \'預覽報表
Tables("Voucher.VoucherDetails").Cols("DebitInitial").Visible = False
Tables("Voucher.VoucherDetails").Cols("CreditInitial").Visible = False