basically finished list item,
no yet confirm stock column
This commit is contained in:
parent
fcbd309c69
commit
7b1ccd61d2
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdio.h": "c"
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#category, brand, product, price, stock, barcode
|
||||
#category, brand, product, price`vc , stock, barcode
|
||||
Test
|
||||
Testing Co Ltd
|
||||
Testing Product
|
||||
|
20
database.h
20
database.h
@ -26,7 +26,7 @@ typedef struct inventory{
|
||||
};
|
||||
typedef struct inventory_row{
|
||||
char category[100];
|
||||
char band[100];
|
||||
char brand[100];
|
||||
char product[100];
|
||||
double price;
|
||||
int stock;
|
||||
@ -54,9 +54,9 @@ typedef struct transaction_row{
|
||||
bool isdeleted;//common for all rows,default is false
|
||||
};
|
||||
typedef enum {
|
||||
date = 1, time = 2, id_tran = 3, price_tran = 5, quantity = 4, barcode_tran = 7
|
||||
date = 1, time = 2, id_tran = 3, price_tran = 4, quantity = 5, barcode_tran = 6
|
||||
}TRANSACTION;
|
||||
#define ENDOFTRANSACTION 7
|
||||
#define ENDOFTRANSACTION 6
|
||||
//user
|
||||
#define USER_DB "data_file_user.txt"
|
||||
typedef struct user{
|
||||
@ -88,15 +88,17 @@ int basic_get_row_count(int end, FILE *fp){
|
||||
while(!feof(fp)&&!ferror(fp)){
|
||||
char buffer[100];
|
||||
fgets(buffer, sizeof(buffer),fp);
|
||||
if(buffer[0] == '#'){//catch comment line and ignore
|
||||
if(buffer[0] == '#' || buffer[0] == '\0'){//catch comment line and ignore
|
||||
continue;
|
||||
}
|
||||
colmun_count++;
|
||||
puts(buffer);
|
||||
if(colmun_count == end){
|
||||
row_count++;
|
||||
colmun_count = 0;
|
||||
}
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
struct inventory read_db_invt(){//please open file in read mode
|
||||
@ -113,7 +115,7 @@ struct inventory read_db_invt(){//please open file in read mode
|
||||
//read data
|
||||
for(int i=0;i<row_count;i++){
|
||||
db.row[i].isdeleted = false;
|
||||
for(INVENTORY j=category;j<ENDOFINVENTORY;j++){
|
||||
for(INVENTORY j=category;j<=ENDOFINVENTORY;j++){
|
||||
char buffer[100];
|
||||
fgets(buffer, sizeof(buffer),fp);
|
||||
if(buffer[0] == '#'){//catch comment line and ignore
|
||||
@ -124,7 +126,7 @@ struct inventory read_db_invt(){//please open file in read mode
|
||||
strcpy(db.row[i].category,buffer);
|
||||
break;
|
||||
case brand:
|
||||
strcpy(db.row[i].band,buffer);
|
||||
strcpy(db.row[i].brand,buffer);
|
||||
break;
|
||||
case product:
|
||||
strcpy(db.row[i].product,buffer);
|
||||
@ -169,7 +171,7 @@ struct transaction read_db_tran(){
|
||||
//read data
|
||||
for(int i=0;i<row_count;i++){
|
||||
db.row[i].isdeleted = false;
|
||||
for(TRANSACTION j=date;j<ENDOFTRANSACTION;j++){
|
||||
for(TRANSACTION j=date;j<=ENDOFTRANSACTION;j++){
|
||||
char buffer[100];
|
||||
fgets(buffer, sizeof(buffer),fp);
|
||||
if(buffer[0] == '#'){//catch comment line and ignore
|
||||
@ -222,7 +224,7 @@ struct user read_db_user(){
|
||||
//read data
|
||||
for(int i=0;i<row_count;i++){
|
||||
db.row[i].isdeleted = false;
|
||||
for(USER j=name;j<ENDOFUSER;j++){
|
||||
for(USER j=name;j<=ENDOFUSER;j++){
|
||||
char buffer[100];
|
||||
fgets(buffer, sizeof(buffer),fp);
|
||||
if(buffer[0] == '#'){//catch comment line and ignore
|
||||
@ -282,7 +284,7 @@ bool update_db_invt(struct inventory* invt){
|
||||
fprintf(fpW,"%s",invt->row[i].category);
|
||||
break;
|
||||
case brand:
|
||||
fprintf(fpW,"%s",invt->row[i].band);
|
||||
fprintf(fpW,"%s",invt->row[i].brand);
|
||||
break;
|
||||
case product:
|
||||
fprintf(fpW,"%s",invt->row[i].product);
|
||||
|
1
main.c
1
main.c
@ -26,6 +26,7 @@ int main(){
|
||||
bool check;
|
||||
do
|
||||
{
|
||||
system("cls");
|
||||
//print welcome message
|
||||
//prompt weather user is admin or normal user
|
||||
//then redirect them to the corisponding menu
|
||||
|
@ -79,13 +79,11 @@ void list_items(){
|
||||
int page = 0;
|
||||
int page_size = PAGE_SIZE;
|
||||
struct inventory db = read_db_invt();
|
||||
int total_pages = ceil(db.db.row_count / page_size);
|
||||
int total_pages = (int)ceil((double)db.db.row_count / page_size);
|
||||
struct Map* map = NULL;
|
||||
|
||||
|
||||
do{
|
||||
|
||||
//ooptions
|
||||
//options
|
||||
system("cls");
|
||||
printf("0 exit\n");
|
||||
printf("1 sort name decending\n");
|
||||
@ -99,17 +97,17 @@ void list_items(){
|
||||
printf("List of items:\n");
|
||||
|
||||
//print items
|
||||
if(map == NULL){
|
||||
print_page(db, page * page_size, (page + 1== total_pages)?db.db.row_count:(page+1) * page_size,(struct Map*)NULL);
|
||||
if(page + 1 >= total_pages){
|
||||
print_page(db, page * page_size, db.db.row_count,map);
|
||||
}else{//sorted)
|
||||
print_page(db, page * page_size, (page + 1== total_pages)?db.db.row_count:(page+1) * page_size,map);
|
||||
print_page(db, page * page_size, (page + 1) * page_size,map);
|
||||
}
|
||||
|
||||
//page control
|
||||
printf("%d next page\n", page_size+3);
|
||||
printf("%d previous page\n", page_size+4);
|
||||
printf("%d set page size\n", page_size+5);
|
||||
printf("%D/%d/%d(page size/page number/total)\n",page_size, page+1,total_pages);
|
||||
printf("%d/%d/%d(page size/page number/total)\n",page_size, page+1,total_pages);
|
||||
|
||||
//prompt user to select an item
|
||||
bool valid = true;
|
||||
@ -127,9 +125,10 @@ void list_items(){
|
||||
printf("Enter page size: ");
|
||||
scanf("%d", &page_size);
|
||||
total_pages = ceil(db.db.row_count / page_size);
|
||||
}else if(choice >= 0 && choice < db.db.row_count){
|
||||
show_item(db,choice-9 + page_size*page);
|
||||
}else{
|
||||
}else if(choice >= 9 && choice < db.db.row_count+9){
|
||||
printf("s");
|
||||
show_item(db,choice - 9 + page_size*page);
|
||||
}else if(choice != 0){
|
||||
printf("Invalid choice\n");
|
||||
valid = false;
|
||||
}
|
||||
@ -153,7 +152,7 @@ struct Map* sortItems(struct inventory db, int sort){
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
map[i].value = (int)db.row[i].band;
|
||||
map[i].value = (int)db.row[i].brand;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
@ -182,10 +181,10 @@ void print_page(struct inventory db, int cur, int end,struct Map* map){
|
||||
for (int i = cur; i < end; i++)
|
||||
{
|
||||
if(map != NULL){
|
||||
printf("%d. %s\n", i + 1, db.row[map[i].key].product);
|
||||
printf("%d item: %s\n", i + 9, db.row[map[i].key].product);
|
||||
}
|
||||
else{
|
||||
printf("item%d. %s\n", i + 3, db.row[i].product);
|
||||
printf("%d item: %s\n", i + 9, db.row[i].product);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,11 +193,13 @@ void show_item(struct inventory db,int index){
|
||||
system("cls");
|
||||
printf("Product: %s\n", db.row[index].product);
|
||||
printf("Catergory: %s\n", db.row[index].category);
|
||||
printf("Band: %d\n", db.row[index].band);
|
||||
printf("Brand: %d\n", db.row[index].brand);
|
||||
printf("Price: $%lf\n", db.row[index].price);
|
||||
printf("Stock: %d\n", db.row[index].stock);
|
||||
printf("Barcode: %ld\n",db.row[index].barcode);
|
||||
|
||||
printf("Press any key to return to the list\n");
|
||||
fflush(stdin);
|
||||
getchar();
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user