-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
122 lines (108 loc) · 4.04 KB
/
MainWindow.xaml.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace ScoreApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void RefreshSummary()
{
try
{
if (string.IsNullOrEmpty(this.TeamName1.Text) && string.IsNullOrEmpty(this.TeamName2.Text))
this.Result.Text = " ...";
else
this.Result.Text = string.Format("{0} {1}:{2} {3}", this.TeamName1.Text, this.Score1.Text, this.Score2.Text, this.TeamName2.Text);
string path = ConfigurationManager.AppSettings["scores_path"].ToString();
File.WriteAllText(path + "scores.txt", this.Result.Text, Encoding.Default);
}
catch(Exception e)
{
System.Windows.MessageBox.Show(e.Message);
}
}
private void Minus1_Click(object sender, RoutedEventArgs e)
{
short i;
if (!Int16.TryParse(this.Score1.Text, out i)) i = 0;
if (i > 0) i--;
this.Score1.Text = i.ToString();
this.RefreshSummary();
}
private void Minus2_Click(object sender, RoutedEventArgs e)
{
short i;
if (!Int16.TryParse(this.Score2.Text, out i)) i = 0;
if (i > 0) i--;
this.Score2.Text = i.ToString();
this.RefreshSummary();
}
private void Plus1_Click(object sender, RoutedEventArgs e)
{
short i;
if (!Int16.TryParse(this.Score1.Text, out i)) i = 0;
i++;
this.Score1.Text = i.ToString();
this.RefreshSummary();
}
private void Plus2_Click(object sender, RoutedEventArgs e)
{
short i;
if (!Int16.TryParse(this.Score2.Text, out i)) i = 0;
i++;
this.Score2.Text = i.ToString();
this.RefreshSummary();
}
private void TeamName1_TextChanged(object sender, TextChangedEventArgs e)
{
this.RefreshSummary();
}
private void TeamName2_TextChanged(object sender, TextChangedEventArgs e)
{
this.RefreshSummary();
}
private void Reset_Click(object sender, RoutedEventArgs e)
{
this.TeamName1.Text = "";
this.TeamName2.Text = "";
this.Score1.Text = "0";
this.Score2.Text = "0";
this.RefreshSummary();
}
private void Select1_Click(object sender, RoutedEventArgs e) =>
this.SelectTeam((dialog, button) => ((o, a) => { this.TeamName1.Text = button.Content.ToString(); dialog.Close(); }));
private void Select2_Click(object sender, RoutedEventArgs e) =>
this.SelectTeam((dialog, button) => ((o, a) => { this.TeamName2.Text = button.Content.ToString(); dialog.Close(); }));
private void SelectTeam(Func<SelectTeamDialog, Button, RoutedEventHandler> onTeamClick)
{
var dialog = new SelectTeamDialog();
dialog.Owner = this;
dialog.WindowState = WindowState.Maximized;
string path = ConfigurationManager.AppSettings["scores_path"].ToString();
if (string.IsNullOrEmpty(path) || Directory.Exists(path))
{
var teamList = File.ReadAllLines(path + "teams.txt", Encoding.Default);
foreach (string team in teamList)
{
var button = new Button();
button.Content = team;
button.Margin = new Thickness(16);
button.FontSize = 24;
button.Click += onTeamClick(dialog, button);
dialog.Space.Children.Add(button);
}
}
dialog.ShowDialog();
}
}
}