inventory bug fixed;
better mechanist
This commit is contained in:
parent
771b36b4a6
commit
9792126a53
24
admin_user.h
24
admin_user.h
@ -123,7 +123,7 @@ void add_item();
|
|||||||
void remove_item(struct inventory db,int index);
|
void remove_item(struct inventory db,int index);
|
||||||
void update_item(struct inventory db,int index);
|
void update_item(struct inventory db,int index);
|
||||||
void admin_list_pages(struct inventory db);
|
void admin_list_pages(struct inventory db);
|
||||||
void item_control(struct inventory db,int index);
|
struct inventory item_control(struct inventory db,int index);
|
||||||
|
|
||||||
int prompt_inv_control(){
|
int prompt_inv_control(){
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
@ -145,7 +145,6 @@ int prompt_inv_control(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void inv_control(){
|
void inv_control(){
|
||||||
struct inventory db = read_db_invt();
|
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
do{
|
do{
|
||||||
choice = prompt_inv_control();
|
choice = prompt_inv_control();
|
||||||
@ -153,6 +152,7 @@ void inv_control(){
|
|||||||
case 1://list
|
case 1://list
|
||||||
//add a new element with product name new item
|
//add a new element with product name new item
|
||||||
//for item control
|
//for item control
|
||||||
|
struct inventory db = read_db_invt();
|
||||||
db.row = (struct inventory_row *)realloc(db.row, sizeof(struct inventory_row) * (db.db.row_count + 1));
|
db.row = (struct inventory_row *)realloc(db.row, sizeof(struct inventory_row) * (db.db.row_count + 1));
|
||||||
db.db.row_count += 1;
|
db.db.row_count += 1;
|
||||||
strcpy(db.row[db.db.row_count - 1].product,"CREATE NEW ITEM");
|
strcpy(db.row[db.db.row_count - 1].product,"CREATE NEW ITEM");
|
||||||
@ -183,11 +183,16 @@ void show_item_admin(struct inventory db,int index){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_control(struct inventory db,int index){
|
struct inventory item_control(struct inventory db,int index){
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
if(db.row[index].barcode == -1024){//new item
|
if(db.row[index].barcode == -1024){//new item
|
||||||
add_item();
|
add_item();
|
||||||
return;
|
struct inventory temp = read_db_invt();//reappend new item at back
|
||||||
|
temp.row = (struct inventory_row *)realloc(temp.row, sizeof(struct inventory_row) * (temp.db.row_count + 1));
|
||||||
|
temp.db.row_count += 1;
|
||||||
|
strcpy(temp.row[temp.db.row_count - 1].product,"CREATE NEW ITEM");
|
||||||
|
temp.row[temp.db.row_count - 1].barcode = -1024;//IMPORTANT: -1024 is reserved for new item
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -212,6 +217,12 @@ void item_control(struct inventory db,int index){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (choice != 0);
|
} while (choice != 0);
|
||||||
|
struct inventory temp = read_db_invt();
|
||||||
|
temp.row = (struct inventory_row *)realloc(temp.row, sizeof(struct inventory_row) * (temp.db.row_count + 1));
|
||||||
|
temp.db.row_count += 1;
|
||||||
|
strcpy(temp.row[temp.db.row_count - 1].product,"CREATE NEW ITEM");
|
||||||
|
temp.row[temp.db.row_count - 1].barcode = -1024;//IMPORTANT: -1024 is reserved for new item
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* prompt_item(char* prompt){
|
char* prompt_item(char* prompt){
|
||||||
@ -222,9 +233,10 @@ char* prompt_item(char* prompt){
|
|||||||
scanf("%[^\n]",item);
|
scanf("%[^\n]",item);
|
||||||
if(strcmp(item,"") == 0){
|
if(strcmp(item,"") == 0){
|
||||||
printf("Invalid input, try again?(y/n)\n");
|
printf("Invalid input, try again?(y/n)\n");
|
||||||
|
char temp[100];
|
||||||
fflush(stdin);
|
fflush(stdin);
|
||||||
char c = getchar();
|
scanf("%[^\n]",temp);
|
||||||
if(c == 'n'){
|
if(strcmp(temp,"n") == 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ void normal_menu(){
|
|||||||
|
|
||||||
//universal functions for normal user
|
//universal functions for normal user
|
||||||
struct Map* sortItems(struct inventory db, int sort);
|
struct Map* sortItems(struct inventory db, int sort);
|
||||||
void show_item(struct inventory db,int index){
|
struct inventory show_item(struct inventory db,int index){
|
||||||
system("cls");
|
system("cls");
|
||||||
printf("Product: %s\n", db.row[index].product);
|
printf("Product: %s\n", db.row[index].product);
|
||||||
printf("Catergory: %s\n", db.row[index].category);
|
printf("Catergory: %s\n", db.row[index].category);
|
||||||
@ -71,7 +71,7 @@ void show_item(struct inventory db,int index){
|
|||||||
printf("Press any key to return to the list\n");
|
printf("Press any key to return to the list\n");
|
||||||
fflush(stdin);
|
fflush(stdin);
|
||||||
getchar();
|
getchar();
|
||||||
return;
|
return db;
|
||||||
}
|
}
|
||||||
int normal_menu_user_choices(){
|
int normal_menu_user_choices(){
|
||||||
int choice;
|
int choice;
|
||||||
@ -87,7 +87,7 @@ int normal_menu_user_choices(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//user for showing list result and search result
|
//user for showing list result and search result
|
||||||
void list_page(struct inventory db,struct Map* map,int row,void (*showitem)(struct inventory,int)){//showitem is a function pointer for showing item,allow customization for better flexibilty
|
void list_page(struct inventory db,struct Map* map,int row,struct inventory (*showitem)(struct inventory,int)){//showitem is a function pointer for showing item,allow customization for better flexibilty
|
||||||
int choice = -1;
|
int choice = -1;
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int page_size = PAGE_SIZE;
|
int page_size = PAGE_SIZE;
|
||||||
@ -140,7 +140,7 @@ void list_page(struct inventory db,struct Map* map,int row,void (*showitem)(stru
|
|||||||
scanf("%d", &page_size);
|
scanf("%d", &page_size);
|
||||||
total_pages = ceil(row / page_size);
|
total_pages = ceil(row / page_size);
|
||||||
}else if(choice >= 9 && choice < row+9){
|
}else if(choice >= 9 && choice < row+9){
|
||||||
(*showitem)(db,choice - 9 + page_size*page);
|
db = (*showitem)(db,choice - 9 + page_size*page);
|
||||||
}else if(choice != 0){
|
}else if(choice != 0){
|
||||||
printf("Invalid choice\n");
|
printf("Invalid choice\n");
|
||||||
valid = false;
|
valid = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user