/
Form1.vb
112 lines (99 loc) · 4.92 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
103
104
105
106
107
108
109
110
111
112
#Region "usings"
Imports System.Net
Imports DevExpress.DataAccess.Json
Imports DevExpress.XtraReports.UI
#End Region
Namespace Create_a_Report_Bound_to_JsonDataSource
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'Enables security protocol versions to access the JSON web data source.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or
SecurityProtocolType.Tls12 Or
SecurityProtocolType.Ssl3
Dim report As XtraReport = CreateReport()
Dim designTool As New ReportDesignTool(report)
designTool.ShowRibbonDesignerDialog()
Application.Exit()
End Sub
#Region "CreateReport_start"
Private Function CreateReport() As XtraReport
Dim report As New XtraReport()
Dim DetailBand As New DetailBand()
DetailBand.HeightF = 50
Dim XRLabel As New XRLabel()
XRLabel.WidthF = 300
XRLabel.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[CompanyName]"))
DetailBand.Controls.Add(XRLabel)
report.Bands.Add(DetailBand)
report.DataSource = CreateDataSourceFromWeb()
'report.DataSource = CreateDataSourceFromFile();
'report.DataSource = CreateDataSourceFromText();
report.DataMember = "Customers"
Return report
End Function
#End Region
#Region "CreateDataSourceFromWeb_start"
Public Shared Function CreateDataSourceFromWeb() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify the endpoint.
jsonDataSource.JsonSource = New UriJsonSource(
New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"))
#End Region
#Region "CreateDataSourceFromWeb_schema"
Dim root = New JsonSchemaNode()
root.NodeType = JsonNodeType.Object
Dim customers = New JsonSchemaNode() With {.NodeType = JsonNodeType.Array, .Name = "Customers", .Selected = True}
customers.AddChildren({
New JsonSchemaNode(New JsonNode("CustomerID", True, JsonNodeType.Property,
GetType(String))) With {.DisplayName = "Customer ID"},
New JsonSchemaNode() With {.Name = "CompanyName", .Selected = True,
.NodeType = JsonNodeType.Property, .Type = GetType(String)},
New JsonSchemaNode(New JsonNode("ContactTitle", True, JsonNodeType.Property,
GetType(String))),
New JsonSchemaNode(New JsonNode("Address", False, JsonNodeType.Property,
GetType(String)))
})
root.AddChildren(customers)
jsonDataSource.Schema = root
#End Region
#Region "CreateDataSourceFromWeb_end"
' The schema is built, you do not have to call the Fill method to populate the Field List.
' The Designer calls the Fill method automatically when a document is generated for preview.
'jsonDataSource.Fill()
Return jsonDataSource
End Function
#End Region
#Region "CreateDataSourceFromFile"
Public Shared Function CreateDataSourceFromFile() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify the JSON file name.
Dim fileUri As New Uri("customers.json", UriKind.RelativeOrAbsolute)
jsonDataSource.JsonSource = New UriJsonSource(fileUri)
' Populate the data source with data.
jsonDataSource.Fill()
Return jsonDataSource
End Function
#End Region
#Region "CreateDataSourceFromText"
Public Shared Function CreateDataSourceFromText() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify a string with JSON data.
Dim json As String = "{""Customers"":[{""Id"":""ALFKI"",""CompanyName"":""Alfreds Futterkiste""," +
"""ContactName"":""Maria Anders"",""ContactTitle"":""Sales Representative""," +
"""Address"":""Obere Str. 57"",""City"":""Berlin"",""PostalCode"":""12209""," +
"""Country"":""Germany"",""Phone"":""030-0074321""," +
"""Fax"":""030-0076545""}],""ResponseStatus"":{}}"
' Specify the object that retrieves JSON data.
jsonDataSource.JsonSource = New CustomJsonSource(json)
' Populate the data source with data.
jsonDataSource.Fill()
Return jsonDataSource
End Function
#End Region
End Class
End Namespace