-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherReport.vb
95 lines (85 loc) · 2.49 KB
/
WeatherReport.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
Option Infer On
Imports System.ComponentModel
Namespace SpreadsheetApiDataBinding
Public Class WeatherReport
<DisplayName("Date")>
Public Property [Date]() As Date
<DisplayName("Weather Condition")>
Public Property Weather() As Weather
<DisplayName("Max and Min Temperature")>
Public Property HourlyReport() As List(Of HourlyReport)
End Class
Public Class HourlyReport
Public Property Hour() As Integer
Public Property Temperature() As Integer
End Class
Public Enum Weather
Sunny
Cloudy
Windy
Gloomy
Foggy
Misty
Rainy
Undefined
End Enum
Public Module MyWeatherReportSource
Private rand As Random = New System.Random()
'INSTANT VB NOTE: The field data was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private data_Renamed As List(Of WeatherReport)
Private dataBindingList As BindingList(Of WeatherReport)
Public ReadOnly Property Data() As List(Of WeatherReport)
Get
If data_Renamed Is Nothing Then
data_Renamed = GetReport()
End If
Return data_Renamed
End Get
End Property
Public ReadOnly Property DataAsBindingList() As BindingList(Of WeatherReport)
Get
If dataBindingList Is Nothing Then
dataBindingList = New BindingList(Of WeatherReport)(Data)
End If
Return dataBindingList
End Get
End Property
Public Function GetReport() As List(Of WeatherReport)
Dim report = New List(Of WeatherReport)()
report.Add(New WeatherReport() With {
.Date = Date.Today,
.Weather = Weather.Rainy,
.HourlyReport = GenerateRandomHourlyReport()
})
report.Add(New WeatherReport() With {
.Date = Date.Today.AddDays(-1),
.Weather = Weather.Cloudy,
.HourlyReport = GenerateRandomHourlyReport()
})
report.Add(New WeatherReport() With {
.Date = Date.Today.AddDays(-2),
.Weather = Weather.Sunny,
.HourlyReport = GenerateRandomHourlyReport()
})
report.Add(New WeatherReport() With {
.Date = Date.Today.AddDays(-3),
.Weather = Weather.Gloomy,
.HourlyReport = GenerateRandomHourlyReport()
})
Return report
End Function
Public Function GenerateRandomHourlyReport() As List(Of HourlyReport)
Dim report = New List(Of HourlyReport)()
For i As Integer = 0 To 23
Dim hourlyReport = New HourlyReport()
hourlyReport.Hour = i
hourlyReport.Temperature = rand.Next(30)
report.Add(hourlyReport)
Next i
Return report
End Function
Public Sub Reload()
data_Renamed = GetReport()
End Sub
End Module
End Namespace