-
Notifications
You must be signed in to change notification settings - Fork 1
/
Computer_Repair_Services_Management_System.c
989 lines (980 loc) · 32.7 KB
/
Computer_Repair_Services_Management_System.c
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
//Name: Abdulmalek Aldhafer
//GitHub username : akaldhafer
//Email : Ak_aldhafer@hotmail.com
//System title : Computer Repair Services Management System
#include <stdio.h> /*/ Header file for simple functions such as input and output /*/
#include <stdlib.h> /*/ header defines four variable types, several macros, and; various functions for performing general functions/*/
#include <windows.h> /*/ Header file to use windows functions like cls and pause /*/
#pragma warning (disable: 4996) /*/ To disable warning for using scanf and scanf_s/*/
/***********************************************************************************/
char v1[50] = "Remove virus, malware or spyware";
char v2[50] = "Troubleshoot and fix a computer running slow"; /*The database for the service type*/
char v3[50] = "Laptop screen replacement";
char v4[50] = "Laptop keyboard replacement";
char v5[50] = "Laptop battery replacement";
char v6[50] = "Operating System Format and Installation";
char v7[50] = "Data backup and recovery";
char v8[50] = "Internet connectivity issues";
/***********************************************************************************/
char choice;
char Cname[20];
void logIn();
void SignUp();
void MenuPage(); /*Declare the functoins*/
void adminMenu();
void service1();
void service2();
void service3();
void service4();
void service5();
void service6();
void service7();
void service8();
void visitdetail();
void NewVisit();
void viewVisit();
void searchVisit();
void All_payment();
void cancelVisit();
void updateVisit();
void updatePayment();
void updateService();
int main();
/***********************************************************************************/
struct Admin { // declare admin variables
char Username[20];
char Password[20];
}a;
/***********************************************************************************/
struct Visit
{ /*Declare visit variables*/
char VID[20];/*visit ID*/
char Vdate[20]; /*visit date*/
char CNAME[20];/*customer name*/
char CPHONE[20];/*customer phone no*/
char service_needed[50];/*the service needed*/
float service_fee; /*service fees*/
float payment_made; /*payment made*/
float unpaid;/*unpaid balance*/
}v;
/***********************************************************************************/
void service1() {
FILE* Visit = fopen("visit.txt", "a"); /*open the file in adding mode*/
strcpy(v.service_needed, v1); /*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (30Rm) 2. Urgent (50 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 30;
}
else if (choice == '2') {
v.service_fee = 50;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service1();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit); /*function to write the data to the file*/
fclose(Visit); /*close the file*/
return;
}
/***********************************************************************************/
void service2() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v2);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (40Rm) 2. Urgent (70 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 40;
}
else if (choice == '2') {
v.service_fee = 70;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service2();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service3() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v3);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (380Rm) 2. Urgent (430 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 380;
}
else if (choice == '2') {
v.service_fee = 430;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service3();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service4() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v4);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (160Rm) 2. Urgent (200 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 160;
}
else if (choice == '2') {
v.service_fee = 200;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service4();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service5() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v5);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (180Rm) 2. Urgent (210 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 180;
}
else if (choice == '2') {
v.service_fee = 210;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service5();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service6() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v6);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (50Rm) 2. Urgent (80 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 50;
}
else if (choice == '2') {
v.service_fee = 80;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service6();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service7() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v7);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (100Rm) 2. Urgent (150 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 100;
}
else if (choice == '2') {
v.service_fee = 150;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service7();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void service8() {
FILE* Visit = fopen("visit.txt", "a");/*open the file in adding mode*/
strcpy(v.service_needed, v8);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (50Rm) 2. Urgent (75 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 50;
}
else if (choice == '2') {
v.service_fee = 75;
}
else if (choice == '3') {
system("pause");
system("CLS");
NewVisit();
}
else {
system("pause");
system("CLS");
service8();
}
visitdetail();
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
printf("\n------ saving the new recode..... -----\n");
fwrite(&v, sizeof(v), 1, Visit);/*function to write the data to the file*/
fclose(Visit);
return;
}
/***********************************************************************************/
void viewVisit() {
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
printf("\n These are all the visit recodes inside the database\n");
while (fread(&v, sizeof(v), 1, Visit)) { /*while the fread is reading the visit file*/
printf("\nVisit ID : %s", v.VID); /*all visit recodes will be printed*/
printf("\nVisit Date : %s", v.Vdate);
printf("\nCustomer Name : %s", v.CNAME);
printf("\nCustomer Phone No: %s", v.CPHONE);
printf("\nService type : %s", v.service_needed);
printf("\nService fees : %.2f RM", v.service_fee);
printf("\nDue payment : %.2f RM", v.unpaid);
printf("\nPayment made : %.2f RM\n", v.payment_made);
}
if (Visit == NULL) {
printf("\n !!The file still empty...\n");
}
fclose(Visit);
return;
}
/***********************************************************************************/
void searchVisit() {
char name[20];
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
getchar();
printf("\nEnter customer name: ");
gets(name); /*get the customer name*/
while (fread(&v, sizeof(v), 1, Visit)) { /*Display the visit recode*/
if (strcmpi(v.CNAME, name) == 0) {/*if the given name is equal to any name inside the file*/
printf("\nThese are all the availalbe details: \n");
printf("\nVisit ID : %s", v.VID); /*all details of that name will be displayed*/
printf("\nVisit Date : %s", v.Vdate);
printf("\nCustomer Name : %s", v.CNAME);
printf("\nCustomer Phone No: %s", v.CPHONE);
printf("\nService type : %s", v.service_needed);
printf("\nService fees : %.2f RM", v.service_fee);
printf("\nDue payment : %.2f RM", v.unpaid);
printf("\nPayment made : %.2f RM\n", v.payment_made);
}
}
if (Visit == NULL) {
printf("\n !!The file still empty...\n");
}
fclose(Visit);
return;
}
/***********************************************************************************/
void All_payment() {
float total_unpaid = 0;
float total_paid = 0;
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
if (Visit == NULL) {
printf("\n !!The file still empty...\n");
}
while (fread(&v, sizeof(v), 1, Visit)) { /*Display the visit recode*/
total_unpaid += v.unpaid; /* add the unpaid payment of each visit to the total_unpaid variable*/
total_paid += v.payment_made;/* add the payment_made of each visit to the total_paid variable*/
}
printf("\nTotal payment made and total unpaid balance for all visits: \n\n");
printf("\nTotal payment made: %.2f RM", total_paid);
printf("\nTotal payment unpaid: %.2f RM\n\n\n", total_unpaid);
fclose(Visit);
return; /*returning to the admin menu*/
}
/***********************************************************************************/
void visitdetail() {
printf("Enter visit ID: ");
scanf("%s", &v.VID);
printf("Enter visit Date: ");
scanf("%s", &v.Vdate);
getchar();
printf("Enter customer name: ");
gets(v.CNAME);
printf("Enter customer phone No: ");
scanf("%s", &v.CPHONE);
return;
}
/***********************************************************************************/
void NewVisit() {
while (1) {
printf("\n##--------------------------------------------------------------##\n");
printf("\n Service Menu \n");
printf("\n##--------------------------------------------------------------##\n");
printf("\nNo| Service Type |Needed days");
printf("\n1.| Remove virus, malware or spyware |2 days");
printf("\n2.| Troubleshot and fix computer running slow |2 days");
printf("\n3.| Laptop screen replacement |3 days");
printf("\n4.| Laptop keyboard replacement |2 days");
printf("\n5.| Laptop battery replacement |1 day ");
printf("\n6.| Operating System Format and Installation |2 days");
printf("\n7.| Data backup and recovery |2 days");
printf("\n8.| Internet connectivity issues |1 days");
printf("\n9.| Back to the admin menu");
printf("\nEnter one choice: ");
scanf("%s", &choice);
switch (choice)
{
case'1':
service1();
break;
case'2':
service2();
break;
case'3':
service3();
break;
case'4':
service4();
break;
case'5':
service5();
break;
case'6':
service6();
break;
case'7':
service7();
break;
case'8':
service8();
break;
case'9':
system("CLS");
adminMenu();
break;
default:
printf(" /*/ You entered a wrong option ..!! /*/");
break;
}
system("pause");
system("CLS");
}
return;
}
/***********************************************************************************/
void updateService() {
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
FILE* forginal;
FILE* fnew;
getchar();
printf("\nEnter customer name: ");
gets(Cname);
while (fread(&v, sizeof(v), 1, Visit)) { /*Display the visit recode*/
if (strcmpi(v.CNAME, Cname) == 0) {
forginal = fopen("visit.txt", "r");
fnew = fopen("visitUpdate.txt", "w");
while (fread(&v, sizeof(v), 1, forginal)) {// fread my orginal file
if (strcmpi(v.CNAME, Cname) != 0) // if the given name is not equal the name in the file
fwrite(&v, sizeof(v), 1, fnew); // write the visit details to the new file
else {
printf("\nNo| Service Type |Needed days");
printf("\n1.| Remove virus, malware or spyware |2 days");
printf("\n2.| Troubleshot and fix computer running slow |2 days");
printf("\n3.| Laptop screen replacement |3 days");
printf("\n4.| Laptop keyboard replacement |2 days");
printf("\n5.| Laptop battery replacement |1 day ");
printf("\n6.| Operating System Format and Installation |2 days");
printf("\n7.| Data backup and recovery |2 days");
printf("\n8.| Internet connectivity issues |1 days");
printf("\nChoose the needed service: ");
scanf("%s", &choice);
if (choice == '1') {
strcpy(v.service_needed, v1); /*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (30Rm) 2. Urgent (50 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 30;
}
else if (choice == '2') {
v.service_fee = 50;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '2') {
strcpy(v.service_needed, v2);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (40Rm) 2. Urgent (70 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 40;
}
else if (choice == '2') {
v.service_fee = 70;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '3') {
strcpy(v.service_needed, v3);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (380Rm) 2. Urgent (430 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 380;
}
else if (choice == '2') {
v.service_fee = 430;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '4') {
strcpy(v.service_needed, v4);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (160Rm) 2. Urgent (200 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 160;
}
else if (choice == '2') {
v.service_fee = 200;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '5') {
strcpy(v.service_needed, v5);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (180Rm) 2. Urgent (210 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 180;
}
else if (choice == '2') {
v.service_fee = 210;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '6') {
strcpy(v.service_needed, v6);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (50Rm) 2. Urgent (80 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 50;
}
else if (choice == '2') {
v.service_fee = 80;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '7') {
strcpy(v.service_needed, v7);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (100Rm) 2. Urgent (150 Rm) 3. Back to service menu");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 100;
}
else if (choice == '2') {
v.service_fee = 150;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else if (choice == '8') {
strcpy(v.service_needed, v8);/*function to copy the string*/
printf("\nChoose Service fee: \n");
printf("1. Normal (50Rm) 2. Urgent (75 Rm)");
printf("\nEnter your choice: ");
scanf("%s", &choice);
if (choice == '1') {
v.service_fee = 50;
}
else if (choice == '2') {
v.service_fee = 75;
}
else {
system("pause");
system("CLS");
updateService();
}
printf("The total payment: %.2f", v.service_fee);
printf("\nEnter the payment: ");
scanf("%f", &v.payment_made);
v.unpaid = v.service_fee - v.payment_made;
printf("Due payment: %.2f", v.unpaid);
}
else {
printf("\n<< Wrong option !!! >>\n");
system("pause");
system("cls");
updateService();
}
fwrite(&v, sizeof(v), 1, fnew); // write the visit details to the new file
}
}
fclose(forginal); // close both files
fclose(fnew);
/*--------------------------------*/
forginal = fopen("visit.txt", "w"); /*rewriting the file with the updated database */
fnew = fopen("visitUpdate.txt", "r");/*openning the file in the reading mode to copy the data to the orginal file*/
while (fread(&v, sizeof(v), 1, fnew))
fwrite(&v, sizeof(v), 1, forginal);
fclose(fnew);
fclose(forginal);
printf("\n#--# The visit record updated successfully..!!! #--#\n");
}
}
fclose(Visit);
return;
}
/***********************************************************************************/
void updatePayment() {
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
FILE* forginal;
FILE* fnew;
float pay;
getchar();
printf("\nEnter customer name: ");
gets(Cname);
while (fread(&v, sizeof(v), 1, Visit)) { /*Display the visit recode*/
if (strcmpi(v.CNAME, Cname) == 0) {
forginal = fopen("visit.txt", "r");
fnew = fopen("visitUpdate.txt", "w");
while (fread(&v, sizeof(v), 1, forginal)) {// fread my orginal file
if (strcmpi(v.CNAME, Cname) != 0) // if the given name is not equal the name in the file
fwrite(&v, sizeof(v), 1, fnew); // write the visit details to the new file
else {
printf("\nThe service fees: %.2f", v.service_fee);
printf("\nThe total paid : %.2f", v.payment_made);
printf("\nThe due payment : %.2f", v.unpaid);
printf("\nEnter the payment: ");
scanf("%f", &pay);
v.unpaid -= pay;
v.payment_made += pay;
fwrite(&v, sizeof(v), 1, fnew); // write the visit details to the new file
}
}
fclose(forginal); // close both files
fclose(fnew);
/*--------------------------------*/
forginal = fopen("visit.txt", "w"); /*rewriting the file with the updated database */
fnew = fopen("visitUpdate.txt", "r");/*openning the file in the reading mode to copy the data to the orginal file*/
while (fread(&v, sizeof(v), 1, fnew))
fwrite(&v, sizeof(v), 1, forginal);
fclose(fnew);
fclose(forginal);
}
}
fclose(Visit);
printf("\n#--# The visit record updated successfully..!!! #--#\n");
return;
}
/***********************************************************************************/
void updateVisit() {
while (1) {
printf("\n##--------------------------------------------------------------##\n");
printf(" Update visit recode Menu ");
printf("\n##--------------------------------------------------------------##\n");
printf("\nNo| Update options: |");
printf("\n1.| Update service type |");
printf("\n2.| Update payment for existing visit recode |");
printf("\n3.| Back to the admin menu |\n");
printf("\nEnter one choice: ");
scanf("%s", &choice);
switch (choice)
{
case'1':
updateService();
break;
case'2':
updatePayment();
break;
case'3':
system("CLS");
adminMenu();
break;
default:
printf(" /*/ You entered a wrong option ..!! /*/");
break;
}
system("pause");
system("CLS");
}
return;
}
/***********************************************************************************/
void cancelVisit() {
FILE* Visit = fopen("visit.txt", "r"); /*opening the file on reading mode*/
FILE* forginal;
FILE* fnew;
printf("\nDeleting an existing visit recode:\n\n");
getchar();
printf("\nEnter customer name: ");
gets(Cname);/*getting the customer name to delete the recode*/
while (fread(&v, sizeof(v), 1, Visit)) {
if (strcmpi(v.CNAME, Cname) == 0) {/*comparing the names to find the needed visit recode to be deleted*/
forginal = fopen("visit.txt", "r"); /*open on reading mode to copy the data into the new file*/
fnew = fopen("visitUpdate.txt", "w"); /*open on writing mode to write the new date*/
while (fread(&v, sizeof(v), 1, forginal)) // fread my orginal file
if (strcmpi(v.CNAME, Cname) != 0) // if the given name is not equal the name in the file
fwrite(&v, sizeof(v), 1, fnew); // write the visit details to the new file
fclose(forginal); // close both files
fclose(fnew);
forginal = fopen("visit.txt", "w"); /*rewriting the file with the updated database */
fnew = fopen("visitUpdate.txt", "r");/*openning the file in the reading mode to copy the data to the orginal file*/
while (fread(&v, sizeof(v), 1, fnew))
fwrite(&v, sizeof(v), 1, forginal);
fclose(fnew); /*close both files*/
fclose(forginal);
}
}
fclose(Visit);
printf("\n#--# The visit record deleted successfully..!!! #--#\n");
return;
}
/***********************************************************************************/
void logIn() {
char Password[20]; //declare the variables
char Username[20];
int loginAttempt = 0;//the number of the available attempts
FILE* fadmin = fopen("admin.txt", "r");/*open admin File for reading mode*/
system("cls");/*clean the screen from the old function*/
printf("\n##--------------------------------------------------------------##\n");
printf("\n Sign in Page \n");
printf("\n##--------------------------------------------------------------##\n");
while (loginAttempt < 5) //while the number of the available attempts is less
{ //than five the user still can retry to login
fread(&a, sizeof(a), 1, fadmin);/*reading the admin details from the file*/
printf("\nPlease fill up the username and the password to login\n\n");
printf("\tEnter The Username: ");
scanf("%s", &Username); /*getting the admin username and the password*/
printf("\n\tEnter The Password: ");
scanf("%s", &Password);
if (strcmp(Username, a.Username) == 0 && strcmp(Password, a.Password) == 0)
{ //strcmp is string compare function
printf("\n#***# You Have Successfully Accessed... ! #***#\n\n");
fclose(fadmin);/*close admin file*/
system("pause");
system("cls"); /*clean the screen from the old function*/
adminMenu(); /*call the adminMenu function*/
break;
}
else
{
printf("\n## Wrong username or password. Please retry..!! ##\n\n");
system("pause");
system("cls");
loginAttempt++;
}
}
if (loginAttempt == 5)
{
printf("\nToo Many Login Attempts! The Program Will Now Terminate..!!!\n");
printf("\n\n##==>> Thanks For Using Our Program <<==##\n\n");
system("pause");
exit(1);
}
return;
}
/***********************************************************************************/
void SignUp()
{
FILE*fadmin = fopen("admin.txt", "a");/*opening admin File for adding mode*/
printf("\n##--------------------------------------------------------------##\n");
printf("\n Sign up page \n");
printf("\n##--------------------------------------------------------------##\n");
printf("\nPlease fill up the needed information: ");
printf("\nEnter your username: ");/*get admin username*/
scanf("%s", &a.Username);
printf("\nEnter your password: "); /*get admin password*/
scanf("%s", &a.Password);
fwrite(&a, sizeof(a), 1, fadmin); /*wirting the data into the admin file*/
fclose(fadmin); /*Close the File*/
printf("\n/*/You have successfully registered...\n");
system("pause");
system("cls");
MenuPage();/*calling MenuPage function*/
}
/***********************************************************************************/
void adminMenu() {
while (1) {
printf("\n##--------------------------------------------------------------##\n");
printf("\n Admin Menu \n");
printf(__DATE__);/*date functoin to display the current date of the device*/
printf("\n##--------------------------------------------------------------##\n");
printf("\n1. Make new visit \t2. Search visit");
printf("\n3. Update visit details \t4. View all visits");
printf("\n5. Cancel existing visit\t6. Sign out");
printf("\n7. Print total payment made and total unpaid balance for all visits.");
printf("\nEnter one choice: ");
scanf("%s", &choice);
switch (choice)
{
case'1':
system("CLS");
NewVisit();
break;
case'2':
system("CLS");
searchVisit();
break;
case'3':
system("CLS");
updateVisit();
break;
case'4':
system("CLS");
viewVisit();
break;
case'5':
system("CLS");
cancelVisit();
break;
case'6':
system("CLS");
MenuPage();
break;
case'7':
system("CLS");
All_payment();
break;
default:
printf("\n /*/ You entered a wrong option ..!! /*/\n");
break;
}
system("pause");
system("CLS");
}
return;
}
/***********************************************************************************/
void MenuPage() {
char option;
while (1) {
system("CLS");
printf("\n##--------------------------------------------------------------##\n");
printf("\n Computer/Laptop Repair Services Management System \n");
printf("\n##--------------------------------------------------------------##\n");
printf("1. Login\t2.Sign up\t3.Exit");
printf("\nEnter one option: ");
scanf("%s", &option);
switch (option){
case '1':
system("CLS");
logIn();
break;
case '2':
system("CLS");
SignUp();
break;
case '3':
exit(1);
break;
default:
printf("\n /*/ You entered a wrong option ..!! /*/\n");
system("pause");
system("CLS");
break;
}
}
return;
}
/***********************************************************************************/
int main() {
/*declare the files*/
FILE* visit = fopen("visit.txt", "a"); /*visit File*/
FILE* admin = fopen("admin.txt", "a");/*admin File*/
fclose(visit); /*Close the File*/
fclose(admin); /*Close the File*/
system("color 3"); // function to change the color
printf("\n The system is loading....\n\n");
system("pause"); /*waiting function to wait the user input*/
for (int i = 0; i < 10; i++)
{
Beep(1000, 1000); /* sound function to make a sound while the system is loading*/
printf("-->-->");
}
printf("\n\n << Done >>\n\n");
system("pause"); /*waiting function to wait the user input*/
MenuPage(); //call the menu page function
return 0; /* Return fales and close the program*/
}