-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sursa_finala.cpp
2052 lines (1939 loc) · 54.8 KB
/
Sursa_finala.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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <string>
#include <chrono>
int locuri_ocupate[4];
int verificari[10];
char* _strrev_(char* nume)
{
int i = 0;
char aux;
for (i = 0;i < strlen(nume) / 2;i++)
{
aux = nume[i];
nume[i] = nume[strlen(nume) - 1 - i];
nume[strlen(nume) - 1 - i] = aux;
}
return nume;
}
char* _strlwr_(char* nume)
{
int i = 0;
for (i = 0;i < strlen(nume);i++)
if (nume[i] >= 'A' && nume[i] <= 'Z')
nume[i] = nume[i] + 32;
return nume;
}
//verifica_adresa, verifica_nume_prenume - pentru a verifica daca prenumele, adresa si numele tuturor sunt caractere alfanumerice specifice
int cauta_duplicat(int n, long long id)
{
char g[10], s[100];
int i, j;
long long id_prov = 0;
switch (n)
{
case 1:
strcpy(g, "grupa1");
break;
case 2:
strcpy(g, "grupa2");
break;
case 3:
strcpy(g, "grupa3");
break;
}
std::ifstream fin(g);
while (fin.getline(s, 100))
{
id_prov = 0;
for (j = 0;j < strlen(s);j++)
if (s[j] == '|')
break;
else
{
id_prov = id_prov * 10 + s[j] - '0';
}
if (id_prov == id)
return 1;
}
return 0;
}
int verifica_adresa(char a[45])
{
int i = 0;
if (strlen(a) > 45)
return 0;
for (i = 0;i < strlen(a);i++)
if (!((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= '0'&&a[i] <= '9') || a[i] == '.' || a[i] == ',' || a[i] == ' ' || a[i] == '-'))
return 0;
return 1;
}
int verifica_nume_prenume(char a[45])
{
int i = 0;
if (strlen(a) > 25)
return 0;
for (i = 0;i < strlen(a);i++)
if (!((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') || a[i] == ' ' || a[i] == '-'))
return 0;
return 1;
}
int verificare_varsta(int varsta)
{
if (varsta < 0 || varsta >= 7)
return 0;
return 1;
}
int stabilire_grupa(int varsta)
{
if (varsta < 2)
return 1;
if (varsta < 4)
return 2;
return 3;
}
int verificare_disponibilitate_grupa(int n)
{
if (locuri_ocupate[n]<25)
return 1;
return 0;
}
void initializeza_locuri_gradinita()
{
int nr;
std::ifstream fin("nrcopiigrupe");
if (fin.good())
{
nr = 0;
fin >> nr;
locuri_ocupate[1] = nr;
nr = 0;
fin >> nr;
locuri_ocupate[2] = nr;
nr = 0;
fin >> nr;
locuri_ocupate[3] = nr;
}
else locuri_ocupate[1] = locuri_ocupate[2] = locuri_ocupate[3] = 0;
}
void refacere_fisier_nr_locuri()
{
std::ofstream fout("nrcopiigrupe");
fout << locuri_ocupate[1] << '\n' << locuri_ocupate[2] << '\n' << locuri_ocupate[3] << '\n';
}
void calculeaza_id(long long &id, char nume[30], char prenume[30], int varsta, char adresa[45], char nume_mama[30], char nume_tata[30], int valid)
{
//initializez locurile ocupate
initializeza_locuri_gradinita();
//initial -1, copilul nu poate fi inscris
id = -1;
//initializez verifica
int j = 0;
for (j = 0;j < 8;j++)
verificari[j] = 0;
verificari[8] = 1;
//fac verificarile de baza
if (verifica_nume_prenume(nume) == 1)
verificari[1] = 1;
if (verifica_nume_prenume(prenume) == 1)
verificari[2] = 1;
if (verifica_nume_prenume(nume_mama) == 1)
verificari[5] = 1;
if (verifica_nume_prenume(nume_tata) == 1)
verificari[6] = 1;
if (verificare_varsta(varsta) == 1)
verificari[3] = 1;
if (verifica_adresa(adresa) == 1)
verificari[4] = 1;
if (valid == 1)
{
if (verificare_disponibilitate_grupa(stabilire_grupa(varsta)) == 1)
verificari[7] = 1;
}
else verificari[7] = 1;
int i = 1, ok = 1;
for (i = 1;i < 8;i++)
if (verificari[i] == 0)
{
ok = 0;
break;
}
//daca totul e ok, pot inscrie copilul, deci creez id
if (ok == 1)
{
verificari[0] = 1;
id = 0;
id = id * 100 + nume[0] - '0';
id = id * 100 + nume[1] - '0';
id = id * 100 + prenume[0] - '0';
id = id * 100 + prenume[1] - '0';
id = id * 10 + varsta;
id = id * 100 + nume_mama[0] - '0';
id = id * 100 + nume_mama[1] - '0';
id = id * 100 + nume_tata[0] - '0';
id = id * 100 + nume_tata[1] - '0';
id = id * 10 + stabilire_grupa(varsta);
}
//verific duplicat
if (valid == 1)
{
if (cauta_duplicat(stabilire_grupa(varsta), id) == 1)
{
verificari[8] = 0;
id = -1;
}
else verificari[8] = 1;
}
}
int verifica_varsta_char(char varsta[4])
{
int i = 0;
if (strlen(varsta) > 2)
return 0;
for (i = 0;i < strlen(varsta);i++)
if (!(varsta[i] >= '0'&&varsta[i] <= '9'))
return 0;
return 1;
}
HWND hnume, hprenume, hvarsta, hadresa, hnume_mama, hnume_tata;
HWND login_window, main_window, logs_window, register_window, view_window, search_window, edit_window, delete_window, editbox_window;
HWND logs_listbox, view_combobox, view_listbox;
HWND search_textbox, search_listbox, search_combobox;
HWND delete_listbox;
HWND edit_listbox;
HWND editboxnume, editboxprenume, editboxvarsta, editboxadresa, editboxnume_mama, editboxnume_tata;
WNDCLASSEX mainw, logsw, registerw, vieww, searchw, editw, deletew, editboxw, loginw;
HINSTANCE hInst;
int showcmd;
int calculare_xpos(int a)
{
return (GetSystemMetrics(SM_CXSCREEN) - a) / 2;
}
int calculare_ypos(int a)
{
return (GetSystemMetrics(SM_CYSCREEN) - a) / 2;
}
void afisare_logs()
{
std::ifstream fin("logs");
long long maxlong = 0;
SIZE lungime;
char s[1000];
if (fin.good())
{
while (fin.getline(s, 999))
{
GetTextExtentPoint32A(GetDC(logs_listbox), s, strlen(s), &lungime);
if (lungime.cx > maxlong)
maxlong = lungime.cx;
SendMessageA(logs_listbox, LB_ADDSTRING, 0, (LPARAM)s);
}
}
else SendMessageA(logs_listbox, LB_ADDSTRING, 0, (LPARAM) "Nu exista evenimente de afisat! (Fisierul logs inexistent!)");
fin.close();
SendMessageA(logs_listbox, LB_SETHORIZONTALEXTENT, maxlong + 10, 0);
int lbn = SendMessage(logs_listbox, LB_GETCOUNT, 0, 0);
SendMessage(logs_listbox, LB_SETTOPINDEX, (WPARAM)lbn - 1, 0);
}
void delete_logs()
{
int result;
result = MessageBoxA(logs_window, "Sunteti sigur ca doriti stergerea fisierului logs?", "Delete Logs!", MB_YESNO | MB_TOPMOST | MB_ICONWARNING);
switch (result)
{
case IDYES:
remove("logs");
SendMessage(logs_listbox, LB_RESETCONTENT, 0, 0);
MessageBoxA(logs_window, "Fisierul a fost sters cu succes!", "Done!", MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
SendMessage(logs_listbox, LB_ADDSTRING, 0, (LPARAM)L"Nimic de afisat. Fisierul logs sters!");
//ShowWindow(main_window, 5);
//DestroyWindow(logs_window);
break;
case IDNO:
break;
}
}
void printare_in_logs(char s[500])
{
std::ofstream fout;
fout.open("logs", std::ofstream::app);
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
fout << /*"<"<<*/ asctime(timeinfo) << "< " << s << ";> \n";
fout.close();
}
int tabnr;
HWND b1, b2, b3, b4, b5, b6, b7, b8;
LRESULT CALLBACK WND_Main_Window(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CHAR:
{
/*if (wParam == VK_ESCAPE)
{
remove("temp");
DestroyWindow(main_window);
}*/
}
case WM_CREATE:
CreateWindow("Button", "Inregistreaza copil", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 100, 200, 30, hwnd, (HMENU)0, 0, 0);
CreateWindow("Button", "Vizualizare grupe", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 150, 200, 30, hwnd, (HMENU)1, 0, 0);
CreateWindow("Button", "Cauta o inregistrare", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 200, 200, 30, hwnd, (HMENU)2, 0, 0);
CreateWindow("Button", "Editeaza o inregistrare", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 250, 200, 30, hwnd, (HMENU)3, 0, 0);
CreateWindow("Button", "Sterge o inregistrare", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 300, 200, 30, hwnd, (HMENU)4, 0, 0);
CreateWindow("Button", "Logs", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 350, 200, 30, hwnd, (HMENU)5, 0, 0);
CreateWindow("Button", "Exit!", WS_VISIBLE | WS_BORDER | WS_CHILD, 40, 400, 200, 30, hwnd, (HMENU)6, 0, 0);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 0:
{
int x = 400;
int y = 300;
register_window = CreateWindow("Register_Window", "Inregistrare Copil", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(register_window, 5);
UpdateWindow(register_window);
}
break;
case 1:
{
int x = 800;
int y = 600;
view_window = CreateWindow("View_Window", "Vizualizare grupe", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(view_window, 5);
UpdateWindow(view_window);
}
break;
case 2:
{
int x = 800;
int y = 600;
search_window = CreateWindow("Search_Window", "Cauta o inregistrare", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(search_window, 5);
UpdateWindow(search_window);
}
break;
case 3:
{
int x = 800;
int y = 600;
edit_window = CreateWindow("Edit_Window", "Editeaza o inregistrare", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(edit_window, 5);
UpdateWindow(edit_window);
}
break;
case 4:
{
int x = 800;
int y = 600;
delete_window = CreateWindow("Delete_Window", "Sterge o inregistrare", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(delete_window, 5);
UpdateWindow(delete_window);
}
break;
case 5:
{
int x = 800;
int y = 600;
logs_window = CreateWindow("Logs_Window", "Logs", WS_SYSMENU | WS_MINIMIZEBOX, calculare_xpos(x), calculare_ypos(y), x, y, HWND_DESKTOP, 0, 0, 0);
ShowWindow(main_window, 0);
ShowWindow(logs_window, showcmd);
UpdateWindow(logs_window);
}
break;
case 6:
remove("temp");
exit(0);
break;
}
break;
case WM_CLOSE:
remove("temp");
DestroyWindow(main_window);
break;
case WM_DESTROY:
remove("temp");
PostQuitMessage(0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 100, 10, " Welcome! ", strlen(" Welcome! "));
TextOut(hDC, 0, 30, " Acesta este meniul aplicatiei Management! ", strlen(" Acesta este meniul aplicatiei Management! "));
TextOut(hDC, 40, 50, " Va rugam selectati o optiune! ", strlen(" Va rugam selectati o optiune! "));
EndPaint(hwnd, &ps);
return 0;
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
LRESULT CALLBACK WND_Logs_Window(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CHAR:
{
if (wParam == VK_ESCAPE)
{
ShowWindow(main_window, 5);
DestroyWindow(logs_window);
}
break;
}
case WM_CREATE:
logs_listbox = CreateWindow("ListBox", "", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | LBS_DISABLENOSCROLL, 20, 30, 740, 460, hwnd, 0, 0, 0);
CreateWindow("Button", "Delete Logs", WS_VISIBLE | WS_BORDER | WS_CHILD, 100, 500, 200, 30, hwnd, (HMENU)1, 0, 0);
CreateWindow("Button", "Back", WS_VISIBLE | WS_BORDER | WS_CHILD, 500, 500, 200, 30, hwnd, (HMENU)2, 0, 0);
afisare_logs();
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 1:
{
delete_logs();
}
break;
case 2:
{
ShowWindow(main_window, 5);
DestroyWindow(logs_window);
}
break;
default:
break;
}
break;
case WM_CLOSE:
{
ShowWindow(main_window, 5);
DestroyWindow(logs_window);
}
break;
case WM_DESTROY:
//PostQuitMessage(0);
break;
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
LRESULT CALLBACK WND_Register_Window(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CHAR:
{
if (wParam == VK_ESCAPE)
{
ShowWindow(main_window, 5);
DestroyWindow(register_window);
}
if (wParam == VK_TAB)
{
}
break;
}
case WM_CREATE:
hnume = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 150, 10, 200, 20, hwnd, 0, 0, 0);
hprenume = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 150, 40, 200, 20, hwnd, 0, 0, 0);
hvarsta = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 150, 70, 200, 20, hwnd, 0, 0, 0);
hadresa = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 150, 100, 200, 20, hwnd, 0, 0, 0);
hnume_mama = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 150, 130, 200, 20, hwnd, 0, 0, 0);
hnume_tata = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 150, 160, 200, 20, hwnd, 0, 0, 0);
CreateWindow("Button", "Cancel", WS_BORDER | WS_CHILD | WS_VISIBLE, 232, 200, 100, 30, hwnd, (HMENU)1, 0, 0);
CreateWindow("Button", "Inregistreaza", WS_BORDER | WS_CHILD | WS_VISIBLE, 66, 200, 100, 30, hwnd, (HMENU)2, 0, 0);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 1:
ShowWindow(main_window, 5);
DestroyWindow(register_window);
break;
case 2:
{
char nume[30], prenume[30], adresa[45], nume_mama[30], nume_tata[30], varsta[30];
int varsta_int;
int gwtstat1 = 0, gwtstat2 = 0, gwtstat3 = 0, gwtstat4 = 0, gwtstat5 = 0, gwtstat6 = 0;
gwtstat1 = GetWindowTextA(hnume, nume, 24);
gwtstat2 = GetWindowTextA(hprenume, prenume, 24);
gwtstat3 = GetWindowTextA(hvarsta, varsta, 24);
gwtstat4 = GetWindowTextA(hadresa, adresa, 44);
gwtstat5 = GetWindowTextA(hnume_mama, nume_mama, 24);
gwtstat6 = GetWindowTextA(hnume_tata, nume_tata, 24);
if (gwtstat1 == 0 || gwtstat2 == 0 || gwtstat3 == 0 || gwtstat4 == 0 || gwtstat5 == 0 || gwtstat6 == 0)
MessageBoxA(0, "Toate campurile trebuiesc completate!", "Eroare!", MB_OK | MB_ICONWARNING);
else if (verifica_varsta_char(varsta) == 1)
{
long long id = 0;
varsta_int = atoi(varsta);
calculeaza_id(id, nume, prenume, varsta_int, adresa, nume_mama, nume_tata, 1);
if (id == -1)
{
int i;
for (i = 1;i < 9;i++)
if (verificari[i] == 0)
break;
switch (i)
{
case 1:
{
MessageBoxA(0, "Nume invalid! Trebuie sã contina doar litere!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 2:
{
MessageBoxA(0, "Prenume invalid! Trebuie sã contina doar litere!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 3:
{
MessageBoxA(0, "Varsta invalida! Varsta trebuie sa fie intre 0 si 7 ani!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 4:
{
MessageBoxA(0, "Adresa invalida! Poate sa contina doar litere, cifre, punct, virgula, cratima!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 5:
{
MessageBoxA(0, "Numele mamei invalid! Trebuie sã contina doar litere!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 6:
{
MessageBoxA(0, "Numele tatalui invalid! Trebuie sã contina doar litere!", "Error!", MB_OK | MB_ICONWARNING);
}
break;
case 7:
{
MessageBoxA(0, "Nu este loc disponibil in grupa pentru a inscrie copilul!", "Error!", MB_OK | MB_ICONWARNING);
ShowWindow(main_window, 5);
DestroyWindow(register_window);
}
break;
case 8:
{
MessageBoxA(0, "Copilul este deja inscris!", "Error!", MB_OK | MB_ICONWARNING);
ShowWindow(main_window, 5);
DestroyWindow(register_window);
}
break;
}
}
else
{
int sigur = MessageBoxA(0, "Sunteti sigur ca doriti sa inscrieti copilul?", "Confirmare inregistrare!", MB_YESNO | MB_ICONQUESTION);
switch (sigur)
{
case IDYES:
{
int nr;
switch (stabilire_grupa(varsta_int))
{
case 1:
{
locuri_ocupate[1]++;
std::ofstream fout;
fout.open("grupa1", std::ofstream::app);
fout << id << "|" << nume << "|" << prenume << "|" << varsta << "|" << adresa << "|" << nume_mama << "|" << nume_tata << '\n';
MessageBoxA(0, "Copil inregistrat cu succes in grupa 1!", "Inregistrare cu succes!", MB_OK | MB_ICONINFORMATION);
}
break;
case 2:
{
locuri_ocupate[2] ++;
std::ofstream fout;
fout.open("grupa2", std::ofstream::app);
fout << id << "|" << nume << "|" << prenume << "|" << varsta << "|" << adresa << "|" << nume_mama << "|" << nume_tata << '\n';
MessageBoxA(0, "Copil inregistrat cu succes in grupa 2!", "Inregistrare cu succes!", MB_OK | MB_ICONINFORMATION);
}
break;
case 3:
{
locuri_ocupate[3]++;
std::ofstream fout;
fout.open("grupa3", std::ofstream::app);
fout << id << "|" << nume << "|" << prenume << "|" << varsta << "|" << adresa << "|" << nume_mama << "|" << nume_tata << '\n';
MessageBoxA(0, "Copil inregistrat cu succes in grupa 3!", "Inregistrare cu succes!", MB_OK | MB_ICONINFORMATION);
}
break;
}
std::ofstream fout;
fout.open("copii", std::ofstream::app);
fout << id << "|" << nume << "|" << prenume << "|" << varsta << "|" << adresa << "|" << nume_mama << "|" << nume_tata << "|" << stabilire_grupa(varsta_int) << '\n';
fout.close();
refacere_fisier_nr_locuri();
fout.open("logs", std::ofstream::app);
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
fout << /*"<"<<*/ asctime(timeinfo) << "< " << ": [RegisterEvent]: " << nume << " " << prenume << " cu id: " << id << " a fost inregistrat in grupa: " << stabilire_grupa(varsta_int) << ";> \n";
fout.close();
ShowWindow(main_window, 5);
DestroyWindow(register_window);
}
break;
case IDNO:
break;
}
}
}
else MessageBoxA(0, "Varsta trebuie sa contina maxim 2 cifre!", "Eroare!", MB_OK | MB_ICONWARNING);
}
break;
}
break;
case WM_CLOSE:
ShowWindow(main_window, 5);
DestroyWindow(register_window);
break;
case WM_DESTROY:
//PostQuitMessage(0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 10, 12, "Nume: ", strlen("Nume: "));
TextOut(hDC, 10, 42, "Prenume: ", strlen("Prenume: "));
TextOut(hDC, 10, 72, "Varsta: ", strlen("Varsta: "));
TextOut(hDC, 10, 102, "Adresa: ", strlen("Adresa: "));
TextOut(hDC, 10, 132, "Numele mamei: ", strlen("Numele mamei: "));
TextOut(hDC, 10, 162, "Numele tatalui: ", strlen("Numele tatalui: "));
EndPaint(hwnd, &ps);
return 0;
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int nr_copii_grupe[4];
void add_combobox()
{
SendMessage(view_combobox, CB_ADDSTRING, 0, (LPARAM)"Grupa 1");
SendMessage(view_combobox, CB_ADDSTRING, 0, (LPARAM)"Grupa 2");
SendMessage(view_combobox, CB_ADDSTRING, 0, (LPARAM)"Grupa 3");
SendMessage(view_combobox, CB_ADDSTRING, 0, (LPARAM)"Total");
}
void initializare_nr_copii(int &ok)
{
std::ifstream fin("nrcopiigrupe");
int nr;
int r = 0;
ok = 1;
nr_copii_grupe[1] = nr_copii_grupe[2] = nr_copii_grupe[3] = 0;
if (fin.good())
{
while (fin >> nr)
{
r++;
nr_copii_grupe[r] = nr;
}
}
else ok = 0;
if (nr_copii_grupe[1] == 0 && nr_copii_grupe[2] == 0 && nr_copii_grupe[3] == 0)
ok = 0;
}
void view_initial()
{
int ok;
initializare_nr_copii(ok);
if (ok == 1)
SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM) "Va rugam sa selectati modul de afisare dorit!");
else SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM) "Nu exista copii inscrisi la gradinita!");
}
void construire_sir_afisari(char s[300], char d[300])
{
char *p;
char sep[] = "|";
char sir[100][200];
p = strtok(s, sep);
int i = 0;
while (p != NULL)
{
strcpy(sir[i], p);
i++;
p = strtok(NULL, sep);
}
strcpy(d, "- ");
strcat(d, sir[1]);
strcat(d, " ");
strcat(d, sir[2]);
strcat(d, ", ");
strcat(d, sir[3]);
strcat(d, " ani"/*, adresa: "*/); //modificari 2 ianuarie 04:31
//strcat(d, sir[4]);
strcat(d, /*" */", id: ");
strcat(d, sir[0]);
d[strlen(d)] = NULL;
}
void afisare_grupe()
{
char a[500], d[500];
char s[300];
int id;
int ok1, ok2;
ok2 = 1;
SendMessage(view_listbox, LB_RESETCONTENT, 0, 0);
id = SendMessage(view_combobox, CB_GETCURSEL, 0, 0);
SendMessageA(view_combobox, CB_GETLBTEXT, id, (LPARAM)a);
initializare_nr_copii(ok1);
if (strcmp(a, "Grupa 1") == 0)
{
if (nr_copii_grupe[1] != 0)
strcpy(d, "grupa1");
else ok2 = 0;
}
else if (strcmp(a, "Grupa 2") == 0)
{
if (nr_copii_grupe[2] != 0)
strcpy(d, "grupa2");
else ok2 = 0;
}
else if (strcmp(a, "Grupa 3") == 0)
{
if (nr_copii_grupe[3] != 0)
strcpy(d, "grupa3");
else ok2 = 0;
}
else if (strcmp(a, "Total") == 0)
{
if (nr_copii_grupe[1] != 0 || nr_copii_grupe[2] != 0 || nr_copii_grupe[3] != 0)
strcpy(d, "copii");
else ok2 = 0;
}
else strcpy(d, "a");
if (ok2 == 0)
strcpy(d, "abcde");
std::ifstream fin(d);
if (strlen(d) > 3)
{
if (ok1 == 1)
{
if (fin.good())
{
if (strcmp(a, "Total") != 0)
strcat(a, " are urmatorii copii inscrisi:");
else strcat(a, " copii inscrisi: ");
SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM)a);
while (fin.getline(s, 300))
{
char d[300];
construire_sir_afisari(s, d);
SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM)d);
}
}
else SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM) "Nu exista copii inscrisi in grupa curent selectata!");
}
else SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM) "Nu exista copii inscrisi la gradinita!");
}
else SendMessageA(view_listbox, LB_ADDSTRING, 0, (LPARAM) "Nu ati selectat corect modul de afisare dorit!");
}
LRESULT CALLBACK WND_View_Window(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CHAR:
{
if (wParam == VK_ESCAPE)
{
ShowWindow(main_window, 5);
DestroyWindow(view_window);
}
break;
}
case WM_CREATE:
view_combobox = CreateWindow("Combobox", "", WS_BORDER | WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_DROPDOWNLIST | CBS_HASSTRINGS, 10, 10, 200, 100, hwnd, (HMENU)4, 0, 0);
view_listbox = CreateWindow("Listbox", "", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | LBS_DISABLENOSCROLL, 10, 40, 760, 480, hwnd, 0, 0, 0);
CreateWindow("Button", "View", WS_BORDER | WS_VISIBLE | WS_CHILD, 225, 10, 70, 20, hwnd, (HMENU)2, 0, 0);
CreateWindow("Button", "Back", WS_BORDER | WS_VISIBLE | WS_CHILD, 350, 515, 70, 20, hwnd, (HMENU)3, 0, 0);
add_combobox();
view_initial();
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 2:
afisare_grupe();
break;
case 3:
ShowWindow(main_window, 5);
DestroyWindow(view_window);
break;
default:
break;
}
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
{
if (LOWORD(wParam) == 4)
afisare_grupe();
}
break;
}
break;
case WM_CLOSE:
ShowWindow(main_window, 5);
DestroyWindow(view_window);
break;
case WM_DESTROY:
//PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int nrcopiitotal;
void initializare_search_combo_list()
{
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Nume");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Prenume");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "ID");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Nume mama");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Nume tata");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Varsta");
SendMessageA(search_combobox, CB_ADDSTRING, 0, (LPARAM) "Grupa");
SendMessageA(search_listbox, LB_ADDSTRING, 0, (LPARAM) "Selectati un parametru de cautare si introduceti termenul de cautat!");
}
struct copil
{
long long id;
char nume[25];
char prenume[25];
char adresa[45];
int varsta;
char nume_mama[25];
char nume_tata[25];
int grupa;
}copil[76];
void construire_struct()
{
std::ifstream fin("copii");
char s[300], *p, sep[] = "|";
int i = 0;
while (fin.getline(s, 299))
{
p = strtok(s, sep);
copil[i].id = atoll(p);
p = strtok(NULL, sep);
strcpy(copil[i].nume, p);
p = strtok(NULL, sep);
strcpy(copil[i].prenume, p);
p = strtok(NULL, sep);
copil[i].varsta = atoi(p);
p = strtok(NULL, sep);
strcpy(copil[i].adresa, p);
p = strtok(NULL, sep);
strcpy(copil[i].nume_mama, p);
p = strtok(NULL, sep);
strcpy(copil[i].nume_tata, p);
p = strtok(NULL, sep);
copil[i].grupa = atoi(p);
i++;
}
nrcopiitotal = i;
}
void debug_struct()
{
std::ofstream fout("temp");
int j = 0;
for (j = 0;j < nrcopiitotal;j++)
fout << copil[j].id << '\n';
}
struct printchar
{
char print[300];
};
printchar construire_print(int i)
{
printchar a;
char varsta[2], grupa[2];
char idchar[100];
long long id_long;
int j;
j = 0;
id_long = copil[i].id;
while (id_long > 0)
{
idchar[j] = (char)(id_long % 10 + '0');
id_long = id_long / 10;
j++;
}
grupa[0] = (char)(copil[i].grupa + '0');
grupa[1] = NULL;
idchar[j] = NULL;
_strrev_(idchar);
varsta[0] = (char)(copil[i].varsta + '0');
varsta[1] = NULL;
strcpy(a.print, "- ");
strcat(a.print, "ID: ");
strcat(a.print, idchar);
strcat(a.print, ", Nume: ");
strcat(a.print, copil[i].nume);
strcat(a.print, ", Prenume: ");
strcat(a.print, copil[i].prenume);
strcat(a.print, ", Grupa: ");
strcat(a.print, grupa);
strcat(a.print, ", Varsta: ");
strcat(a.print, varsta);
strcat(a.print, ", Adresa: ");
strcat(a.print, copil[i].adresa);
strcat(a.print, ", Numele mamei: ");
strcat(a.print, copil[i].nume_mama);
strcat(a.print, ", Numele tatalui: ");
strcat(a.print, copil[i].nume_tata);
return a;
}
void itemsearch(char* parametru, char* searchtext, int &ok, SIZE &lungimepixeli, long &maxlong, int i, int permite)
{
if (permite == 1)
_strlwr_(parametru);
if (strstr(parametru, _strlwr_(searchtext)) != 0)
{
ok = 1;
printchar a;
a = construire_print(i);
GetTextExtentPoint32A(GetDC(search_listbox), a.print, strlen(a.print), &lungimepixeli);
if (lungimepixeli.cx > maxlong)
maxlong = lungimepixeli.cx;
SendMessageA(search_listbox, LB_ADDSTRING, 0, (LPARAM)a.print);
}
}
void search_procedure()
{
construire_struct();
int gwtstats = 0;
char searchtext[45];
gwtstats = GetWindowTextA(search_textbox, searchtext, 45);
if (gwtstats == 0)
MessageBoxA(0, "Nu ati completat cuvantul de cautat!", "Error!", MB_OK | MB_ICONWARNING);
else
{
SIZE lungimepixeli;