-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHall_Management_System.c
1528 lines (1272 loc) · 52.8 KB
/
Hall_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
990
991
992
993
994
995
996
997
998
999
1000
/**
HALL MANAGEMENT SYSTEM
AUTHORS:
ASSWAD SARKER NOMAAN
ID: 160101006
MST. MONAKKARA BEGUM
ID: 160101026
ABDULLAH AL BAKI
ID: 160101004
CSE 3RD BATCH, BAUST
**/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct data{
int meal;
char mealday[31][7];
char room[10];
char roll[20];
char name[100];
char dept[30];
char batch[10];
char phone[20];
char district[50];
};
struct setup{
int hallcharge;
int days;
double srvcharge;
double fuel;
double fuel_std;
double meal_b;
double meal_l;
double meal_d;
double mealrate[31][3];
char mm[10];
char month[10];
char year[10];
char pass[41];
char hallname[200];
char hallname_s[200];
};
struct data std,chk,upd;
struct setup set;
char temp[6];
char temp_m[6];
void menu(void);
void add_std(void);
void modify_std(void);
void view_rooms(void);
void meal_edit(void);
void bill_info(void);
void settings(void);
void generate_html(void);
int main()
{
int i,c;
char password[41] = "";
system("color a");
printf("\n\n\t\t::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::: :::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::: HALL MANAGEMENT SYSTEM :::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::: :::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");
printf("\t\t::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n\n");
FILE *cfgfile;
cfgfile = fopen("hms_config.dat", "r");
fscanf(cfgfile, "%[^\n]", &set.pass);
fclose(cfgfile);
for(i=0;set.pass[i];i++)
set.pass[i] += 15;
printf("\t\t--> WELCOME TO HALL MANAGEMENT SYSTEM");
printf("\n\n\t\t-----> Please Enter Your Password: ");
while(strcmp(password,set.pass) != 0)
{
for(i=0;(c=getch()) != '\r';i++)
{
if(i == 40 && c != '\b')
i--;
else if(c == '\b' && i != 0)
{
printf("\b \b");
i = i-2;
}
else if(c != '\b')
{
password[i] = c;
printf("*");
}
else
i--;
}
password[i] = '\0';
if(strcmp(password,set.pass) != 0)
{
system("cls");
system("color c");
printf("\n\n\n\n\t\tWrong Password! Enter Again: ");
}
}
FILE *setfile;
setfile = fopen("hms_settings.dat", "r");
fscanf(setfile, "%s\n%s %s %s %d %d %lf %lf", &set.hallname, &set.year,&set.mm,&set.month,&set.days,&set.hallcharge,&set.srvcharge,&set.fuel);
for(i=0;i<31;i++)
fscanf(setfile, "%lf %lf %lf", &set.mealrate[i][0], &set.mealrate[i][1], &set.mealrate[i][2]);
fclose(setfile);
strcpy(set.hallname_s,set.hallname);
for(i=0;i<strlen(set.hallname_s);i++)
{
if(set.hallname_s[i] == '#')
set.hallname_s[i] =' ';
}
menu();
return 0;
}
void menu(void)
{
int choice;
system("cls");
system("color a");
printf("\t\t\t::::::::::::::::::::::::::::::::\n");
printf("\t\t\t:::: HALL MANAGEMENT SYSTEM ::::\n");
printf("\t\t\t::::::::::::::::::::::::::::::::\n\n");
printf(" %s\t\t\t\tMonth: %s-%s\n\n\n\n",set.hallname_s,set.month,set.year);
printf("\t\t1 :: Add Student\n");
printf("\t\t2 :: Modify Student Information\n");
printf("\t\t3 :: View Room Information\n");
printf("\t\t4 :: Meal Edit\n");
printf("\t\t5 :: Bill Information\n");
printf("\t\t6 :: Settings\n");
printf("\t\t0 :: Exit\n\n");
printf("\t\tEnter Choice >> ");
scanf("%d", &choice);
system("cls");
switch(choice)
{
case 1:
add_std();
break;
case 2:
modify_std();
break;
case 3:
view_rooms();
break;
case 4:
meal_edit();
break;
case 5:
bill_info();
break;
case 6:
settings();
break;
case 0:
exit(0);
break;
default:
printf("Wrong Choice.. Please Select Correct One\n");
getch();
menu();
break;
}
}
void add_std(void)
{
int i,r_count = 0;
char again = 'y';
FILE *data;
while(again == 'y' || again == 'Y')
{
printf("HALL MANAGEMENT SYSTEM >>\tADD STUDENT\n\n");
do
{
data = fopen("hms_data.dat", "r");
r_count = 0;
printf("Enter Room No: ");
scanf("%s", &std.room);
printf("\tChecking room... ");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(i=0;i<31;i++)
{
fscanf(data,"%s", &temp_m);
}
if(strcmp(std.room,chk.room) == 0)
{
r_count++;
if(r_count == 4)
break;
}
}
if(r_count >= 4)
{
printf("Room %s is Full!!\n", std.room);
}
else
printf("Free space: %d\n", 4-r_count);
fclose(data);
} while(r_count >= 4);
do
{
data = fopen("hms_data.dat", "r");
printf("Enter Student's ID/Roll: ");
scanf("%s", &std.roll);
printf("\tChecking ID... ");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(i=0;i<31;i++)
{
fscanf(data,"%s", &temp_m);
}
if(strcmp(std.roll,chk.roll) == 0)
{
printf("ID %s already exists in room %s\n", chk.roll,chk.room);
break;
}
}
fclose(data);
} while(strcmp(std.roll,chk.roll) == 0);
printf("OK\n");
printf("Enter Student Name: ");
scanf(" %[^\n]", &std.name);
printf("Enter Department: ");
scanf(" %[^\n]", &std.dept);
printf("Enter Batch: ");
scanf(" %[^\n]", &std.batch);
printf("Enter Phone no: ");
scanf(" %[^\n]", &std.phone);
printf("Enter Home District: ");
scanf(" %[^\n]", &std.district);
for(i=0;i<strlen(std.name);i++)
{
if(std.name[i] == ' ')
std.name[i] ='#';
}
data = fopen("hms_data.dat", "a");
fprintf(data,"%s %s %s %s %s %s %s meals: ", std.room, std.roll, std.name, std.dept, std.batch, std.phone, std.district);
for(i=1000;i<=31000;i=i+1000)
{
if(i<10000)
fprintf(data,"0%d ", i);
else
fprintf(data,"%d ", i);
}
fprintf(data,"\n");
fclose(data);
printf("\nAdd Success!!!!!!!!\nDo you want to add more? (y/n) >> ");
scanf(" %c", &again);
system("cls");
}
system("cls");
menu();
}
void modify_std(void)
{
FILE *data,*new_data;
int i,j,choice,confirm,flag=0;
printf("HALL MANAGEMENT SYSTEM >>\tMODIFY STUDENT INFORMATION\n\n");
printf("Enter Student ID/Roll: ");
scanf("%s", &std.roll);
printf("\tSearching ID... ");
data = fopen("hms_data.dat","r");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
if(strcmp(std.roll,chk.roll) == 0)
{
flag = 1;
for(i=0;i<strlen(chk.name);i++)
{
if(chk.name[i] == '#')
chk.name[i] =' ';
}
printf("Found!!\n\nStudent Information:\n");
printf("\tRoom No : %s\n", chk.room);
printf("\tID No : %s\n", chk.roll);
printf("\tName : %s\n", chk.name);
printf("\tDepartment : %s\n", chk.dept);
printf("\tBatch : %s\n", chk.batch);
printf("\tPhone No : %s\n", chk.phone);
printf("\tHome District : %s\n", chk.district);
break;
}
}
fclose(data);
if(flag == 1)
{
printf("\nType '1' to Edit :: '2' to Delete :: '0' to Go Back >> ");
scanf("%d", &choice);
if(choice == 1)
{
printf("\n\nEnter new Data: \n");
printf("\tRoom No : %s\n", chk.room);
printf("\tStudent Roll/ID : ");
scanf("%s", &upd.roll);
printf("\tEnter Student Name : ");
scanf(" %[^\n]", &upd.name);
printf("\tEnter Department : ");
scanf("%s", &upd.dept);
printf("\tEnter Batch : ");
scanf("%s", &upd.batch);
printf("\tEnter Phone No. : ");
scanf("%s", &upd.phone);
printf("\tEnter Home District : ");
scanf("%s", &upd.district);
for(i=0;i<strlen(upd.name);i++)
{
if(upd.name[i] == ' ')
upd.name[i] ='#';
}
data = fopen("hms_data.dat","r");
new_data = fopen("hms_data.tmp","w");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
if(strcmp(std.roll,chk.roll) == 0)
{
fprintf(new_data,"%s %s %s %s %s %s %s %s ", chk.room,upd.roll,upd.name,upd.dept,upd.batch,upd.phone,upd.district,temp);
for(j=0;j<31;j++)
{
fprintf(new_data,"%s ", chk.mealday[j]);
}
fprintf(new_data,"\n");
}
else
{
fprintf(new_data,"%s %s %s %s %s %s %s %s ", chk.room,chk.roll,chk.name,chk.dept,chk.batch,chk.phone,chk.district,temp);
for(j=0;j<31;j++)
{
fprintf(new_data,"%s ", chk.mealday[j]);
}
fprintf(new_data,"\n");
}
}
fclose(data);
fclose(new_data);
remove("hms_data.dat");
rename("hms_data.tmp","hms_data.dat");
printf("Done!\n");
}
else if(choice == 2)
{
printf("\n\t1: Confirm Delete || 0: Cancel >> ");
scanf("%d", &confirm);
if(confirm == 1)
{
data = fopen("hms_data.dat","r");
new_data = fopen("hms_data.tmp","w");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
if(strcmp(std.roll,chk.roll) == 0)
printf("Deleting Record..\n");
else
{
fprintf(new_data,"%s %s %s %s %s %s %s %s ", chk.room,chk.roll,chk.name,chk.dept,chk.batch,chk.phone,chk.district,temp);
for(j=0;j<31;j++)
{
fprintf(new_data,"%s ", chk.mealday[j]);
}
fprintf(new_data,"\n");
}
}
fclose(data);
fclose(new_data);
remove("hms_data.dat");
rename("hms_data.tmp","hms_data.dat");
printf("Done!\n");
}
}
else if(choice == 0)
menu();
else
printf("Wrong choice!!\n");
}
else
printf("Not Found!\n");
printf("Press any key to go back.");
getch();
system("cls");
menu();
}
void view_rooms(void)
{
FILE *data;
char again= 'a';
int i,j,page=1,flag;
char search_rm[10];
printf("HALL MANAGEMENT SYSTEM >>\tVIEW ROOM INFORMATION\n\n");
printf("Enter 'A' to view all rooms or Enter Room Number: ");
scanf("%s", &search_rm);
data = fopen("hms_data.dat","r");
if(strcmp(search_rm,"A") == 0 || strcmp(search_rm,"a") == 0)
{
flag = 0;
while(again != 27)
{
system("cls");
printf("Showing Result: (Page %d)\n\n", page);
printf("\tPress any key to go to next page or 'Esc' to go back\n");
printf("\n\nRoom Roll Name Dept. Batch Phone Home District\n");
for(i=0;i<20;i++)
{
if(fscanf(data,"%s %s %s %s %s %s %s %s", &std.room,&std.roll,&std.name,&std.dept,&std.batch,&std.phone,&std.district,&temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &temp_m);
}
for(j=0;j<strlen(std.name);j++)
{
if(std.name[j] == '#')
std.name[j] = ' ';
}
printf("%-7s %-13s %-27s %-7s %-7s %-14s %s\n", std.room,std.roll,std.name,std.dept,std.batch,std.phone,std.district);
}
else
{
flag=1;
break;
}
}
if(flag == 1)
{
printf("\nAll records loaded. Press any key to go back..\n");
getch();
break;
}
else
{
again = getch();
page++;
}
}
}
else
{
flag = 0;
printf("\n\nRoom Roll Name Dept. Batch Phone Home District\n");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &std.room,&std.roll,&std.name,&std.dept,&std.batch,&std.phone,&std.district,&temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &temp_m);
}
for(j=0;j<strlen(std.name);j++)
{
if(std.name[j] == '#')
std.name[j] = ' ';
}
if(strcmp(search_rm,std.room) == 0)
{
flag = 1;
printf("%-7s %-13s %-27s %-7s %-7s %-14s %s\n", std.room,std.roll,std.name,std.dept,std.batch,std.phone,std.district);
}
}
if(flag == 1)
printf("\n All records loaded. Press any key to go back..\n");
else
printf("\n Not Found!! Press any key to go back..\n");
getch();
}
fclose(data);
system("cls");
menu();
}
void meal_edit(void)
{
FILE *data,*new_data;
int i,j,check,flag=0,r_count=0,CountDay = 0, CountMeals = 0, start_date, end_date, cancel = 0;
char meal_temp[6];
printf("HALL MANAGEMENT SYSTEM >>\tMEAL ON / OFF\n\n");
printf("Enter Student's ID/Roll: ");
scanf("%s", &std.roll);
printf("\tSearching ID... ");
data = fopen("hms_data.dat","r");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
strcpy(upd.mealday[j], chk.mealday[j]);
}
if(strcmp(std.roll,chk.roll) == 0)
{
for(j=0;j<set.days;j++)
{
if(chk.mealday[j][2] == '1')
CountMeals++;
if(chk.mealday[j][3] == '1')
CountMeals++;
if(chk.mealday[j][4] == '1')
CountMeals++;
if(chk.mealday[j][2] == '1' || chk.mealday[j][3] == '1' || chk.mealday[j][4] == '1')
CountDay++;
}
flag = 1;
for(i=0;i<strlen(chk.name);i++)
{
if(chk.name[i] == '#')
chk.name[i] =' ';
}
printf("Found!!\n\nStudent Information:\n");
printf("\tRoom No : %s\n", chk.room);
printf("\tID No : %s\n", chk.roll);
printf("\tName : %s\n", chk.name);
printf("\tDepartment : %s\n", chk.dept);
printf("\tBatch : %s\n", chk.batch);
printf("\tPhone No : %s\n", chk.phone);
printf("\tHome District : %s\n\n", chk.district);
printf("\tMeal Days : %d (%d Meals)", CountDay, CountMeals);
printf(" [Month: %s-%s]\n", set.month,set.year);
printf("\n\n MEAL INFORMATION OF ID %s", std.roll);
printf("\n\n Total Meals: %d (%d Days)\n\n", CountMeals, CountDay);
printf(" Day :::: B L D\n");
for(i=0;i<set.days;i++)
printf("%3d :::: %3s %5s %5s\n", i+1, chk.mealday[i][2]=='1'?"ON":"-",chk.mealday[i][3]=='1'?"ON":"-",chk.mealday[i][4]=='1'?"ON":"-");
break;
}
}
fclose(data);
if(flag == 1)
{
printf("\n\t1 : Add/Edit Meal(s) || 0 : Cancel >> ");
scanf("%d", &check);
switch(check)
{
case 1:
printf("\n\nEnter New Meal: \n");
printf("\nEnter Start Date: ");
scanf("%d", &start_date);
if(start_date < 1 || start_date > set.days)
{
printf("Invalid Start Date\nPress any key..");
getch();
break;
}
printf("\nEnter End Date: ");
scanf("%d", &end_date);
if(start_date > set.days || end_date > set.days || end_date < start_date)
{
printf("Invalid End Date\n");
break;
}
for(i=start_date;i<=end_date;i++)
{
printf("Day %2d: ", i);
fflush(stdin);
gets(meal_temp);
if(meal_temp[0] == 'x' || meal_temp[0] == 'X' || meal_temp[1] == 'x' || meal_temp[1] == 'X' || meal_temp[2] == 'x' || meal_temp[2] == 'X')
break;
while( (meal_temp[0] < '0' || meal_temp[0] > '1' || meal_temp[1] < '0' || meal_temp[1] > '1' || meal_temp[2] < '0' || meal_temp[2] > '1') )
{
printf("\nEnter Again\n");
printf("Day %2d: ", i);
gets(meal_temp);
if(meal_temp[0] == 'x' || meal_temp[0] == 'X' || meal_temp[1] == 'x' || meal_temp[1] == 'X' || meal_temp[2] == 'x' || meal_temp[2] == 'X')
{
cancel = 1;
break;
}
}
if(cancel == 1)
break;
upd.mealday[i-1][2] = (meal_temp[0]=='1'?'1':'0');
upd.mealday[i-1][3] = (meal_temp[1]=='1'?'1':'0');
upd.mealday[i-1][4] = (meal_temp[2]=='1'?'1':'0');
}
for(i=0;i<strlen(std.name);i++)
{
if(std.name[i] == ' ')
std.name[i] ='#';
}
data = fopen("hms_data.dat","r");
new_data = fopen("hms_data.tmp","w");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
if(strcmp(std.roll,chk.roll) == 0)
{
//fprintf(new_data,"%s %s %s %s %s %s %s %d\n", chk.room,chk.roll,chk.name,chk.dept,chk.batch,chk.phone,chk.district,std.meal);
fprintf(new_data,"%s %s %s %s %s %s %s %s ", chk.room,chk.roll,chk.name,chk.dept,chk.batch,chk.phone,chk.district,temp);
for(j=0;j<31;j++)
{
fprintf(new_data,"%s ", upd.mealday[j]);
}
fprintf(new_data,"\n");
}
else
{
fprintf(new_data,"%s %s %s %s %s %s %s %s ", chk.room,chk.roll,chk.name,chk.dept,chk.batch,chk.phone,chk.district,temp);
for(j=0;j<31;j++)
{
fprintf(new_data,"%s ", chk.mealday[j]);
}
fprintf(new_data,"\n");
}
}
fclose(data);
fclose(new_data);
remove("hms_data.dat");
rename("hms_data.tmp","hms_data.dat");
printf("Done!\n");
break;
default:
menu();
break;
}
}
else
printf("Not Found!\n");
printf("\nPress any key to go back.");
getch();
system("cls");
menu();
}
void bill_info(void)
{
system("cls");
FILE *data;
char again= 'a', search_rm[10];
int i,j,page=1,flag=0, choice, CountDay = 0, CountMeals = 0;
double meal_charge, bill_srvcharge,bill_total,bill_meal;
//meal_charge = set.meal_b + set.meal_l + set.meal_d;
for(j=0;j<set.days;j++)
meal_charge += set.mealrate[j][0] + set.mealrate[j][1] + set.mealrate[j][2];
printf("HALL MANAGEMENT SYSTEM >>\tBILL INFORMATION\n\n");
printf("\t\t1 :: Show All Bills\n");
printf("\t\t2 :: Show Bill By ID\n");
printf("\t\t3 :: Show Bills By Room\n");
printf("\t\t4 :: Generate HTML\n");
printf("\t\t0 :: Back\n");
printf("\t\tEnter Choice >> ");
scanf("%d", &choice);
if(choice == 1)
{
system("cls");
flag = 0;
data = fopen("hms_data.dat","r");
while(again != 27)
{
system("cls");
printf("Showing Result: (Page %d)\n\n", page);
printf("\tPress any key to go to next page or 'Esc' to go back\n");
printf("\n\nRoom Roll Name Dept. Batch Meals Meal Charge Service Charge Fuel & Spices Hall Charge Total\n");
for(i=0;i<20;i++)
{
if(fscanf(data,"%s %s %s %s %s %s %s %s", &std.room,&std.roll,&std.name,&std.dept,&std.batch,&std.phone,&std.district,&temp) != EOF)
{
CountMeals = 0;
CountDay = 0;
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
for(j=0;j<set.days;j++)
{
if(chk.mealday[j][2] == '1')
CountMeals++;
if(chk.mealday[j][3] == '1')
CountMeals++;
if(chk.mealday[j][4] == '1')
CountMeals++;
if(chk.mealday[j][2] == '1' || chk.mealday[j][3] == '1' || chk.mealday[j][4] == '1')
CountDay++;
}
for(j=0;j<strlen(std.name);j++)
{
if(std.name[j] == '#')
std.name[j] = ' ';
}
if(CountDay == 0)
set.fuel_std = 0;
else
set.fuel_std = set.fuel;
/*bill_meal = (set.meal_b + set.meal_l + set.meal_d) * std.meal;
bill_srvcharge = bill_meal * (set.srvcharge/100);
bill_total = bill_meal + bill_srvcharge + set.fuel_std + set.hallcharge;*/
bill_meal = 0;
for(j=0;j<set.days;j++)
{
bill_meal += (chk.mealday[j][2]=='1'?set.mealrate[j][0]:0) + (chk.mealday[j][3]=='1'?set.mealrate[j][1]:0) + (chk.mealday[j][4]=='1'?set.mealrate[j][2]:0);
}
bill_srvcharge = bill_meal * (set.srvcharge/100);
bill_total = bill_meal + bill_srvcharge + set.fuel_std + set.hallcharge;
printf("%-7s %-13s %-27s %-7s %-7s %-7d %-13.2lf %-16.2lf %-15.2lf %-13d %.2lf\n", std.room, std.roll, std.name, std.dept, std.batch, CountMeals, bill_meal, bill_srvcharge, set.fuel_std, set.hallcharge, bill_total);
}
else
{
flag=1;
break;
}
}
if(flag == 1)
{
printf("\nAll records loaded. Press any key to go back..\n");
getch();
break;
}
else
{
again = getch();
page++;
}
}
fclose(data);
bill_info();
}
else if(choice == 2)
{
system("cls");
printf("Enter Student's ID/Roll: ");
scanf("%s", &std.roll);
printf("\tSearching ID... ");
data = fopen("hms_data.dat","r");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &chk.room, &chk.roll, &chk.name, &chk.dept, &chk.batch, &chk.phone, &chk.district, &temp) != EOF)
{
CountMeals = 0;
CountDay = 0;
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
for(j=0;j<set.days;j++)
{
if(chk.mealday[j][2] == '1')
CountMeals++;
if(chk.mealday[j][3] == '1')
CountMeals++;
if(chk.mealday[j][4] == '1')
CountMeals++;
if(chk.mealday[j][2] == '1' || chk.mealday[j][3] == '1' || chk.mealday[j][4] == '1')
CountDay++;
}
if(strcmp(std.roll,chk.roll) == 0)
{
flag = 1;
if(CountDay == 0)
set.fuel_std = 0;
else
set.fuel_std = set.fuel;
/*bill_meal = (set.meal_b + set.meal_l + set.meal_d) * chk.meal;
bill_srvcharge = bill_meal * (set.srvcharge/100);
bill_total = bill_meal + bill_srvcharge + set.fuel_std + set.hallcharge;*/
bill_meal = 0;
for(j=0;j<set.days;j++)
{
bill_meal += (chk.mealday[j][2]=='1'?set.mealrate[j][0]:0) + (chk.mealday[j][3]=='1'?set.mealrate[j][1]:0) + (chk.mealday[j][4]=='1'?set.mealrate[j][2]:0);
}
bill_srvcharge = bill_meal * (set.srvcharge/100);
bill_total = bill_meal + bill_srvcharge + set.fuel_std + set.hallcharge;
for(i=0;i<strlen(chk.name);i++)
{
if(chk.name[i] == '#')
chk.name[i] =' ';
}
printf("Found!!\n\nStudent Information:\n");
printf("\tRoom No : %s\n", chk.room);
printf("\tID No : %s\n", chk.roll);
printf("\tName : %s\n", chk.name);
printf("\tDepartment : %s\n", chk.dept);
printf("\tBatch : %s\n", chk.batch);
printf("\tPhone No : %s\n", chk.phone);
printf("\tHome District : %s\n\n", chk.district);
printf("\tMeal Days : %d", CountDay);
printf(" (Month: %s-%s)\n\n", set.month,set.year);
printf("Bill Information:\n");
printf("\tTotal Meals : %d\n", CountMeals);
printf("\tMeal Charge : %.2lf TK\n", bill_meal);
printf("\tService Charge : %.2lf TK\n", bill_srvcharge);
printf("\tFuel & Spices : %.2lf TK\n", set.fuel_std);
printf("\tHall Charge : %d TK\n", set.hallcharge);
printf("\tTotal : %.2lf TK\n", bill_total);
break;
}
}
fclose(data);
printf("\nDone. Press any key to go back\n");
getch();
bill_info();
}
else if(choice == 3)
{
system("cls");
flag = 0;
printf("Enter Room: ");
scanf("%s", &search_rm);
printf("\n\nRoom Roll Name Dept. Batch Meals Meal Charge Service Charge Fuel & Spices Hall Charge Total\n");
data = fopen("hms_data.dat","r");
while(fscanf(data,"%s %s %s %s %s %s %s %s", &std.room,&std.roll,&std.name,&std.dept,&std.batch,&std.phone,&std.district,&temp) != EOF)
{
CountMeals = 0;
CountDay = 0;
for(j=0;j<31;j++)
{
fscanf(data,"%s", &chk.mealday[j]);
}
for(j=0;j<set.days;j++)
{
if(chk.mealday[j][2] == '1')
CountMeals++;
if(chk.mealday[j][3] == '1')
CountMeals++;
if(chk.mealday[j][4] == '1')
CountMeals++;
if(chk.mealday[j][2] == '1' || chk.mealday[j][3] == '1' || chk.mealday[j][4] == '1')
CountDay++;
}
if(strcmp(search_rm,std.room) == 0)