From acef6ad63013f05139a8becd068e2811cf9d026f Mon Sep 17 00:00:00 2001 From: smarttommyau Date: Sat, 27 Aug 2022 11:39:59 +0800 Subject: [PATCH] first commit --- admin_user.h | 8 +++ data_file_inventory.txt | 31 +++++++++++ data_file_transaction.txt | 67 +++++++++++++++++++++++ data_file_user.txt | 10 ++++ database.h | 112 ++++++++++++++++++++++++++++++++++++++ dateNtime.h | 45 +++++++++++++++ filecontrol.h | 8 +++ main.c | 54 ++++++++++++++++++ menu.h | 26 +++++++++ normal_user.h | 20 +++++++ 10 files changed, 381 insertions(+) create mode 100644 admin_user.h create mode 100644 data_file_inventory.txt create mode 100644 data_file_transaction.txt create mode 100644 data_file_user.txt create mode 100644 database.h create mode 100644 dateNtime.h create mode 100644 filecontrol.h create mode 100644 main.c create mode 100644 menu.h create mode 100644 normal_user.h diff --git a/admin_user.h b/admin_user.h new file mode 100644 index 0000000..95e5890 --- /dev/null +++ b/admin_user.h @@ -0,0 +1,8 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif \ No newline at end of file diff --git a/data_file_inventory.txt b/data_file_inventory.txt new file mode 100644 index 0000000..6c26fe7 --- /dev/null +++ b/data_file_inventory.txt @@ -0,0 +1,31 @@ +#category, brand, product, price, cost, stock, barcode +Test +Testing Co Ltd +Testing Product +15.0 +1122 +Juice +Mr Juicy +Orange Juice Drink 360mL (Bottle) +9.9 +9665 +Juice +F&N Fruit Tree +Apple & Aloe Vera Juice Drink 500mL +16.0 +6479 +Juice +F&N Fruit Tree +Apple & Aloe Vera Juice Drink 1L +22.9 +5155 +Juice +Homegrown Juice Company +Cold Pressed NZ Apple Juice 1L +35.5 +6470 +T2 +T2 Brand +T2 Product +20.0 +2983 diff --git a/data_file_transaction.txt b/data_file_transaction.txt new file mode 100644 index 0000000..c0fbf9a --- /dev/null +++ b/data_file_transaction.txt @@ -0,0 +1,67 @@ +#date,time,id,price,qty,barcode +2022-08-10 +18:55:30 +32001 +20 +-10 +5155 +2022-08-10 +18:55:30 +32001 +15 +-5 +6479 +2022-08-11 +10:55:21 +20001 +22.9 +1 +5155 +2022-08-11 +19:49:42 +32001 +16.0 +2 +6479 +2022-08-12 +12:34:12 +20002 +16 +1 +6479 +2022-08-12 +18:49:33 +30001 +22.9 +10 +5155 +2022-08-12 +18:49:51 +20001 +15.0 +5 +1122 +2022-08-12 +22:43:53 +30001 +22.9 +2 +5155 +2022-08-12 +22:44:54 +30001 +15.0 +1 +1122 +2022-08-12 +23:11:05 +30002 +5.0 +-1 +2983 +2022-08-12 +23:59:02 +20001 +22.9 +1 +5155 diff --git a/data_file_user.txt b/data_file_user.txt new file mode 100644 index 0000000..c819cd0 --- /dev/null +++ b/data_file_user.txt @@ -0,0 +1,10 @@ +#name,role,id +Wu Ka Cheuk +teacher +32001 +Chan Tai Man +student +20001 +Chan Siu Man +student +20002 diff --git a/database.h b/database.h new file mode 100644 index 0000000..94bb8bb --- /dev/null +++ b/database.h @@ -0,0 +1,112 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif +#ifndef DNT_H +#define DNT_H +#include "dateNtime.h" +#endif // !DNT_H +typedef struct basic_db{ + FILE *fp; + int row_count; + //array of struct of row +}; + +//inventory +typedef struct inventory{ + struct basic_db db; + struct inventory_row* row; + +}; +typedef struct inventory_row{ + char category[100]; + char band[100]; + char product[100]; + double price; + double cost; + int stock; + long barcode; +}; +typedef enum INVENTORY { + category = 1, brand = 2, product = 3, price = 4, cost = 5, stock = 6 , barcode = 7 + }; + +//transaction +typedef struct transaction{ + struct basic_db db; + struct transaction_row* row; + +}; +typedef struct transaction_row{ + struct date date; + struct time time; + long id; + double price; + int quantity; + long barcode; +}; +typedef enum TRANSACTION { + date = 1, time = 2, id = 3, price = 5, quantity = 4, barcode = 7 + }; + +//user +typedef struct user{ + struct basic_db db; + struct user_row* row; +}; +typedef struct user_row{ + char name[100]; + char role[100]; + long id; + bool isAdmin; +}; + +typedef enum USER { + name = 1, role = 2,id = 3 + }; + + + + + +//list of db func +bool read_db_invt(FILE* fp,enum INVENTORY inventory){ + return true; +} +bool read_db_tran(FILE* fp,enum TRANSACTION transaction){ + return true; +} +bool read_db_user(FILE* fp,enum USER user){ + return true; +} +bool new_db_invt(FILE* fp,enum INVENTORY inventory){ + return true; +} +bool new_db_tran(FILE* fp,enum TRANSACTION transaction){ + return true; +} +bool new_db_user(FILE* fp,enum USER user){ + return true; +} +bool edit_db_invt(FILE* fp,enum INVENTORY inventory){ + return true; +} +bool edit_db_tran(FILE* fp,enum TRANSACTION transaction){ + return true; +} +bool edit_db_user(FILE* fp,enum USER user){ + return true; +} +bool rm_db_invt(FILE* fp,enum INVENTORY inventory){ + return true; +} +bool rm_db_tran(FILE* fp,enum TRANSACTION transaction){ + return true; +} +bool rm_db_user(FILE* fp,enum USER user){ + return true; +} \ No newline at end of file diff --git a/dateNtime.h b/dateNtime.h new file mode 100644 index 0000000..cb2a10c --- /dev/null +++ b/dateNtime.h @@ -0,0 +1,45 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif +//DATE +typedef struct date{ + int day; + int month; + int year; +}; + + +struct date convert_to_date(char* date){ + struct date d; + char* token = strtok(date, "-"); + d.day = atoi(token); + token = strtok(NULL, "-"); + d.month = atoi(token); + token = strtok(NULL, "-"); + d.year = atoi(token); + return d; +} + +//TIME + +typedef struct time{ + int hour; + int minute; + int second; +}; + +struct time convert_to_time(char* time){ + struct time t; + char* token = strtok(time, ":"); + t.hour = atoi(token); + token = strtok(NULL, ":"); + t.minute = atoi(token); + token = strtok(NULL, ":"); + t.second = atoi(token); + return t; +} \ No newline at end of file diff --git a/filecontrol.h b/filecontrol.h new file mode 100644 index 0000000..53b4675 --- /dev/null +++ b/filecontrol.h @@ -0,0 +1,8 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif diff --git a/main.c b/main.c new file mode 100644 index 0000000..1ab985b --- /dev/null +++ b/main.c @@ -0,0 +1,54 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif +#ifndef CUSTOM_H +#define CUSTOM_H +#include "database.h" +#endif // !CUSTOM_H + +#ifndef MENU_H +#define MENU_H +#include "menu.h" +#endif //MENU_H +#include "normal_user.h" +#include "admin_user.h" + + + + +int main(){ + bool check; + do + { + //print welcome message + //prompt weather user is admin or normal user + //then redirect them to the corisponding menu + welcome_message();//refer to menu.h, keep things easier for repeat use on future + int choice = user_choices();//same as above + switch (choice) + { + case 1://admin + check = admin_menu();//refers to admin_user.h + break; + case 2://normal user + check = normal_menu();//refers to normal_user.h + break; + case 3://exit + check = false; + break; + default://invalid input + printf("Invalid choice\n"); + check = false; + break; + } + + + } while (check); + + return 0; +} \ No newline at end of file diff --git a/menu.h b/menu.h new file mode 100644 index 0000000..1cb33e1 --- /dev/null +++ b/menu.h @@ -0,0 +1,26 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif + + +void welcome_message(){ + printf("><\n");//welcome messgae +} + +int user_choices(){ + int choice; + + printf("Are you an admin or a normal user?\n"); + printf("1. Admin\n"); + printf("2. Normal User\n"); + printf("3. Exit\n"); + + scanf("%d", &choice); + + return choice; +} \ No newline at end of file diff --git a/normal_user.h b/normal_user.h new file mode 100644 index 0000000..fe2826d --- /dev/null +++ b/normal_user.h @@ -0,0 +1,20 @@ +//include std lib if they havent been included +#ifndef STD_LIB_H +#define STD_LIB_H +#include +#include +#include +#include +#endif + +#ifndef MENU_H +#define MENU_H +#include "menu.h" +#endif //MENU_H + +bool normal_menu(){ + + + + retrurn true +} \ No newline at end of file