mirror of https://github.com/IoTcat/HOMES.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
438 lines
14 KiB
438 lines
14 KiB
|
|
int demo__test_fundamental_functions(); |
|
int demo__menu(); |
|
void demo__print__menu(int nPnt); |
|
void demo__data__insert_visitor_info(); |
|
void demo__data__del_visitor_info(); |
|
void demo__data__get_visitor_info(); |
|
void demo__data__insert_room_info(); |
|
void demo__data__del_room_info(); |
|
void demo__data__get_room_info(); |
|
void demo__create_visitor(); |
|
void demo__create_room(); |
|
void demo__display_all_visitors(); |
|
void demo__display_all_rooms(); |
|
|
|
/*********** demo test function, you can find the demo of most fundamental function here ********/ |
|
|
|
/* demo guide function*/ |
|
int demo__test_fundamental_functions() |
|
{ |
|
printf("Please Press 't' to goto test screen, or press any other key to goto your main fuction!\n"); |
|
|
|
if(input__detect_input_ASCII()=='t') |
|
{ |
|
system("cls");/*clean the screen */ |
|
printf("1. press 'p' to goto input and print fundamental function demo.\n\n"); |
|
printf("2. press 'd' to goto data fundamental function demo.\n\n"); |
|
printf("3. press 'g' to create visitor and room data to support your own code!\n\n"); |
|
|
|
/* get user pressed key */ |
|
char tmp_getPress=input__detect_input_ASCII(); |
|
|
|
if(tmp_getPress=='p') |
|
{ |
|
system("cls");/* clean the screen */ |
|
|
|
/* initialize the window */ |
|
print__setup(); |
|
|
|
/* quit untill press an esc*/ |
|
while(demo__menu()!=6); |
|
|
|
/* quit the demo function */ |
|
return 0; |
|
} |
|
|
|
if(tmp_getPress=='d') |
|
{ |
|
system("cls");/* clean the screen */ |
|
|
|
printf("Please select:\n\n"); |
|
printf("1. data__insert_visitor_info() demo\n\n"); |
|
printf("2. data__del_visitor_info() demo\n\n"); |
|
printf("3. data__get_visitor_info() demo\n\n\n"); |
|
printf("4. data__insert_room_info() demo\n\n"); |
|
printf("5. data__del_room_info() demo\n\n"); |
|
printf("6. data__get_room_info() demo\n\n"); |
|
|
|
tmp_getPress=input__detect_input_ASCII(); |
|
|
|
system("cls");/* clean the screen */ |
|
|
|
if(tmp_getPress=='1') demo__data__insert_visitor_info(); |
|
if(tmp_getPress=='2') demo__data__del_visitor_info(); |
|
if(tmp_getPress=='3') demo__data__get_visitor_info(); |
|
if(tmp_getPress=='4') demo__data__insert_room_info(); |
|
if(tmp_getPress=='5') demo__data__del_room_info(); |
|
if(tmp_getPress=='6') demo__data__get_room_info(); |
|
|
|
system("echo Press any key to goto main()&pause>nul"); |
|
|
|
} |
|
|
|
if(tmp_getPress=='g') |
|
{ |
|
system("cls"); |
|
|
|
printf("Please select:\n\n"); |
|
printf("1. Create a visitor data\n\n"); |
|
printf("2. Create a room data\n\n"); |
|
printf("3. Display all visitors\n\n"); |
|
printf("4. Display all rooms\n\n"); |
|
|
|
tmp_getPress=input__detect_input_ASCII(); |
|
|
|
system("cls"); |
|
|
|
if(tmp_getPress=='1') demo__create_visitor(); |
|
if(tmp_getPress=='2') demo__create_room(); |
|
if(tmp_getPress=='3') demo__display_all_visitors(); |
|
if(tmp_getPress=='4') demo__display_all_rooms(); |
|
|
|
system("echo Press any key to goto main()&pause>nul"); |
|
} |
|
|
|
/* clean the screen */ |
|
system("cls"); |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
|
|
|
|
/* demo function for display menu, you can design your menu logic here*/ |
|
int demo__menu() |
|
{ |
|
int nVal=54; |
|
int nArrw=0; |
|
do |
|
{ |
|
/* print out the menu */ |
|
demo__print__menu(nVal%6+1); |
|
|
|
/* detect user keyboard press*/ |
|
nArrw= input__get_arrow(); |
|
|
|
/* when input a arrow */ |
|
if(nArrw==1||nArrw==-1) |
|
nVal+=nArrw; |
|
|
|
/* when press enter */ |
|
if(nArrw==6) |
|
break; |
|
/* when press esc */ |
|
if(nArrw==9) |
|
return 6; |
|
|
|
}while(1); |
|
|
|
/* return user choice by number*/ |
|
return nVal%6+1; |
|
} |
|
|
|
|
|
/* demo function for printing a menu ,you can design your menu here*/ |
|
void demo__print__menu(int nPnt) |
|
{ |
|
|
|
/* clear screen */ |
|
system("cls"); |
|
|
|
/* print the screen header */ |
|
print__header(); |
|
|
|
printf("Please use Arrows on Keyboard to Choose:\n"); |
|
char chItem1[]="Choose 1"; |
|
/* function pringt__item has three parameters: display string, if it is choosed,extra space on its left*/ |
|
print__item(chItem1,(nPnt==1)?1:0,0); |
|
|
|
char chItem2[]="Choose 2"; |
|
print__item(chItem2,(nPnt==2)?1:0,0); |
|
|
|
char chItem3[]="Choose 3"; |
|
print__item(chItem3,(nPnt==3)?1:0,0); |
|
|
|
char chItem4[]="Choose 4"; |
|
print__item(chItem4,(nPnt==4)?1:0,0); |
|
|
|
char chItem5[]="Choose 5"; |
|
print__item(chItem5,(nPnt==5)?1:0,0); |
|
|
|
char chItem6[]="Exit "; |
|
print__item(chItem6,(nPnt==6)?1:0,0); |
|
|
|
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
|
printf("Press ESC to Exit!"); |
|
|
|
} |
|
|
|
|
|
/* demo for data_insert visitor_info() */ |
|
void demo__data__insert_visitor_info() |
|
{ |
|
|
|
printf("Demo 1:\nThis demo will create a visitor file of yimian. \nto begin with this function, you need a visitor struct which include the visitor info you want to insert. \nYou can see this code in demo__data_insert_visitor_info() function\n\n"); |
|
|
|
/* Create a new visitor struct variable with some user info */ |
|
visitor demo_NewVisitor={0/*this is the visitor id, please leave 0 here */,"yimian Liu"/*name*/,"18118155257"/*tel*/,1/*vip*/,"370902199909041813"/*nationalId*/,"china"/*nation*/,"shandong"/*province*/,"taian"/*city*/}; |
|
|
|
/* excute the data__insert_visitor_info function and when the function crash, print the error info on screen */ |
|
if(data__insert_visitor_info(&demo_NewVisitor)) printf("Error in Function data__insert_visitor_info: %s\n",strerror(errno)); |
|
else printf("Create successfully!\n"); |
|
|
|
} |
|
|
|
|
|
|
|
/* demo for data__del_visitor_info */ |
|
void demo__data__del_visitor_info() |
|
{ |
|
printf("Demo 2:\nTo delete a visitor info, you need to provide the visitor's ID.\n\n"); |
|
printf("you can see detailed info in demo__data__del_visitor_info()\n\n"); |
|
|
|
printf("Please input the ID:\n"); |
|
|
|
/* get ID input */ |
|
char tmp_visitorId[11]; |
|
gets(tmp_visitorId); |
|
|
|
/* del the visitor info */ |
|
if(data__del_visitor_info(atoi(tmp_visitorId))) printf("Error in Function data__del_visitor_info: %s\n",strerror(errno));; |
|
|
|
} |
|
|
|
|
|
/* demo for data__get_visitor_info() */ |
|
void demo__data__get_visitor_info() |
|
{ |
|
printf("Demo 3:\nGet Visitors info, index key word is 'china' in this case. \n"); |
|
printf("to search a visitor info, data__get_visitor_info() need a key word and a visitor pointer.\n"); |
|
printf("the key word must be more than three word and the visito info found will be store in the visitor point you provided\n"); |
|
printf("for more info please see demo__data__get_visitor_info() function!\n\n"); |
|
|
|
/* provide a key word to search visitors*/ |
|
char tmp_Nation[35]="china"; |
|
|
|
/* declear a visitor pointer to receive the matched visitors info */ |
|
struct visitor *pVstr=NULL; |
|
pVstr= data__get_visitor_info(tmp_Nation,pVstr); |
|
|
|
/* show error hint if the function not runing successfully */ |
|
if(errno) printf("Error in Function data__get_visitor_info: %s\n",strerror(errno)); |
|
|
|
/* deal with situation that nothing found */ |
|
if(!g_nRtrnRows) printf("No visitor found!!\n"); |
|
|
|
/* print all these visitors info on screen */ |
|
for(int i=0;i<g_nRtrnRows;i++) |
|
printf("ID:%d Name:%s Tel:%s VIP:%d NationalID:%s Nation:%s province:%s City:%s\n", (pVstr+i)->id, (pVstr+i)->name, (pVstr+i)->tel,(pVstr+i)->vip, (pVstr+i)->nationalId,(pVstr+i)->nation, (pVstr+i)->province, (pVstr+i)->city); |
|
|
|
} |
|
|
|
|
|
/* demo function for data__insert_room_info() */ |
|
void demo__data__insert_room_info() |
|
{ |
|
printf("Demo 4:\nThis demo will create a room file of room 666 in 20181111.\n"); |
|
printf("data__insert_room_info() need the address of a room struct before insert one info.\n"); |
|
printf("for more info please see demo__data__insert_room_info()\n\n"); |
|
|
|
/* Create a new visitor struct variable with some user info */ |
|
room demo_NewRoom={0/*this is the visitor id, please leave 0 here */,666/*roomId*/,20181111/*date*/,{2/*visitor number*/,1234567899,1243567899}/*visitorId*/,2/*room type*/,66.66/*price*/,2/*checkIn*/,1/*checkOut*/}; |
|
|
|
/* excute the data__insert_visitor_info function and when the function crash, print the error info on screen */ |
|
if(data__insert_room_info(&demo_NewRoom)) printf("Error in Function data__insert_room_info: %s\n",strerror(errno)); |
|
else printf("Create successfully!\n"); |
|
|
|
} |
|
|
|
|
|
|
|
/* demo for data__del_room_info() */ |
|
void demo__data__del_room_info() |
|
{ |
|
printf("Demo 5:\nTo delete a room info, you need to provide the index and the roomId.\n\n"); |
|
printf("See more in function demo__data__del_room_info()\n\n" ); |
|
|
|
printf("Please input the Index:\n"); |
|
|
|
/* get index input */ |
|
char tmp_roomIndex[11]; |
|
while(!scanf("%s",tmp_roomIndex)) fflush(stdin); |
|
|
|
printf("Please input the RoomId:\n"); |
|
|
|
/* get room input */ |
|
char tmp_roomId[11]; |
|
while(!scanf("%s",tmp_roomId)) fflush(stdin); |
|
|
|
/* del the visitor info */ |
|
if(data__del_room_info(atoi(tmp_roomIndex),atoi(tmp_roomId))) printf("Error in Function data__del_room_info: %s\n",strerror(errno)); |
|
} |
|
|
|
|
|
|
|
void demo__data__get_room_info() |
|
{ |
|
printf("Demo 6:\nGet room info, you need to set one or more condition, and the function will return all the room info which satisfy your condition.\n"); |
|
printf("to learn more please see demo__data__get_room_info()\n\n"); |
|
printf("in this case, we had set some condition for rooms searching.\n"); |
|
printf("You can find more detail in function demo__data__get_room_info()\n\n"); |
|
|
|
/* declear a room pointer to receive the matched rooms info */ |
|
struct room *pRm=NULL; |
|
|
|
int hh[]={2/* number of visitors*/,1234567899/* visitorId*/,1243567899/* visitorId*/}; |
|
pRm= data__get_room_info(0/*index*/,666/*roomId*/,0/*date*/,hh/*visitorId*/,2/*type*/,0/*price*/,0/*checkIn*/,1/*checkOut*/,pRm); |
|
|
|
/* show error hint if the function not runing successfully */ |
|
if(!pRm) printf("Error in Function data__get_room_info: %s\n",strerror(errno)); |
|
|
|
/* deal with situation that nothing found */ |
|
if(!g_nRtrnRows) printf("No room found!!\n"); |
|
|
|
/* print all these rooms info on screen */ |
|
for(int i=0;i<g_nRtrnRows;i++) |
|
printf("Index:%d Room:%d date:%d VisitorNum:%d Type:%d Price:%f CheckIn:%d CheckOut:%d\n", (pRm+i)->index, (pRm+i)->roomId, (pRm+i)->date,(pRm+i)->visitorId[0], (pRm+i)->type,(pRm+i)->price, (pRm+i)->checkIn, (pRm+i)->checkOut); |
|
|
|
} |
|
|
|
|
|
/* function for create a visitor*/ |
|
void demo__create_visitor() |
|
{ |
|
visitor demo_NewVisitor; |
|
|
|
printf("Please input a name:\n"); |
|
while(!scanf("%s",demo_NewVisitor.name)) fflush(stdin); |
|
|
|
printf("Please input a tel:\n"); |
|
while(!scanf("%s",demo_NewVisitor.tel)) fflush(stdin); |
|
|
|
printf("Please input if it is vip (not vip->1,vip->2) :\n"); |
|
char tmp_ch[15]; |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewVisitor.vip=atoi(tmp_ch); |
|
|
|
printf("Please input a nationalId:\n"); |
|
while(!scanf("%s",demo_NewVisitor.nationalId)) fflush(stdin); |
|
|
|
printf("Please input a nation:\n"); |
|
while(!scanf("%s",demo_NewVisitor.nation)) fflush(stdin); |
|
|
|
printf("Please input a province:\n"); |
|
while(!scanf("%s",demo_NewVisitor.province)) fflush(stdin); |
|
|
|
printf("Please input a city:\n"); |
|
while(!scanf("%s",demo_NewVisitor.city)) fflush(stdin); |
|
|
|
demo_NewVisitor.id=0; |
|
|
|
/* excute the data__insert_visitor_info function and when the function crash, print the error info on screen */ |
|
if(data__insert_visitor_info(&demo_NewVisitor)) printf("Error in Function data__insert_visitor_info: %s\n",strerror(errno)); |
|
else printf("Create successfully!\n"); |
|
} |
|
|
|
|
|
void demo__create_room() |
|
{ |
|
|
|
room demo_NewRoom={0/*this is the visitor id, please leave 0 here */,666/*roomId*/,20181111/*date*/,{2/*visitor number*/,1234567899,1243567899}/*visitorId*/,2/*room type*/,66.66/*price*/,2/*checkIn*/,1/*checkOut*/}; |
|
|
|
char tmp_ch[25]; |
|
|
|
printf("Please input a roomId (e.g. 205):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.roomId=atoi(tmp_ch); |
|
|
|
printf("Please input a date (e.g. 20181111):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.date=atoi(tmp_ch); |
|
|
|
printf("Please input the number of visitors:\n"); |
|
int tmp_vNum=0; |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
tmp_vNum=atoi(tmp_ch); |
|
|
|
if(tmp_vNum) |
|
{ |
|
for(int i=0;i<tmp_vNum;i++) |
|
{ |
|
printf("Please input visitors Id\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.visitorId[i+1]=atoi(tmp_ch); |
|
} |
|
} |
|
|
|
demo_NewRoom.visitorId[0]=tmp_vNum; |
|
|
|
printf("Please input a room type (e.g. 1,2,3,4,5):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.type=atoi(tmp_ch); |
|
|
|
printf("Please input a price (e.g. 205.5):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.price=atof(tmp_ch); |
|
|
|
printf("Please input if it is checkIn (not In->1, In->2):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.checkIn=atoi(tmp_ch); |
|
|
|
printf("Please input if it is checkOut (not Out->1, Out->2):\n"); |
|
while(!scanf("%s",tmp_ch)) fflush(stdin); |
|
demo_NewRoom.checkOut=atoi(tmp_ch); |
|
|
|
|
|
/* excute the data__insert_visitor_info function and when the function crash, print the error info on screen */ |
|
if(data__insert_room_info(&demo_NewRoom)) printf("Error in Function data__insert_room_info: %s\n",strerror(errno)); |
|
else printf("Create successfully!\n"); |
|
} |
|
|
|
|
|
|
|
void demo__display_all_visitors() |
|
{ |
|
char tmp_chTmp[35]; |
|
tmp_chTmp[0]='\0'; |
|
/* declear a visitor pointer to receive the matched visitors info */ |
|
struct visitor *pVstr=NULL; |
|
pVstr= data__get_visitor_info(tmp_chTmp,pVstr); |
|
|
|
/* show error hint if the function not runing successfully */ |
|
if(!pVstr) printf("Error in Function data__get_visitor_info: %s\n",strerror(errno)); |
|
|
|
/* print all these visitors info on screen */ |
|
for(int i=0;i<g_nRtrnRows;i++) |
|
printf("ID:%d Name:%s Tel:%s VIP:%d NationalID:%s Nation:%s province:%s City:%s\n", (pVstr+i)->id, (pVstr+i)->name, (pVstr+i)->tel,(pVstr+i)->vip, (pVstr+i)->nationalId,(pVstr+i)->nation, (pVstr+i)->province, (pVstr+i)->city); |
|
} |
|
|
|
|
|
|
|
void demo__display_all_rooms() |
|
{ |
|
/* declear a room pointer to receive the matched rooms info */ |
|
struct room *pRm=NULL; |
|
|
|
pRm= data__get_room_info(0/*index*/,0/*roomId*/,0/*date*/,NULL/*visitorId*/,0/*type*/,0/*price*/,0/*checkIn*/,0/*checkOut*/,pRm); |
|
|
|
/* show error hint if the function not runing successfully */ |
|
if(!pRm) printf("Error in Function data__get_room_info: %s\n",strerror(errno)); |
|
|
|
/* print all these rooms info on screen */ |
|
for(int i=0;i<g_nRtrnRows;i++) |
|
printf("Index:%d Room:%d date:%d VisitorNum:%d Type:%d Price:%f CheckIn:%d CheckOut:%d\n", (pRm+i)->index, (pRm+i)->roomId, (pRm+i)->date,(pRm+i)->visitorId[0], (pRm+i)->type,(pRm+i)->price, (pRm+i)->checkIn, (pRm+i)->checkOut); |
|
|
|
} |
|
|
|
/***************above are the demo function********************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********!!!!!!!!!!above are fundamental functions!!!!!!!!!************/ |