fix scanf to item_inputer
This commit is contained in:
parent
d61a2abc6a
commit
7587d48557
101
admin_user.h
101
admin_user.h
@ -499,66 +499,22 @@ void add_tran(){
|
|||||||
struct transaction update_tran(struct transaction db,int index){
|
struct transaction update_tran(struct transaction db,int index){
|
||||||
char temp[100];
|
char temp[100];
|
||||||
printf("Update transaction(empty value to not change the value)\n");
|
printf("Update transaction(empty value to not change the value)\n");
|
||||||
printf("Please input the Date:day(original:%d)\n>",db.row[index].date.day);
|
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
||||||
fflush(stdin);
|
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
||||||
scanf("%[^\n]", temp);//input until /n
|
printf("%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity","Total");
|
||||||
if(strcmp(temp,"") != 0){//check if temp is not empty
|
printf("%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
|
||||||
db.row[index].date.day = atoi(temp);
|
|
||||||
}//else preserve the original value
|
item_inputer("Date:day",INT,&db.row[index].date.day);
|
||||||
printf("Please input the Date:month(original:%d)\n>",db.row[index].date.month);
|
item_inputer("Date:month",INT,&db.row[index].date.month);
|
||||||
fflush(stdin);
|
item_inputer("Date:year",INT,&db.row[index].date.year);
|
||||||
scanf("%[^\n]", temp);
|
item_inputer("Time:hour",INT,&db.row[index].time.hour);
|
||||||
if(strcmp(temp,"") != 0){
|
item_inputer("Time:minute",INT,&db.row[index].time.minute);
|
||||||
db.row[index].date.month = atoi(temp);
|
item_inputer("Time:second",INT,&db.row[index].time.second);
|
||||||
}
|
item_inputer("Price",DOUBLE,&db.row[index].price);
|
||||||
printf("Please input the Date:year(original:%d)\n>",db.row[index].date.year);
|
item_inputer("Quantity",INT,&db.row[index].quantity);
|
||||||
fflush(stdin);
|
item_inputer("ID",LONG,&db.row[index].id);
|
||||||
scanf("%[^\n]", temp);
|
item_inputer("Barcode",LONG,&db.row[index].barcode);
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].date.year = atoi(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Time:hour(original:%d)\n>",db.row[index].time.hour);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].time.hour = atoi(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Time:minute(original:%d)\n>",db.row[index].time.minute);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].time.minute = atoi(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Time:second(original:%d)\n>",db.row[index].time.second);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].time.second = atoi(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Price(original:%.1lf)\n>",db.row[index].price);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].price = atof(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Quantity(original:%d)\n>",db.row[index].quantity);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].quantity = atoi(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the ID(original:%d)\n>",db.row[index].id);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].id = atol(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the Barcode(original:%d)\n>",db.row[index].barcode);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].barcode = atol(temp);
|
|
||||||
}
|
|
||||||
if(!update_db_tran(db)){
|
if(!update_db_tran(db)){
|
||||||
printf("Failed to update transaction\n");
|
printf("Failed to update transaction\n");
|
||||||
exit(1);//exit program to prevent errors
|
exit(1);//exit program to prevent errors
|
||||||
@ -702,24 +658,13 @@ struct user add_user(struct user db){
|
|||||||
}
|
}
|
||||||
struct user edit_user(struct user db,int index){
|
struct user edit_user(struct user db,int index){
|
||||||
char temp[100];
|
char temp[100];
|
||||||
printf("Please input the username(original:%s)\n>",db.row[index].name);
|
printf("Update transaction(empty value to not change the value)\n");
|
||||||
fflush(stdin);
|
printf("%-20s%-10s%-10s\n","Username","ID","Role");
|
||||||
scanf("%[^\n]", temp);
|
printf("%-20s%-10ld%-10s\n",db.row[index].name,db.row[index].id,db.row[index].role);
|
||||||
if(strcmp(temp,"") != 0){
|
item_inputer("username",STRING,db.row[index].name);
|
||||||
strcpy(db.row[index].name,temp);
|
item_inputer("id",LONG,db.row[index].id);
|
||||||
}
|
item_inputer("role",STRING,db.row[index].role);
|
||||||
printf("Please input the id(original:%d)\n>",db.row[index].id);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
db.row[index].id = atol(temp);
|
|
||||||
}
|
|
||||||
printf("Please input the role(original:%s)\n>",db.row[index].role);
|
|
||||||
fflush(stdin);
|
|
||||||
scanf("%[^\n]", temp);
|
|
||||||
if(strcmp(temp,"") != 0){
|
|
||||||
strcpy(db.row[index].role,temp);
|
|
||||||
}
|
|
||||||
if(!update_db_user(db)){
|
if(!update_db_user(db)){
|
||||||
printf("Failed to update user\n");
|
printf("Failed to update user\n");
|
||||||
exit(1);//exit program to prevent errors
|
exit(1);//exit program to prevent errors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user