-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherReport.cs
95 lines (86 loc) · 2.84 KB
/
WeatherReport.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace DataBindingToListExample {
#region #WeatherReport
public class WeatherReport {
[DisplayName("Date")]
public DateTime Date { get; set; }
[DisplayName("Weather Condition")]
public Weather Weather { get; set; }
[DisplayName("Max and Min Temperature")]
public List<HourlyReport> HourlyReport { get; set; }
}
public class HourlyReport {
public int Hour { get; set; }
public int Temperature { get; set; }
}
public enum Weather {
Sunny,
Cloudy,
Windy,
Gloomy,
Foggy,
Misty,
Rainy,
Undefined
}
#endregion #WeatherReport
public static class MyWeatherReportSource {
private static Random rand = new System.Random();
static List<WeatherReport> data;
static BindingList<WeatherReport> dataBindingList;
public static List<WeatherReport> Data
{
get {
if (data == null) {
data = GetReport();
}
return data;
}
}
public static BindingList<WeatherReport> DataAsBindingList
{
get {
if (dataBindingList == null) {
dataBindingList = new BindingList<WeatherReport>(Data);
}
return dataBindingList;
}
}
public static List<WeatherReport> GetReport() {
var report = new List<WeatherReport>();
report.Add(new WeatherReport() {
Date = DateTime.Today,
Weather = Weather.Rainy,
HourlyReport = GenerateRandomHourlyReport()
});
report.Add(new WeatherReport() {
Date = DateTime.Today.AddDays(-1),
Weather = Weather.Cloudy,
HourlyReport = GenerateRandomHourlyReport()
});
report.Add(new WeatherReport() {
Date = DateTime.Today.AddDays(-2),
Weather = Weather.Sunny,
HourlyReport = GenerateRandomHourlyReport()
});
report.Add(new WeatherReport() {
Date = DateTime.Today.AddDays(-3),
Weather = Weather.Gloomy,
HourlyReport = GenerateRandomHourlyReport()
});
return report;
}
public static List<HourlyReport> GenerateRandomHourlyReport() {
var report = new List<HourlyReport>();
for (int i = 0; i < 24; i++) {
var hourlyReport = new HourlyReport();
hourlyReport.Hour = i;
hourlyReport.Temperature = rand.Next(30);
report.Add(hourlyReport);
}
return report;
}
}
}