first commit

This commit is contained in:
smarttommyau 2022-08-27 11:39:59 +08:00
commit acef6ad630
No known key found for this signature in database
GPG Key ID: D7832FC94BD13B6A
10 changed files with 381 additions and 0 deletions

8
admin_user.h Normal file
View File

@ -0,0 +1,8 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#endif

31
data_file_inventory.txt Normal file
View File

@ -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

67
data_file_transaction.txt Normal file
View File

@ -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

10
data_file_user.txt Normal file
View File

@ -0,0 +1,10 @@
#name,role,id
Wu Ka Cheuk
teacher
32001
Chan Tai Man
student
20001
Chan Siu Man
student
20002

112
database.h Normal file
View File

@ -0,0 +1,112 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#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;
}

45
dateNtime.h Normal file
View File

@ -0,0 +1,45 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#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;
}

8
filecontrol.h Normal file
View File

@ -0,0 +1,8 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#endif

54
main.c Normal file
View File

@ -0,0 +1,54 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#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;
}

26
menu.h Normal file
View File

@ -0,0 +1,26 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#endif
void welcome_message(){
printf("><Welcome to the Student Union POS system><\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;
}

20
normal_user.h Normal file
View File

@ -0,0 +1,20 @@
//include std lib if they havent been included
#ifndef STD_LIB_H
#define STD_LIB_H
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#endif
#ifndef MENU_H
#define MENU_H
#include "menu.h"
#endif //MENU_H
bool normal_menu(){
retrurn true
}