-
Notifications
You must be signed in to change notification settings - Fork 0
/
Restaurant Management System.c
1352 lines (902 loc) · 31.8 KB
/
Restaurant 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
/* Restaurant Management System for Final Project */
#include<ctype.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<windows.h>
/* Constants */
#define F "\x1b[1;91m" // Red
#define G "\x1b[1;32m" // Green
#define H "\x1b[3;37m" // Italic
#define R "\x1b[0m" // Reset
#define O "\x1b[30;107m" // White Background
#define S "\x1b[2m" // Faint
#define W "\x1b[1;37m" // W
#define CLR system("cls") // Clear screen
#define SPASI printf("%s", spasi)
/*---------------------------------*/
/* Global Variables */
FILE *fp, *ft; // pointers
int jmlh_menu = 5;
bool hides = FALSE; // set
char data_user[100], order_user[100];
struct sort_f{
int s_jumlah;
int s_harga;
char s_nama[16];
}linez[128];
/* -------------------------------------------------------------------------- */
/* Function prototypes */
void intro(); void lobby(); void credits(); void header(); void credits(); void exits();
void menu(); void art(); void chinese(); void japanese(); void western();
void login(); void pembayaran(); void signup();
void edit(); void edit_menu(); void list_ord(int y);
void hide(bool hides);
void post(int x, int y);
void gotoxy(int x, int y);
void p(int x, int y, const char *format, ...);
void cursor_control(int num_options, char options[][16], void (*fns[])(void), bool callob);
void lobby_control(void (*fns[])(void));
void intro_control(void (*fns[])(void));
void food_control(int jmlh_menu, char nama_makanan[][16], int harga[], int callf);
void shp_cart(bool lizt);
void food(int jmlh_menu, char nama[][16], int harga[], int callf);
void update_food(const char *file, const char *inp_nama, int inp_jumlah, int inp_harga, bool edit);
/* --------------------------------------------------------------------------- */
/* 14 Functions dibawah ini berfungsi sebagai display output dalam program ini */
void art(){
p (22,6," _ __ __ __ ");
p (22,5,"| | /| / /__ / /______ __ _ ___ / /____ ");
p (22,4,"| |/ |/ / -_) / __/ _ \\/ ' \\/ -_) / __/ _ \\ ");
p (22,3,"|__/|__/\\__/_/\\__/\\___/_/_/_/\\__/ \\__/\\___/ ");
p (35,2," ____ _ __ ___ __ __");
p (35,1," / __/_ _____ (_) / / _ \\___ ___ / /____ ___ _________ ____ / /_");
p (35,0," _\\ \\/ // / _ \\/ / _ \\ / , _/ -_|_-</ __/ _ `/ // / __/ _ `/ _ \\/ __/");
p (35,-1,"/___/\\_,_/_//_/_/_.__/ /_/|_|\\__/___/\\__/\\_,_/\\_,_/_/ \\_,_/_//_/\\__/ ");
}
void intro(){ CLR;
art();
p (23, -5, W"[Sign Up]");
p (-15,-5, "[Login]");
p (4, -5, "[Credits]");
p (3, -8, "[Exit.]");
void (*fns[4])(void) = {signup, login, credits, exits};
intro_control(fns);
}
void lobby(){ CLR;
p (5, 6, H"Lobby-Resto"R);
p (25, 2, W"[Order Makanan]");
p (-10, 2, "[List Orderan]");
p (22, -2, "[Pembayaran]");
p (-10,-2, "[Edit]");
p (3,- 6, "[Exits]"R);
void (*fns[4])(void) = {menu, pembayaran, edit_menu, exits};
lobby_control(fns);
}
void menu(){ CLR; // Menu Option
p (5,5 , H"List Menu"R);
p (9,1 , W"[1] Chinese Food");
p (9,-2, "[2] Japanese Food");
p (9,-5, "[3] Western Food"R);
char options[3][16] = {"Chinese Food", "Japanese Food", "Western Food"};
void (*fns[3])(void) = {chinese, japanese, western};
cursor_control(3, options, fns, true); // pergi ke plihan user
}
void header(){
p (6, 9 , H"Daftar Menu"R);
p (18,-7, S"Tekan ESC untuk melihat list menu."R);
}
void chinese(){ // Chinese Menu
char nama[5][16] = {"Capcay","Wonton", "Dimsum", "Kungpao-Chicken", "Hot-Pot"};
int harga[5] = {20000, 25000, 30000, 30000, 40000};
food(jmlh_menu, nama, harga, 1);
}
void japanese(){ // Japanese Menu
char nama[5][16] = {"Onigiri","Udon", "Yakisoba", "Sushi", "Raw-Tuna"};
int harga[5] = {20000, 25000, 30000, 40000, 50000};
food(jmlh_menu, nama, harga, 2);
}
void western(){ // Western Menu
char nama[5][16] = {"Mac-N-Cheese","Spaghetti", "Aglio-Olio", "Pizza", "Rendang"};
int harga[5] = {20000, 25000, 30000, 40000, 99000};
food(jmlh_menu, nama, harga, 3);
}
void food(int jmlh_menu, char nama[][16], int harga[], int callf){ CLR;
header();
for(int i=0 ;i<jmlh_menu; i++){
p (18, 5-(2*i), "[%d] %s\n", (i+1), nama[i]);
p (-8, 5-(2*i), "Rp%d\n", harga[i]);
}
food_control(jmlh_menu, nama, harga, callf);
}
char *format_duit(int duit, char *str){
char temp[5];
if(duit<1000.00){
sprintf(str, "%d", duit);
return str;
}
format_duit(duit/1000, str);
sprintf(temp, ".%03d", duit%1000);
strcat(str,temp);
return str;
}
void waktu(int x, int y){
char jam[10], buffer[80];
time_t rawtime = time(NULL);
struct tm *timeinfo = localtime(&rawtime);
strftime(jam, sizeof(jam), "%H:%M", timeinfo);
strftime(buffer, 80, "%d/%m/%Y", timeinfo);
p (-13, x, "%s WIB ", jam);
p (-12, y, "%s ", buffer);
}
void edit_menu(){ CLR;
p (14, 3, "Pilih menu yang ingin di edit");
p (24, -1, "[Edit Data]");
p (3, -1, "[Lobby]");
p (-14, -1, "[Edit Orderann]");
int x=0;
while(1){
post(x,-2);
putchar('^');
int ch=getch();
printf("\b \b");
x += (ch==75) ? ((x==-21) ? 21 : (x==0) ? 19 : 0) :
(ch==77) ? ((x==19) ? -19 : (x==0) ? -21 : 0) : 0;
if(ch==13) break;
}
//if(x==21) edit_data();
if(x==0) lobby();
if(x==-21) shp_cart(FALSE);
}
void exits(){
p (15,-11,"\033[1;21mTerima kasih sudah berkunjung %c\n\n\n\n\n\033[7m", 2);
exit(0);
}
void credits(){ CLR; // Member group project
fp = fopen("credits.txt", "r");
if(fp==NULL){
fp=fopen("credits.txt","w");
fprintf(fp,
"Project singkat yang bertemakan Aplikasi Restaurant ini ditujukan sebagai Tugas akhir Mata Kuliah Algoritma dan Pemograman\n\n\n"
"Kami dari kelompok X yang beranggotakan\n\n"
"# Christopher Seriwijaya - 2602124644\n"
"# Edbert Purwanto - 2602063043\n"
"# Efren Christofer - 2602080320\n"
"# Mhd. Fauzan Devinto - 2602225201\n"
"# Wan Mohamad Axel Rinaldi - 2602208750\n\n\n"
" Kami ingin mengucapkan Terima kasih. ");
fclose(fp);
}
fclose(fp);
fp = fopen("credits.txt", "r");
char credit[100];
int stop=1, x=62, y=6;
while(fgets(credit, 100, fp) != NULL){
if(strstr(credit, "#") != NULL)
stop = 0;
if(strstr(credit, "kasih") != NULL)
stop = 1;
for(int i=0 ;i<strlen(credit); i++){
if(credit[i] == '\n'){
y--;
if(y<=4) x=19;
}
else if(stop==1){
p (x,y,"%c", credit[i]);
fflush(stdout);
usleep(45000);
x--;
}
else if(stop==0){
p (x,y,"%c", credit[i]);
fflush(stdout);
x--;
}
}
}
fclose(fp);
getch(); intro();
}
/* -------------------------------------------------------------------------- */
/*4 Functions dibawah ini digunakan untuk mengatur posisi cursor pada layar konsol,
termasuk menyembunyikan/menampilkan cursor dan menempatkan cursor pada posisi tertentu di layar.*/
void hide(bool hides){
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor;
cursor.dwSize = 100;
cursor.bVisible = hides;
SetConsoleCursorInfo(consoleHandle, &cursor);
}
void gotoxy(int x, int y){
COORD koordinat = {0, 0};
koordinat.X=x; koordinat.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), koordinat);
}
void post(int x, int y){
int kolom, baris;
CONSOLE_SCREEN_BUFFER_INFO posisi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &posisi);
kolom=posisi.srWindow.Right-posisi.srWindow.Left + 1;
baris=posisi.srWindow.Bottom-posisi.srWindow.Top + 1;
gotoxy(kolom/2-x,baris/2-y);
}
void p(int x, int y, const char* format, ...){
int kolomp, barisp;
char buffer[1024];
CONSOLE_SCREEN_BUFFER_INFO posisi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &posisi);
kolomp = posisi.srWindow.Right - posisi.srWindow.Left + 1;
barisp = posisi.srWindow.Bottom - posisi.srWindow.Top + 1;
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
gotoxy(kolomp / 2 - x, barisp / 2 - y);
printf("%s", buffer);
}
/* ------------------------------------------------------------------------- */
/* 4 Functions ini digunakan untuk mengontrol cursor dan membuat interaksi
dengan user saat memilih menu yang ada dalam program. */
void cursor_control(int num_options, char options[][16], void (*fns[])(void), bool callob){
int y = 1;
while(1){
post(-10, y);
putchar('<');
int ch = getch();
printf("\b \b");
y += (ch==72) ? (y==1) ? -6 : (y==-2) ? 3 : 3 :
(ch==80) ? (y==1) ? -3 : (y==-2) ? -3 : 6 : 0;
if(ch==13) break;
if(ch==27 &&callob) lobby();
}
int index = (y==1) ? 0 : (y==-2) ? 1 : 2;
fns[index]();
}
void lobby_control(void (*fns[])(void)){
int y = 2, x = 8, c = 0;
while(1){
char cursorz[4][2]={"<", ">", "v"};
post(x, y);
printf("%s",cursorz[c]);
int ch = getch();
printf("\b \b");
(ch==72) ? ((x==8 && y==-2) ? (y+=4, c=0) : (x==-8 && y==-2) ? (y+=4, c=1) : (x==0 && y==-5) ? (x-=8, y+=3, c=1) : 0) :
(ch==75) ? ((x==-8 && y==2) ? (x+=16, c=0) : (x==-8 && y==-2) ? (x+=16, c=0) : 0) :
(ch==77) ? ((x==8 && y==2) ? (x-=16, c=1) : (x==8 && y==-2) ? (x-=16, c=1) : 0) :
(ch==80) ? ((x==8 && y==2) ? (y-=4, c=0) : (x==-8 && y== 2) ? (y-=4) : ((x==8 && y==-2) || (x==-8 && y==-2)) ? (x=0, y-=3, c=2) : 0) : 0;
if(ch==13) break;
}
if(x==-8&&y==2)
shp_cart(TRUE);
else{
int index = (x==8&&y==2) ? 0 : (x==8&&y==-2) ? 1 : (x==-8&&y==-2) ? 2 : 3;
fns[index]();
}
}
void intro_control(void (*fns[])(void)){
int y = -6, x = 0;
while(1){
post(x, y);
putchar('^');
int ch = getch();
printf("\b \b");
x = (ch==75 && y==-6) ? (x==0 ? x+19 : x==-18 ? x+18 : x) : x;
x = (ch==77 && y==-6) ? (x==0 ? x-18 : x==19 ? x-19 : x) : x;
y = (ch==72 && x==0 && y==-9) ? y+3 : y;
y = (ch==80 && (x==0 || x==-18 || x==19) && y==-6) ? (x=0, y-3) : y;
if(ch == 13) break;
}
int index = (x==19&&y==-6) ? 0 : (x==-18&&y==-6) ? 1 : (x==0&&y==-6) ? 2 : 3 ;
fns[index]();
}
void food_control(int jmlh_menu, char nama_makanan[][16], int harga[], int callf){
int i, y = 5;
char jumlah[100], f_baris[128];
while(1){
post(-17, y);
putchar('<');
int ch = getch();
printf("\b \b");
y += (ch==72) ? (y>=-3 && y<5) ? 2 : -8 :
(ch==80) ? (y>-3 && y<=5) ? -2 : 8 : 0;
i = (y==5) ? 0 : (y==3) ? 1 : (y==1) ? 2 : (y==-1) ? 3 : (y==-3) ? 4 : i;
if(ch==13){
p ((strlen(nama_makanan[i])+40)/2, -7, "Berapa banyak \x1b[1;37m%s\x1b[0m yang ingin kamu beli? ", nama_makanan[i]);
scanf("%s", jumlah); getchar();
for(int i=0; i<strlen(jumlah); i++){
if(!isdigit(jumlah[i])){
p (7, -10, F"Invalid Input! "R);
getch();
callf == 1 ? chinese() : callf == 2 ? japanese() : callf == 3 ? western() : 0;
}
}
update_food(order_user, nama_makanan[i], atoi(jumlah), harga[i]*atoi(jumlah), FALSE);
p (8, -10, G"Order berhasil. "R); getch();
callf==1 ? chinese() : callf==2 ? japanese() : callf==3 ? western() : 0;
}
else if(ch==27) menu();
}
}
/* ------------------------------------------------------------------------ */
/* 5 Functions dibawah ini digunakan untuk mengecek informasi user saat proses login dan sign up,
termasuk memvalidasi nomor telepon, email dan password user */
int check_hp(char *hp){ // Phone Number Check
int valid=1;
if(hp[0]=='0' && hp[1]=='8' && (strlen(hp)==11 || strlen(hp)==12)){ // di Indo no hp pasti depannya 0*
for(int i=0 ;i<strlen(hp); i++) // panjang no hp bisa 11 / 12
if(!isdigit(hp[i])) valid = 0;
}
else valid = 0;
return valid;
}
int check_mail(char *email){ // E-mail Check
int len = strlen(email), akeong = 0, username_len = 0, domain_len = 0, titik = 0, tld = 0;
for(int i=0 ;i<len; i++){
if(email[i] == '@'){
akeong = 1;
break;
}
}
for(int i=0 ;i<len; i++){
if(email[i] =='@') break;
username_len++;
}
for(int i=len-1 ;i>=0; i--){
if(email[i] == '@') break;
domain_len++;
if(email[i]=='.')
titik=1;
if(titik && isalpha(email[i])){
tld = 1;
break;
}
}
if(len>100)
return 0;
if(!akeong)
return 0;
if(username_len==0)
return 0;
if(domain_len<5 || !titik || !tld) // Domain Lenght
return 0;
return 1;
}
int check_login(char *email, char* password) {
int check=0;
char line[200], curr_mail[100], curr_pass[100];
fp=fopen("Data.txt", "r");
while(fgets(line, 200, fp)!=NULL){
sscanf(line,"%s %s", curr_mail, curr_pass);
if(strcmp(email, curr_mail)==0&&strcmp(password,curr_pass)==0){
check = 1;
break;
}
}
fclose(fp);
return check;
}
void signup(){ CLR;
while(1){ CLR;
char nama[100], hp[13], email[100], password[100], validasi[100];
p (6,11, H"Sign-Up"R);
p (22,7, "Masukkan Nama");
p (2, 7, ": ");
scanf("%[^\n]",nama); getchar();
p (22,5, "Masukkan Nomor HP");
p (2, 5, ": ");
scanf("%[^\n]", hp); getchar();
if(!check_hp(hp)){ // check sesuai kriteria
p (22, 2, F"Nomor HP yang kamu daftarkan tidak valid. "R);
p (22,-2, S"Tekan ESC jika ingin kembali ke menu utama. "R);
if(getch()==27) break;
continue;
}
p (22,3, "Daftarkan E-mail");
p (2, 3, ": ");
scanf("%[^\n]", email); getchar();
int check_email=0;
if(!check_mail(email)){
p (22 ,0, F"E-mail yang kamu daftarkan tidak valid !"R);
p (22,-4, S"Tekan ESC jika ingin kembali ke menu utama. "R);
if(getch()==27) break;
continue;
}
fp=fopen("Data.txt", "r");
char baris_f[200], check_maill[200];
while (fgets(baris_f, 200, fp) != NULL){
sscanf(baris_f,"%s", check_maill);
if(!strcmp(email, check_maill)){
check_email = 1;
break;
}
}
fclose(fp);
if(check_email){
Sleep(1000);
p (22, 0, F"E-mail sudah digunakan, silahkan daftarkan e-mail yang lain. "R);
p (22,-4, S"Tekan ESC jika ingin kembali ke menu utama. "R);
if(getch()==27) break;
continue;
}
p (22,1, "Masukkan password");
p (2,1 , ": ");
scanf("%[^\n]",password); getchar();
int len=0, lower=0, upper=0, number=0;
for(int i=0 ;i<strlen(password); i++){
if(islower(password[i])) lower=1;
if(isupper(password[i])) upper=1;
if(isdigit(password[i])) number=1;
}
if(strlen(password)>7) len=1;
// panjang harus lebih dari 8
// harus ada nomer
// harus ada uppercase
// harus ada lowercase
if(!len||!lower||!upper||!number){// keluarin pesan error
p (22,-2, F"Password tidak valid harap masukkan ulang."R);
p (22,-4, "Password minimal harus terdiri atas :");
p (22,-6, "1. Satu Huruf Besar.");
p (22,-7, "2. Satu Huruf Kecil.");
p (22,-8, "3. Satu Angka.");
p (22,-9, "4. Memiliki panjang minimal 8 karakter.");
p (22,-12, S"Tekan S jika ingin kembali ke menu utama. "R);
if(getch()==27) break;
continue;
}
p (22,-1, "Konfirmasi password : ");
scanf("%[^\n]",validasi); getchar();
if(strcmp(password,validasi)){
p (22,-4, F"Validasi gagal, password tidak sesuai. "R);
p (22,-8, S"Tekan ESC jika ingin kembali ke menu utama. "R);
if(getch()==27) break;
continue;
}
snprintf(data_user, sizeof(data_user), "data-%s.txt", email);
snprintf(order_user, sizeof(order_user), "order-%s.txt", email);
fp = fopen(data_user, "w");
fprintf(fp,"Nama Customer : %s\nNo. HP : %s\nE-mail : %s\nPassword : %s\n\n",nama, hp, email, password);
fclose(fp);
fp = fopen(order_user, "w");
fclose(fp);
fp =fopen("Data.txt","a+");
fprintf(fp,"%s %s\n",email ,password);
fclose(fp);
Sleep(1000);
p (22,-4, G"Akun berhasil terdaftar. "R); getch();
break;
}
intro();
}
void login(){ CLR;
while(1){ CLR;
char login_password[100];
char login_email[100];
p (6,7, H"Log-In"R);
p (22,3, W"Masukkan E-mail ");
p (4, 3, ": "R);
scanf("%s", login_email); getchar();
p (22,0, W"Masukkan Password : "R);
scanf("%[^\n]", login_password); getchar();
if(!check_login(login_email, login_password)){
Sleep(1000);
p (22,-3, F"Invalid E-mail/ Password !"R);
p (22,-7, S"Tekan ESC untuk kembali ke menu ke menu utama. "R);
if(getch()==27) // asci 27 adalah esc
break; continue;
}
Sleep(1500);
snprintf(data_user, sizeof(data_user), "data-%s.txt", login_email);
snprintf(order_user, sizeof(order_user), "order-%s.txt", login_email);
p (22, -3, G"Login Berhasil. "R); getch();
lobby();
}
intro();
}
/* ------------------------------------------------------------------------- */
/* 4 Functions dibawah ini berfungsi sebagai penyortiran dan peng-update-an file user selama program berlangsung */
int compare_lines(const void *a, const void *b){
struct sort_f *line_a = (struct sort_f *)a;
struct sort_f *line_b = (struct sort_f *)b;
return line_a->s_harga - line_b->s_harga;
}
void sort_file(const char *file){
fp = fopen(file, "r");
int baris_f=0;
rewind(fp);
while(fscanf(fp, "%d %s %d", &linez[baris_f].s_jumlah, linez[baris_f].s_nama, &linez[baris_f].s_harga) == 3){
baris_f++;
}
fclose(fp);
qsort(linez, baris_f, sizeof(struct sort_f), compare_lines);
fp = fopen(file, "w");
for (int i=0 ;i<baris_f; i++) {
fprintf(fp, "%d %-16s %d\n", linez[i].s_jumlah, linez[i].s_nama, linez[i].s_harga);
}
fclose(fp);
}
void update_food(const char *file, const char *inp_nama, int inp_jumlah, int inp_harga, bool edit){
fp = fopen(file, "r+");
bool dah_ada = false;
int f_jumlah, f_harga;
char f_nama[16];
rewind(fp);
while(fscanf(fp, "%d %s %d\n", &f_jumlah, f_nama, &f_harga)==3){
if(strcmp(f_nama, inp_nama) == 0){
if(edit==TRUE){
f_jumlah = inp_jumlah;
f_harga = inp_harga;
}
else{
f_jumlah += inp_jumlah;
f_harga += inp_harga;
}
dah_ada = true;
break;
}
}
char temp_file[]="temp.txt";
char line[128];
ft = fopen(temp_file, "w");
rewind(fp);
while(fgets(line, sizeof(line), fp) != NULL){
if(strstr(line, inp_nama) == NULL)
fputs(line, ft);
}
if(dah_ada)
fprintf(ft, "%d %-16s %d\n", f_jumlah, inp_nama, f_harga);
else
fprintf(ft, "%d %-16s %d\n", inp_jumlah, inp_nama, inp_harga);
_fcloseall();
remove(file);
rename(temp_file, file);
sort_file(file);
}
void edit(char nama_edt[][100], int biaya_edt[100], int jumlah_edt[100], int top, int bot, int baris_ord){
int idx=0, yy=top;
char str[100], spasi[1000];
memset(spasi, ' ', 53);
p (20,bot-3,"Arahkan cursor ke menu yang ingin diedit");
p (16,bot-7,S"Tekan ESC untuk kembali ke lobby"R);
while(1){
if(baris_ord>1){
post(-18,yy);
putchar('<');
int ch = getch();
printf("\b \b");
yy = (ch==72) ? (yy>=bot&&yy<top) ? yy+1 : bot :
(ch==80) ? (yy>bot&&yy<=top) ? yy-1 : top : yy;
idx = (ch==72) ? (idx>=0&&idx<=baris_ord-1) ? idx-1 : baris_ord :
(ch==80) ? (idx>=0&&idx<baris_ord-1) ? idx+1 : 0 : idx;
if(ch==13) break;
if(ch==27) lobby();
}
else{
post(-18,yy);
putchar('<');
int ch = getch();
if(ch==13) break;
if(ch==27) lobby();
}
}
post(20,bot-3); SPASI;
p((strlen(nama_edt[idx])+26)/2,bot-3,"Masukkan jumlah %s yang baru", nama_edt[idx]);
post(16,bot-7); SPASI;
p (14,bot-7,S" Tekan ESC untuk membatalkan"R);
post(16,yy);
printf(" ");
post(16,yy);
char input[3];
int i = 0, promptLength = 15, cursorPosition = promptLength;
while(1){
char ch = _getch();
if(ch == '\r')
break;
if (ch==27)
shp_cart(FALSE);
if(ch=='\b'){
if(i>0){
i--;
if(cursorPosition > promptLength){
printf("\b \b");
cursorPosition--;
}
continue;
}
}
if(i<2){
putchar(ch);
input[i] = ch;
i++;
cursorPosition++;
}
}
input[2] = '\0';
if(strlen(input)==0){
post(20,bot-3); SPASI;
p (7, bot-3, F"Invalid Input! "R);
getch(); shp_cart(FALSE);
}
for(int i=0; i<strlen(input); i++){
if(!isdigit(input[i]) || input[0]=='0'){
post(20,bot-3); SPASI;
p (7, bot-3, F"Invalid Input! "R);
getch(); shp_cart(FALSE);
}
}
update_food(order_user, nama_edt[idx], atoi(input), (biaya_edt[idx]/jumlah_edt[idx])*atoi(input), TRUE);
post(20,bot-3); SPASI;
p(15,bot-3, G"Orderan kamu berhasil di update"R); getch(); shp_cart(FALSE);
}
/* ------------------------------------------------------------------------ */
/* 3 Functions dibwayah ini digunakan ketika user ingin melakukan pembayaran atau ketika user ingin melihat list orderan*/
void pembayaran(){ CLR;
int chr;
char c, str[30], baris_f[1024], cust[20], nama[20];
srand(time(NULL));
fp=fopen(data_user, "r");
char hp[20];
char nama_user[50];
while(fgets(baris_f, sizeof(baris_f), fp)!=NULL){
sscanf(baris_f, "Nama Customer : %s", nama_user);
}
fclose(fp);
fp = fopen(order_user, "r");
fseek(fp, 0, SEEK_END);
if(ftell(fp)==0){
post(15,0);
puts("List Orderan kamu masih kosong. ");
getch(); lobby();
}
int baris=0, top=1;
rewind(fp);
while((chr=fgetc(fp))!=EOF){
if(chr=='\n'){
baris++; if(baris%2==0) top++;
}
}
int top_rcp=top;
for(int y=((baris+25)/2) ;y>=((baris+26)/2)*-1; y--){