-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
107 lines (89 loc) · 3.08 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
using System.Windows;
using System.Windows.Input;
namespace Wake_On_Lan_Lite
{
public partial class MainWindow : Window
{
private fileControl file = new fileControl();
public MainWindow()
{
InitializeComponent();
file.createFileIfNotExist();
dataRefresh();
}
//Function that refresh listBox data
public void dataRefresh()
{
this.deviceList.ItemsSource = null;
this.deviceList.ItemsSource = file.getAllAddresses();
}
//Show the edit device window to add or update a device
public void showEditDevice(object sender, RoutedEventArgs e)
{
editDevice edit = new editDevice(this);
Device device = (Device)this.deviceList.SelectedItem;
if (sender.ToString().Contains("Button") || device.NAME == "+")
{
edit.editDeviceTitle.Text = "Add device";
edit.editDeviceButton.Content = "Add";
}
else
{
edit.editDeviceTitle.Text = "Update device";
edit.editDeviceButton.Content = "Update";
edit.nameTextBox.Text = device.NAME;
edit.addressTextBox.Text = device.ADDRESS;
}
edit.Show();
}
//Delete a device
public void deleteDevice(object sender, RoutedEventArgs e)
{
Device device = (Device)this.deviceList.SelectedItem;
if (device != null && device.NAME != "+")
{
this.file.deleteAddress(device, this);
dataRefresh();
}
else
{
appMessageBox appMessage = new appMessageBox();
appMessage.Show();
appMessage.showMsg("Please select a device");
}
}
//Send the magic packet
private void WakeUp(object sender, RoutedEventArgs e)
{
Device device = (Device)this.deviceList.SelectedItem;
if (device != null && device.NAME != "+")
{
networkControl nc = new networkControl();
notificationService ns = new notificationService();
nc.wakeUp(device.ADDRESS);
ns.sendNotification(device.NAME);
}
else
{
appMessageBox appMessage = new appMessageBox();
appMessage.Show();
appMessage.showMsg("Please select a device");
}
}
// Can execute
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
// Minimize
private void CommandBinding_Executed_Minimize(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.MinimizeWindow(this);
}
// Close
private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.CloseWindow(this);
}
}
}