-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployees.cpp
520 lines (434 loc) · 12.3 KB
/
Employees.cpp
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
#include "Employees.h"
void employees_InsertListBill(LIST_EMPLOYEES &le, char *code, struct NODE_BILL* data)
{
for (int run = 0; run < le.size; run++)
{
if (strcmp(le.arr[run].employeesCode, code) == 0)
{
//le.arr[run].list_Bill = data;
dslk_addHead(le.arr[run].list_Bill, data);
}
}
}
void REALLOC(EMPLOYEES *&list, int oldSize, int newSize)
{
EMPLOYEES *temp = new EMPLOYEES[oldSize];
for (int i = 0; i < oldSize; i++)
{
temp[i] = list[i];
}
delete[] list;
list = new EMPLOYEES[newSize];
int min = oldSize < newSize ? oldSize : newSize;
for (int i = 0; i < min; i++)
{
list[i] = temp[i];
}
delete[] temp;
}
bool isEmpty(LIST_EMPLOYEES list)
{
return list.size == 0;
}
bool isFull(LIST_EMPLOYEES list)
{
return list.size == employees_quantityMax;
}
bool employees_insertItem(LIST_EMPLOYEES &list, int LOCATIONAdd, EMPLOYEES data)
{
if (LOCATIONAdd < 0 || LOCATIONAdd > list.size || isFull(list))
{
return false;
}
REALLOC(list.arr, list.size, list.size + 1);
for (int i = list.size - 1; i >= LOCATIONAdd; i--)
{
list.arr[i + 1] = list.arr[i];
}
list.arr[LOCATIONAdd] = data;
list.size++;
return true;
}
int employees_deleteItem(LIST_EMPLOYEES &list, int LOCATIONDelete)
{
if (LOCATIONDelete < 0 || LOCATIONDelete > employees_quantityMax || isEmpty(list))
{
return false;
}
for (int i = LOCATIONDelete + 1; i < list.size; i++)
{
list.arr[i - 1] = list.arr[i];
}
REALLOC(list.arr, list.size, list.size - 1);
list.size--;
return true;
}
bool isExits(LIST_EMPLOYEES le, char *code)
{
for (int run = 0; run < le.size; run++)
{
if (strcmp(le.arr[run].employeesCode, code) == 0)
{
return true;
}
}
return false;
}
void swap(EMPLOYEES &a, EMPLOYEES &b)
{
EMPLOYEES temp;
temp = b;
b = a;
a = temp;
}
void employees_Sort(LIST_EMPLOYEES &le)
{
for (int run = 0; run < le.size - 1; run++)
{
for (int runin = run + 1; runin < le.size; runin++)
{
if (strcmp(le.arr[run].firstName, le.arr[runin].firstName) > 0)
{
swap(le.arr[run], le.arr[runin]);
}
else if (strcmp(le.arr[run].firstName, le.arr[runin].firstName) == 0)
{
if (strcmp(le.arr[run].familyName, le.arr[runin].familyName) > 0)
{
swap(le.arr[run], le.arr[runin]);
}
}
}
}
}
int employees_search(LIST_EMPLOYEES lm, char *code)
{
for (int run = 0; run < lm.size; run++)
{
if (strcmp(lm.arr[run].employeesCode, code) == 0)
{
return run;
}
}
return -1;
}
STR employees_GetFullName(LIST_EMPLOYEES le, char *code)
{
STR fullName = {'\0'};
for (int run = 0; run < le.size; run++)
{
if (strcmp(le.arr[run].employeesCode, code) == 0)
{
strcpy_s(fullName.str, le.arr[run].familyName);
strcat_s(fullName.str, " ");
strcat_s(fullName.str, le.arr[run].firstName);
return fullName;
}
}
return fullName;
}
STR employees_EntryCode(char *notify, int color, char *text)
{
LIST_PROPERTIES arrProp;
PROPERTIES item;
strcpy_s(item.variables.name, "Ma Nhan Vien");
item.variables.color = color;
strcpy_s(item.variables.notify, notify);
strcpy_s(item.variables.data, text);
item.mode.modeImport = UPPER_NUMBER;
item.mode.enable = true;
item.maxLength = employees_maxSize_Code;
List_InsertItem(arrProp, arrProp.size, item);
LOCATION lc;
lc.x = 5; lc.y = 5;
//get data
LIST_ARRAY_CHAR destination;
enterDataToVariable(destination, arrProp, lc);
//handling
if (strcmp(destination.listSTR[destination.size - 1].str, "CANCEL") == 0) // cancel
{
STR temp;
strcpy_s(temp.str, "");
return temp;
}
STR temp;
temp = destination.listSTR[0];
// delete
List_Clear(destination);
return temp;
}
void employees_InitProperties(LIST_PROPERTIES &lprop)
{
PROPERTIES prop;
strcpy_s(prop.variables.name, "Ma Nhan Vien");
strcpy_s(prop.variables.data, "");
strcpy_s(prop.variables.notify, "Format: 0-9, A-Z");
prop.mode.enable = false;
prop.mode.modeImport = UPPER_NUMBER;
prop.maxLength = employees_maxSize_Code;
List_InsertItem(lprop, lprop.size, prop);
strcpy_s(prop.variables.name, "Ho va Ten Lot");
strcpy_s(prop.variables.data, "");
strcpy_s(prop.variables.notify, "Format: a-z, A-Z");
prop.mode.enable = true;
prop.mode.modeImport = UPPER_LOWER;
prop.maxLength = employees_maxSize_FamilyName;
List_InsertItem(lprop, lprop.size, prop);
strcpy_s(prop.variables.name, "Ten");
strcpy_s(prop.variables.data, "");
strcpy_s(prop.variables.notify, "Format: a-z, A-Z");
prop.mode.enable = true;
prop.mode.modeImport = UPPER_LOWER;
prop.maxLength = employees_maxSize_FirstName;
List_InsertItem(lprop, lprop.size, prop);
strcpy_s(prop.variables.name, "Gioi Tinh");
strcpy_s(prop.variables.data, "");
strcpy_s(prop.variables.notify, "0: Nam; 1: Nu");
prop.mode.enable = true;
prop.mode.modeImport = SEX;
prop.maxLength = 1;
List_InsertItem(lprop, lprop.size, prop);
}
void employees_InitTiTle(LIST_TITLE <)
{
TITLE t;
int size;
strcpy_s(t.data, "Ma Nhan Vien");
size = strlen(t.data);
t.width = (size > employees_maxSize_Code ? size : employees_maxSize_Code) + 4;
List_InsertItem(lt, lt.size, t);
strcpy_s(t.data, "Ho va Ten Dem");
size = strlen(t.data);
t.width = (size > employees_maxSize_FamilyName ? size : employees_maxSize_FamilyName) + 4;
List_InsertItem(lt, lt.size, t);
strcpy_s(t.data, "Ten");
size = strlen(t.data);
t.width = (size > employees_maxSize_FirstName ? size : employees_maxSize_FirstName) + 4;
List_InsertItem(lt, lt.size, t);
strcpy_s(t.data, "Gioi Tinh");
size = strlen(t.data);
t.width = size + 4;
List_InsertItem(lt, lt.size, t);
}
void employees_Edit(LIST_EMPLOYEES &le, LOCATION displayLC)
{
/*
LOCATION displayLC;
displayLC.x = displayLC.y = 5;
char notify[maxLengthChar];
strcpy_s(notify, "Format: 0-9, A-Z");
int color = ColorCode_White;
STR code;
while (true)
{
code = employees_EntryCode(notify, color, "");
if (strcmp(code.str, "") == 0)// cancel
{
return;
}
else
{
if (isExits(le, code.str))
{
break;
}
else
{
strcpy_s(notify, "Ma nhan vien khong ton tai");
color = ColorCode_Red;
}
}
}
int check = employees_search(le, code.str);
if (check != -1)
{
EMPLOYEES temp = le.arr[check];
LIST_PROPERTIES lprop;
employees_InitProperties(lprop);
strcpy_s(lprop.lprop[0].variables.data, temp.employeesCode);
strcpy_s(lprop.lprop[1].variables.data, temp.familyName);
strcpy_s(lprop.lprop[2].variables.data, temp.firstName);
char *a = new char[2];
_itoa_s(temp.sex, a, 2, 10);
strcpy_s(lprop.lprop[3].variables.data, a);
delete[] a;
system("cls");
LIST_ARRAY_CHAR arrData;
enterDataToVariable(arrData, lprop, displayLC);
if (strcmp(arrData.listSTR[arrData.size - 1].str, "DONE") == 0)
{
strcpy_s(le.arr[check].familyName, char_formartText(arrData.listSTR[1].str));
strcpy_s(le.arr[check].firstName, char_formartText(arrData.listSTR[2].str));
le.arr[check].sex = atoi(arrData.listSTR[3].str);
messagebox("Ban da cap nhat thong tin thanh cong.", YES, displayLC);
return;
}
else
{
messagebox("Ban da huy qua trinh cap nhat thong tin.", YES, displayLC);
return;
}
}
messagebox("Khong tim thay voi ma nhan vien tuong ung.", YES, displayLC);
return;*/
LOCATION lChoose, lShow;
Size sGird;
LIST_TITLE title;
LIST_ARRAY_CHAR notify;
employees_InitTiTle(title);
LIST_LOCATION listLC;
List_InsertItem(notify, notify.size, "Employees");
List_InsertItem(notify, notify.size, "0-9, A-Z");
List_InsertItem(notify, notify.size, "Ma nhan vien khong ton tai.");
lChoose = { displayLC.x + 6, displayLC.y + 1 };
lShow = { displayLC.x + 3, displayLC.y + 13 };
drawBorder(listLC, lShow, le.size, 5, title);
for (int run = 0; run < le.size; run++)
{
int indexNow = run * employees_quantityFields;
gotoxy(listLC.lloca[indexNow].x, listLC.lloca[indexNow].y); BGColorText(le.arr[run].employeesCode, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 1].x, listLC.lloca[indexNow + 1].y); BGColorText(le.arr[run].familyName, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 2].x, listLC.lloca[indexNow + 2].y); BGColorText(le.arr[run].firstName, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 3].x, listLC.lloca[indexNow + 3].y);
if (le.arr[run].sex == 0)
{
BGColorText("Nam", ColorCode_Black, ColorCode_DarkWhite);
}
else if (le.arr[run].sex == 1)
{
BGColorText("Nu", ColorCode_Black, ColorCode_DarkWhite);
}
}
if (le.size == 0)
{
sGird = { 64, 20 };
}
else
{
sGird = { (listLC.lloca[listLC.size - 1].x + title.ltitle[title.size - 1].width) - displayLC.x, (listLC.lloca[listLC.size - 1].y + 5) - displayLC.y };
}
drawBox(displayLC, sGird, "Danh Sach Nhan Vien");
//action
while (true)
{
STR codeBill;
NBD bd = NULL;
LIST_BILL lb; dslk_Initialize(lb);
codeBill = dis_chooseViewDetail(lb, bd, le, lChoose, sGird.width, notify, 1);
if (strcmp(codeBill.str, "DONE") == 0)
{
break;
}
else
{
//edit
int check = employees_search(le, codeBill.str);
displayLC = { displayLC.x = 3, displayLC.y + 3 };
if (check != -1)
{
EMPLOYEES temp = le.arr[check];
LIST_PROPERTIES lprop;
employees_InitProperties(lprop);
strcpy_s(lprop.lprop[0].variables.data, temp.employeesCode);
strcpy_s(lprop.lprop[1].variables.data, temp.familyName);
strcpy_s(lprop.lprop[2].variables.data, temp.firstName);
char *a = new char[2];
_itoa_s(temp.sex, a, 2, 10);
strcpy_s(lprop.lprop[3].variables.data, a);
delete[] a;
system("cls");
LIST_ARRAY_CHAR arrData;
enterDataToVariable(arrData, lprop, displayLC);
if (strcmp(arrData.listSTR[arrData.size - 1].str, "DONE") == 0)
{
strcpy_s(le.arr[check].familyName, char_formartText(arrData.listSTR[1].str));
strcpy_s(le.arr[check].firstName, char_formartText(arrData.listSTR[2].str));
le.arr[check].sex = atoi(arrData.listSTR[3].str);
employees_Sort(le);
messagebox("Ban da cap nhat thong tin thanh cong.", YES, displayLC);
return;
}
else
{
messagebox("Ban da huy qua trinh cap nhat thong tin.", YES, displayLC);
return;
}
}
messagebox("Khong tim thay voi ma nhan vien tuong ung.", YES, displayLC);
return;
}
}
List_Clear(listLC);
List_Clear(title);
}
void employees_Show(LIST_EMPLOYEES le, LIST_MATERIAL lm, LOCATION displayLC)
{
LOCATION lChoose, lShow;
Size sGird;
LIST_TITLE title;
LIST_ARRAY_CHAR notify;
employees_InitTiTle(title);
LIST_LOCATION listLC;
List_InsertItem(notify, notify.size, "Employees");
List_InsertItem(notify, notify.size, "0-9, A-Z");
List_InsertItem(notify, notify.size, "Ma nhan vien khong ton tai.");
lChoose = { displayLC.x + 6, displayLC.y + 1};
lShow = { displayLC.x + 3, displayLC.y + 13};
drawBorder(listLC, lShow, le.size, 5, title);
for (int run = 0; run < le.size; run++)
{
int indexNow = run * employees_quantityFields;
gotoxy(listLC.lloca[indexNow].x, listLC.lloca[indexNow].y); BGColorText(le.arr[run].employeesCode, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 1].x, listLC.lloca[indexNow + 1].y); BGColorText(le.arr[run].familyName, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 2].x, listLC.lloca[indexNow + 2].y); BGColorText(le.arr[run].firstName, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLC.lloca[indexNow + 3].x, listLC.lloca[indexNow + 3].y);
if (le.arr[run].sex == 0)
{
BGColorText("Nam", ColorCode_Black, ColorCode_DarkWhite);
}
else if (le.arr[run].sex == 1)
{
BGColorText("Nu", ColorCode_Black, ColorCode_DarkWhite);
}
}
if (le.size == 0)
{
sGird = { 64, 20 };
}
else
{
sGird = { (listLC.lloca[listLC.size - 1].x + title.ltitle[title.size - 1].width) - displayLC.x, (listLC.lloca[listLC.size - 1].y + 5) - displayLC.y };
}
drawBox(displayLC, sGird, "Danh Sach Nhan Vien");
//action
while (true)
{
STR codeBill;
NBD bd = NULL;
LIST_BILL lb; dslk_Initialize(lb);
codeBill = dis_chooseViewDetail(lb, bd, le, lChoose, sGird.width, notify, 1);
if (strcmp(codeBill.str, "DONE") == 0)
{
break;
}
else
{
//show
for (int run = 0; run < le.size; run++)
{
if (strcmp(codeBill.str, le.arr[run].employeesCode) == 0)
{
//show bill
LIST_BILL lbill;
lbill.pHead = le.arr[run].list_Bill;
LOCATION lcShow;
lcShow = {displayLC.x + sGird.width + 3, displayLC.y};
bill_Show(lbill, lm, lcShow);
dis_Clear(lcShow, {70, 40});
}
}
}
}
List_Clear(listLC);
List_Clear(title);
}