-
Notifications
You must be signed in to change notification settings - Fork 6
/
EmployeeUI.cs
316 lines (273 loc) · 9.42 KB
/
EmployeeUI.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using custom_alert_notifications;
namespace Kimathi_Construction
{
public partial class EmployeeUI : UserControl
{
private static EmployeeUI _instance;
Employee theemp;
public static EmployeeUI Instance
{
get
{
if (_instance == null)
{
_instance = new EmployeeUI();
}
return _instance;
}
}
public EmployeeUI()
{
InitializeComponent();
}
public void Gloabal_EmployeeUI_Load()
{
CheckInPrep();
}
private void EmployeeUI_Load(object sender, EventArgs e)
{
//UI code
SetToolTip(owner, "Follow at twitter @Job_Getabu ;)");
CheckInPrep();
}
private void owner_Click(object sender, EventArgs e)
{
//UI code
SetToolTip(owner, "Follow at twitter @Job_Getabu ;)");
string fbPage = "https://twitter.com/job_getabu";
try
{
System.Diagnostics.ProcessStartInfo sInfo = new System.Diagnostics.ProcessStartInfo(fbPage);
System.Diagnostics.Process.Start(sInfo);
}
catch (Exception) { }
}
private void SetToolTip(Control ctl, string message)
{
ToolTip toolTip1 = new ToolTip();
toolTip1.UseFading = true;
toolTip1.UseAnimation = true;
toolTip1.IsBalloon = true;
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(ctl, message);
}
private void btnRegister_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(tbFullName.Text))
{
//UI code
alert.Show("Required info \n Enter Name !", alert.AlertType.warnig);
return;
}
if (string.IsNullOrEmpty(tbDept.Text))
{
//UI code
alert.Show("Required info \n Enter Department !", alert.AlertType.warnig);
return;
}
if (string.IsNullOrEmpty(tbTypeOfemployee.Text))
{
//UI code
alert.Show("Required info \n Enter Employee Type !", alert.AlertType.warnig);
return;
}
if (string.IsNullOrEmpty(tbIdReg.Text))
{
//UI code
alert.Show("Required info \n Enter Employee ID !", alert.AlertType.warnig);
return;
}
Employee yy = empFound(long.Parse(tbIdReg.Text));
theemp = yy;
if (yy != null)
{
//UI code
alert.Show("Error \n Employee ID Found!", alert.AlertType.warnig);
return;
}
try
{
Employee my = new Employee();
my.IdNum = long.Parse(tbIdReg.Text);
my.Name = tbFullName.Text;
my.TypeOfEmployee = tbTypeOfemployee.Text;
my.Department = tbDept.Text;
using (var context = new KimathiEntities())
{
try
{
context.Employees.Add(my);
context.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
alert.Show("Saved !", alert.AlertType.success);
CheckInPrep();
}
}
catch (Exception) { }
}
private void btnVerify_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(tbId.Text))
{
//UI code
alert.Show("Required info \n Enter Employee ID !", alert.AlertType.warnig);
return;
}
Employee yy = empFound(long.Parse(tbId.Text));
theemp = yy;
if (yy != null)
{
lblVerificationReport.Text = "Employee Found";
lblVerificationReport.ForeColor = Color.Black;
alert.Show("Employee Found !", alert.AlertType.success);
theemp = yy;
CheckInPrep();
UICode();
}
else
{
lblVerificationReport.Text = "Employee not Found";
lblVerificationReport.ForeColor = Color.Crimson;
alert.Show("Employee not Found !", alert.AlertType.error);
theemp = yy;
CheckInPrep();
UICode();
}
}
private Employee empFound(long idnum)
{
using (var context = new KimathiEntities())
{
var userList = context.Employees.ToList();
foreach (var ss in userList.Where(a => a.IdNum == (idnum)))
{
if (ss.IdNum == idnum)
{
return ss;
}
}
return null;
}
}
private void UICode()
{
try
{
tbFullName.Text = theemp.Name;
tbIdReg.Text = theemp.IdNum.ToString();
tbDept.Text = theemp.Department;
tbTypeOfemployee.Text = theemp.TypeOfEmployee;
}
catch (Exception) { }
}
private void CheckInPrep()
{
lblDate.Text = DateTime.Now.ToString("dd MMM yyy");
Work dowork = null;
if (theemp != null)
{
long xx = theemp.IdNum;
using (var context = new KimathiEntities())
{
var wList = context.Works
.OrderBy(a => a.TimeIn)
.Where(a => a.IdNum_fk == xx)
.ToList();
foreach (var ss in wList.Where(a => a.Employee == theemp))
{
if (ss.Id == theemp.IdNum)
{
//returns the latest work entry
dowork = ss;
break;
}
}
if (dowork != null)
{
dTimePickerIn.Value = dowork.TimeIn.Value;
dTimePickerOut.Value = dowork.TimeOut.Value;
}
else
{
dTimePickerIn.Value = DateTime.Now;
dTimePickerOut.Value = DateTime.Now;
}
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
Work dowork = null;
if (theemp != null)
{
long xx = theemp.IdNum;
using (var context = new KimathiEntities())
{
var wList = context.Works
.OrderBy(a => a.TimeOut)
.Where(a => a.IdNum_fk == xx)
.ToList();
foreach (var ss in wList.Where(a => a.Employee == theemp))
{
if (ss.Id == theemp.IdNum)
{
//returns the latest work entry
dowork = ss;
break;
}
}
if (dowork != null)
{
dowork.TimeIn = dTimePickerIn.Value;
dowork.TimeOut = dTimePickerOut.Value;
dowork.IdNum_fk = theemp.IdNum;
context.Entry<Work>(dowork).State = EntityState.Modified;
try
{
context.SaveChanges();
alert.Show("Updated !", alert.AlertType.success);
}
catch (Exception) { }
}
else
{
Work d = new Work();
d.IdNum_fk = theemp.IdNum;
d.TimeIn = dTimePickerIn.Value;
d.TimeOut = dTimePickerOut.Value;
d.Payed = 0;
//d.Employee = theemp;
try
{
context.Works.Add(d);
context.SaveChanges();
alert.Show("Saved !", alert.AlertType.success);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
}
}
}
}
}