Fix some cross-compat problem
This commit is contained in:
parent
ea4a7526c4
commit
d74170536c
@ -38,13 +38,13 @@ void admin_menu(){
|
|||||||
"Role control",
|
"Role control",
|
||||||
};
|
};
|
||||||
char welcome[256];
|
char welcome[256];
|
||||||
|
sprintf(welcome,"welcome %s(%s)\n",user->name,user->role);
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
do{
|
do{
|
||||||
sprintf(welcome,"welcome %s(%s)\n",user->name,user->role);
|
|
||||||
|
|
||||||
switch (choices_selecter(Items,4,welcome))
|
switch (choices_selecter(Items,4,welcome))
|
||||||
{
|
{
|
||||||
case 1://action with inventory
|
case 1:;//action with inventory
|
||||||
inv_control();
|
inv_control();
|
||||||
break;
|
break;
|
||||||
case 2://action with transction
|
case 2://action with transction
|
||||||
|
@ -7,7 +7,7 @@ char * show_item_admin(struct inventory db,int index);
|
|||||||
void * show_item(void * ddb,int index);
|
void * show_item(void * ddb,int index);
|
||||||
void print_page(void * ddb, int cur, int end,struct Map* map);
|
void print_page(void * ddb, int cur, int end,struct Map* map);
|
||||||
struct Map* sortItems(void * ddb, int sort);
|
struct Map* sortItems(void * ddb, int sort);
|
||||||
|
void search_item(void * (*showitem)(void *,int));
|
||||||
void inv_control(){
|
void inv_control(){
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
do{
|
do{
|
||||||
@ -258,4 +258,4 @@ struct Map* sortItems(void * ddb, int sort){
|
|||||||
map = realloc(map, sizeof(struct Map) * db.db.row_count);
|
map = realloc(map, sizeof(struct Map) * db.db.row_count);
|
||||||
map[db.db.row_count-1].key = db.db.row_count-1;
|
map[db.db.row_count-1].key = db.db.row_count-1;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ void normal_menu(){
|
|||||||
},3,buf);
|
},3,buf);
|
||||||
switch (choice)
|
switch (choice)
|
||||||
{
|
{
|
||||||
case 1://List items
|
case 1:;//List items
|
||||||
struct inventory db = read_db_invt();
|
struct inventory db = read_db_invt();
|
||||||
char * SortItems[] = {
|
char * SortItems[] = {
|
||||||
"Name",
|
"Name",
|
||||||
@ -353,7 +353,7 @@ struct cart* list_cart(struct cart* cart){
|
|||||||
printf("<------------------------>\n");
|
printf("<------------------------>\n");
|
||||||
|
|
||||||
printf("\n%d CHECKOUT\n",i);
|
printf("\n%d CHECKOUT\n",i);
|
||||||
printf("Clear Cart\n",i+1);
|
printf("%d Clear Cart\n",i+1);
|
||||||
}
|
}
|
||||||
do{
|
do{
|
||||||
printf("input the corresponding value for more action\n>");
|
printf("input the corresponding value for more action\n>");
|
||||||
|
@ -22,7 +22,7 @@ void role_control(){
|
|||||||
case 1:
|
case 1:
|
||||||
add_role();
|
add_role();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:;
|
||||||
char * SortItems[] = {
|
char * SortItems[] = {
|
||||||
"admin",
|
"admin",
|
||||||
"role",
|
"role",
|
||||||
|
@ -16,7 +16,7 @@ void tran_control(){
|
|||||||
"new transaction"
|
"new transaction"
|
||||||
},2,buf);
|
},2,buf);
|
||||||
switch(choice){
|
switch(choice){
|
||||||
case 1:
|
case 1:;
|
||||||
char * SortItems[] = {
|
char * SortItems[] = {
|
||||||
"Date&Time",
|
"Date&Time",
|
||||||
"product(barcode)",
|
"product(barcode)",
|
||||||
@ -26,7 +26,7 @@ void tran_control(){
|
|||||||
lister(&tran,NULL,tran.db.row_count,"Transaction",SortItems,4,print_tran,sortTrans,showTran);
|
lister(&tran,NULL,tran.db.row_count,"Transaction",SortItems,4,print_tran,sortTrans,showTran);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
add_tran(tran);
|
add_tran();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -47,7 +47,7 @@ void print_tran(void * ddb, int cur, int end,struct Map* map){
|
|||||||
char time[9];
|
char time[9];
|
||||||
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
||||||
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
||||||
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
|
printf("%-5d%-15s%-10s%-10ld%-10ld%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
|
||||||
}else{
|
}else{
|
||||||
double total = db.row[i].price * db.row[i].quantity;
|
double total = db.row[i].price * db.row[i].quantity;
|
||||||
//reconstuct date and time and print all transaction info out
|
//reconstuct date and time and print all transaction info out
|
||||||
@ -55,7 +55,7 @@ void print_tran(void * ddb, int cur, int end,struct Map* map){
|
|||||||
char time[9];
|
char time[9];
|
||||||
sprintf(date,"%02d-%02d-%04d",db.row[i].date.day,db.row[i].date.month,db.row[i].date.year);
|
sprintf(date,"%02d-%02d-%04d",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);
|
sprintf(time,"%02d:%02d:%02d",db.row[i].time.hour,db.row[i].time.minute,db.row[i].time.second);
|
||||||
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[i].barcode,db.row[i].id,db.row[i].price,db.row[i].quantity,total);
|
printf("%-5d%-15s%-10s%-10ld%-10ld%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[i].barcode,db.row[i].id,db.row[i].price,db.row[i].quantity,total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ void * showTran(void * ddb,int index){
|
|||||||
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
||||||
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
||||||
sprintf(buff+strlen(buff),"%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity","Total");
|
sprintf(buff+strlen(buff),"%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity","Total");
|
||||||
sprintf(buff+strlen(buff),"%-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);
|
sprintf(buff+strlen(buff),"%-15s%-10s%-10ld%-10ld%-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);
|
||||||
choice = choices_selecter((char*[]){
|
choice = choices_selecter((char*[]){
|
||||||
"Edit transaction",
|
"Edit transaction",
|
||||||
"Delete transaction",
|
"Delete transaction",
|
||||||
@ -152,7 +152,7 @@ struct transaction update_tran(struct transaction db,int index){
|
|||||||
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
||||||
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
||||||
printf("%-15s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity");
|
printf("%-15s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity");
|
||||||
printf("%-15s%-10s%-10d%-10d%-10.2lf%-10d\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity);
|
printf("%-15s%-10s%-10ld%-10ld%-10.2lf%-10d\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity);
|
||||||
|
|
||||||
item_inputer("Date:day",INT,&db.row[index].date.day,true);
|
item_inputer("Date:day",INT,&db.row[index].date.day,true);
|
||||||
item_inputer("Date:month",INT,&db.row[index].date.month,true);
|
item_inputer("Date:month",INT,&db.row[index].date.month,true);
|
||||||
@ -246,4 +246,4 @@ struct Map* sortTrans(void * ddb,int choice){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ void user_control(){
|
|||||||
case 1:
|
case 1:
|
||||||
db = add_user(db);
|
db = add_user(db);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:;
|
||||||
char * SortItems[] = {
|
char * SortItems[] = {
|
||||||
"Name",
|
"Name",
|
||||||
"ID",
|
"ID",
|
||||||
|
9
utils.h
9
utils.h
@ -13,7 +13,7 @@
|
|||||||
//for fflush_stdin
|
//for fflush_stdin
|
||||||
#include <stdio_ext.h>
|
#include <stdio_ext.h>
|
||||||
#endif
|
#endif
|
||||||
#define PAGE_SIZE 20
|
#define SIZE_OF_PAGE 20
|
||||||
|
|
||||||
void Cls(){
|
void Cls(){
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -35,11 +35,12 @@ char * welcome_message(void * ptr){ //cross compatible
|
|||||||
if(!ptr){//if fp is NULL
|
if(!ptr){//if fp is NULL
|
||||||
return "><Welcome to the Student Union POS system><\n";
|
return "><Welcome to the Student Union POS system><\n";
|
||||||
}
|
}
|
||||||
if(feof(ptr)){// if ptr a string or file
|
if(strlen(ptr)){// if ptr a string or file
|
||||||
sprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
|
sprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
|
||||||
}else{
|
}else{
|
||||||
fprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
|
fprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
|
||||||
}
|
}
|
||||||
|
return (char*)NULL;
|
||||||
}
|
}
|
||||||
int choices_selecter(char * Items[],int items,char * welcome_messages){
|
int choices_selecter(char * Items[],int items,char * welcome_messages){
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
@ -74,7 +75,7 @@ char* prompt_item(char* prompt,bool empty_allowed){
|
|||||||
printf("%s",prompt);
|
printf("%s",prompt);
|
||||||
fflush_stdin();
|
fflush_stdin();
|
||||||
scanf("%[^\n]",item);//input until /n
|
scanf("%[^\n]",item);//input until /n
|
||||||
if(!empty_allowed&&(item,"") == 0){//check if temp is not empty
|
if(!empty_allowed&&strcmp(item,"") == 0){//check if temp is not empty
|
||||||
printf("Invalid input, try again?(y/n)\n");
|
printf("Invalid input, try again?(y/n)\n");
|
||||||
char temp[100];
|
char temp[100];
|
||||||
fflush_stdin();
|
fflush_stdin();
|
||||||
@ -119,7 +120,7 @@ bool item_inputer(char * varname,INPUT_TYPE type,void * item,bool empty_allowed)
|
|||||||
void lister(void * db,struct Map* map, int row,char * lister_name,char * SortItems[],int NoSortItems,void (*page_printer)(void*,int,int,struct Map*) , struct Map* (*sorter)(void *,int),void * (*showitem)(void *,int)){
|
void lister(void * db,struct Map* map, int row,char * lister_name,char * SortItems[],int NoSortItems,void (*page_printer)(void*,int,int,struct Map*) , struct Map* (*sorter)(void *,int),void * (*showitem)(void *,int)){
|
||||||
int choice = -1;
|
int choice = -1;
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int page_size = PAGE_SIZE;
|
int page_size = SIZE_OF_PAGE;
|
||||||
int total_pages = ceil((double)row / page_size);
|
int total_pages = ceil((double)row / page_size);
|
||||||
do{
|
do{
|
||||||
Cls();
|
Cls();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user