This commit is contained in:
smarttommyau 2023-07-11 02:00:13 +00:00
parent 04af514d7c
commit a19fec0548
2 changed files with 52 additions and 48 deletions

View File

@ -14,7 +14,10 @@
#define MENU_H #define MENU_H
#include "menu.h" #include "menu.h"
#endif //MENU_H #endif //MENU_H
#ifndef Utils
#define Utils
#include "utils.h"
#endif // !Utils
//list of functions //list of functions
//TODO: split all controller functions into their own files //TODO: split all controller functions into their own files
//TODO: reformat all output to be formatted and unifed //TODO: reformat all output to be formatted and unifed
@ -35,31 +38,34 @@ void admin_menu(){
if(user == NULL){//invalid user if(user == NULL){//invalid user
return; return;
} }
int choice = 0; printf("Welcome %s(%s)\n", user->name,user->role);
do char * Items = {
"Inventory control",
"Transaction control",
"User control",
"Role control",
};
choice = choices_selecter(Items,4)
switch (choice)
{ {
choice = admin_menu_user_choices(user->name,user->role); case 1://action with inventory
switch (choice) inv_control();
{ break;
case 1://action with inventory case 2://action with transction
inv_control(); tran_control();
break; break;
case 2://action with transction case 3://action with user
tran_control(); user_control();
break; break;
case 3://action with user case 4://role management
user_control(); role_control();
break; break;
case 4://role management case 5://Exit
role_control(); break;
break; default://invalid input ,should not happen,as it is already catch in above function
case 5://Exit printf("Invalid choice\n");
break; break;
default://invalid input ,should not happen,as it is already catch in above function }
printf("Invalid choice\n");
break;
}
}while(choice != 5);
return; return;
@ -99,27 +105,6 @@ struct user_row *prompt_user(){
return user; return user;
} }
int admin_menu_user_choices(char* name,char* role){
int choice = 0;
do{
system("cls");
printf("Welcome %s(%s)\n", name,role);
printf("Please select an option:\n");
printf("1. Inventory control\n");
printf("2. Transaction control\n");
printf("3. User control\n");
printf("4. Role control\n");
printf("5. Exit and Logout\n");
printf(">");
scanf("%d", &choice);
if(choice < 1 || choice > 5){
printf("Invalid choice...press any key to retry....\n");
fflush(stdin);
getchar();
}
}while(choice < 1 || choice > 5);
return choice;
}
//invetory control //invetory control
void add_item(); void add_item();

19
utils.h Normal file
View File

@ -0,0 +1,19 @@
int choices_selecter(char * Items,int items) {
int choice =0
do{
printf("Select An Option:");
int i;
for (i=0, i<items;i++){
print("%d. %s\n",i+1,Items[i]);
}
printf("%d. Exit\n",i+1);
printf(">");
if(choice < 1 || choice > items+1){
printf("Invalid choice...press any key to retry....\n");
fflush(stdin);
getchar();
}
}while(choice < 1 || choice > items+1);
return choice;
}