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
#include "menu.h"
#endif //MENU_H
#ifndef Utils
#define Utils
#include "utils.h"
#endif // !Utils
//list of functions
//TODO: split all controller functions into their own files
//TODO: reformat all output to be formatted and unifed
@ -35,32 +38,35 @@ void admin_menu(){
if(user == NULL){//invalid user
return;
}
int choice = 0;
do
printf("Welcome %s(%s)\n", user->name,user->role);
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);
switch (choice)
{
case 1://action with inventory
inv_control();
break;
case 2://action with transction
tran_control();
break;
case 3://action with user
user_control();
break;
case 4://role management
role_control();
break;
case 5://Exit
break;
default://invalid input ,should not happen,as it is already catch in above function
printf("Invalid choice\n");
break;
}
}while(choice != 5);
case 1://action with inventory
inv_control();
break;
case 2://action with transction
tran_control();
break;
case 3://action with user
user_control();
break;
case 4://role management
role_control();
break;
case 5://Exit
break;
default://invalid input ,should not happen,as it is already catch in above function
printf("Invalid choice\n");
break;
}
return;
}
@ -99,27 +105,6 @@ struct user_row *prompt_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
void add_item();
@ -1294,4 +1279,4 @@ struct Map* sortRole(struct linkedlist* list,int choice){
break;
}
return map;
}
}

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;
}