-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPharmacy Mangement System.cpp
6388 lines (5192 loc) · 209 KB
/
Pharmacy Mangement System.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//**********Libraries***********//
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <algorithm>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
#include <SFML/System/Clock.hpp>
#include "SaveData.h"
using namespace std;
using namespace sf;
//**********Declarations***********//
extern vector<string> paymentMethods;
const int Size = 100;
int medicine_data = 0;
int user_data = 0;
int requestcounter = 0;
int orderCounter = 0;
int chosenOption; // variable to choose with which order you want to go through
// after log in
bool activeDisplay = true; // Initialize active display to display1
bool activeS1 = true, activeS2 = false, activeS3 = false, activesS4 = false,
activeS5 = false;
bool IsHeAUser = true;
bool issignin = false; //check if i need to switch to sign in page
bool doneAdding = false;//to add
bool active_1 = false, active_2 = false, active_3 = false; // switches between input fields in Medicine Edit page
RenderWindow window(VideoMode(1366, 768), "Your pharmacy", Style::Fullscreen);
Font Calibri;
Texture BackgroundSign;
Texture ButtonTexture, TextTexture, darkbox, textbox, headerbox, Signbox,
buttonup, buttonin;
Texture ButtonEditInfo, ButtonLogOut, ButtonMakeOrder, Buttonsearch,
ButtonViewPrev, backgroundUser;
Texture ButtonManageUser, ButtonManagePay, ButtonManageOrder,
ButtonManageMedicine, backgroundAdmin;
Texture changeButton, WhiteBox;
Texture byName, byCategory, searchBar, resultTable, backgroundsearch;
Texture backgroundShowReceipt, showTable, confirm, price, quantity;
Texture backgroundManageUser, buttonAddUser, buttonRemoveUser, buttonEditUser;
Texture buttonAddMedicine, buttonRemoveMedicine, buttonEditMedicine;
Texture backgroundTex, secbackgroundTex, textboxTex, roleAdminbuttonTex,
roleUserbuttonTex, buttonTex;
string display1, display2;
Text displaytext1, displaytext2;
Text managetext1, managetext2;
string managedisplay1, managedisplay2;
string displayS1, displayS2, displayS3, displayS4, displayS5;
Text displayStext1, displayStext2, displayStext3, displayStext4, displayStext5;
Texture userButton, notuserButton, adminButton, notadminButton;
Texture backgroundMakeOrder, confrimOrder, semitransparent;
string inputUserID, inputMedicineID;
Text inputUserIDText, inputMedicineIDText;
Texture makereq;
Texture mainmenuButton;
Sprite makerequ;
Texture Request;
///dont't use this because it will break makeorder if used
Text Tsearchentered;
string stringsearch;
Text searchID[10], searchName[10], searchQuantity[10], searchCategory[10], searchPrice[10];
Text intitialvalue;
bool searchmakeRequest = false;
//don't use this because make order will get broken
bool makeorderactive1 = true, makeorderactive2 = false, makeorderactive3 = false;
Text makeordertext1, makeordertext2, makeordertext3;
string stmakeorder1, stmakeorder2, stmakeorder3;
string current_time;
Text error_text;
//don't use this because request a drug will get broken
bool requestactive1 = true;
Text requesttext1, requesttext2;
string strequest1, strequest2;
// bool and texts for inout displays for edit info (Admin) page ..... don't use it anywhere else to avoid conflicts and glitches
bool editactive1, editactive2, editactive3;
Text editAtext1, editAtext2, editAtext3;
string editAdisplay1, editAdisplay2, editAdisplay3;
string inputMedicineID2, inputQuantity, inputPrice;
Text inputMedicineID2Text, inputQuantityText, inputPriceText;
bool editUactive;
Text editUtext1, editUtext2;
string editUdisplay1, editUdisplay2;
// for edit order only
string medn, medc, ordd, ords, priceee;
// manage order
bool order_display;
Text orderId_text, orderPrice_text;
string orderdisplay_Id, orderdisplay_Price;
const Time displayDuration = milliseconds(5000);
bool usernameSc, addressSc, emailSc, phoneSc, passwordSc;
string usernameSt, addressSt, emailSt, phoneSt, passwordSt;
Text usernameDis, addressDis, emailDis, phoneDis, passwordDis;
bool medNameSc, medCataSc, medConcSc, medPriceSc, medQuantitySc, medDescSc;
string medNameSt, medCataSt, medConcSt, medPriceSt, medQuantitySt, medDescSt;
Text medNameDis, medCataDis, medConcDis, medPriceDis, medQuantityDis, medDescDis;
struct medicine {
int ID;
string name;
string description;
string concentration;
bool availability;
string category;
float price;
int quantity_in_stock;
void initialize(int _id, string _name, string _desc, string _conc,
bool _avail, string _category, float _price, int _quantity) {
ID = _id;
name = _name;
description = _desc;
concentration = _conc;
availability = _avail;
category = _category;
price = _price;
quantity_in_stock = _quantity;
}
};
medicine medicines[Size];
struct user {
enum role { User, Admin };
int ID;
string username;
string password;
string email;
string address;
string phone;
role his_role;
void initialize(int _id, string _name, string _pass, string _email,
string _address, string _phone, role _rol) {
ID = _id;
username = _name;
password = _pass;
email = _email;
address = _address;
phone = _phone;
his_role = _rol;
}
};
user users[Size];
user newUser;
user currentUser; // Temp to keep the current user's data
int currentUser_Index;
struct order {
int userID;
string orderDate;
int orderID;
bool orderState = false;
int medicine_ID[10] = {};
float totalPrice;
string shipDate;
void initialize(int _id, string _orderDate, int _medicine_ID[], float _Price,
string _shipDate, int order_id, bool order_state) {
userID = _id;
orderDate = _orderDate;
totalPrice = _Price;
shipDate = _shipDate;
orderID = order_id;
orderState = order_state;
int i = 0;
while (_medicine_ID[i] != 0) {
medicine_ID[i] = _medicine_ID[i];
i++;
}
}
};
order orders[Size] = {};
order lastyorder = {};
struct request {
int userID;
string medicineName;
int amountNeeded;
};
request requests[15];
// All GUI structures
struct StmakeOrder {
Sprite background;
Sprite semiTransparent_1, semiTransparent_2, textbox_1, textbox_2, textbox_3,
confrimOrder, mainbutton;
};
StmakeOrder makeorder;
struct RequestaDrug {
Sprite backgroundy;
Sprite request;
Sprite semiBlack;
Sprite valuefield1, valuefield2;
Sprite mainbutton;
};
RequestaDrug requestadrug;
struct Header {
Sprite background;
Text user, pharmacy;
};
Header header;
struct SignUp {
Sprite background1,
background2; // background 1 is for fields ..... background 2 is for sign
// in instead option
Sprite buttonup, buttonin;
Sprite valuefield1, valuefield2, valuefield3, valuefield4,
valuefield5; // username, phone num, location, role, new password
Text user, location, number, role, forgot, password;
Sprite Background, mainbutton;
Sprite userButton1, adminButton1, userButton2, adminButton2;
Text UsernameTaken;
};
SignUp signup;
struct Edit_Info {
Texture edit_background, change_phone, change_address, make_admin_green,
make_user_green, make_user_red, make_admin_red, confirm_button, change_user, change_password;
Sprite background, changePhone, changeAddress, log_out, changeUser, changePass;
Sprite valuefield1, valuefield2, valuefield3, mainbutton;
Sprite makeAdminGreen, makeUserGreen, makeAdminRed, makeUserRed, confirm;
Text input_id, wrng_id;
Text address, phonenum;
};
Edit_Info edit_info;
struct strShowAllOrders {
Sprite background, mainbutton;
Sprite trans_back;
Sprite button1;
};
strShowAllOrders ShowAllOrders;
struct AddUsers
{
Sprite background, secbackground, usernametextbox, addresstextbox,
emailtextbox, phonetextbox, passwordtextbox, optionsbutton,
roleAdminbutton, roleUserbutton, mainbutton;
Text headerText, usernametext, addresstext, emailtext, phonetext,
passwordtext, roletext, confirmationtext;
};
AddUsers adduser;
struct AddMedicine
{
Sprite background, secbackground, medNametextbox, medCatagorytextbox,
medConcentrationtextbox, medPricetextbox, medQuantitytextbox,
optionsbutton, medDesctextbox, mainbutton;
Text medNametext, medCatagorytext, medConcentrationtext, medPricetext,
medQuantitytext, medConfirmationtext, medDescriptiontext;
};
AddMedicine addmedicine;
struct manageUser {
Sprite background, semiTransparent, idTextBox, addUser, removeUser, editUser, mainbutton;
Text Title, userID;
};
manageUser manage_user;
struct manageMedicine {
Sprite background, semiTransparent, idTextBox, addMedicine, removeMedicine,
editMedicine, mainbutton;
Text Title, medicineID;
};
manageMedicine manage_medicine;
struct MedicineInfo {
Sprite backgroundy;
Sprite confirm, quantity, price;
Sprite valuefield1, valuefield2, valuefield3, mainbutton;
};
MedicineInfo medicineinfo;
struct searchMedicine {
Sprite backgroundx;
Sprite byName, byCategory, searchBar, resultTable, mainbutton;
};
searchMedicine searchmedicine;
struct showReceipt {
Sprite backgroundy;
Sprite showTable, confirm, mainbutton;
};
showReceipt showreceipt;
struct managePayment {
Sprite background, confirm_button, delete_button, backgroundview, mainbutton;
Texture managepayment_background, confirm, Delete;
Sprite valuefield1, valuefield2;
Text button1, button2, method, numb;
} manage_payment;
struct SignIn {
Sprite background1,
background2; // background 1 is for fields ..... background 2 is for sign
// in instead option
Sprite buttonup, buttonin;
Sprite valuefield1, valuefield2;
Text user, password, alreadyhave;
Sprite Background;
};
SignIn signin;
struct userMenu {
Sprite buttonEditInfo, buttonLogOut, buttonMakeOrder, buttonsearch,
buttonViewPrev;
Sprite background;
};
userMenu usermenu;
struct adminMenu {
Sprite buttonViewPrev, buttonsearch, buttonManageUser, buttonManagePay,
buttonManageOrder, buttonManageMedicine, buttonLogOut, buttonEditInfo,
buttonMakeorder;
Sprite background;
};
adminMenu adminmenu;
struct EditOrderInfo {
Sprite textboxID, textBoxPrice, semiTransparentBack, changeButton,
changeButton2, WhiteBox1, WhiteBox2, mainbutton;
Sprite Background;
Text OrderID, OrderDetails, MedicineNme, MedicineConcentration, OrderDate,
OrderState, TotalPrice;
Text WantChange, OrderState2, TotalPrice2;
Texture confirm_button;
Sprite confirm;
Text medname, medconc, ordDate, ordstate, price;
};
EditOrderInfo editOrder;
//********Function Declares***********//
void manage_orders(order orders[Size]);
void dataForTestPurposes();
bool isUsernameTaken(string username);
void signUp(string user, string phonenumber, string location, string email,
string password);
bool validateUser(string username, string password, user& currentUser);
void logInInterface();
void userPermissions();
void adminPermissions();
void editUserCredentials(int index);
bool searchForMedicineByName(string name);
void searchForMedicineByCategory(string category);
void makeOrder(string medicineIDS, string quantity, string payment_method);
void makeOrderFunctional(StmakeOrder& makeorder);
void showOrderReceipt(order lastOrder, string current_time);
void makeRequest( string _medicineName, string _amountReq);
void showAllPreviousOrders();
void addUser(string, string, string, string, string);
void addNewMedicine(string name, string concentraiton, string catagory, string description, string price, string quantity);
void updateUser();
bool removeUser(int userID);
bool removeMedicine(int medID);
void logOut();
void managePaymentMethodes();
void showPaymentMehtode(vector<string> x);
void logInInterface(string username, string password);
//**********GUI FUNCTIONS DECLARATION***********//
void TextureAFonts();
// user menu
void DrawUserMenu(userMenu usermenu);
void SetUserMenu(userMenu& usermenu);
void functioningUserMenu();
void drawShowAllOrders(strShowAllOrders ShowAllOrders);
void setShowAllOrders(strShowAllOrders& ShowAllOrders);
// admin menu
void DrawAdminMenu(adminMenu adminmenu);
void SetAdminMenu(adminMenu& adminmenu);
void functioningAdminMenu();
void DrawSearch(searchMedicine searchmedicine);
void SetSearch(searchMedicine& searchmedicine);
void functioningsearch();
void DrawMakeOrder(StmakeOrder& makeorder);
void SetMakeOrder(StmakeOrder& makeorder);
void DrawShowReceipt(showReceipt showreceipt);
void SetShowReceipt(showReceipt& showreceipt);
void DrawSignUp(SignUp signup);
void SetSignUp(SignUp& signup);
void functioningSignUp();
void setAddMedicine(AddMedicine& addmedicine);
void drawAddMedicine(AddMedicine& addmedicine);
void functioningAddMedicine();
void setAddusers(AddUsers& adduser);
void drawAddusers(AddUsers& adduser);
void functioningAddUser();
void SetMedicineEdit(MedicineInfo& medicineinfo);
void MedicineEditShow();
void Set_Request_drug(RequestaDrug& requestadrug);
void Requestadrug_showfunctional(bool& requestdrug);
void Draw_Requestadrug(RequestaDrug& requestadrug);
void DrawSignIn(SignIn signin);
void SetSignIn(SignIn& signin);
void functioningSignIn();
void SetMedicineEdit(MedicineInfo& medicineinfo);
void MedicineEditShow();
void MedicineEditShowFunctional(bool& medicineEdit, MedicineInfo& medicineinfo);
// Manage User
void set_manageUser(manageUser& manage_user);
void draw_manageUser(manageUser manage_user);
void functioning_manageUser();
// Manage Medicine
void set_manageMedicine(manageMedicine& manage_medicine);
void draw_manageMedicine(manageMedicine manage_medicine);
void functioning_manageMedicine();
// manage payment
void set_managePayment(managePayment& manage_payment);
void Draw_managePayment(managePayment& manage_payment);
void ManagePayment_functional(managePayment& manage_payment);
void showOrderReceipt(order lastOrder, string current_time);
void ShowReceiptFunctional( bool& show_order_receipt,
showReceipt showreceipt);
void page_switcher(Header& header, SignUp& signup, SignIn& signin,
userMenu& usermenu, adminMenu& adminmenu,
searchMedicine& searchmedicine, showReceipt& showreceipt,
Edit_Info& edit_info,
StmakeOrder makeorder, manageMedicine manage_medicine);
//edit info pages:-
//user
void Set_EditInfo_User(Edit_Info& edit_info);
void Draw_EditInfo_User(Edit_Info& edit_info);
void EditInfo_User_Functional(Edit_Info& edit_info);
String trackorder(order orders[], int orderid);
//admin
void Set_EditInfo_Admin(Edit_Info& edit_info);
void Draw_EditInfo_Admin(Edit_Info& edit_info);
void SetEditOrderInfo(EditOrderInfo& edit);
void DrawEditOrderInfo(EditOrderInfo edit);
bool sign_up;
bool requestdrug = 0;
int page_num = 0;
bool show_order_receipt = 0;
bool medicineEdit = 0;
int main() {
saveAllDataToArr();
dataForTestPurposes();
TextureAFonts();
// sign_up = true;
// background
Texture backgroundTexture;
backgroundTexture.loadFromFile("Assets/pharmacy2.jpg");
Sprite background;
background.setTexture(backgroundTexture);
background.setScale(0.276, 0.218);
// setting up headers and sign up/in
// SetHeader(header);
SetSignUp(signup);
SetSignIn(signin);
SetUserMenu(usermenu);
SetAdminMenu(adminmenu);
SetSearch(searchmedicine);
SetShowReceipt(showreceipt);
Set_EditInfo_Admin(edit_info);
Set_EditInfo_User(edit_info);
SetMakeOrder(makeorder);
SetEditOrderInfo(editOrder);
setAddusers(adduser);
setAddMedicine(addmedicine);
SetMedicineEdit(medicineinfo);
set_manageUser(manage_user);
setShowAllOrders(ShowAllOrders);
set_managePayment(manage_payment);
set_manageMedicine(manage_medicine);
MedicineEditShow();
Set_Request_drug(requestadrug);
// functioningSignUp();
// window display
displaytext1.setFont(Calibri);
displaytext1.setScale(1, 1);
displaytext1.setPosition(810, 435);
displaytext1.setFillColor(Color::Black);
displaytext1.setString(display1);
//settind display2 :: password
displaytext2.setFont(Calibri);
displaytext2.setScale(1, 1);
displaytext2.setPosition(810, 555);
displaytext2.setFillColor(Color::Black);
displaytext2.setString(display2);
//For signIn function
//setting display2 :: username
displaytext1.setFont(Calibri);
displaytext1.setFont(Calibri);
displaytext1.setScale(1, 1);
displaytext1.setScale(1, 1);
displaytext1.setPosition(810, 435);
displaytext1.setPosition(810, 435);
displaytext1.setFillColor(Color::Black);
displaytext1.setFillColor(Color::Black);
displaytext1.setString(display1);
displaytext1.setString(display1);
//settind display2 :: password
//setting display2 :: password
displaytext2.setFont(Calibri);
displaytext2.setFont(Calibri);
displaytext2.setScale(1, 1);
displaytext2.setScale(1, 1);
displaytext2.setPosition(810, 555);
displaytext2.setPosition(810, 555);
displaytext2.setFillColor(Color::Black);
displaytext2.setFillColor(Color::Black);
displaytext2.setString(display2);
displaytext2.setString(display2);
//For SignUp function
//setting display1 :: username
displayStext1.setFont(Calibri);
displayStext1.setScale(1, 1);
displayStext1.setPosition(810, 170);
displayStext1.setFillColor(Color::Black);
displayStext1.setString(displayS1);
//setting display2 :: phone num
TextureAFonts();
displayStext2.setFont(Calibri);
set_managePayment(manage_payment);
displayStext2.setScale(1, 1);
displayStext2.setPosition(810, 255);
displayStext2.setFillColor(Color::Black);
displayStext2.setString(displayS2);
//setting display3 :: location
displayStext3.setFont(Calibri);
displayStext3.setScale(1, 1);
displayStext3.setPosition(810, 340);
displayStext3.setFillColor(Color::Black);
displayStext3.setString(displayS3);
//setting display4 :: email
displayStext4.setFont(Calibri);
displayStext4.setScale(1, 1);
displayStext4.setPosition(810, 425);
displayStext4.setFillColor(Color::Black);
displayStext4.setString(displayS4);
//setting display5 :: password
displayStext5.setFont(Calibri);
displayStext5.setScale(1, 1);
displayStext5.setPosition(810, 510);
displayStext5.setFillColor(Color::Black);
displayStext5.setString(displayS5);
Event event;
while (window.pollEvent(event)) {
/*if (event.type == Event::Closed)
{
window.close();
}*/
if (Keyboard::isKeyPressed(Keyboard::Key::Escape)) {
window.close();
}
// createEditMedicineWindow(window);
/*if (event.type == Event::MouseButtonPressed) {
// Check if left mouse button is pressed
if (show_order_receipt) {
if (event.mouseButton.button == Mouse::Left) {
// Get the current mouse position
Vector2i mousePosition = Mouse::getPosition(window);
// Check if the mouse position intersects with confirm button
if (showreceipt.confirm.getGlobalBounds().contains(
static_cast<Vector2f>(mousePosition))) {
// action performed to get to main menu
show_order_receipt = 0;
if (currentUser.his_role == user::User) {
window.clear();
page_num = 2;
}
else {
window.clear();
page_num = 3;F
}
}
}
}
}*/
/*if (event.type == Event::MouseButtonPressed) {
// Check if left mouse button is pressed
if (event.mouseButton.button == Mouse::Left) {
// Get the current mouse position
Vector2i mousePosition = Mouse::getPosition(window);
// Check if the mouse position intersects with signup button
if (sign_up) {
if (signup.buttonin.getGlobalBounds().contains(
static_cast<Vector2f>(mousePosition))) {
// action performed for sign in
sign_up = false;
}
}
else {
if (signin.buttonup.getGlobalBounds().contains(
static_cast<Vector2f>(mousePosition)) and
!sign_up) {
sign_up = true;
}
}
}
}*/
//window.clear();
//ManagePayment_functional(manage_payment);
// DrawSignUp(signup);
//window.display();
/*if (sign_up) {
DrawSignUp(signup);
window.draw(displaytext);
}
else {
DrawSignIn(signin);
}*/
while (window.isOpen())
{
page_switcher(header, signup, signin, usermenu, adminmenu, searchmedicine,
showreceipt, edit_info, makeorder, manage_medicine);
}
}
saveAllDataLocally();
}
//**********Functions***********//
void dataForTestPurposes() {
//*******************Medicine data****************************
medicines[0].initialize(1, "Paracetamol", "Pain reliever and fever reducer",
"500 mg", true, "Analgesic", 5.99, 100);
medicines[1].initialize(2, "Lisinopril", "Used to treat high blood pressure",
"10 mg", true, "Antihypertensive", 10.49, 50);
medicines[2].initialize(3, "Omeprazole",
"Treats heartburn, stomach ulcers, and "
"gastroesophageal reflux disease (GERD)",
"20 mg", true, "Gastrointestinal", 7.25, 80);
medicines[3].initialize(4, "Atorvastatin",
"Lowers high cholesterol and triglycerides", "20 mg",
true, "Lipid-lowering", 15.75, 30);
medicines[4].initialize(5, "Metformin", "Treats type 2 diabetes", "500 mg",
true, "Antidiabetic", 8.99, 60);
medicines[5].initialize(6, "Amoxicillin",
"Antibiotic used to treat bacterial infections",
"250 mg", true, "Antibiotic", 6.50, 0);
medicines[6].initialize(7, "Alprazolam", "Treats anxiety and panic disorders",
"0.25 mg", true, "Anxiolytic", 12.99, 40);
medicines[7].initialize(8, "Ibuprofen",
"Nonsteroidal anti-inflammatory drug (NSAID)",
"200 mg", true, "Analgesic", 4.75, 200);
medicines[8].initialize(9, "Cetirizine",
"Antihistamine used for allergy relief", "10 mg",
true, "Antihistamine", 9.25, 0);
medicines[9].initialize(
10, "Ranitidine",
"Reduces stomach acid production to treat heartburn and ulcers", "150 mg",
true, "Gastrointestinal", 6.99, 90);
//--------------------------------------------------------------------------------------------------------------------------------------------------------
//*******************User data****************************
users[0].initialize(1, "Naruto", "NotNaruto", "[email protected]",
"123 Main St, Cityville", "+1234567890", user::User);
users[1].initialize(2, "Madara", "password2", "[email protected]",
"456 Elm St, Townsville", "+1987654321", user::User);
users[2].initialize(3, "Cillian", "Cillianpass", "[email protected]",
"789 Oak St, Villageton", "+1122334455", user::Admin);
users[3].initialize(4, "Aras", "passBulut", "[email protected]",
"987 Pine St, Hamletville", "+9988776655", user::User);
users[4].initialize(5, "Sung", "jinwoo", "[email protected]",
"654 Birch St, Countryside", "+1122334455", user::User);
users[5].initialize(6, "Iman", "imangadzhi", "[email protected]",
"321 Maple St, Suburbia", "+9988776655", user::User);
users[6].initialize(7, "Ali", "AliAli", "[email protected]",
"111 Cedar St, Ruralville", "+1122334455", user::Admin);
//--------------------------------------------------------------------------------------------------------------------------------------------------------
int medicine1[] = { 1, 2, 3, 0 };
orders[0].initialize(0, "2024-03-27", medicine1, 500.0, "2024-03-27", 1,
false);
int medicine2[] = { 4, 5, 0 };
orders[1].initialize(1, "2024-03-28", medicine2, 300.0, "2024-03-28", 2,
true);
int medicine3[] = { 9, 4, 5, 7, 0 };
orders[2].initialize(2, "2024-03-29", medicine3, 3000.0, "2024-03-29", 3,
true);
}
void signUp(string user, string phonenumber, string location, string email,
string password) {
int id = user_data + 1; // Next available ID
newUser.ID = id;
newUser.username = user;
newUser.phone = phonenumber;
newUser.address = location;
newUser.password = password;
newUser.email = email;
users[id - 1] = newUser; // Save the new user data into our users array
saveOneUserDataLocally();
user_data++; // Increment user_data to keep track of the total number of users
displayS1.resize(0);
displayS2.resize(0);
displayS3.resize(0);
displayS4.resize(0);
displayS5.resize(0);
displayStext1.setString(displayS1);
displayStext2.setString(displayS2);
displayStext3.setString(displayS3);
displayStext4.setString(displayS4);
displayStext5.setString(displayS5);
}
void logInInterface() {
bool loggedIn = false;
while (!loggedIn) {
cout << "Enter your username: ";
cin >> currentUser.username;
cout << "Enter your password: ";
cin >> currentUser.password;
if (validateUser(currentUser.username, currentUser.password, currentUser)) {
loggedIn = true;
cout << "Log in success. Welcome back, " << currentUser.username
<< " :D\n-------------------------------------------\n";
if (currentUser.his_role == user::User) {
userPermissions();
}
else {
adminPermissions();
}
cin >> chosenOption;
}
else {
cout << "Invalid credentials. The username or password you entered is "
"incorrect. Please try again.\n";
}
}
}
void userPermissions() {
cout << "1- Search for medicine by name\n";
cout << "2- Search for medicine by category\n";
cout << "3- Add order\n";
cout << "4- Choose payment method\n";
cout << "5- View order\n";
cout << "6- Request drug\n";
cout << "7- View all previous orders\n";
cout << "8- Log out\n";
}
void adminPermissions() {
cout << "1- Add new user\n";
cout << "2- Update user information\n";
cout << "3- Remove user\n";
cout << "4- Add new medicine\n";
cout << "5- Remove medicine\n";
cout << "6- Manage orders\n";
cout << "7- Manage payments\n";
cout << "8- Search for medicine by name\n";
cout << "9- Search for medicine by category\n";
cout << "10- Add order\n";
cout << "11- Choose payment method\n";
cout << "12- View order\n";
cout << "13- Request drug\n";
cout << "14- View all previous orders\n";
}
bool searchForMedicineByName(string name) {
searchmakeRequest = false;
int x = name.size();
if (name[0] >= 'a' && name[0] <= 'z') {
name[0] -= 32;
}
int i = 0;
bool found = 0;
float y = 300;
int emptytextarr = 0;
while (emptytextarr != 10) {
searchID[emptytextarr].setString("");
searchQuantity[emptytextarr].setString("");
searchPrice[emptytextarr].setString("");
searchName[emptytextarr].setString("");
searchCategory[emptytextarr].setString("");
emptytextarr++;
}
int textarrindex = 0;
while (medicines[i].ID != 0) {
string_view sv(medicines[i].name.c_str(), x);
if (name == sv) {
DrawSearch(searchmedicine);
float x = 20;
searchID[textarrindex].setFont(Calibri);
searchID[textarrindex].setString(to_string(medicines[i].ID));
searchID[textarrindex].setPosition(x, y);
x += 40;
searchName[textarrindex].setFont(Calibri);
searchName[textarrindex].setString(medicines[i].name);
searchName[textarrindex].setPosition(x, y);
x += 160;
searchCategory[textarrindex].setFont(Calibri);
searchCategory[textarrindex].setString(medicines[i].category);
searchCategory[textarrindex].setPosition(x, y);
x += 200;
searchPrice[textarrindex].setFont(Calibri);
searchPrice[textarrindex].setString(to_string(medicines[i].price));
searchPrice[textarrindex].setPosition(x, y);
x += 160;
searchQuantity[textarrindex].setFont(Calibri);
searchQuantity[textarrindex].setString(to_string(medicines[i].quantity_in_stock));
searchQuantity[textarrindex].setPosition(x, y);
x += 80;
y += 40;
textarrindex++;
found = 1;
}
i++;
}
if (found) {
return 1;
}
else {
//int amountrequested;
searchmakeRequest = true;
return 0;
}
}
void searchForMedicineByCategory(string category) {
searchmakeRequest = false;
float y = 300;
int emptytextarr = 0;
while (emptytextarr != 10) {
searchID[emptytextarr].setString("");
searchQuantity[emptytextarr].setString("");
searchPrice[emptytextarr].setString("");
searchName[emptytextarr].setString("");
searchCategory[emptytextarr].setString("");
emptytextarr++;
}
int textarrindex = 0;
bool found = false;
if (category[0] >= 'a' && category[0] <= 'z') {
category[0] -= 32;
}
for (int i = 0; i < Size; i++) {
if (category == medicines[i].category) {
DrawSearch(searchmedicine);
float x = 20;
searchID[textarrindex].setFont(Calibri);
searchID[textarrindex].setString(to_string(medicines[i].ID));
searchID[textarrindex].setPosition(x, y);
x += 40;
searchName[textarrindex].setFont(Calibri);
searchName[textarrindex].setString(medicines[i].name);
searchName[textarrindex].setPosition(x, y);
x += 160;
searchCategory[textarrindex].setFont(Calibri);
searchCategory[textarrindex].setString(medicines[i].category);
searchCategory[textarrindex].setPosition(x, y);
x += 200;
searchPrice[textarrindex].setFont(Calibri);
searchPrice[textarrindex].setString(to_string(medicines[i].price));
searchPrice[textarrindex].setPosition(x, y);
x += 160;
searchQuantity[textarrindex].setFont(Calibri);
searchQuantity[textarrindex].setString(to_string(medicines[i].quantity_in_stock));
searchQuantity[textarrindex].setPosition(x, y);
x += 80;
y += 40;
textarrindex++;
found = true;
}
}
if (found == false) {
//int amountrequested;
searchmakeRequest = true;
}
}
// Convert date string to integers
void parseDateString(const std::string& dateString, int& year, int& month,
int& day) {
std::stringstream ss(dateString);
char dash;
ss >> year >> dash >> month >> dash >> day;
}
// calculate the difference in days between two dates
int dateDifference(const std::string& date1, const std::string& date2) {
int year1, month1, day1;
int year2, month2, day2;
parseDateString(date1, year1, month1, day1);
parseDateString(date2, year2, month2, day2);
// Calculate the total number of days for each date
int days1 = year1 * 365 + month1 * 30 + day1;
int days2 = year2 * 365 + month2 * 30 + day2;
// Calculate the difference in days
int difference = days2 - days1;
return difference;
}
void makeRequest( string _medicineName, string _amountReq) {
requestcounter++;
/*for (int i = 0; i < Size; i++) {
if (_username == users[i].username) {
currentUser.ID = users[i].ID;
}
}*/
int amountReq = stoi(_amountReq);
for (int j = 0; j < 15; j++) {
if (requests[j].userID == 0) {
requests[j].userID = currentUser.ID;
requests[j].medicineName = _medicineName;
requests[j].amountNeeded = amountReq;
break;
}
}
}
void showAllPreviousOrders(RenderWindow& window) {
drawShowAllOrders(ShowAllOrders);
for (int i = 0; i < Size; i++) { // checking for the current user ID to be
// able to get his/her orders using ID
if (currentUser.username == users[i].username) {
currentUser.ID == users[i].ID;
break;
}