error fix;

list view updated;
transaction table view updated;
still undergo debug for transaction;
fix some format error on the data_file_transaction.txt
This commit is contained in:
stmctommyau 2022-09-17 11:36:52 +08:00
parent 409901fb0e
commit c69d312335
3 changed files with 64 additions and 25 deletions

View File

@ -406,7 +406,7 @@ void tran_control(){
getchar();
break;
}
}while(choice != 5);
}while(choice != 3);
}
@ -433,17 +433,20 @@ void list_tran(struct transaction db){
printf("5 sort quantity decending\n");
printf("6 sort quantity ascending\n");
printf("7 sort total decending\n");
printf("8 sort total ascending\n");
printf("No. Date Time Price Quantity Total\n");
printf("8 sort total ascending\n");
if(page+1 == total_pages){
print_tran(db,page*page_size,row,map);
}else{
print_tran(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);
int current_page_size = page_size+8;
if(page+1 == total_pages){
current_page_size = row - page*page_size+8;
}
printf("%d next page\n", current_page_size+1);
printf("%d previous page\n", current_page_size+2);
printf("%d set page size\n", current_page_size+3);
printf("%d/%d/%d(page size/page number/total)\n",page_size, page+1,total_pages);
bool valid = true;
@ -455,16 +458,26 @@ void list_tran(struct transaction db){
if(choice <=8 && choice > 0){
printf("sorting...\n");
map = sortTrans(db,choice);
}else if(choice == page_size+3 && page + 1 < total_pages){
page++;
}else if(choice == page_size+4 && page > 0){
page--;
}else if(choice == page_size+5){
}else if(choice == current_page_size+1 ){
if(page + 1 < total_pages){
page++;
}else{
printf("Already at last page\n");
valid = false;
}
}else if(choice == current_page_size+2){
if(page > 0){
page--;
}else{
printf("Already at first page\n");
valid = false;
}
}else if(choice == current_page_size+3){
printf("Enter page size: ");
fflush(stdin);
scanf("%d", &page_size);
total_pages = ceil(row / page_size);
}else if(choice >= 9 && choice < row+9){
}else if(choice >= 9 && choice <= current_page_size){
if(map == NULL){
db = showTran(db,choice - 9 + page_size*page);
}else{
@ -482,14 +495,25 @@ void list_tran(struct transaction db){
void print_tran(struct transaction db, int cur, int end,struct Map* map){
printf("%-5s%-15s%-10s%-10s%-10s%-10s%-10s\n","No.","Date","Time","Barcode","Price","Quantity","Total");
for (int i = cur; i < end; i++)
{
if(map != NULL){
double total = db.row[map[i].key].price * db.row[map[i].key].quantity;
printf("%-4d%-12s%-12s$%-12.1lf%-12d$%-12.1lf\n",i+1,db.row[map[i].key].date,db.row[map[i].key].time,db.row[map[i].key].price,db.row[map[i].key].quantity,total);
//reconstuct date and time and print all transaction info out
char date[11];
char time[9];
sprintf(date,"%04d-%02d-%02d",db.row[map[i].key].date.day,db.row[map[i].key].date.month,db.row[map[i].key].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[map[i].key].time.hour,db.row[map[i].key].time.minute,db.row[map[i].key].time.second);
printf("%-5d%-15s%-10s%-10ld%-10.2lf%-10d%-10.2lf\n",i+9-cur,date,time,db.row[map[i].key].barcode,db.row[map[i].key].price,db.row[map[i].key].quantity,total);
}else{
double total = db.row[i].price * db.row[i].quantity;
printf("%-4d%-12s%-12s$%-12.1lf%-12d$%-12.1lf\n",i+1,db.row[i].date,db.row[i].time,db.row[i].price,db.row[i].quantity,total);
//reconstuct date and time and print all transaction info out
char date[11];
char time[9];
sprintf(date,"%04d-%02d-%02d",db.row[i].date.day,db.row[i].date.month,db.row[i].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[i].time.hour,db.row[i].time.minute,db.row[i].time.second);
printf("%-5d%-15s%-10s%-10ld%-10.2lf%-10d%-10.2lf\n",i+9-cur,date,time,db.row[i].barcode,db.row[i].price,db.row[i].quantity,total);
}
}
}

View File

@ -64,9 +64,10 @@
20001
22.9
1
5155
2022-09-03
22:14:48
32001
15.000000
10
1122
5155

View File

@ -115,9 +115,13 @@ void list_page(struct inventory db,struct Map* map,int row,struct inventory (*sh
}
//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);
int current_page_size = 8 + page_size;
if(page + 1 >= total_pages){
current_page_size = row - page * page_size+8;
}
printf("%d next page\n", current_page_size+1);
printf("%d previous page\n", current_page_size+2);
printf("%d set page size\n", current_page_size+3);
printf("%d/%d/%d(page size/page number/total)\n",page_size, page+1,total_pages);
//prompt user to select an item
@ -130,16 +134,26 @@ void list_page(struct inventory db,struct Map* map,int row,struct inventory (*sh
if(choice <=8 && choice > 0){
printf("sorting...\n");
map = sortItems(db,choice);
}else if(choice == page_size+3 && page + 1 < total_pages){
page++;
}else if(choice == page_size+4 && page > 0){
page--;
}else if(choice == page_size+5){
}else if(choice == current_page_size+1 ){
if(page + 1 < total_pages){
page++;
}else{
printf("Already at last page\n");
valid = false;
}
}else if(choice == current_page_size+2){
if(page > 0){
page--;
}else{
printf("Already at first page\n");
valid = false;
}
}else if(choice == current_page_size+3){
printf("Enter page size: ");
fflush(stdin);
scanf("%d", &page_size);
total_pages = ceil(row / page_size);
}else if(choice >= 9 && choice < row+9){
}else if(choice >= 9 && choice <= current_page_size){
if(map == NULL){
db = (*showitem)(db,choice - 9 + page_size*page);
}else{
@ -328,7 +342,7 @@ struct Map* searchItems(struct inventory db, char* searchstr){
}
}
int* k_star = malloc(sizeof(int));
*k_star = --k;
*k_star = --k;//decrement and assign to k star;don't use k-- as it will decrement after the assignment
map[0].value = (void*)k_star;
map[0].key = -1;
return map;