-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
116 lines (95 loc) · 3.06 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
using System.Collections.ObjectModel;
using System.Windows;
using EmployeeViewer.Model;
using log4net;
namespace EmployeeViewer
{
public partial class MainWindow : Window
{
#region Properties
private static ObservableCollection<Employee> Employees { get; set; }
#endregion
#region Public fields
public static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
#endregion
#region Constructor
public MainWindow()
{
InitializeComponent();
Employees = new ObservableCollection<Employee>();
MainDataGrid.ItemsSource = Employees;
log4net.Config.XmlConfigurator.Configure();
}
#endregion
#region Private methods
private void Add_Button_Click(object sender, RoutedEventArgs e)
{
AddItem();
log.Info("Add item");
}
private void Remove_Button_Click(object sender, RoutedEventArgs e)
{
RemoveItem();
log.Info("Remove item");
}
private void Edit_Button_Click(object sender, RoutedEventArgs e)
{
EditItem();
}
private void DoubleClick_On_Item(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
EditItem();
}
private void SaveFile_Click_Button(object sender, RoutedEventArgs e)
{
Core.Instance.SaveToFile(Employees);
log.Info("Save to file");
}
private void Load_Button_Click(object sender, RoutedEventArgs e)
{
var tempEmloyees = Core.Instance.LoadFromFile();
Employees = tempEmloyees != null ? tempEmloyees : Employees;
MainDataGrid.ItemsSource = Employees;
log.Info("Load from file");
}
#endregion
#region Public methods
/// <summary>
/// Adds the item.
/// </summary>
public void AddItem()
{
var employeeInfo = new EmployeeInfo();
if (employeeInfo.ShowDialog() == true & employeeInfo.CurrentEmployee != null)
{
var employee = employeeInfo.CurrentEmployee;
Employees.Add(employeeInfo.CurrentEmployee);
}
}
/// <summary>
/// Removes selected item.
/// </summary>
public void RemoveItem()
{
if (MainDataGrid.SelectedIndex >= 0)
{
Employee employee = MainDataGrid.SelectedItem as Employee;
Employees.Remove(employee);
}
}
/// <summary>
/// Edits selected item.
/// </summary>
public void EditItem()
{
if (MainDataGrid.SelectedIndex >= 0)
{
Employee employee = MainDataGrid.SelectedItem as Employee;
var employeeInfo = new EmployeeInfo();
employeeInfo.DataContext = employee;
employeeInfo.ShowDialog();
}
}
#endregion
}
}