您的当前位置:首页正文

餐馆点菜系统

2024-11-07 来源:个人技术集锦

Think:
文件的输入输出那一块儿 还是不怎么会~~ 好像只成功输入输出了 user.dat那一份~~ 用了好久好久的时间写的程序~~, 感觉和上一篇blog的思路基本相同就是 各种调用函数。。。

系统模块:

程序架构:

模块汇总:

以台桌模块为例:

整体框架如下:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<bits/stdc++.h>
using namespace std;

char enter_name[50];

struct node
{
    char name[50];  //订单号
    char num[50];   //桌号
    char status[50];//订单状态
    char action[50];//活动
    char payoff[50];//付款状态
    double price;//金额
    int dish_num;//菜号
    int typ; //菜品名字
    struct node *next;
}*tab, *dish, *user, *order;


/*台桌界面*/
void add_table();//增加台桌
void delete_table();//删去台桌
void alter_table();
void look_table();

/*人员界面*/
void add_staff();
void delete_staff();
void alter_staff();
void look_staff();

/*菜单界面*/
void add_dish();
void delete_dish();
void alter_dish();
void look_dish();
void all_dish();

/*服务员操作界面*/
void see_order();
void see_dish();
void pay_off();
void start_table();
void start_dish();
void see_table();

/*经理操作界面*/
void menu();
void table_charge();
void staff_charge();

/*主管管理界面*/
void total_sell();

/*开始界面*/
void manager_enter();
void staff_enter();
void charge_enter();
void user_enter();
void system_enter();

/*通用操作界面*/

struct node *read_link(int number, struct node *head); /*将链表从文件中读取*/
struct node *write_link(int number, struct node *head);/*将链表写入文件*/
int check_password();/*匹配用户*/
void quitsystem(); /*退出系统*/
void order_menu(); /*订餐系统*/
void dish_menu();/*菜单*/
void table_menu();/* 桌号菜单 */
struct node *creat_table(); /*建立台桌文件*/
struct node *creat_dish(); /*建立菜单文件*/
struct node *creat_users();/*建立用户文件*/
struct node *creat_order();/*建立订单文件*/

—————————————分割线————————————

完整代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<bits/stdc++.h>
using namespace std;

char enter_name[50];

struct node
{
    char name[50];  //订单号
    char num[50];   //桌号
    char status[50];//订单状态
    char action[50];//活动
    char payoff[50];//付款状态
    double price;//金额
    int dish_num;//菜号
    int typ; //菜品名字
    struct node *next;
}*tab, *dish, *user, *order;


/*台桌界面*/
void add_table();//增加台桌
void delete_table();//删去台桌
void alter_table();
void look_table();

/*人员界面*/
void add_staff();
void delete_staff();
void alter_staff();
void look_staff();

/*菜单界面*/
void add_dish();
void delete_dish();
void alter_dish();
void look_dish();
void all_dish();

/*服务员操作界面*/
void see_order();
void see_dish();
void pay_off();
void start_table();
void start_dish();
void see_table();

/*经理操作界面*/
void menu();
void table_charge();
void staff_charge();

/*主管管理界面*/
void total_sell();

/*开始界面*/
void manager_enter();
void staff_enter();
void charge_enter();
void user_enter();
void system_enter();

/*通用操作界面*/

struct node *read_link(int number, struct node *head); /*将链表从文件中读取*/
struct node *write_link(int number, struct node *head);/*将链表写入文件*/
int check_password();/*匹配用户*/
void quitsystem(); /*退出系统*/
void order_menu(); /*订餐系统*/
void dish_menu();/*菜单*/
void table_menu();/* 桌号菜单 */
struct node *creat_table(); /*建立台桌文件*/
struct node *creat_dish(); /*建立菜单文件*/
struct node *creat_users();/*建立用户文件*/
struct node *creat_order();/*建立订单文件*/



int main()
{
    system("color 9E");
    system_enter();
    return 0;
}






struct node *read_link(int number, struct node *head)/*将链表从文件中读取*/
{
    FILE *fp;
    if (number == 1)
    {
        fp = fopen("d:\\user.dat", "rb");
    }
    else if (number == 2)
    {
        fp = fopen("d:\\dish.dat", "rb");
    }
    else if (number == 3)
    {
        fp = fopen("d:\\tab.dat", "rb");
    }
    else if (number == 4)
    {
        if((fp = fopen("d:\\order.dat", "rb")) == NULL)
        {
            printf("没有订单信息!");
            char ch;
            ch = getch();
            if (ch == 27) // 27 == esc???
                staff_enter();
        }
    }
    struct node *p, *t;
    t = head;
    p = new node;
    fread(p, sizeof(node), 1, fp);
    while(!feof(fp))
    {
        t -> next = p;
        t = t -> next;
        p = new node;
        fread(p, sizeof(node), 1, fp);
    }
    fclose(fp);
    return head;
}




struct node *write_link(int number, struct node *head) //将链表写入文件//
{
    FILE *in;
    struct node *p;
    if (number == 1)
    {
        in = fopen("d:\\user.dat", "wb+");
    }
    else if (number == 2)
    {
        in = fopen("d:\\dish.dat", "wb+");
    }
    else if(number == 3)
    {
        in = fopen("d:\\tab.dat", "wb+");
    }
    else if(number == 4)
    {
        in = fopen("d:\\order.dat", "wb+");
    }

    p = head -> next;
    while(p)
    {
        fwrite(p, sizeof(struct node), 1, in);
        p = p -> next;
    }
    fclose(in);
}


int check_password() //匹配用户//
{
    char name[30];
    char PW[30];
    printf("请输入用户名:\n");
    cin >> name;
    printf("请输入用户密码:\n");
    cin >> PW;
    FILE *fp;
    struct node *p, *q, *t, *head;
    head = new node;
    t = head;
    p = new node;
    fp = fopen("d:\\user.dat", "rb");
    fread(p, sizeof(node), 1, fp);
    while(!feof(fp))
    {
        t -> next = p;
        t = t -> next;
        p = new node;
        fread(p, sizeof(node), 1, fp);
    }
    fclose(fp);
    q = head -> next;
    while(q)
    {
        if ((strcmp(name, q -> name) == 0) && (strcmp(PW, q -> num) == 0))
        {
            if(q -> typ == 2)
            {
                strcpy(enter_name, q -> name);
            }
            return q -> typ;
        }
        else
        {
            q = q -> next;
        }
    }
    p = user -> next;
    q = user;
    while(p)
    {
        if ((strcmp(name, p -> name) == 0) && (strcmp(PW, p -> num) == 0))
        {
            return p -> typ;
        }
        else
        {
            q = q -> next;
            p = p -> next;
        }
    }
    return 0;
}

void quitsystem()
{
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎再次使用              ***\n");
    printf("***                        —————By棺木酥***\n");
    printf("*******************************************\n");
    exit(1);
}

void order_menu()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用点餐系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("单号        桌号      已买单       活动  \n");
    struct node *head, *p;
    head = new node;
    head = read_link(4, head);
    p = head -> next;
    while(p)
    {
        printf("%s %10s %10s %10s\n", p -> name, p -> num, p -> status, p -> action);
        p = p -> next;
    }
    char ch;
//    system("cls");
//    printf("*******************************************");
//    printf("*******************************************");
//    printf("***           欢迎使用棺木系统          ***");
//    printf("***                                     ***");
//    printf("*******************************************");
    ch = getch();
    if (ch == 27)
        staff_enter();
}

void dish_menu()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("菜号        菜名      价格       状态         是否活动  \n");

    struct node *q, *head;
    head = new node;
    head = read_link(2, head);
    q = head -> next;
    while(q)
    {
        printf("%s %10s %.2f %10s %10s\n", q -> num, q -> name, q -> price, q -> status, q -> action);
        q = q -> next;
    }

}

void table_menu()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("桌号             状态             活动   \n");
    struct node *q, *head;
    head = new node;
    head = read_link(3, head);
    q = head -> next;
    while(q)
    {
        printf("%s               %s               %s\n", q -> num, q -> status, q -> action);
        q = q -> next;
    }
}


struct node *creat_table() /*建立台桌文件*/
{
    FILE *ff;
    if((ff = fopen("d:\\tab.data", "rb")) == NULL)
    {
        int i;
        struct node *p, *t, *head;
        head = new node;
        t = head;
        for (i = 0; i < 1; i ++)
        {
            p = new node;
            strcpy(p -> num, "001");
            strcpy(p -> status, "Y");
            strcpy(p -> action, "Y");

            p -> typ = 0;
            t -> next = p;
            p -> next = NULL;
            t = p;
        }
        tab = head;
        FILE *in = fopen("d:\\tab.dat", "wb+");
        p = head -> next;
        while(p)
        {
            fwrite(p, sizeof(struct node), 1, in);
            p = p -> next;
        }
        fclose(in);
    }
}


struct node *creat_dish() /*建立菜单文件*/
{
    FILE *ff;
    if((ff = fopen("d:\\dish.data", "rb")) == NULL)
    {
        int i;
        struct node *p, *t, *head;
        head = new node;
        t = head;
        for (i = 0; i < 1; i ++)
        {
            p = new node;
            strcpy(p -> num, "0001");
            strcpy(p -> status, "Y");
            strcpy(p -> name, "土豆丝");
            strcpy(p -> action, "N");
            p -> price = 15.00;

            t -> next = p;
            p -> next = NULL;
            t = p;
        }
        dish = head;
        FILE *in = fopen("d:\\dish.dat", "wb+");
        p = head -> next;
        while(p)
        {
            fwrite(p, sizeof(struct node), 1, in);
            p = p -> next;
        }
        fclose(in);
    }
}
struct node *creat_users()/*建立用户文件*/
{
    FILE *ff;
    if((ff = fopen("d:\\user.dat", "rb")) == NULL)
    {
        int i;
        struct node *p, *t, *head;
        head = new node;
        t = head;
        for (i = 0; i < 1; i ++)
        {
            p = new node;
            strcpy(p -> name, "111");
            strcpy(p -> num, "111");
            p -> typ = 1;
            t -> next = p;
            p -> next = NULL;
            t = p;
        }
        user = head;
        FILE *in = fopen("d:\\user.dat", "wb+");
        p = head -> next;
        while(p)
        {
            fwrite(p, sizeof(struct node), 1, in);
            p = p -> next;
        }
        fclose(in);
    }
}

struct node *creat_order()/*建立订单文件*/
{
    FILE *ff;
    if ((ff = fopen("d:\\order.dat", "rb")) == NULL)
    {
        int i;
        struct node *p, *t, *head;
        head = new node;
        t = head;
        for (i = 0; i < 1; i ++)
        {
            p = new node;
            strcpy(p -> name, "001");
            strcpy(p -> num, "001");
            p -> price = 0.00;
            t -> next = p;
            p -> next = NULL;
            t = p;
        }
        user = head;
        FILE *in = fopen("d:\\order.dat", "wb+");
        p = head -> next;
        while(p)
        {
            fwrite(p, sizeof(struct node), 1, in);
            p = p -> next;
        }
        fclose(in);
    }
};

void add_table()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    FILE *fp;
    struct node *p;
    p = new node;
    printf("输入桌号:");
    cin >> p -> num;
    printf("输入状态: ");
    cin >> p -> status;
    printf("输入活动: ");
    cin >> p -> action;
    if((fp = fopen("d:\\tab.dat", "ab+")) == NULL)
    {
        printf("No File in there!\n");
    }
    fwrite(p, sizeof(struct node), 1, fp);
    free(p);;
    fclose(fp);
    char key;
    printf("是否继续添加<Y / N>: ");
    cin >> key;
    if (key == 'Y')
        add_table();
    else if(key == 'N')
        table_charge();
}


void delete_table()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    char s[20];
    char ch;
    struct node *head, *p, *q;
    head = new node;
    head = read_link(3, head);
    printf("请输入要删除的桌号: ");
    cin >> s;
    p = head;
    q = p -> next;
    while(q)
    {
        if (strcmp(s, q -> num) == 0)
        {
            p -> next = q -> next;
            free(q);
            break;
        }
        else
        {
            p = p -> next;
            q = q -> next;
        }
    }
    if (q == NULL)
    {
        printf("该桌号不存在!\n");
        ch = getch();
        if (ch == 27)
        {
            table_charge();
        }
    }
    else
    {
        write_link(3, head);
        printf("修改成功!\n");
    }

    ch = getch();
    if (ch == 27)
    {
        table_charge();
    }

}

void alter_table()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    struct node *q, *head;
    char s[20];
    char ch;
    head = new node;
    head = read_link(3, head);
    q = head -> next;
    printf("请输入桌号: ");
    cin >> s;
    while(q)
    {
        if (strcmp(s, q -> num) == 0)
        {
            printf("请输入新桌号: ");
            cin >> q -> num;
            printf("请输入新状态: ");
            cin >> q -> status;
            printf("请输入新活动: ");
            cin >> q -> action;
            break;
        }
        else
            q = q -> next;
    }

    if (q == NULL)
    {
        printf("该桌号不存在!");
        ch = getch();
        if (ch == 27)
            table_charge();
    }
    else
    {
        write_link(3, head);
        printf("修改成功! 请按ESC键返回\n");
    }
    ch = getch();
    if(ch == 27)
        table_charge();
}


void look_table()
{
    table_menu();
    char ch;
    ch = getch();
    if (ch == 27)
        table_charge();
}


void add_staff()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    FILE *fp;
    struct node *p, *t, *head;
    p = new node;
    p -> price = 0.00;
    printf("请输入用户名: ");
    cin >> p -> name;
    head = new node;
    head = read_link(1, head);
    t = head -> next;
    while(t)
    {
        if (strcmp(p -> name, t -> name) == 0)
        {
            printf("用户已存在!\n");
            Sleep(500);
            add_staff();
        }
        t = t -> next;
    }
    printf("请输入用户密码: ");
    cin >> p -> num;
    printf("请输入用户类型 <1>经理  <2>服务员 <3>主管 \n");
    cin >> p -> typ;
    if(p -> typ == 2)
    {
        p -> price = 0.00;
    }
    if((fp = fopen("d:\\user.dat", "ab+")) == NULL)
    {
        printf("No File in there!\n");
    }
    fwrite(p, sizeof(struct node), 1, fp);
    free(p);
    fclose(fp);
    char ch;
    printf("是否继续添加<Y / N> :");
    cin >> ch;
    if (ch == 'Y')
    {
        add_staff();
    }
    if(ch == 'N')
    {
        staff_charge();
    }
}


void delete_staff()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    char s[30];
    char ch;
    struct node *head, *p, *q;
    head = new node;
    head = read_link(1, head);

    printf("请输入要删除的用户名:");
    cin >> s;
    p = head;
    q = p -> next;
    while(q)
    {
        if(strcmp(s, q -> name) == 0)
        {
            p -> next = q -> next;
            free(q);
            break;
        }
        else
        {
            p = p -> next;
            q = q -> next;
        }
    }
    if(q == NULL)
    {
        printf("该用户名不存在: ");
        ch = getch();
        if(ch == 27)
        {
            staff_charge();
        }
    }
    else
    {
        write_link(1, head);
        printf("修改成功! ");
    }
    ch = getch();
    if(ch == 27)
    {
        staff_charge();
    }
}


void alter_staff()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    struct node *q, *head;
    head = new node;
    char s[30];
    char ch;
    head = read_link(1, head);
    q = head -> next;
    printf("请输入用户名: ");
    cin >> s;
    while(q)
    {
        if (strcmp(s, q -> name) == 0)
        {
            printf("输入新用户名: ");
            cin >> q -> name;
            printf("输入新用密码: ");
            cin >> q -> num;
            printf("输入新用类型: ");
            cin >> q -> typ;
            break;
        }
        else
            q = q -> next;
    }
    if(q == NULL)
    {
        printf("该用户名不存在!\n");
        ch = getch();
        if (ch == 27)
            alter_staff();
    }
    else
    {
        write_link(1, head);
        printf("修改成功!\n");
    }
    ch = getch();
    if (ch == 27)
        alter_staff();
}



void look_staff()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("用户名              密码               类型\n");
    struct node *q, *head;
    head = new node;
    head = read_link(1, head);
    q = head -> next;
    while(q)
    {
        cout << q -> name << "       " << q -> num << "       " << q -> typ << endl;
        q = q -> next;
    }

    char ch;
    ch = getch();
    if (ch == 27)
        staff_charge();
}


void add_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    FILE *fp;
    struct node *p;
    p = new node;
    printf("请输入菜品编号: ");
    cin >> p -> num;
    printf("请输入菜品名称:  ");
    cin >> p -> name;
    printf("请输入菜品价格: ");
    cin >> p -> price;
    printf("请输入菜品状态<Y / N>: ");
    cin >> p -> status;
    printf("请输入菜品活动<Y / N>: ");
    cin >> p -> action;
    if ((fp = fopen("d:\\dish.dat","ab+")) == NULL)
    {
        printf("No file in there\n");
    }
    fwrite(p, sizeof(struct node), 1, fp);
    free(p);
    fclose(fp);
    char c;
    printf("是否继续输入<Y / N>: ");
    cin >> c;
    if (c == 'Y')
        add_dish();
    if (c == 'N')
        menu();
}



void delete_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    char s[20];
    char key;
    char ch;
    printf("请输入要删除的菜号: ");
    cin >> s;
    printf("是否确认删除 <Y / N> :");
    cin >> key;
    if (key == 'Y')
    {
        struct node *p, *q,*head;
        head = new node;
        head = read_link(2, head);
        p = head;
        q = p -> next;
        while(q)
        {
            if (strcmp(s, q -> name) == 0)
            {
                p = q -> next;
                free(p);
                break;
            }
            else
            {
                p = p -> next;
                q = q -> next;
            }
        }

        if(q == NULL)
        {
            printf("该菜品不存在! \n");
            ch = getch();
            if (ch == 27)
                staff_charge();
        }
        else
        {
            write_link(2, head);
            printf("修改成功! \n");
        }
        printf("是否继续修改<Y / N>: ");
        cin >> key;
        if (key == 'Y')
            delete_dish();
        else if (key == 'N')
            menu();
    }
    if(key == 'N')
        menu();
    else
    {
        ch = getch();
        if (ch == 27);
        menu();
    }
}



void alter_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    struct node *q, *head;
    head = new node;
    char s[20];
    char ch;
    head = read_link(2, head);
    q = head -> next;
    printf("请输入菜号: ");
    cin >> s;
    while(q)
    {
        if (strcmp(s, q -> num) == 0)
        {
            printf("请输入新菜号: ");
            cin >> q -> num;
            printf("请输入新菜名:  ");
            cin >> q -> name;
            printf("请输入新价格:   ");
            cin >> q -> price;
            printf("请输入新状态:   ");
            cin >> q -> status;
            printf("请输入新活动:   ");
            cin >> q -> action;
            break;
        }
        else
            q = q -> next;
    }

    if (q == NULL)
    {
        printf("该菜品不存在!\n");
        ch = getch();
        if (ch == 27)
            menu();
    }
    else
    {
        write_link(2, head);
        printf("修改成功!请按ESC返回\n");
    }
    ch = getch();
    if (ch == 27)
        menu();
}




void look_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    char s[20], ch, key;
    struct node *p, *q, *head;
    printf("请输入查询单号: ");
    cin >> s;
    printf("是否确认查询<Y / N> :");
    cin >> key;
    if (key == 'Y')
    {
        head = new node;
        head = read_link(2, head);
        p = head;
        q = head -> next;
        while(q)
        {
            if (strcmp(q -> num, s) == 0)
            {
                printf("菜号              菜名          价格            状态             是否活动\n");
                printf("%s                %s            %.2lf           %s               %s\n", q -> num, q -> name, q -> price, q -> status, q -> action);
                break;
            }
            else
            {
                p = p -> next;
                q = q -> next;
            }
        }
        if (q == NULL)
        {
            printf("该菜不存在!\n");
            ch = getch();
            if (ch == 27)
                menu();
        }
        printf("是否继续查询<Y / N> :");
        cin >> key;
        if (key == 'Y')
            look_dish();
        if (key == 'N')
            menu();
    }
    else if (key == 'N')
        look_dish();
    else
    {
        ch = getch();
        if (ch == 27)
            menu();
    }

}



void all_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    dish_menu();
    char ch;
    ch = getch();
    if (ch == 27)
        menu();
}


void menu()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:增加菜目\n\n");
    printf("           2:删除菜目\n\n");
    printf("           3:修改菜目\n\n");
    printf("           4:查询菜目\n\n");
    printf("           5:所有菜目\n\n");
    printf("           q:返回目录\n\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        system("cls");
        manager_enter();
    }
    else
    {
        if (key == '1')
            add_dish();
        if (key == '2')
            delete_dish();
        if (key == '3')
            alter_dish();
        if (key == '4')
            look_dish();
        if (key == '5')
            all_dish();

    }
}




void table_charge()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:增加台桌\n\n");
    printf("           2:删除台桌\n\n");
    printf("           3:修改台桌\n\n");
    printf("           4:查询台桌\n\n");
    printf("           q:返回目录\n\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        system("cls");
        manager_enter();
    }
    else
    {
        if (key == '1')
            add_table();
        if (key == '2')
            delete_table();
        if (key == '3')
            alter_table();
        if (key == '4')
            look_table();
    }

}





void staff_charge()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:增加人员\n\n");
    printf("           2:删除人员\n\n");
    printf("           3:修改人员\n\n");
    printf("           4:查询人员\n\n");
    printf("           q:返回目录\n\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        system("cls");
        manager_enter();
    }
    else
    {
        if (key == '1')
            add_staff();
        if (key == '2')
            delete_staff();
        if (key == '3')
            alter_staff();
        if (key == '4')
            look_staff();
    }
}



void total_sell()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    double totalmoney = 0;
    printf("用户名          金额\n");
    struct node *head, *t;
    head = new node;
    head = read_link(1, head);
    t = head -> next;
    while(t)
    {
        if (t -> typ == 2)
        {
            printf("%s       %.2lf\n", t -> name, t -> price);
            totalmoney = totalmoney + t -> price;
        }
        t = t -> next;
    }

    printf("总金额\n");
    printf("%.2lf\n", totalmoney);
    char ch;
    ch = getch();
    if (ch == 27)
        charge_enter();
}




void see_order()
{
    system("cls");
    order_menu();
}




void see_dish()
{
    system("cls");
    order_menu();
    char ch;
    ch = getch();
    if (ch == 27)
        staff_enter();
}





void pay_off()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    order_menu();
    printf("请输入要付账的订单号:");
    char num[50];
    cin >> num;
    struct node *head, *p; //结账操作
    head = new node;
    head = read_link(4, head);
    p = head -> next;
    while(p)
    {
        if (strcmp(p -> num, num) == 0 && (strcmp(p -> status, "N") == 0))
        {
            printf("是否确认结账<Y / N> :");
            char key;
            cin >> key;
            if (key == 'Y')
            {
                printf("结账成功!\n");
                strcpy(p -> status, "Y");
                write_link(4, head);

                struct node *head2, *t2; //进行修改台桌操作
                head2 = new node;
                head2 = read_link(3, head);
                t2 = head2 -> next;
                while(t2)
                {
                    if (strcmp(t2 -> num, p -> num) == 0)
                    {
                        strcpy(t2 -> status, "Y");
                        write_link(3, head2);
                        break;
                    }
                    t2 = t2 -> next;
                }

                struct node *head1, *t; //进行记录账单操作
                head1 = new node;
                head1 = read_link(1, head1);
                t = head1 -> next;
                while(t)
                {
                    if (strcmp(t -> name, enter_name) == 0) //如果登陆用户 与t相同
                    {
                        t -> price = t -> price + p -> price;
                        write_link(1, head1);
                        printf("已将销售金额写入该用户!");
                        Sleep(500);
                        break;
                    }
                    t = t -> next;
                }
                break;
            }
            if (key == 'N')
            {
                pay_off();
            }
        }
        else
            p = p -> next;
    }
    if (p == NULL)
    {
        printf("没有该订单!");
        Sleep(500);
        pay_off();
    }

    char ch;
    ch = getch();
    if (ch == 27)
        staff_enter();
}



void start_dish()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("请输入需要点菜的订单号:");
    char ordernum[50];
    cin >> ordernum;
    struct node *head2, *t;
    head2 = new node;
    head2 = read_link(4, head2);
    t = head2 -> next;
    while(t)
    {
        if (strcmp(t -> num, ordernum) == 0)
        {
            printf("这是菜单\n");
            dish_menu();
            printf("请输入菜号: ");
            char number1[50];
            int num2;
            cin >> number1;
            printf("是否确认点菜<Y / N>: ");
            char key;
            cin >> key;
            if (key == 'Y')
            {
                struct node *p, *head1;
                head1 = new node;
                head1 = read_link(2, head1);
                p = head1 -> next;
                while(p)
                {
                    if (strcmp(number1, p -> num) == 0)
                    {
                        printf("请输入份数:  ");
                        cin >> num2;
                        t -> price = t -> price + num2 * p -> price;
                        strcpy(t -> action, "Y");
                        strcpy(t -> status, "N");
                        printf("是否继续点菜<Y / N> :");
                        cin >> key;
                        if (key == 'Y')
                            start_dish();
                        if (key == 'N')
                            staff_enter();
                    }
                    p = p -> next;
                }
                if (p == NULL)
                    printf("没有此菜!!!\n");
                Sleep(500);
                start_dish();
            }
        }
        t = t -> next;
    }
    if (t == NULL)
    {
        printf("没有此订单或该订单已结账! ");
        Sleep(500);
        start_dish();
    }
}












void see_table()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    table_menu(); //打印 台桌情况
    char ch;
    ch = getch();
    if (ch == 27)
        staff_enter();
}




void start_table()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    table_menu();
    FILE *fp;
    struct node *p, *head, *t;
    p = new node;
    printf("请输入桌号 :");
    cin >> p -> num;
    head = new node;
    head = read_link(3, head);
    t = head -> next;
    while(t)
    {
        if (strcmp(t -> num, p -> num) == 0 &&(strcmp(t -> status, "Y") == 0))
        {
            strcpy(t -> status, "N");
            if ((fp = fopen("d:\\order.dat", "rb")) == NULL)
            {
                fp = fopen("d:\\order.dat", "wb+");
                fwrite(p, sizeof(struct node), 1, fp);
                free(p);;
                fclose(fp);
                write_link(3, head);
                printf("是否继续添加<Y / N> :");
                char key;
                cin >> key;
                if (key == 'Y')
                    start_table();
                if (key == 'N')
                    staff_enter();
                break;
            }
            else
            {
                fp = fopen("d:\\order.dat", "ab+");
                fwrite(p, sizeof(struct node), 1, fp);
                free(p);
                fclose(fp);
                write_link(3, head);
                printf("是否继续添加<Y / N> :");
                char key;
                cin >> key;
                if (key == 'Y')
                    start_table();
                if (key == 'N')
                    staff_enter();
                break;
            }

        }
        t = t -> next;
    }
    if (t == NULL)
    {
        printf("不能添加此桌!\n");
        Sleep(500);
        start_table();
    }
}



void manager_enter()  //经理界面
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:菜谱管理\n\n");
    printf("           2:餐桌管理\n\n");
    printf("           3:人员管理\n\n");
    printf("           c:切换用户\n\n");
    printf("           q:退出系统\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        quitsystem();
    }
    if (key == '1')
    {
        menu();
    }
    if (key == '2')
    {
        table_charge();
    }
    if (key == '3')
    {
        staff_charge();
    }
    if (key == 'c')
    {
        system("cls");
        Sleep(500);
        user_enter();
    }
}



void staff_enter()  //服务员界面
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:开    桌\n\n");
    printf("           2:点    菜\n\n");
    printf("           3:查询台桌\n\n");
    printf("           4:点菜记录\n\n");
    printf("           5:查询订单\n\n");
    printf("           6:买    单\n\n");
    printf("           c:切换用户\n\n");
    printf("           q:退出系统\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        quitsystem();
    }
    if (key == 'c')
    {
        system("cls");
        Sleep(500);
        user_enter();
    }
    if (key == '1')
    {
        add_table();
    }
    if (key == '2')
    {
        start_dish();
    }
    if (key == '3')
    {
        see_table();
    }
    if (key == '4')
    {
        see_dish();
    }
    if (key == '5')
    {
        see_order();
    }
    if (key == '6')
    {
        pay_off();
    }
}






void charge_enter()  //主管界面
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    printf("           1:营销统计\n\n");
    printf("           2:        \n\n");
    printf("           3:       \n\n");
    printf("           c:切换用户\n\n");
    printf("           q:退出系统\n");
    printf("请输入您的选择: \n");
    char key;
    cin >> key;
    if (key == 'q')
    {
        quitsystem();
    }
    if (key == 'c')
    {
        system("cls");
        Sleep(500);
        user_enter();
    }
    if (key == '1')
    {
        total_sell();
    }
}




void user_enter()
{
    system("cls");
    printf("*******************************************\n");
    printf("*******************************************\n");
    printf("***           欢迎使用棺木系统          ***\n");
    printf("***                                     ***\n");
    printf("*******************************************\n");
    int s;
    s = check_password();
    if (s == 1)
    {
        printf("\n          正在进入                 \n");
        for (int i = 0; i <= 20; i ++)
        {
            Sleep(50);
            printf("***");
        }
        system("cls");
        manager_enter();
    }
    if (s == 2)  //服务员
    {
        printf("\n          正在进入                 \n");
        for (int i = 0; i <= 17; i ++)
        {
            Sleep(50);
            printf("%***");
        }
        system("cls");
        staff_enter();
    }
    if (s == 3)
    {
        printf("\n          正在进入                 \n");
        for (int i = 0; i <= 17; i ++)
        {
            Sleep(50);
            printf("***");
        }
        system("cls");
        charge_enter();
    }
    if (s != 1 && s != 2 && s != 3)
    {
        printf("用户不存在,或密码错误!\n");
        Sleep(100);
        system("cls");
        user_enter();
    }
}





void system_enter()
{
    printf("系统初始化\n");
    Sleep(500);
    printf("初始化成功\n");
    Sleep(500);
    system("pause");
    printf("初始化文件默认在D盘\n");
    Sleep(500);
    creat_users();
    creat_dish();
    creat_table();
    printf("\n          系统启动中        \n");
    for (int i = 0; i <= 20; i ++)
    {
        Sleep(50);
        printf("***");
    }
    system("cls");
    user_enter();
}
Top