-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventSelector.xaml.cs
More file actions
113 lines (98 loc) · 3.07 KB
/
EventSelector.xaml.cs
File metadata and controls
113 lines (98 loc) · 3.07 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading.Tasks;
namespace FIRST
{
/// <summary>
/// Interaction logic for EventSelector.xaml
/// </summary>
public partial class EventSelector : Window
{
EventLoader selector;
public Event SelectedEvent;
private Task eventLoader;
public EventSelector()
{
InitializeComponent();
selector = new EventLoader();
EventYear.Text = "" + DateTime.Now.Year;
selector.DownloadProgressChanged += (sender, e) =>
{
DownloadProgress.Dispatcher.Invoke(new Action(() =>
{
DownloadProgress.Value = (e.ProgressPercentage - 50) * 2;
}));
};
IsVisibleChanged += (sender, ev) =>
{
if (Visibility == Visibility.Visible)
BeginRequestEvents(DateTime.Now.Year);
};
selector.EventsUpdated += (sender, e) =>
{
if (Visibility == Visibility.Visible)
{
SetProgressVisibility(System.Windows.Visibility.Hidden);
EventsBox.Dispatcher.Invoke(new Action(() =>
{
UpdateEventBox();
}));
}
};
}
private void BeginRequestEvents(int year)
{
SetProgressVisibility(System.Windows.Visibility.Visible);
selector.GetEvents(year);
}
private void Button_Click(object sender, RoutedEventArgs ev)
{
int year;
if (int.TryParse(EventYear.Text, out year))
{
Mouse.SetCursor(Cursors.AppStarting);
BeginRequestEvents(year);
}
}
private void UpdateEventBox()
{
EventsBox.Items.Clear();
foreach (Event e in selector.events)
{
EventsBox.Items.Add(e);
}
EventsBox.SelectedIndex = 0;
Mouse.SetCursor(Cursors.AppStarting);
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void Select_Click(object sender, RoutedEventArgs e)
{
if (EventsBox.SelectedItem != null)
{
SelectedEvent = EventsBox.SelectedItem as Event;
DialogResult = true;
}
else
{
MessageBox.Show("Please Select an Event");
}
}
private void SetProgressVisibility(Visibility visible)
{
DownloadProgress.Dispatcher.Invoke(new Action(() => DownloadProgress.Visibility = visible));
}
}
}