-
Notifications
You must be signed in to change notification settings - Fork 2
/
EmployeeEidtWindow.xaml.cs
169 lines (153 loc) · 5.54 KB
/
EmployeeEidtWindow.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HSMS.Model;
using HSMS.DAL;
using System.Windows.Media.Effects;
using Microsoft.Win32;
using System.IO;
namespace HSMS.UI
{
/// <summary>
/// EmployeeEidtWindow.xaml 的交互逻辑
/// </summary>
public partial class EmployeeEidtWindow : Window
{
public EmployeeEidtWindow()
{
InitializeComponent();
}
public Guid EditingId { set; get; }
public bool IsAddNew { set; get; }
private void Window_Loaded(object sender, RoutedEventArgs e)
{
cbDepartment.ItemsSource = DepartmentDAL.ListALL();
cbEducation.ItemsSource = IdNameDAL.GetByCatagory("学历");
cbGender.ItemsSource = IdNameDAL.GetByCatagory("性别");
cbMarriage.ItemsSource = IdNameDAL.GetByCatagory("婚姻状况");
cbPartyStatus.ItemsSource = IdNameDAL.GetByCatagory("政治面貌");
if (IsAddNew)
{
Employee employee = new Employee();
employee.InDate = DateTime.Today;
employee.ContractStartDay = DateTime.Today;
employee.ContractEndDay = DateTime.Today.AddYears(1);
employee.Nationality = "汉族";
employee.Email = "836246914@qq.com";
//employee.Number = "Ideas";
employee.Number = SettingDAL.GetValue("员工工号前缀");
gridEmployee.DataContext = employee;
}
else
{
Employee employee = EmployeeDAL.GetById(EditingId);
gridEmployee.DataContext = employee;
if (employee.Photo!= null)
{
ShowImage(employee.Photo);
}
}
}
private void ShowImage(byte[] imageByte)
{
MemoryStream stream = new MemoryStream(imageByte);
BitmapImage bitImage = new BitmapImage();
bitImage.BeginInit();
bitImage.StreamSource = stream;
bitImage.EndInit();
imgPhoto.Source = bitImage;
}
private void CheckTextBoxNotNull(ref bool IsOk,params TextBox[] textBoxs)
{
foreach (TextBox textBox in textBoxs)
{
if (textBox.Text.Length <= 0)
{
IsOk = false;
textBox.Background = Brushes.Red;
}
else
{
textBox.Background = null;
}
}
}
private void CheckComboBoxNotNull(ref bool IsOk, params ComboBox[] cbxs)
{
foreach (ComboBox cbx in cbxs)
{
if (cbx.SelectedIndex<0)
{
IsOk = false;
//cbx.Effect=new DropShadow
cbx.Effect = new DropShadowEffect { Color=Colors.Red};
}
else
{
cbx.Background = null;
}
}
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
bool IsOK = true;
CheckTextBoxNotNull(ref IsOK, txtName, txtNational, txtNativeAddr, txtAddr,
txtBaseSalary, txtTelNum, txtIdNum, txtPosition, txtNumber);
CheckComboBoxNotNull(ref IsOK, cbGender, cbMarriage,
cbPartyStatus, cbEducation, cbDepartment);
if (IsOK == false)
return;
Guid operatorId = CommonHelper.GetOperatorId();
if (IsAddNew)
{
Employee employee = (Employee)gridEmployee.DataContext;
if (employee.Photo == null)
EmployeeDAL.InsertImageNull(employee);
else
EmployeeDAL.Insert(employee);
T_OperationLogDAL.Insert(operatorId, "新增职员" + employee.Name);
}
else
{
Employee employee = (Employee)gridEmployee.DataContext;
if (employee.Photo == null)
EmployeeDAL.UpdateImageNull(employee);
else
EmployeeDAL.Update(employee);
T_OperationLogDAL.Insert(operatorId, "修改职员" + employee.Name);
}
DialogResult = true;
}
private void btnChoosePhoto_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "png图片|*.png|jpg图片|*.jpg";
if (ofd.ShowDialog() == true)
{
string fileName = ofd.FileName;
Employee employee = (Employee)gridEmployee.DataContext;
employee.Photo = File.ReadAllBytes(fileName);
imgPhoto.Source = new BitmapImage(new Uri(fileName));
}
}
private void btnCapture_Click(object sender, RoutedEventArgs e)
{
CaptureWindow win = new CaptureWindow();
if (win.ShowDialog() == true)
{
ShowImage(win.CaptureData);
Employee employee = (Employee)gridEmployee.DataContext;
employee.Photo = win.CaptureData;
}
}
}
}