-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddAlarm.xaml.cs
98 lines (86 loc) · 3.26 KB
/
AddAlarm.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
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace AlarmApp
{
/// <summary>
/// Interaction logic for AddAlarm.xaml
/// </summary>
public partial class AddAlarm : Window
{
public Times timeType;
private readonly MainWindowViewModel mainWindowViewModel;
public AddAlarm(MainWindowViewModel mainWindowViewModel)
{
InitializeComponent();
this.mainWindowViewModel = mainWindowViewModel;
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
Keyboard.ClearFocus();
}
private void Seconds_MenuItem_Click(object sender, RoutedEventArgs e)
{
timeType = Times.Seconds;
TimeSplitButton.Content = timeType;
}
private void Minutes_MenuItem_Click(object sender, RoutedEventArgs e)
{
timeType = Times.Minutes;
TimeSplitButton.Content = timeType;
}
private void Hours_MenuItem_Click(object sender, RoutedEventArgs e)
{
timeType = Times.Hours;
TimeSplitButton.Content = timeType;
}
private void Days_MenuItem_Click(object sender, RoutedEventArgs e)
{
timeType = Times.Days;
TimeSplitButton.Content = timeType;
}
private void Cancel_Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Set_Button_Click(object sender, RoutedEventArgs e)
{
if (Enum.IsDefined(typeof(Times), TimeSplitButton.Content))
{
if (TimePicker_TextBox.Text.Any())
{
if (NameTextBox.Text.Length > 15)
{
MessageBox.Show("The name of the Alarm can be 15 characters at most!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (Util.AreDigitsOnly(TimePicker_TextBox.Text))
{
DateTime time = Util.ConvertStringToTime(TimePicker_TextBox.Text, timeType);
var alarm = new AlarmViewModel()
{
Name = NameTextBox.Text,
Date = time
};
alarm.Update(time);
mainWindowViewModel.AddAlarm(alarm);
Close();
}
else
{
MessageBox.Show("You need to put in a valid time!\nValid Format Example: (Minutes) 10:20 => 10 minutes and 20 seconds.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("You need to put in a time!\nValid Format Example: (Minutes) 10:20 => 10 minutes and 20 seconds.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("You need to put in a valid time format in the Time Format Picker Box!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}