From a19fec0548c553132399418e1b7f26cd9dc34eb7 Mon Sep 17 00:00:00 2001 From: smarttommyau Date: Tue, 11 Jul 2023 02:00:13 +0000 Subject: [PATCH] Utils.h --- admin_user.h | 81 +++++++++++++++++++++------------------------------- utils.h | 19 ++++++++++++ 2 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 utils.h diff --git a/admin_user.h b/admin_user.h index f537c55..9f9533f 100644 --- a/admin_user.h +++ b/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; -} \ No newline at end of file +} diff --git a/utils.h b/utils.h new file mode 100644 index 0000000..d11a648 --- /dev/null +++ b/utils.h @@ -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"); + 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; + +}