Utils.h
This commit is contained in:
parent
04af514d7c
commit
a19fec0548
81
admin_user.h
81
admin_user.h
@ -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
19
utils.h
Normal 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;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user