transaction bug fix;

transaction fix
This commit is contained in:
stmctommyau 2022-09-21 12:55:21 +08:00
parent dc8329de35
commit a0ddf33d85
4 changed files with 49 additions and 34 deletions

View File

@ -216,7 +216,7 @@ struct inventory item_control(struct inventory db,int index){
default:
break;
}
} while (choice != 0);
} while (choice != 0&&choice != 2);
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;
@ -562,42 +562,57 @@ struct transaction showTran(struct transaction db,int index){
}
}while(!valid);
}while(choice != 3);
return db;
}
//tran controls
void add_tran(){
char* temp;
struct transaction_row* row = (struct transaction_row*)malloc(sizeof(struct transaction_row));
temp = prompt_item("Please input date:day \n>");
if(temp == NULL){
free(row);
return;
char check;
printf("Use current date time? (y/n): ");
fflush(stdin);
scanf("%c",&check);
if(check == 'y'){
row->date = get_date();
row->time = get_time();
}else{
temp = prompt_item("Please input date:day \n>");
if(temp == NULL){
free(row);
return;
}
row->date.day = atoi(temp);
temp = prompt_item("Please input date:month \n>");
if(temp == NULL){
free(row);
return;
}
row->date.month = atoi(temp);
temp = prompt_item("Please input date:year \n>");
if(temp == NULL){
free(row);
return;
}
row->date.year = atoi(temp);
temp = prompt_item("Please input time:hour \n>");
if(temp == NULL){
free(row);
return;
}
row->time.hour = atoi(temp);
temp = prompt_item("Please input time:minute \n>");
if(temp == NULL){
free(row);
return;
}
row->time.minute = atoi(temp);
temp = prompt_item("Please input time:second \n>");
if(temp == NULL){
free(row);
return;
}
}
row->date.day = atoi(temp);
temp = prompt_item("Please input date:month \n>");
if(temp == NULL){
free(row);
return;
}
row->date.month = atoi(temp);
temp = prompt_item("Please input date:year \n>");
if(temp == NULL){
free(row);
return;
}
row->date.year = atoi(temp);
temp = prompt_item("Please input time:hour \n>");
if(temp == NULL){
free(row);
return;
}
row->time.hour = atoi(temp);
temp = prompt_item("Please input time:minute \n>");
if(temp == NULL){
free(row);
return;
}
row->time.minute = atoi(temp);
temp = prompt_item("Please input price \n>");
if(temp == NULL){
free(row);

View File

@ -70,4 +70,4 @@
32001
15.000000
10
5155
5155

View File

@ -469,7 +469,7 @@ bool append_transaction_db(struct transaction_row* row){
printf("Error in opening file\n");
return false;
}
fprintf(fp,"%d-%02d-%02d\n",row->date.year,row->date.month,row->date.day);
fprintf(fp,"%04d-%02d-%02d\n",row->date.year,row->date.month,row->date.day);
fprintf(fp,"%02d:%02d:%02d\n",row->time.hour,row->time.minute,row->time.second);
fprintf(fp,"%ld\n",row->id);
fprintf(fp,"%.1f\n",row->price);

View File

@ -20,11 +20,11 @@ typedef struct Date{
struct Date convert_to_date(char* date){
struct Date d;
char* token = strtok(date, "-");
d.day = atoi(token);
d.year = atoi(token);
token = strtok(NULL, "-");
d.month = atoi(token);
token = strtok(NULL, "-");
d.year = atoi(token);
d.day = atoi(token);
return d;
}