Restaurant order system C language source code

  • 2020-06-23 01:11:00
  • OfStack

Restaurant a la carte system c language source code, 1 some packaged functions, the operation of the linked list, as well as the access to the file, for your reference, the specific content is as follows


#include "public.h"
struct NODE *myhead;
struct NODE *orderhead;
struct NODE *ashead;
char waiter_ID[4+1];

/******************************* Set the color of the input field *******************************************
  Name: Sets the color of the input field 
  Parameters: 
 iNum  said :  The length of the edit box 
 
  function :
 *************************************************************************************/

void SetColorEdit(int iNum)
{
 SetColor(4,14);
 while (iNum--)
 {
 putchar(' ');
 }
}

void SetColor(unsigned short ForeColor,unsigned short BackGroundColor) 
{
 HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));
}

/******************************* Edit box aUI function *******************************************
  Name: Edit box aUI function 
  Parameters: 
 iLong  said :  The length of the edit box 
 iWide  said :  The width of the edit box 
 x  said :  Position of the start line of the edit box 
 y  said :  Edit box starting column position 
 acBuffer
  said :  Edit what the box displays 
  function :
  in x line y Columns made 1 A long for iLong Wide for iWide Edit box, box Chinese text display acBuffer The contents of the string 
 *************************************************************************************/
void UI_EditBox(int iLong,int iWide,int x,int y,char acBuffer[30])
{
 int i; /* wide */
 int j; /* long */
 
 Gotoxy(x,y);
 
 for(i = 0; i <= iWide; i++)
 {
 Gotoxy(x+i,y);
 if(i == 0 || i == iWide)
 {
 for(j = 0; j <= iLong; j++)
 {
 if(i == 0 && j == 0)
 {
  printf(" ┏ ");
 }
 else if(i == 0 && j == iLong)
 {
  printf(" ┓ ");
 }
 else if(i == iWide && j == 0)
 {
  printf(" ┗ ");
 }
 else if(i == iWide && j == iLong)
 {
  printf(" ┛ ");
 }
 else
 {
  printf(" ┅ ");
 } 
 } 
 }
 else
 {
 Gotoxy(x+i,y); 
 printf (" ┇ ");
 Gotoxy(x+i,y+2*iLong);
 printf (" ┇ ");
 }
 putchar ('\n');
 }
 
 Gotoxy(x + 1,y + 2);
 printf ("%s",acBuffer);
}

/******************************* The text box UI function *******************************************
  Name: Edit box UI function 
  Parameters: 
 x  said :  The starting line position of a text box 
 y  said :  The starting column position of the text box 
 acBuffer
  said :  The contents of the text box 
  function :
  in x line y Column shows acBuffer The contents of the string 
 *************************************************************************************/

void UI_TestBox(int x,int y,char acBuffer[30])
{
 Gotoxy(x,y);
 printf ("%s",acBuffer);
}

/******************************* Cursor movement function ********************************
  Name: Cursor movement function 
  Parameters: 
 x  said : line 
 y  said : column 
  function :
  Move the cursor to x line y The column location 
 **************************************************************************/
void Gotoxy(int x,int y)
{
 CONSOLE_SCREEN_BUFFER_INFO   csbiInfo;        
 HANDLE  hConsoleOut;
 hConsoleOut = GetStdHandle (STD_OUTPUT_HANDLE);
 GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo); 
 csbiInfo.dwCursorPosition.X = y;         
 csbiInfo.dwCursorPosition.Y = x;         
 SetConsoleCursorPosition (hConsoleOut,csbiInfo.dwCursorPosition); 
}

/******************************* Control input function encapsulation ************************************

  Name: Function that allows input of letters and Numbers 
  Parameters: 
 acStr  said :  Saved array 
 iMaxLen said :  Maximum number of input characters 
 iPutType said : 
 0 ( There is no control ) 1( You can only enter Numbers ) 2( You can only type letters )
  3 ( Only Numbers and letters can be entered )
 isPlaintext Indicates whether to display plaintext  1 Said clear 
 iTmp  said : for 1 (the first 1 Press enter if the bit is not empty )
   for 2( You can't enter until you reach the maximum number )
   for 3( There is no control )

 **********************************************************************************/

int Glb_putString(char acStr[], int iMaxLen, int iPutType, int isPlaintext,int iTmp) 
{
 char Tmp;
 int i = 0;
 int j;
 int flg;
 
 for(j = 0;j < iMaxLen; j++)
 {
 acStr[j] = '\0'; 
 }

 while(1)
 {
 Tmp=getch();
 //printf("%d",Tmp);
 if(Tmp==27)
 {
 //printf("%d",Tmp);
 return 1;
 }
 flg = 0;

 if(Tmp == 13)
 {
 if(iTmp == 1) /***** The first 1 Press enter if the bit is not empty *****/
 {
 if(acStr[0] != 0)
 {
  break;
 }
 }
 else if(iTmp == 2) /****** You can't enter until you reach the maximum number *****/
 {
 j = 0;
 while(j < iMaxLen)
 {
  if(acStr[j] == '\0')
  {
  break;
  }
  j++;
 }
 if((j == iMaxLen))
 {
  flg = 1;
 }
 }
 else if(iTmp == 3) /******* There is no control *******/
 {
 break;  
 }
 }
 else if(Tmp == 8)
 {
 if(i > 0)
 {
 printf("\b \b"); 
 acStr[--i] = '\0'; 
 }
 }
 else 
 {
 if(i < iMaxLen)
 {
 switch(iPutType)/****0( There is no control ) 1( You can only enter Numbers ) 2( You can only type letters ) 3( Only Numbers and letters can be entered )*****/
 {
 case Not:
  { 
  if(isPlaintext == NotPwd)
  {
  putchar(Tmp);
  }
  else
  {
  putchar('*');
  }
  acStr[i++] = Tmp;
  }break;
 case Int:
  {
  if(Tmp >= '0' && Tmp <= '9')
  {
  if(isPlaintext == NotPwd)
  {
  putchar(Tmp);
  }
  else
  {
  putchar('*');
  }
  acStr[i++] = Tmp;
  }
  }break;
 case Char:
  {
  if((Tmp >= 'A' && Tmp <= 'Z') || (Tmp >='a' && Tmp <='z'))
  {
  if(isPlaintext == NotPwd)
  {
  putchar(Tmp);
  }
  else
  {
  putchar('*');
  }
  acStr[i++] = Tmp;
  }
  }break;
 case IntOrChar:
  {
  if((Tmp >= 'A' && Tmp <= 'Z') || (Tmp >='a' && Tmp <='z') || (Tmp >= '0' && Tmp <= '9'))
  {
  if(isPlaintext == NotPwd)
  {
  putchar(Tmp);
  }
  else
  {
  putchar('*');
  }
  acStr[i++] = Tmp;
  }
  }break;
 } 
 }
 }
 if(flg == 1) break;
 }
 acStr[i] = '\0';
 return 0;
}

/******************************* List initialization function ********************************
  Name: Linked list initialization function 
  Parameters: 
 data Data: 
 head : Pointer to the head of a linked watch 
  function :
  List initialization 
 **************************************************************************/
void* LinkInit(void *data)
{
 struct NODE *head;
 head = (struct NODE*)malloc(sizeof(struct NODE));
 if(head == NULL)
 {
 perror("linkinit error");
 return NULL;
 }
 head->data = data;
 head->NEXT = NULL;

 return head;
}

/******************************* Add linked list node function ********************************
  Name: Added list node function 
  Parameters: 
 phead : Linked watch head node 
 data Data: 
 len : The size of the linked list node data structure to be manipulated 
  function :
  Add linked list nodes 
 **************************************************************************/
void LinkAddNode(struct NODE *phead, void *data, int len)
{
 struct NODE *pNew;
 struct NODE *pTemp;
 pTemp = phead;
 while(pTemp->NEXT != NULL)
 {
 pTemp = pTemp->NEXT;
 }
 pNew = (struct NODE *)malloc(sizeof(struct NODE));
 if(pNew == NULL)
 {
 perror("LindAddNode error");
 return;
 }
 else
 {
 pNew->data = malloc(len);
 if(pNew->data == NULL)
 {
 perror("LindAddNode error");
 return;
 }
 }
 memcpy(pNew->data, data, len);
 pNew->NEXT = NULL;
 pTemp->NEXT = pNew;
 return;
}

/*int DataInit()
{
 int i;
 struct MAN m[] = 
 {
 {"1001", "admin", "123456", 0, 1}, 
 {"1002", "manager", "123456", 1, 1},
 {"1003", "waiter", "123456", 2, 1}
 };
 i = 0;
 myhead = (struct NODE*)LinkInit(NULL);
 
 for(i = 0; i < 3; i++)
 {
 LinkAddNode(myhead, &m[i], sizeof(m[i]));
 }
 return 0;
}*/

/******************************* Release the list function ********************************
  Name: Release list function 
  Parameters: 
 phead : Linked watch head node 
  function :
  Release of the list 
 **************************************************************************/
void LinkFreeNode(struct NODE *phead)
{
 struct NODE *pTemp = phead;
 //static int aaa = 0;
 while(pTemp != NULL)
 {
 phead = phead->NEXT;
 free(pTemp->data);
 free(pTemp);
 pTemp = phead;
 //printf(" Release the number of =%d\n", ++aaa);
 }
 return;
}

/******************************* Print the list function ********************************
  Name: Print list function 
  Parameters: 
 phead : Linked watch head node 
 myprint : Function pointer 
 data : The data to be printed 
 f : The number of lines in the location to be printed 
  function :
  Print the list 
 **************************************************************************/
void LinkPrint(struct NODE *phead, void(*myprint)(void* data,int f))
{
 int i=5;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 Gotoxy(i++, 3);
 myprint(pTemp->data,i);  // In the first i Line print data 
 pTemp = pTemp->NEXT;
 }
}
/******************************* Only the on-the-job information node function is printed ********************************
  Name: Print only the on-the-job information node function 
  Parameters: 
 phead : Linked watch head node 
 myprint : Function pointer 
 data : The data to be printed 
 f : The number of lines in the location to be printed 
  function :
  Only on-the-job information nodes are printed 
 **************************************************************************/
void Man_Half_Print(struct NODE *phead, void(*myprint)(void* data,int f))
{
 int i=5;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 if(((struct MAN*)(pTemp->data))->flag==49) // judge flag Whether it is 1 If, for 1 On the job, print it 
 {
 Gotoxy(i++, 3);
 myprint(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
}
/******************************* Only print functions using the member information node ********************************
  Name: Only prints in the function using the member information node 
  Parameters: 
 phead : Linked watch head node 
 myprint : Function pointer 
 data : The data to be printed 
 f : The number of lines in the location to be printed 
  function :
  Only print in using the member information node 
 **************************************************************************/

void As_Half_Print(struct NODE *phead, void(*myprint)(void* data,int f))
{
 int i=5;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 if(((struct ASSOCIATOR*)(pTemp->data))->flag==49)
 {
 Gotoxy(i++, 3);
 myprint(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
}

/******************************* Only print in use table information node function ********************************
  Name: Only print in use table information node function 
  Parameters: 
 phead : Linked watch head node 
 myprint : Function pointer 
 data : The data to be printed 
 f : The number of lines in the location to be printed 
  function :
  Only print in the use desk information node 
 **************************************************************************/

void Table_Half_Print(struct NODE *phead, void(*myprint)(void* data,int f))
{
 int i=5;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 if(((struct TABLE*)(pTemp->data))->role==49)
 {
 Gotoxy(i++, 3);
 myprint(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
}
/******************************* Only print the function using the recipe information node ********************************
  Name: Only prints in function with recipe information node 
  Parameters: 
 phead : Linked watch head node 
 myprint : Function pointer 
 data : The data to be printed 
 f : The number of lines in the location to be printed 
  function :
  Only print in using recipe information node 
 **************************************************************************/
void Dish_Half_Print(struct NODE *phead, void(*myprint)(void* data,int f))
{
 int i=4;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 if(((struct DISH*)(pTemp->data))->flag==49)
 {
 Gotoxy(i++, 3);
 myprint(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
}
/******************************* Print each employee information node function ********************************
  Name: Prints each employee information node function 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print each employee information node 
 **************************************************************************/

void ManPrint(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct MAN*)data)->id);
 Gotoxy(i, 19);
 printf("%s",((struct MAN*)data)->name);
 Gotoxy(i, 35);
 printf("*******");
 Gotoxy(i, 51);
 if(((struct MAN*)data)->role==48)
 printf(" The administrator ");
 if(((struct MAN*)data)->role==49)
 printf(" The manager ");
 if(((struct MAN*)data)->role==50)
 printf(" The waiter ");

 Gotoxy(i, 67);
 if(((struct MAN*)data)->flag==48)
 printf(" departure ");
 if(((struct MAN*)data)->flag==49)
 printf(" on-the-job ");
}
/******************************* Print each member information node function ********************************
  Name: Prints each member information node function 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print each member information node 
 **************************************************************************/

void AsPrint(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct ASSOCIATOR*)data)->no);
 Gotoxy(i, 19);
 printf("%s",((struct ASSOCIATOR*)data)->name);
 Gotoxy(i, 35);
 printf("%s",((struct ASSOCIATOR*)data)->score);
 Gotoxy(i, 51);
 printf("%c",((struct ASSOCIATOR*)data)->flag);
}

/******************************* Print each desk information node function ********************************
  Name: Print each desk information node function 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print each desk information node 
 **************************************************************************/
void TablePrint(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct TABLE*)data)->no);
 Gotoxy(i, 24);
 printf("%s",((struct TABLE*)data)->flag);
 Gotoxy(i, 45);
 printf("%s",((struct TABLE*)data)->des);

}

/******************************* Print each dish information node function ********************************
  Name: Prints each dish information node function 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print each dish information node 
 **************************************************************************/
void DishPrint(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct DISH*)data)->no);
 Gotoxy(i, 24);
 printf("%s",((struct DISH*)data)->name);
 Gotoxy(i, 45);
 printf(" RMB %s",((struct DISH*)data)->price);
}
/******************************* Order and display the function ********************************
  Name: Order and display function 
  Parameters: 
 phead : The head of a linked table 
 data : Node data of dishes ordered in the order 
 pTmp : A pointer to a recipe node 
 money : The sum of the unit prices of the ordered dishes 
 f: Sign a 
 n: Additional copies 
  function :
  Order and display 
 **************************************************************************/
void Link_Dish_Print(struct NODE *phead,void *data)
{
 int i=5,j,n=0,money=0,f;
 struct NODE *pTemp = phead->NEXT;
 while(pTemp != NULL)
 {
 f=0;
 Gotoxy(i, 3);
 for(j=0;j<11;j++)
 {
 if(strcmp((((struct ORDER*)data)->x[j]).no,((struct DISH*)(pTemp->data))->no)==0) // Find the corresponding order   order   And get the unit price of the dish from the recipe 
 {
 n=number_change((((struct ORDER*)data)->x[j]).num)+n;
 money=number_change(((struct DISH*)(pTemp->data))->price)*number_change((((struct ORDER*)data)->x[j]).num)+money;
 order_dish_difprint(pTemp->data,i++,number_change((((struct ORDER*)data)->x[j]).num)); // There are" * The print function of" 
 f=1;
 }
 }
 if(f==0 && ((struct DISH*)(pTemp->data))->flag==49)
 order_dish_print(pTemp->data,i++);    // There is no" * The print function of" 
 pTemp = pTemp->NEXT;
 //i++;
 }
 char_change(money,((struct ORDER*)data)->money);   // will char Type converted to int Function of type 
 Gotoxy(18, 44);
 printf("%d",money);
 Gotoxy(18, 66);
 printf("%d",n);
}
/******************************* Print the information node function of each dish in the menu interface ********************************
  Name: Function to print information node of each dish in the menu interface 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print each item information node in the ordering interface 
 **************************************************************************/
void order_dish_print(void *data,int i)
{
 Gotoxy(i, 4);
 printf("%s",((struct DISH*)data)->no);
 Gotoxy(i, 24);
 printf("%s",((struct DISH*)data)->name);
 Gotoxy(i, 45);
 printf(" RMB %s",((struct DISH*)data)->price);
 Gotoxy(i, 66);
 printf("%s",((struct DISH*)data)->num);
}
/******************************* Print order menu interface with" * "For each dish information node function ********************************
  Name: Print order menu interface with" * "For each dish information node function 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print order menu interface with" * "For each dish information node 
 **************************************************************************/
void order_dish_difprint(void *data,int i,int num)
{
 Gotoxy(i, 3);
 putchar('*');
 Gotoxy(i, 4);
 printf("%s",((struct DISH*)data)->no);
 Gotoxy(i, 24);
 printf("%s",((struct DISH*)data)->name);
 Gotoxy(i, 45);
 printf(" RMB %s",((struct DISH*)data)->price);
 Gotoxy(i, 66);
 printf("%d",num);
}
/******************************* Print the information function of each order node in the bill of purchase interface ********************************
  Name: Function to print the information of each order node in the payment interface 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print the information of each order node in the payment interface 
 **************************************************************************/
void Order_Checkout_Print(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct ORDER*)data)->order_no);
 Gotoxy(i, 24);
 printf(" RMB %s",((struct ORDER*)data)->money);
 Gotoxy(i, 45);
 printf("%s",((struct ORDER*)data)->order_flag);
}
/******************************* Print the information function of each paid order node in the turnover query interface ********************************
  Name: Information function of each paid order node in print turnover query interface 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print information of each paid order node in the turnover query interface 
 **************************************************************************/
void Order_Checkouted_Print(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct ORDER*)data)->order_no);
 Gotoxy(i, 24);
 printf("%s",((struct ORDER*)data)->time);
 Gotoxy(i, 45);
 printf(" RMB %s",((struct ORDER*)data)->money);
}
/******************************* Print order query interface for each order node information function ********************************
  Name: Information function of each order node in the print order query interface 
  Parameters: 
 data : The data to be printed 
 i : in the first i Lines of print 
  function :
  Print the information of each order node in the order query interface 
 **************************************************************************/
void Check_Order_id(void *data,int i)
{
 Gotoxy(i, 3);
 printf("%s",((struct ORDER*)data)->order_no);
 Gotoxy(i, 18);
 printf("%s",((struct ORDER*)data)->time);
 Gotoxy(i, 33);
 printf(" RMB %s",((struct ORDER*)data)->money);
 Gotoxy(i, 48);
 printf("%s",((struct ORDER*)data)->order_flag);

}
/******************************* Write data from the linked list to the file function ********************************
  Name: Writes data from the linked list to a file function 
  Parameters: 
 phead : Pointer to the head of a linked watch 
 datalen : The size of a single node 
 f : Flag bit to determine which file to write to 
  function :
  Writes data from a linked list to a file 
 **************************************************************************/
int linktofile(struct NODE *phead, int datalen,int f)
{
 FILE *fp;
 struct NODE *pTemp = phead->NEXT;
 if(f==1)
 fp = fopen("./maninfo.txt", "wb+");  // Write to staff file 
 else if(f==2)
 fp = fopen("./tableinfo.txt", "wb+");  // Write to the desk file 
 else if(f==3)
 fp = fopen("./dishinfo.txt", "wb+");  // I'm gonna go to the recipe file 
 else if(f==4)
 fp = fopen("./orderinfo.txt", "wb+");  // Write to order file 
 else if(f==5)
 fp = fopen("./associatorinfo.txt", "wb+");   // Write to member file 
 if(fp == NULL)
 {
 perror("open file(man)");
 return -1;
 }
 while(pTemp != NULL)
 {
 
 fwrite(pTemp->data, 1, datalen, fp);
 pTemp = pTemp->NEXT;
 }
 LinkFreeNode(phead);
 if(f==4)           // Free the linked list in memory 
 orderhead = (struct NODE*)LinkInit(NULL);
 if(f==5)
 ashead = (struct NODE*)LinkInit(NULL);
 if(f!=4 && f!=5) 
 myhead = (struct NODE*)LinkInit(NULL);
 fclose(fp);
 return 0;
}
/******************************* Read data from file to linked list function ********************************
  Name: Reads data from file to linked list function 
  Parameters: 
 phead : Pointer to the head of a linked watch 
 datalen : The size of a single node 
 f : Flag bit to determine which file to write to 
  function :
  Read data from a file to a linked list 
 **************************************************************************/
void linkfromfile(struct NODE *phead,int datalen,int f)
{
 int x,i;
 FILE *fp;
 void *q;
 q=(void *)malloc(datalen);
 //struct MAN *q;
 //q=new MAN;
 memset(q, 0, sizeof(datalen));
 if(f==1)
 fp = fopen("./maninfo.txt", "rb+");
 else if(f==2)
 fp = fopen("./tableinfo.txt", "rb+");
 else if(f==3)
 fp = fopen("./dishinfo.txt", "rb+");
 else if(f==4)
 fp = fopen("./orderinfo.txt", "rb+");
 else if(f==5)
 fp = fopen("./associatorinfo.txt", "rb+");
 if(fp == NULL)
 {
 return ;
 }
 fseek(fp,0,SEEK_END);
 x=ftell(fp);
 rewind(fp);
 //printf("%d\n",(x/datalen));
 for(i=0;i<(x/datalen);i++)
 {
 fread(q,1,datalen,fp);
 if(q==NULL)
 {
 printf(" No number of records \n");
 }
 LinkAddNode(phead,q,datalen);
 }
 free(q);
 q=NULL;
 fclose(fp);
}
/******************************* Gets the specified node function from the linked list ********************************
  Name: Gets the specified node function from the linked list 
  Parameters: 
 iIndex : The parameter that specifies the location 
 phead : Pointer to the head of a linked watch 
 f : Flag bit to determine which linked list to operate on 
  function :
  Gets the specified node from the linked list 
 **************************************************************************/
NODE* LIST_GetNode(int iIndex,struct NODE *phead,int f)
{
 int n;
 struct NODE *tmp=NULL;
 tmp=phead->NEXT;
 while(tmp!=NULL)
 {
 if(f==1)
 n=number_change(((struct MAN *)(tmp->data))->id);
 else if(f==2)
 n=number_change(((struct TABLE *)(tmp->data))->no);
 else if(f==3)
 n=number_change(((struct DISH *)(tmp->data))->no);
 else if(f==4)
 n=number_change(((struct ASSOCIATOR *)(tmp->data))->no);
 if(n==iIndex)
 break;
 tmp=tmp->NEXT;
 }
 if(tmp== NULL)
 {
 perror(" The specified node index was not found ");
 return 0;
 }
 return tmp;
}
/******************************* Removes the specified node function from the list (true deletion) ********************************
  Name: Removes the specified node function from the list 
  Parameters: 
 iIndex : The parameter that specifies the location 
 phead : Pointer to the head of a linked watch 
 f : Flag bit to determine which linked list to operate on 
  function :
  Removes the specified node from the linked list 
 **************************************************************************/
void LIST_Del(int iIndex,struct NODE *phead,int f)
{
 int n;
 struct NODE *tmp=NULL,*pre=NULL;
 tmp=phead->NEXT;
 pre=phead;
 while(tmp!=NULL)
 {
 if(f==1)
 n=number_change(((struct MAN *)(tmp->data))->id);
 else if(f==2)
 n=number_change(((struct TABLE *)(tmp->data))->no);
 else if(f==3)
 n=number_change(((struct DISH *)(tmp->data))->no);
 else if(f==4)
 n=number_change(((struct ASSOCIATOR *)(tmp->data))->no);
 if(n==iIndex)
 break;
 pre=tmp;
 tmp=tmp->NEXT;
 //tmp=tmp->NEXT;
 }
 //printf("%d\n",n);
 if(tmp== NULL)
 {
 perror(" The specified node index was not found ");
 return ;
 }
 pre->NEXT=tmp->NEXT;
 free(tmp);
 return;
}
/******************************* Removes the specified node function from the list (false deletion) ********************************
  Name: Removes the specified node function from the list 
  Parameters: 
 iIndex : The parameter that specifies the location 
 phead : Pointer to the head of a linked watch 
 f : Flag bit to determine which linked list to operate on 
  function :
  Removes the specified node from the linked list 
 **************************************************************************/
void LIST_Del_FS(int iIndex,struct NODE *phead,int f)
{
 int n;
 struct NODE *tmp;
 tmp=phead->NEXT;
 while(tmp!=NULL)
 {
 if(f==1)
 n=number_change(((struct MAN *)(tmp->data))->id);
 else if(f==2)
 n=number_change(((struct TABLE *)(tmp->data))->no);
 else if(f==3)
 n=number_change(((struct DISH *)(tmp->data))->no);
 else if(f==4)
 n=number_change(((struct ASSOCIATOR *)(tmp->data))->no);
 if(n==iIndex)
 break;
 tmp=tmp->NEXT;
 }
 if(tmp== NULL)     // Change the state of the node 
 {
 perror(" The specified node index was not found ");
 return ;
 }
 if(f==1)
 ((struct MAN *)(tmp->data))->flag=48;
 if(f==2)
 ((struct TABLE *)(tmp->data))->role=48;
 if(f==3)
 ((struct DISH *)(tmp->data))->flag=48;
 if(f==4)
 ((struct ASSOCIATOR *)(tmp->data))->flag=48;
 return;
}
/******************************* will char Type converted to int Function of type ********************************
  Name: char Type converted to int Function of type 
  Parameters: 
 id : char Type array pointer 
  function :
  will char Type converted to int The type of 
 **************************************************************************/
int number_change(char *id)
{
 int num=0,i,n=1;
 for(i=0;i<strlen(id);i++)
 {
 num=(id[strlen(id)-i-1]-48)*n+num;
 n=n*10;
 }
 return num;
}
/******************************* will int Type converted to char Function of type ********************************
  Name: int Type converted to char Function of type 
  Parameters: 
 n: int Type data 
 p : char Type array pointer 
  function :
  will int Type converted to char The type of 
 **************************************************************************/
void char_change(int n,char *p)
{
 int num[10+1];
 int i=0,j=0;
 memset(p,0,sizeof(p));
 while(n)
 {
 num[i]=n%10;
 n=n/10;
 i++;
 }
 while(i)
 {
 p[j++]=num[--i]+48;
 }
}
/******************************* The staff identification function at login time ********************************
  Name: The person identification function at login 
  Parameters: 
 acStr1[]:  The user name entered 
 acStr2[] : The password entered 
 datalen : The size of a single node 
  function :
  The identity of the person at login 
 **************************************************************************/
char real_identifine(char acStr1[],char acStr2[],int datalen)
{
 int f;
 struct NODE *tmp=NULL;
 if(!strcmp(acStr1,"admin"))    // The super user 
 {
 if(!strcmp(acStr2,"123456"))
 {
 return '3';
 }
 else
 printf(" Password error! ");
 }
 linkfromfile(myhead,datalen,1);
 tmp=myhead->NEXT;
 while(tmp)    // Traverses the staff linked list to see if it exists, and returns its corresponding role if it does 
 {
 if(!strcmp(acStr1,((struct MAN *)(tmp->data))->id))
 {
 if(!strcmp(acStr2,((struct MAN *)(tmp->data))->pwd))
 {
 return ((struct MAN *)(tmp->data))->role;
 }
 else
 printf(" Password error! ");
 }
 tmp=tmp->NEXT;
 }
 printf(" The user does not exist! ");
 /*if(tmp== NULL)
 {
 perror(" The specified node index was not found ");
 return 0;
 }*/
}
/******************************* Initializes the order node function ********************************
  Name: Initializes the order node function 
  Parameters: 
 no : Table number corresponding to the order 
 n: Buffer data to record the number of orders 
 m: The order node created 
  function :
  Initializes the order node 
 **************************************************************************/
void OrderData(char *no)
{
 time_t t=time(0);
 char time[11];
 int n;
 struct ORDER m;
 memset(&m,0,sizeof(struct ORDER));
 n=1000+link_sum(orderhead,sizeof(struct ORDER),4);
 char_change(n,m.order_no);

 //memcpy(m.man_id,id,5);
 strcpy(m.man_id,waiter_ID);
 //strcpy(m.man_id,"1001");

 memcpy(m.table_no,no,11);

 strftime(time, sizeof(time), "%Y%m%d",localtime(&t));
 memset(m.time,0,sizeof(m.time));
 strcpy(m.time,time);

 strcpy(m.order_flag," Not paying ");

 strcpy(m.money,"0");

 memset(m.x,0,sizeof(m.x));

 linkfromfile(orderhead,sizeof(m),4);    // Read the order list from the file 
 LinkAddNode(orderhead, &m, sizeof(m));   // Add the newly created order node to the linked list  
 linktofile(orderhead, sizeof(m),4);    // Write the linked list to a file 
}

/******************************* Function to calculate the number of nodes in the file ********************************
  Name: Function to calculate the number of nodes in the file 
  Parameters: 
 phead : Pointer to the head of a linked watch 
 datalen : The size of a single node 
 f: Flag bit to determine which file it is 
  function :
  Calculate the number of nodes in the file 
 **************************************************************************/
int link_sum(struct NODE *phead,int datalen,int f)
{
 int x,i;
 FILE *fp;

 if(f==1)
 fp = fopen("./maninfo.txt", "rb+");
 else if(f==2)
 fp = fopen("./tableinfo.txt", "rb+");
 else if(f==3)
 fp = fopen("./dishinfo.txt", "rb+");
 else if(f==4)
 fp = fopen("./orderinfo.txt", "rb+");
 else if(f==5)
 fp = fopen("./associatorinfo.txt", "rb+");
 if(fp == NULL)
 {
 return 0;
 }
 fseek(fp,0,SEEK_END);
 x=ftell(fp);
 rewind(fp);
 return (x/datalen);
 
 fclose(fp);
}
/******************************* Function that displays the occupied table in the order menu ********************************
  Name: Function that displays the occupied table in the order menu 
  Parameters: 
 i : the number of rows 
 pTemp : A pointer to a node in a linked list 
  function :
  Display the occupied table in the order menu 
 **************************************************************************/
void busy_table()
{
 int i=5;
 struct NODE *pTemp;
 ui_function_table();

 linkfromfile(myhead,sizeof(struct TABLE),2);  // Read the table list from the file 
 pTemp = myhead->NEXT;
 while(pTemp != NULL)
 {
 if(strcmp(((struct TABLE*)(pTemp->data))->flag," Take up ")==0 && ((struct TABLE*)(pTemp->data))->role==49)// Select the table that is occupied and in use and print it 
 {
 Gotoxy(i++, 3);
 TablePrint(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
 LinkFreeNode(myhead);
 myhead = (struct NODE*)LinkInit(NULL);
}
/******************************* Displays the order information function for outstanding orders in the order query interface ********************************
  Name: Displays the order information function for outstanding orders in the order query interface 
  Parameters: 
 i : the number of rows 
 pTemp : A pointer to a node in a linked list 
  function :
  Display outstanding order information in the order query interface 
 **************************************************************************/
void un_checkout()
{
 int i=5;
 struct NODE *pTemp;
 ui_function_checkout();

 linkfromfile(orderhead,sizeof(struct ORDER),4);
 pTemp = orderhead->NEXT;
 while(pTemp != NULL)
 {
 if(strcmp(((struct ORDER*)(pTemp->data))->order_flag," Not paying ")==0) // Select the outstanding order and print it 
 {
 Gotoxy(i++, 3);
 Order_Checkout_Print(pTemp->data,i);
 }
 pTemp = pTemp->NEXT;
 }
 LinkFreeNode(orderhead);
 orderhead = (struct NODE*)LinkInit(NULL);
}
/******************************* Display the paid order information function in the turnover query interface ********************************
  Name: Display the paid order information function in the turnover query interface 
  Parameters: 
 begin : Start time 
 end:  The end of time 
 sum : Total amount 
  function :
  Display the paid order information in the turnover query interface 
 **************************************************************************/
void checkout_ed(char *begin,char *end)
{
 int i=5,f=0,sum=0;
 struct NODE *pTemp;
 ui_function_checkmoney();
 
 linkfromfile(orderhead,sizeof(struct ORDER),4);
 pTemp = orderhead->NEXT;
 while(pTemp != NULL)
 {
 if(number_change(((struct ORDER*)(pTemp->data))->time)>=number_change(begin) && number_change(((struct ORDER*)(pTemp->data))->time)<=number_change(end) && strcmp(((struct ORDER*)(pTemp->data))->order_flag," Payment has been ")==0)
 {
 Gotoxy(i++, 3);
 Order_Checkouted_Print(pTemp->data,i);
 f=1;
 sum=number_change(((struct ORDER*)(pTemp->data))->money)+sum;
 }
 pTemp = pTemp->NEXT;
 }
 Gotoxy(15, 60);
 printf(" RMB %d",sum);
 if(f==0)
 {
 Gotoxy(6, 20);
 printf(" No data for the time being! ");
 }
 LinkFreeNode(orderhead);
 orderhead = (struct NODE*)LinkInit(NULL);
}
/******************************* Displays the paid and unpaid order information function in the order query interface ********************************
  Name: Display the paid and unpaid order information in the order query interface 
  Parameters: 
 begin : Start time 
 end:  The end of time 
 g:  Specifies whether you want to check whether the bill has been paid or not 
  function :
  Display the paid and unpaid order information in the order query interface 
 **************************************************************************/
void check_order_id(char *begin,char *end,int g)
{
 int i=5,f=0,j=5;
 struct NODE *pTemp,*p;
 ui_function_checkorderid();
 
 linkfromfile(orderhead,sizeof(struct ORDER),4);
 linkfromfile(myhead,sizeof(struct MAN),1);

 pTemp = orderhead->NEXT;
 p=myhead->NEXT;
 while(pTemp != NULL && g==50) // Print paid 
 {
 if(number_change(((struct ORDER*)(pTemp->data))->time)>=number_change(begin) && number_change(((struct ORDER*)(pTemp->data))->time)<=number_change(end) && strcmp(((struct ORDER*)(pTemp->data))->order_flag," Payment has been ")==0)
 {
 while(p != NULL)
 {
 if(strcmp(((struct MAN*)(p->data))->id,((struct ORDER*)(pTemp->data))->man_id)==0)
 {
  Gotoxy(j++, 63);
  printf("%s",((struct MAN*)(p->data))->name);
 }
 p=p->NEXT;
 }
 p=myhead->NEXT;
 Gotoxy(i, 3);
 Check_Order_id(pTemp->data,i++);
 f=1;
 
 }
 pTemp = pTemp->NEXT;
 }
 pTemp = orderhead->NEXT;
 p=myhead->NEXT;
 while(pTemp != NULL && g==49)  // Print unpaid 
 {
 if(number_change(((struct ORDER*)(pTemp->data))->time)>=number_change(begin) && number_change(((struct ORDER*)(pTemp->data))->time)<=number_change(end) && strcmp(((struct ORDER*)(pTemp->data))->order_flag," Not paying ")==0)
 {
 while(p != NULL)
 {
 if(strcmp(((struct MAN*)(p->data))->id,((struct ORDER*)(pTemp->data))->man_id)==0)
 {
  Gotoxy(j++, 63);
  printf("%s",((struct MAN*)(p->data))->name);
 }
 p=p->NEXT;
 }
 p=myhead->NEXT;
 Gotoxy(i, 3);
 Check_Order_id(pTemp->data,i++);
 f=1;
 }
 pTemp = pTemp->NEXT;
 }
 if(f==0)
 {
 Gotoxy(6, 20);
 printf(" No data for the time being! ");
 }
 LinkFreeNode(orderhead);
 orderhead = (struct NODE*)LinkInit(NULL);
 LinkFreeNode(myhead);
 myhead = (struct NODE*)LinkInit(NULL);
}
/******************************* Show the paid and unpaid order information function in the revenue query interface ********************************
  Name: Display the paid order information function in the revenue query interface 
  Parameters: 
 begin : Start time 
 end:  The end of time 
 sum : The total turnover of a waiter 
 count : Total revenue for all waiters and waitresses 
  function :
  Display the paid order information in the revenue query interface 
 **************************************************************************/
void check_waiter_money(char *begin,char *end)
{
 int i=5,sum,count=0;
 struct NODE *pTemp;
 struct NODE *p;
 ui_count_director();
 
 linkfromfile(orderhead,sizeof(struct ORDER),4);
 linkfromfile(myhead,sizeof(struct MAN),1);
 pTemp = orderhead->NEXT;
 p=myhead->NEXT;

 while(p != NULL)
 {
 sum=0;
 if(((struct MAN*)(p->data))->role==50)
 {
 while(pTemp != NULL)   // Select the orders with the required time, the paid ones and the corresponding employees, and add them up 
 {
 if(number_change(((struct ORDER*)(pTemp->data))->time)>=number_change(begin) && number_change(((struct ORDER*)(pTemp->data))->time)<=number_change(end))
  if(strcmp(((struct ORDER*)(pTemp->data))->order_flag," Payment has been ")==0)
  if(strcmp(((struct MAN*)(p->data))->id,((struct ORDER*)(pTemp->data))->man_id)==0)
  {
  sum=number_change(((struct ORDER*)(pTemp->data))->money)+sum;
  }
  pTemp = pTemp->NEXT;
 }
 pTemp = orderhead->NEXT;
 Gotoxy(i, 3);
 printf("%s",((struct MAN*)(p->data))->name);
 Gotoxy(i, 48);
 printf(" RMB %d",sum);
 i++;
 }
 count=count+sum;
 Gotoxy(16, 60);
 printf(" RMB %d",count);
 p=p->NEXT;
 }
 /*if(f==0)
 {
 Gotoxy(24, 10);
 printf(" No data for the time being! ");
 }*/
 LinkFreeNode(orderhead);
 orderhead = (struct NODE*)LinkInit(NULL);
 LinkFreeNode(myhead);
 myhead = (struct NODE*)LinkInit(NULL);
}


/******************************* Menu items function ********************************
  Name: Add dish function 
  Parameters: 
 data : Order node data section 
 no : Menu number to be specified 
 num : The number of orders 
  function :
  Add food 
 **************************************************************************/
void add_dish(void *data,char *no,char *num)
{
 int i,n;
 for(i=0;i<11;i++)
 {
 if(strcmp((((struct ORDER*)data)->x[i]).no,no)==0)  // Find the unit price of the dish 
 {
 n=number_change((((struct ORDER*)data)->x[i]).num)+number_change(num);
 char_change(n,(((struct ORDER*)data)->x[i]).num);
 //puts((((struct ORDER*)data)->x[i]).num);
 return;
 }
 }
 for(i=0;i<11;i++)
 {
 if((((struct ORDER*)data)->x[i]).no[0]=='\0')  // Locate the specified order node and add the order number and number of servings 
 {
 strcpy((((struct ORDER*)data)->x[i]).no,no);
 n=number_change((((struct ORDER*)data)->x[i]).num)+number_change(num);
 char_change(n,(((struct ORDER*)data)->x[i]).num);
 return;
 }
 }
}
/******************************* Refund food function ********************************
  Name: Return function 
  Parameters: 
 data : Order node data section 
 no : Menu number to be specified 
 num : The number of orders 
  function :
  Food back 
 **************************************************************************/
void sub_dish(void *data,char *no,char *num)
{
 int i,n;
 for(i=0;i<11;i++)
 {
 if(strcmp((((struct ORDER*)data)->x[i]).no,no)==0)
 {
 n=number_change((((struct ORDER*)data)->x[i]).num)-number_change(num);
 char_change(n,((((struct ORDER*)data)->x[i]).num));
 puts((((struct ORDER*)data)->x[i]).num);
 if(n==0)
 {
 char_change(n,(((struct ORDER*)data)->x[i]).num);
 memset((((struct ORDER*)data)->x[i]).no,0,sizeof((((struct ORDER*)data)->x[i]).no));
 }

 return;
 }
 }
}

For more information, please pay attention to the topic management System Development.


Related articles: