This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
Form1.vb
102 lines (78 loc) · 3.42 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Namespace RepTreeListHierarchicalDataRelationships
Partial Public Class Form1
Inherits Form
Private report As XtraReport
Private dataSet As DataSet
Private indent As Integer = 0
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
Dim employes As List(Of Employee) = Employee.GenerateSeveralEmployes()
dataSet = DataSetHelper.HierarchicalListToDataSet(employes, "Id", "ParentId")
DataSetHelper2.FillTreeView(treeView1, dataSet)
treeView1.CollapseAll()
button2.Enabled = True
End Sub
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
GenerateReport()
CType(New ReportPrintTool(report), ReportPrintTool).ShowPreviewDialog()
End Sub
Private Sub GenerateReport()
Dim headerBand As New ReportHeaderBand()
Dim detailBand As New DetailBand()
Dim title As New XRLabel()
Dim dataPath As String = dataSet.Tables(0).TableName
report = New XtraReport()
report.DataMember = dataPath
headerBand.Height = 50
detailBand.Height = 25
title.Size = New Size(report.PageWidth - report.Margins.Left - report.Margins.Right - 1, 50)
title.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter
title.Font = New Font(title.Font.FontFamily, 20)
title.Text = "Hierarchical Data Report"
headerBand.Controls.Add(title)
report.Bands.Add(headerBand)
report.Bands.Add(detailBand)
AddDataFieldsToBand(dataSet.Tables(0), detailBand, dataPath, False)
Dim nextReport As XtraReportBase = report
For i As Integer = 0 To dataSet.Relations.Count - 1
Dim dataRelation As DataRelation = dataSet.Relations(i)
dataPath &= "." & dataRelation.RelationName
nextReport = CreateReportForTable(nextReport, dataRelation.ChildTable, dataPath)
Next i
report.DataSource = dataSet
End Sub
Private Sub AddDataFieldsToBand(ByVal dataTable As DataTable, ByVal band As DetailBand, ByVal dataPath As String, ByVal addKeyFields As Boolean)
Dim table As XRTable = XRTable.CreateTable(New Rectangle(indent, 0, report.PageWidth - report.Margins.Left - report.Margins.Right - indent - 1, 25), 1, dataTable.Columns.Count - (If(addKeyFields, 0, 2)))
Dim cellIndex As Integer = 0
For i As Integer = 0 To dataTable.Columns.Count - 1
Dim dataColumn As DataColumn = dataTable.Columns(i)
If addKeyFields OrElse ((Not addKeyFields) AndAlso (Not dataColumn.ColumnName.ToUpper().Contains("ID"))) Then
table.Rows(0).Cells(cellIndex).DataBindings.Add("Text", Nothing, dataPath & "." & dataColumn.ColumnName)
cellIndex += 1
End If
Next i
table.Padding = New DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0)
band.Controls.Add(table)
indent += 50
End Sub
Private Function CreateReportForTable(ByVal parentReport As XtraReportBase, ByVal dataTable As DataTable, ByVal dataPath As String) As XtraReportBase
Dim detailReport As New DetailReportBand()
Dim detailBand As New DetailBand()
detailBand.Height = 25
detailReport.Bands.Add(detailBand)
parentReport.Bands.Add(detailReport)
AddDataFieldsToBand(dataTable, detailBand, dataPath, False)
detailReport.DataMember = dataPath
Return detailReport
End Function
End Class
End Namespace