-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
1482 lines (1318 loc) · 51.9 KB
/
Copy pathSource.cpp
File metadata and controls
1482 lines (1318 loc) · 51.9 KB
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
#include <windows.h>
#include <fstream>
#include "resource.h"
#include <stdlib.h>
#include <commctrl.h>
#include <vector>
#include <algorithm>
#include <ctime>
#include <string>
#include <cstdio>
struct nodo_doctor {
char cedula[10];
char namedoc[30];
char user[20];
char password[12];
char foto[MAX_PATH];
nodo_doctor* ant;
nodo_doctor* sig;
};
struct nodo_clients {
char date[20]; // La fecha debe ser una cadena con formato "DD/MM/AAAA"
char hour[10]; // La hora debe ser una cadena con formato "HH:MM"
char nameclient[30];
char phone[15];
char pettype[15];
char namepet[15];
char motive[50];
char total[10];
char status[15];
nodo_clients* ant;
nodo_clients* sig;
};
nodo_doctor* lista_doctores = nullptr;
nodo_clients* lista_clientes = nullptr;
nodo_clients* lista_auxiliar;
nodo_clients* modificar;
nodo_doctor* aux = 0, * prim = 0, * ult = 0;
nodo_clients* auxiliar = 0, * primero = 0, * ultimo = 0;
//Ventanas
LRESULT CALLBACK AltaCitas(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EliminarCita(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ModificarCita(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ModificarAltaCita(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK FiltrarCita(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK VenInfoDocModif(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK VenAgenda(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK VenInfoDoc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK VenMenu(HWND, UINT, WPARAM, LPARAM);//Ventana menu inicio
LRESULT CALLBACK VenInicioSesion(HWND, UINT, WPARAM, LPARAM);
//Prototipo extras funciones
void agregarcliente(nodo_clients* nuevoCliente);
void eliminarcliente(char NomElim[50]);
void busquedaNom(char NomModif[50]);
void busquedaFechas(char fechaInicio[11], char fechaFin[11]);
void agregardoc(nodo_doctor* aux);
bool compararFechas(tm fecha1, tm fecha2);
//Prototipos leer y escribir archivo
void leer_info_doctor(const char* archivo);
void escribir_info_doctor(const char* archivo);
void leer_info_citas(const char* archivo);
void escribir_info_citas(const char* archivo);
//Prototipos tiempo
tm obtenerFechaHoraActual();
tm convertirSystemTimeATm(const SYSTEMTIME& st);
time_t convertirFechaATime(const char* fecha);
//Leer archivo datos del doctor
void leer_info_doctor(const char* archivo) {
std::ifstream arch_doctor;
arch_doctor.open(archivo, std::ios::binary);
if (arch_doctor.is_open()) {
nodo_doctor* nuevo_doctor = new nodo_doctor;
arch_doctor.read(reinterpret_cast<char*>(nuevo_doctor), sizeof(nodo_doctor));
while (!arch_doctor.eof()) {
agregardoc(nuevo_doctor);
nuevo_doctor = new nodo_doctor;
arch_doctor.read(reinterpret_cast<char*>(nuevo_doctor), sizeof(nodo_doctor));
}
arch_doctor.close();
}
else {
}
}
//Escribir archivo datos del doctor
void escribir_info_doctor(const char* archivo) {
std::ofstream arch_doctor;
arch_doctor.open(archivo, std::ios::trunc | std::ios::binary);
if (arch_doctor.is_open()) {
// Recorrer toda la lista ligada, nodo por nodo
nodo_doctor* aux = lista_doctores;
while (aux != nullptr) {
// Guardar en el archivo cada nodo
arch_doctor.write(reinterpret_cast<char*>(aux), sizeof(nodo_doctor));
// Leer el siguiente nodo
aux = aux->sig;
}
arch_doctor.close();
}
else {
}
}
void agregardoc(nodo_doctor* aux) {
aux->ant = 0;
aux->sig = 0;
if (lista_doctores == 0) {
lista_doctores = aux;
}
else
{
ult->sig = aux;
aux->ant = ult;
}
ult = aux;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, PSTR cmdLine, int cShow)
{
//Al inicio lee los archivos de la información del doctor y las citas
leer_info_doctor("arch_doctores.dat");
leer_info_citas("arch_citas.dat");
HWND hInicioSesion = CreateDialog(hInst, MAKEINTRESOURCE(INICIARSESION), NULL, VenInicioSesion);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
ShowWindow(hInicioSesion, cShow);
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Antes de salir, guarda la información del doctor
escribir_info_doctor("arch_doctores.dat");
return 0;
}
//VENTANA INICIARSESION-------------------------------------------------------------------------------------------------------------------------
const char usuario_predefinido[] = "Veterinario";
const char contrasena_predefinida[] = "progra123*";
LRESULT CALLBACK VenInicioSesion(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg)
{
case WM_CLOSE:
{
int respuesta = MessageBox(hwnd, "¿Deseas cerrar el programa?", "Confirmacion", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
}
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
}break;
case WM_COMMAND:
{
if (LOWORD(wParam) == BTN_INGRESAR_ISESION && HIWORD(wParam) == BN_CLICKED) {
HWND hUsuario = GetDlgItem(hwnd, BTN_USUARIO_ISESION);
int usuariolenght = GetWindowTextLength(hUsuario);
char buffer[256];
GetWindowText(hUsuario, buffer, sizeof(buffer));
HWND hContrasena = GetDlgItem(hwnd, BTN_CONTRA_ISESION);
int contralenght = GetWindowTextLength(hContrasena);
char buffer1[256];
GetWindowText(hContrasena, buffer1, sizeof(buffer1));
if (usuariolenght < 4) {
MessageBox(hwnd, "El nombre de usuario debe tener mínimo 4 caracteres", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
}
if (contralenght != 10 || strcmp(buffer1, contrasena_predefinida) != 0) {
MessageBox(hwnd, "La contraseña debe ser 'progra123*'", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
}
if (4 <= usuariolenght && contralenght == 10 && strcmp(buffer, usuario_predefinido) == 0) {
// Usuario y contraseña correctos
EndDialog(hwnd, 0);
HWND hMenu = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(MENU_INICIO), hwnd, VenMenu);
ShowWindow(hMenu, SW_SHOW);
}
else {
MessageBox(hwnd, "Usuario o contraseña incorrectos", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
}
}
}
}
return FALSE;
}
//VENTANA MENU_INICIO-------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK VenMenu(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg)
{
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_INFODOC_INICIO && HIWORD(wParam) == BN_CLICKED) //Botón información del doctor
{
EndDialog(hwnd, 0);
HWND hInfoDoctor = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(INFO_DOC), hwnd, VenInfoDoc);
ShowWindow(hInfoDoctor, SW_SHOW); //Cierra el menú y muestra la ventana de información del doctor
}
if (LOWORD(wParam) == BTN_MANEJOC_INICIO && HIWORD(wParam) == BN_CLICKED) // Botón manejo de citas
{
EndDialog(hwnd, 0);
HWND hCitas = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(A_CITA), hwnd, AltaCitas);
ShowWindow(hCitas, SW_SHOW); //Cierra el menú y muestra la ventana para dar de alta citas
}
if (LOWORD(wParam) == BTN_AGENDA_INICIO && HIWORD(wParam) == BN_CLICKED) //Botón agenda
{
EndDialog(hwnd, 0);
HWND hAgenda = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hAgenda, SW_SHOW); //Cierra el menú y muestra la ventana agenda
}
if (LOWORD(wParam) == BTN_SALIR_INICIO && HIWORD(wParam) == BN_CLICKED) //Botón salir
{
int respuesta = MessageBox(hwnd, "El programa esta por cerrarse, ¿deseas continuar?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
}
}
return FALSE;
}
//VENTANA INFO_DOC-------------------------------------------------------------------------------------------------------------------------
void ActualizarInfoDoc(HWND hwnd, nodo_doctor* infoActualizada) {
HWND hNomDoc = GetDlgItem(hwnd, BTN_NOMBRE_ID);
HWND hCedulaProf = GetDlgItem(hwnd, BTN_CEDULA_ID);
HWND hUsu = GetDlgItem(hwnd, BTN_CLAVE_ID);
HWND hContra = GetDlgItem(hwnd, BTN_CONTRA_ID);
SetWindowText(hNomDoc, infoActualizada->namedoc);
SetWindowText(hCedulaProf, infoActualizada->cedula);
SetWindowText(hUsu, infoActualizada->user);
SetWindowText(hContra, infoActualizada->password);
}
LRESULT CALLBACK VenInfoDoc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg)
{
case WM_INITDIALOG: {
aux = lista_doctores;
if (aux != nullptr) {
// Hay al menos un doctor registrado
HWND hNomDoc = GetDlgItem(hwnd, BTN_NOMBRE_ID);
HWND hCedulaProf = GetDlgItem(hwnd, BTN_CEDULA_ID);
HWND hUsu = GetDlgItem(hwnd, BTN_CLAVE_ID);
HWND hContra = GetDlgItem(hwnd, BTN_CONTRA_ID);
SetWindowText(hNomDoc, aux->namedoc);
SetWindowText(hCedulaProf, aux->cedula);
SetWindowText(hUsu, aux->user);
SetWindowText(hContra, aux->password);
}
else {
}
} break;
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_MANEJOC_ID && HIWORD(wParam) == BN_CLICKED) // Botón manejo de citas
{
EndDialog(hwnd, 0);
HWND hCitas = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(A_CITA), hwnd, AltaCitas);
ShowWindow(hCitas, SW_SHOW); //Cierra la ventana y abre manejo de citas
}
if (LOWORD(wParam) == BTN_AGENDA_ID && HIWORD(wParam) == BN_CLICKED) //Botón agenda
{
EndDialog(hwnd, 0);
HWND hAgenda = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hAgenda, SW_SHOW); //Cierra la ventana y abre la agenda
}
if (LOWORD(wParam) == BTN_SALIR_ID && HIWORD(wParam) == BN_CLICKED) //Botón salir
{
int respuesta = MessageBox(hwnd, "El programa esta por cerrarse, ¿deseas continuar?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
if (LOWORD(wParam) == BTN_EDITINFO_ID && HIWORD(wParam) == BN_CLICKED) //Botón editar info del doctor
{
EndDialog(hwnd, 0);
HWND hInfoDocModif = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(INFO_DOC_EDIT), hwnd, VenInfoDocModif);
ShowWindow(hInfoDocModif, SW_SHOW); //Cierra la ventana y abre para editar la info del doctor
}
}break;
}
return FALSE;
}
///VENTANA INFO_DOC_EDIT-------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK VenInfoDocModif(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg)
{
case WM_INITDIALOG: {
nodo_doctor* inicio = aux;
aux = lista_doctores;
if (aux == NULL) {
// No hay doctor registrado, permitir ingresar la información
}
else {
HWND hNomDocModif = GetDlgItem(hwnd, BTN_NOMBRE_IDE);
HWND hCedulaProfModif = GetDlgItem(hwnd, BTN_CEDULA_IDE);
HWND hUsuModif = GetDlgItem(hwnd, BTN_CLAVE_IDE);
HWND hContraModif = GetDlgItem(hwnd, BTN_CONTRA_IDE);
while (aux != nullptr) {
SetWindowText(hNomDocModif, aux->namedoc);
SetWindowText(hCedulaProfModif, aux->cedula);
SetWindowText(hUsuModif, aux->user);
SetWindowText(hContraModif, aux->password);
aux = aux->sig;
}
aux = inicio;
}
} break;
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_MANEJOC_IDE && HIWORD(wParam) == BN_CLICKED) // Botón manejo de citas
{
EndDialog(hwnd, 0);
HWND hCitas = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(A_CITA), hwnd, AltaCitas);
ShowWindow(hCitas, SW_SHOW);
}
if (LOWORD(wParam) == BTN_AGENDA_IDE && HIWORD(wParam) == BN_CLICKED) //Botón agenda
{
EndDialog(hwnd, 0);
HWND hAgenda = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hAgenda, SW_SHOW);
}
if (LOWORD(wParam) == BTN_SALIR_IDE && HIWORD(wParam) == BN_CLICKED) //Botón salir
{
int respuesta = MessageBox(hwnd, "El programa esta por cerrarse, ¿deseas continuar?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
if (LOWORD(wParam) == BTN_GUARDAR_IDE && HIWORD(wParam) == BN_CLICKED)
{
HWND hNomDoc = GetDlgItem(hwnd, BTN_NOMBRE_IDE);
char NombreDoctor[30];
GetWindowText(hNomDoc, NombreDoctor, sizeof(NombreDoctor));
// Validación: el nombre del doctor no puede contener números
bool contieneNumeros = false;
for (int i = 0; NombreDoctor[i] != '\0'; ++i) {
if (isdigit(NombreDoctor[i])) {
contieneNumeros = true;
break;
}
}
if (contieneNumeros) {
MessageBox(hwnd, "El nombre del doctor no puede contener números", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
return FALSE; // No continuar con el proceso de guardado
}
HWND hCedula = GetDlgItem(hwnd, BTN_CEDULA_IDE);
char cedprof[10];
GetWindowText(hCedula, cedprof, sizeof(cedprof));
HWND hUsuarioMod = GetDlgItem(hwnd, BTN_CLAVE_IDE);
char usumod[20];
GetWindowText(hUsuarioMod, usumod, sizeof(usumod));
HWND hContraMod = GetDlgItem(hwnd, BTN_CONTRA_IDE);
char contramod[20];
GetWindowText(hContraMod, contramod, sizeof(contramod));
if (aux == nullptr) {
// No hay doctor registrado, permitir ingresar la información y agregarla a la lista
nodo_doctor* docmodif = new nodo_doctor();
strcpy_s(docmodif->namedoc, NombreDoctor);
strcpy_s(docmodif->cedula, cedprof);
strcpy_s(docmodif->user, usumod);
strcpy_s(docmodif->password, contramod);
ActualizarInfoDoc(GetParent(hwnd), docmodif);
agregardoc(docmodif);
// Guardar la información actualizada en el archivo
escribir_info_doctor("arch_doctores.dat");
MessageBox(hwnd, "Informacion guardada con exito", "", MB_OK);
}
else {
// Elimina el nodo existente y crea uno nuevo con la información modificada
delete aux;
aux = new nodo_doctor();
strcpy_s(aux->namedoc, NombreDoctor);
strcpy_s(aux->cedula, cedprof);
strcpy_s(aux->user, usumod);
strcpy_s(aux->password, contramod);
// Guardar la información actualizada en el archivo
escribir_info_doctor("arch_doctores.dat");
MessageBox(hwnd, "Información guardada con éxito", "", MB_OK);
EndDialog(hwnd, 0);
HWND hMenu = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(MENU_INICIO), hwnd, VenMenu);
ShowWindow(hMenu, SW_SHOW);
}
}
} break;
}
return FALSE;
}
///VENTANA AGENDA-------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK VenAgenda(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
nodo_clients* busqueda = 0;
switch (msg)
{
case WM_INITDIALOG: {
int idx = 0;
HWND hListaCitas = GetDlgItem(hwnd, LISTA_CITAS_AGENDA);
auxiliar = lista_clientes;
if (auxiliar == NULL)
{
SendMessage(hListaCitas, LB_ADDSTRING, 0, (LPARAM)"NO HAY NINGUNA CITA AGENDADA");
}
else {
while (auxiliar != 0) {
// Convierte la fecha a time_t
time_t fechaCita = convertirFechaATime(auxiliar->date);
// Obtener la fecha y hora actuales
time_t fechaHoraActual = time(0);
if (fechaCita != -1 && fechaCita >= fechaHoraActual) {
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Fecha:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->date);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Hora:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->hour);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Cliente:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->nameclient);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Teléfono:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->phone);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Especie de la mascota:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->pettype);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Mascota:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->namepet);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Motivo:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->motive);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Total:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->total);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"Estatus:");
SendDlgItemMessage(hwnd, LISTA_CITAS_AGENDA, LB_ADDSTRING, idx, (LPARAM)auxiliar->status);
SendMessage(hListaCitas, LB_ADDSTRING, idx, (LPARAM)"\n");
idx++;
}
auxiliar = auxiliar->sig;
}
}
}break;
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_INFODOC_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hInfoDoctor = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(INFO_DOC), hwnd, VenInfoDoc);
ShowWindow(hInfoDoctor, SW_SHOW);
}
if (LOWORD(wParam) == BTN_MANEJOC_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hCitas = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(A_CITA), hwnd, AltaCitas);
ShowWindow(hCitas, SW_SHOW);
}
if (LOWORD(wParam) == BTN_ELIMINARC_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hEliminarCita = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(ELIMINARCITA), hwnd, EliminarCita);
ShowWindow(hEliminarCita, SW_SHOW);
}
if (LOWORD(wParam) == BTN_MODIFICARC_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hModificarCita = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(PRE_MODIFCITA), hwnd, ModificarCita);
ShowWindow(hModificarCita, SW_SHOW);
}
if (LOWORD(wParam) == BTN_FILTRADO_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hFiltrado = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(FILTRADO), hwnd, FiltrarCita);
ShowWindow(hFiltrado, SW_SHOW);
}
if (LOWORD(wParam) == BTN_SALIR_AGENDA && HIWORD(wParam) == BN_CLICKED)
{
int respuesta = MessageBox(hwnd, "El programa esta por cerrarse, ¿deseas continuar?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
}break;
}
return FALSE;
}
///VENTANA A_CITAS-------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK AltaCitas(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG: {
char perro[] = "Perro";
char gato[] = "Gato";
char ave[] = "Ave";
char otra[] = "Otra";
char estatusP[] = "Pendiente";
char estatusE[] = "Efectuada";
char estatusC[] = "Cancelada";
HWND hListaMascotas = GetDlgItem(hwnd, COMBO_ESPECIE_ACITA); //Opciones tipo de mascota
SendMessage(hListaMascotas, CB_ADDSTRING, NULL, (LPARAM)perro);
SendMessage(hListaMascotas, CB_ADDSTRING, NULL, (LPARAM)gato);
SendMessage(hListaMascotas, CB_ADDSTRING, NULL, (LPARAM)ave);
SendMessage(hListaMascotas, CB_ADDSTRING, NULL, (LPARAM)otra);
HWND hEstatus = GetDlgItem(hwnd, BTN_ESTATUS_ACITA); //Opciones estatus
SendMessage(hEstatus, CB_ADDSTRING, NULL, (LPARAM)estatusP);
SendMessage(hEstatus, CB_ADDSTRING, NULL, (LPARAM)estatusE);
SendMessage(hEstatus, CB_ADDSTRING, NULL, (LPARAM)estatusC);
}break;
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_INFODOC_ACITA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hInfoDoctor = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(INFO_DOC), hwnd, VenInfoDoc);
ShowWindow(hInfoDoctor, SW_SHOW);
}
if (LOWORD(wParam) == BTN_AGENDA_ACITA && HIWORD(wParam) == BN_CLICKED)
{
EndDialog(hwnd, 0);
HWND hCitas = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hCitas, SW_SHOW);
}
if (LOWORD(wParam) == BTN_GUARDAR_ACITA && HIWORD(wParam) == BN_CLICKED)
{
bool validardatos = true;
bool validarnom = true;
bool validarcelular = true;
bool validarnombremascota = true;
bool validarcosto = true;
//Obtener la fecha
HWND hFecha = GetDlgItem(hwnd, IDC_FECHA_ACITA);
SYSTEMTIME stFecha;
ZeroMemory(&stFecha, sizeof(stFecha));
SendMessage(hFecha, DTM_GETSYSTEMTIME, 0, (LPARAM)&stFecha);
// Obtener la hora
HWND hHora = GetDlgItem(hwnd, IDC_HORA_ACITA);
SYSTEMTIME stHora;
ZeroMemory(&stHora, sizeof(stHora));
SendMessage(hHora, DTM_GETSYSTEMTIME, 0, (LPARAM)&stHora);
char FechaCita[100];
sprintf_s(FechaCita, "%02d/%02d/%d", stFecha.wDay, stFecha.wMonth, stFecha.wYear);
char HoraCita[100];
sprintf_s(HoraCita, "%02d:%02d", stHora.wHour, stHora.wMinute);
// Obtener la fecha y hora actual
tm fechaHoraActual = obtenerFechaHoraActual();
// Comparar la fecha seleccionada con la fecha actual
if (compararFechas(fechaHoraActual, convertirSystemTimeATm(stFecha))) {
MessageBox(hwnd, "No se puede agendar una cita con fecha anterior a la actual", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
HWND hNombreCliente = GetDlgItem(hwnd, BTN_NOMBRE_ACITA);
char nomcliente[50];
GetWindowText(hNombreCliente, nomcliente, sizeof(nomcliente));
int nomlong = GetWindowTextLength(hNombreCliente);
if (nomlong == 0) { //Si no contiene nada el editcontrol da un avisp
MessageBox(hwnd, "Debe registrar un nombre", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
for (int i = 0; i < nomlong; i++) {
if (isalpha(nomcliente[i])); //Busca letras caracter por caracter
{
validarnom = true;
validardatos = true;
}
if (isdigit(nomcliente[i])) { //Busca numeros en el nombre
validarnom = false;
validardatos = false; //Si encuentra un número el bool será falso y no dejará guardar la información
}
}
if (validarnom == false) {
MessageBox(hwnd, "El nombre del cliente solo acepta letras", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
break;
}
HWND hTelefono = GetDlgItem(hwnd, BTN_TELEFONO_ACITA);
char telefono[15];
GetWindowText(hTelefono, telefono, sizeof(telefono));
int digitos = GetWindowTextLength(hTelefono); //Obtener la cantidad de dígitos del celular
if (digitos != 10)
{
MessageBox(hwnd, "El telefono debe tener 10 digitos", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
for (int i = 0; i < digitos; i++) {
if (isalpha(telefono[i])); //Busca letras caracter por caracter
{
validarcelular = false; //Si encuentra una letra el bool será falso y no dejará guardar la información
validardatos = false;
}
if (isdigit(telefono[i])) { //Valida que haya números
validarcelular = true;
validardatos = true;
}
}
if (validarcelular == false) {
MessageBox(hwnd, "El telefono solo acepta numeros", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
break;
}
HWND hEspecieMascota = GetDlgItem(hwnd, COMBO_ESPECIE_ACITA);
char TipoMascota[30];
GetWindowText(hEspecieMascota, TipoMascota, sizeof(TipoMascota));
int EspecieMascotaLong = SendMessage(hEspecieMascota, CB_GETCURSEL, 0, 0); //Obtener el texto del combobox
if (EspecieMascotaLong == CB_ERR) { //Validar que si el combobox no tiene nada arroje un messagebox
MessageBox(hwnd, "Seleccione el tipo de mascota", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
HWND hNombreMascota = GetDlgItem(hwnd, BTN_MASCOTA_ACITA);
char nommascota[50];
GetWindowText(hNombreMascota, nommascota, sizeof(nommascota));
int mascotalong = GetWindowTextLength(hNombreMascota);
if (mascotalong == 0) { //Si no contiene nada el editcontrol da un aviso
MessageBox(hwnd, "Debe registrar el nombre de la mascota", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
for (int i = 0; i < mascotalong; i++) {
if (isalpha(nommascota[i])); //Busca letras carcater por caracter
{
validarnombremascota = true;
validardatos = true;
}
if (isdigit(nommascota[i])) { //Busca números en el nombre
validarnombremascota = false;
validardatos = false; //Si encuentra un número el bool será falso y no dejará guardar la información
}
}
if (validarnombremascota == false) {
MessageBox(hwnd, "El nombre de la mascota solo acepta letras", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
break;
}
HWND hConsulta = GetDlgItem(hwnd, BTN_MOTIVO_ACITA);
char consulta[100];
GetWindowText(hConsulta, consulta, sizeof(consulta));
int consultalong = GetWindowTextLength(hConsulta);
if (consultalong == 0)
{
MessageBox(hwnd, "Ingrese el motivo de la consulta", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
HWND hCosto = GetDlgItem(hwnd, BTN_COSTO_ACITA);
char costo[20];
GetWindowText(hCosto, costo, sizeof(costo));
int costolong = GetWindowTextLength(hCosto);
if (costolong == 0)
{
MessageBox(hwnd, "Ingrese un precio", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
for (int i = 0; i < costolong; i++) {
if (isalpha(costo[i])); //Busca letras caracter por caracter
{
validarcosto = false; //Si encuentra una letra el bool será falso y no dejará guardar la información
validardatos = false;
}
if (isdigit(costo[i])) { //Valida que haya números
validarcosto = true;
validardatos = true;
}
}
if (validarcosto == false) {
MessageBox(hwnd, "El costo solo acepta numeros", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
break;
}
HWND hEstatusConsu = GetDlgItem(hwnd, BTN_ESTATUS_ACITA);
char ConsultaEst[30];
GetWindowText(hEstatusConsu, ConsultaEst, sizeof(ConsultaEst));
int EstatusConsLong = SendMessage(hEstatusConsu, CB_GETCURSEL, 0, 0); //Obtener el texto del combobox
if (EstatusConsLong == CB_ERR) { //Validar que si el combobox no tiene nada arroje un messagebox
MessageBox(hwnd, "Seleccione el estatus de la consulta", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
validardatos = false;
break;
}
if (validardatos == true) { //Valida si los datos ingresados son correctos
nodo_clients* cliente = new nodo_clients();
strcpy_s(cliente->date, FechaCita);
strcpy_s(cliente->hour, HoraCita);
strcpy_s(cliente->nameclient, nomcliente);
strcpy_s(cliente->phone, telefono);
strcpy_s(cliente->pettype, TipoMascota);
strcpy_s(cliente->namepet, nommascota);
strcpy_s(cliente->motive, consulta);
strcpy_s(cliente->total, costo);
strcpy_s(cliente->status, ConsultaEst);
agregarcliente(cliente);
escribir_info_citas("arch_citas.dat");
MessageBox(hwnd, "Informacion guardada con exito", "", MB_OK);
SendMessage(hFecha, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hHora, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hNombreCliente, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hTelefono, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hEspecieMascota, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hNombreMascota, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hConsulta, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hCosto, WM_SETTEXT, 0, (LPARAM)"");
SendMessage(hEstatusConsu, WM_SETTEXT, 0, (LPARAM)"");
EndDialog(hwnd, 0);
HWND hMenu = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(MENU_INICIO), hwnd, VenMenu);
ShowWindow(hMenu, SW_SHOW);
}
}
if (LOWORD(wParam) == BTN_SALIR_ACITA && HIWORD(wParam) == BN_CLICKED)
{
int respuesta = MessageBox(hwnd, "El programa esta por cerrarse, ¿deseas continuar?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
}break;
}
return FALSE;
}
bool compararFechas(tm fecha1, tm fecha2) {
if (fecha1.tm_year != fecha2.tm_year) {
return fecha1.tm_year > fecha2.tm_year;
}
if (fecha1.tm_mon != fecha2.tm_mon) {
return fecha1.tm_mon > fecha2.tm_mon;
}
if (fecha1.tm_mday != fecha2.tm_mday) {
return fecha1.tm_mday > fecha2.tm_mday;
}
if (fecha1.tm_hour != fecha2.tm_hour) {
return fecha1.tm_hour > fecha2.tm_hour;
}
return fecha1.tm_min > fecha2.tm_min;
}
// Función para obtener la fecha y hora actual
tm obtenerFechaHoraActual() {
time_t tiempoActual;
time(&tiempoActual);
tm resultado;
localtime_s(&resultado, &tiempoActual);
return resultado;
}
tm convertirSystemTimeATm(const SYSTEMTIME& st) {
tm resultado;
resultado.tm_sec = st.wSecond;
resultado.tm_min = st.wMinute;
resultado.tm_hour = st.wHour;
resultado.tm_mday = st.wDay;
resultado.tm_mon = st.wMonth - 1; // tm_mon es de 0 a 11
resultado.tm_year = st.wYear - 1900; // tm_year es el año desde 1900
resultado.tm_isdst = -1; // -1 indica que el horario de verano es desconocido
return resultado;
}
time_t convertirFechaATime(const char* fecha) {
// Asumiendo que la fecha tiene el formato "DD/MM/YYYY"
int day, month, year;
if (sscanf_s(fecha, "%d/%d/%d", &day, &month, &year) == 3) {
tm tmFecha = {};
tmFecha.tm_mday = day;
tmFecha.tm_mon = month - 1; // Ajustar el mes
tmFecha.tm_year = year - 1900; // Ajustar el año
return std::mktime(&tmFecha);
}
return -1;
}
void agregarcliente(nodo_clients* auxiliar) {
auxiliar->ant = nullptr;
auxiliar->sig = nullptr;
if (lista_clientes == nullptr) {
// La lista está vacía, asigna el nuevo cliente como el primero
lista_clientes = auxiliar;
ultimo = auxiliar;
}
else {
// Buscar la posición correcta para insertar según la fecha y hora
nodo_clients* actual = lista_clientes;
while (actual != nullptr) {
tm fechaHoraActual, fechaHoraAuxiliar;
// Convertir cadenas de fecha y hora a estructuras tm
sscanf_s(actual->date, "%d/%d/%d", &fechaHoraActual.tm_mday, &fechaHoraActual.tm_mon, &fechaHoraActual.tm_year);
sscanf_s(actual->hour, "%d:%d", &fechaHoraActual.tm_hour, &fechaHoraActual.tm_min);
sscanf_s(auxiliar->date, "%d/%d/%d", &fechaHoraAuxiliar.tm_mday, &fechaHoraAuxiliar.tm_mon, &fechaHoraAuxiliar.tm_year);
sscanf_s(auxiliar->hour, "%d:%d", &fechaHoraAuxiliar.tm_hour, &fechaHoraAuxiliar.tm_min);
// Comparar las fechas y horas utilizando la función de comparación personalizada
if (compararFechas(fechaHoraActual, fechaHoraAuxiliar)) {
break;
}
actual = actual->sig;
}
if (actual == nullptr) {
// El nuevo cliente tiene la fecha y hora más grandes, al final
ultimo->sig = auxiliar;
auxiliar->ant = ultimo;
ultimo = auxiliar;
}
else {
// Insertar el nuevo cliente antes del cliente actual
auxiliar->sig = actual;
auxiliar->ant = actual->ant;
if (actual->ant != nullptr) {
actual->ant->sig = auxiliar;
}
else {
// El nuevo cliente será el primero de la lista
lista_clientes = auxiliar;
}
actual->ant = auxiliar;
}
}
}
//Escribir archivo de citas
void escribir_info_citas(const char* archivo) {
std::ofstream arch_citas;
arch_citas.open(archivo, std::ios::trunc | std::ios::binary);
if (arch_citas.is_open()) {
nodo_clients* aux = lista_clientes;
while (aux != nullptr) {
// Guardar en el archivo cada nodo
arch_citas.write(reinterpret_cast<char*>(aux), sizeof(nodo_clients));
// Leer el siguiente nodo
aux = aux->sig;
}
arch_citas.close();
}
else {
MessageBox(nullptr, "Error al abrir el archivo para escribir.", "Error", MB_OK | MB_ICONERROR);
}
}
//Leer archivo de citas
void leer_info_citas(const char* archivo) {
std::ifstream arch_citas;
arch_citas.open(archivo, std::ios::binary);
if (arch_citas.is_open()) {
nodo_clients* nuevo_cliente = new nodo_clients;
arch_citas.read(reinterpret_cast<char*>(nuevo_cliente), sizeof(nodo_clients));
while (!arch_citas.eof()) {
nodo_clients* aux = new nodo_clients;
aux = nuevo_cliente;
agregarcliente(aux);
nuevo_cliente = new nodo_clients;
arch_citas.read(reinterpret_cast<char*>(nuevo_cliente), sizeof(nodo_clients));
}
arch_citas.close();
}
else {
MessageBox(nullptr, "Error al abrir el archivo para leer.", "Error", MB_OK | MB_ICONERROR);
}
}
///VENTANA ELIMINARCITA-------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK EliminarCita(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg)
{
case WM_COMMAND: {
if (LOWORD(wParam) == BTN_DELETE && HIWORD(wParam) == BN_CLICKED)
{
HWND hElimCita = GetDlgItem(hwnd, IDC_ELIMCITA);
char NomElim[50];
GetWindowText(hElimCita, NomElim, sizeof(NomElim));
int ElimLong = GetWindowTextLength(hElimCita);
if (ElimLong == 0) {
MessageBox(hwnd, "Debes introducir un nombre", "ADVERTENCIA", MB_OK | MB_ICONWARNING);
}
else
{
eliminarcliente(NomElim);
escribir_info_citas("arch_citas.dat");
EndDialog(hwnd, 0);
HWND hAgenda = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hAgenda, SW_SHOW);
}
}
if (LOWORD(wParam) == BTN_CANCEL && HIWORD(wParam) == BN_CLICKED)
{
int respuesta = MessageBox(hwnd, "¿Deseas cancelar la operacion?", "ADVERTENCIA", MB_YESNO | MB_ICONWARNING);
if (respuesta == IDYES)
{
EndDialog(hwnd, 0);
HWND hAgenda = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(AGENDA), hwnd, VenAgenda);
ShowWindow(hAgenda, SW_SHOW); //Si se cancela la operación, vuelve a la ventana de cancelar
}
}
}break;
}
return FALSE;
}
void eliminarcliente(char NomElim[50]) {
nodo_clients* auxi1 = lista_clientes;
nodo_clients* anterior = NULL;
if (auxi1 == NULL) {
MessageBox(0, "La lista está vacía", "ERROR", MB_OK | MB_ICONERROR);
return;
}
while (auxi1 != NULL) {
if (strcmp(auxi1->nameclient, NomElim) == 0) {
if (anterior == NULL) {
lista_clientes = auxi1->sig;
if (lista_clientes != NULL) {
lista_clientes->ant = NULL;
}
}
else {
anterior->sig = auxi1->sig;
if (auxi1->sig != NULL) {
auxi1->sig->ant = anterior;
}
if (auxi1 == lista_clientes) {