-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsWindow.xaml.cs
131 lines (112 loc) · 4.55 KB
/
SettingsWindow.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
123
124
125
126
127
128
129
130
131
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using AutoUpdaterDotNET;
namespace powerLabel
{
/// <summary>
/// Interaction logic for SettingsWindow.xaml
/// </summary>
public partial class SettingsWindow : Window
{
public SettingsWindow()
{
InitializeComponent();
refreshSettings();
}
private void refreshSettings()
{
SettingsHandler.Settings settings = SettingsHandler.ReadSettings();
employeeList.Items.Clear();
foreach (string item in settings.employees)
{
ListViewItem listViewItem = new ListViewItem();
listViewItem.Content = item;
employeeList.Items.Add(listViewItem);
}
printerHost.Text = settings.printerHost;
printerShareName.Text = settings.printerShareName;
ip.Text = settings.databaseIP;
database.Text = settings.databaseName;
username.Text = settings.databaseUser;
password.Text = settings.databasePass;
}
private void addEmployeeBtn_Click(object sender, RoutedEventArgs e)
{
if (employeeTextbox.Text.Trim() != "")
{
ListViewItem employee = new ListViewItem();
employee.Content = employeeTextbox.Text.Trim();
employeeList.Items.Add(employee);
employeeTextbox.Text = "";
}
}
private void updateEmployeeBtn_Click(object sender, RoutedEventArgs e)
{
if (employeeTextbox.Text.Trim() != "")
{
ListViewItem selected = (ListViewItem)employeeList.SelectedItem;
selected.Content = employeeTextbox.Text;
employeeTextbox.Text = "";
employeeList.UnselectAll();
}
}
private void Employee_Selection_Changed(object sender, RoutedEventArgs e)
{
ListViewItem selected = (ListViewItem)employeeList.SelectedItem;
if (selected != null)
{
addEmployeeBtn.Content = "Update";
employeeTextbox.Text = selected.Content.ToString();
addEmployeeBtn.Click += updateEmployeeBtn_Click;
addEmployeeBtn.Click -= addEmployeeBtn_Click;
deleteBtn.Visibility = Visibility.Visible;
}
else
{
addEmployeeBtn.Content = "Add employee";
employeeTextbox.Text = "";
addEmployeeBtn.Click -= updateEmployeeBtn_Click;
addEmployeeBtn.Click += addEmployeeBtn_Click;
deleteBtn.Visibility = Visibility.Collapsed;
}
}
private void saveSettings(object sender, RoutedEventArgs e)
{
SettingsHandler.Settings sett = new SettingsHandler.Settings(); // Create a new settings object
List<string> empList = new List<string>(); // Make a list for the employees
foreach (ListViewItem item in employeeList.Items)
{
empList.Add(item.Content.ToString()); // Add every employee in the listview to the list
}
sett.employees = empList; // Add the list to the settings
sett.printerHost = printerHost.Text; // Add the printer host to the settings
sett.printerShareName = printerShareName.Text; // Add the printer share name to the settings
sett.databaseIP = ip.Text;
sett.databaseName = database.Text;
sett.databaseUser = username.Text;
sett.databasePass = password.Text;
SettingsHandler.WriteSettings(sett); // Write settings to json
DialogResult = true; // Close window
}
private void employeeTextbox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Return)
{
addEmployeeBtn_Click(sender, e);
}
}
private void deleteBtn_Click(object sender, RoutedEventArgs e)
{
ListViewItem selected = (ListViewItem)employeeList.SelectedItem;
employeeList.Items.Remove(selected);
employeeTextbox.Text = "";
employeeList.UnselectAll();
}
private void printerSettings_TextChanged(object sender, TextChangedEventArgs e)
{
printerAddress.Text = @"\\" + printerHost.Text + @"\" + printerShareName.Text;
}
}
}