-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherReport.vb
82 lines (70 loc) · 2.89 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
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Namespace DataBindingToListExample
#Region "#WeatherReport"
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
#End Region ' #WeatherReport
Public NotInheritable Class MyWeatherReportSource
Private Sub New()
End Sub
Private Shared rand As Random = New System.Random()
Private Shared data_Renamed As List(Of WeatherReport)
Private Shared dataBindingList As BindingList(Of WeatherReport)
Public Shared 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 Shared 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 Shared 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 Shared 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
End Class
End Namespace