基于Linux、QT、C++的点餐系统
一、功能实现
管理员及收银员的注册登录、人员信息管理、账单查看、餐品信息管理、顾客点餐、厨房上菜、收银结账。
二、项目描述
1、项目采用 C/S 架构,利用 TCP 协议进行通信,采用了多线程的方法解决服务端与多个客服端的通信。 2、通过vector容器来存放顾客的订单信息,顾客提交订单时,将容器发送给管理端和厨房。 3、通过MySQL数据库来储存用户信息、菜单信息、账单信息,及厨房待做餐品清单。 4、采用中介者模式和状态模式,实现不同客服端间的信息交互。 5、顾客提交订单后可随时进行加餐,对未上餐品可进行催餐和退餐。 6、收银员可查询相应桌号的消费详情和消费总额并进行结账。 7、管理员可进行对用户信息和菜单信息的修改、添加和删除,并可查看账单及账单详情。
三、界面展示
1、顾客端(客户端) 2、厨房端(客户端) 3、收银端(客户端)
4、管理端(服务端)
四、MySQL表数据
1、表 2、菜单 3、饮品 4、用户 5、餐桌状态 6、厨房待做菜品 7、账单 8、账单详情
五、代码展示
1、顾客端 widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QSqlQuery>
#include <vector>
#include<QString>
#include<QTcpSocket>
#include "childdorm.h"
#include "structural.h"
using namespace std;
namespace Ui {
class Widget;
}
class childdorm;
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void Init();
void client();
void flag(QByteArray array);
void Menu_print();
void Chef_in(vector<MenuInfo> menuVec);
vector<FoodInfo>* getVecNo(){return &FoodVec_no;}
vector<FoodInfo>* getVec(){return &FoodVec;}
QTcpSocket * getsocket(){return tcpsocket;}
private slots:
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void comeback();
void Delete();
public:
float m_sum;
Ui::Widget *ui;
QSqlDatabase db;
FoodInfo F_head;
vector<FoodInfo> foodVec;
vector<FoodInfo> FoodVec;
vector<FoodInfo> FoodVec_no;
vector<FoodInfo> FoodVec_in;
QTcpSocket *tcpsocket;
vector<MenuInfo> MenuVec;
MenuInfo M_head;
childdorm *child ;
};
#endif
childdrom.h
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include <QWidget>
#include<QDesktopWidget>
#include<QMessageBox>
#include<vector>
#include"widget.h"
#include "structural.h"
using namespace std;
namespace Ui {
class childdorm;
}
class Widget;
class childdorm : public QWidget
{
Q_OBJECT
signals:
void Interface();
void Inter_delete();
public:
explicit childdorm(QWidget *parent = 0 );
~childdorm();
void getvec(vector<FoodInfo> FoodVec_no,vector<FoodInfo> FoodVec_in);
void Delete_food();
void getData(QWidget *parent);
private slots:
void on_pushButton_3_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::childdorm *ui;
FoodInfo F_head;
vector<FoodInfo> *FoodVec_No;
vector<FoodInfo> *FoodVec;
vector<FoodInfo> DeleteVec;
QTcpSocket *tcpsocket;
Widget * p;
};
#endif
structural.h
#ifndef STRUCTURAL_H
#define STRUCTURAL_H
typedef struct Food
{
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
}FoodInfo;
typedef struct Menu
{
char number[10];
char food[100];
char price[10];
char state[20];
}MenuInfo;
#endif
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QDesktopWidget>
#include<QSqlQuery>
#include<QDebug>
#include<QString>
#include<cstring>
#include<QMessageBox>
#include<QSqlError>
#include<QHostAddress>
#include<QTableWidgetItem>
#include <QVariant>
#include<unistd.h>
using namespace std;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->tabWidget->setTabText(0,"主餐");
ui->tabWidget->setTabText(1,"饮品");
this->setFixedSize(1500,800);
this->setWindowTitle(QStringLiteral("点餐窗口"));
this->setWindowIcon(QIcon(":/image/28.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
setPalette(pal);
ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_3->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
Init();
client();
QStringList headtext2;
headtext2<<"序号"<<"餐名"<<"价格"<<"数量"<<"备注";
ui->tableWidget->setColumnCount(headtext2.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext2);
ui->tableWidget->setRowCount(0);
m_sum = 0;
child = new childdorm();
child->hide();
child->getData(this);
connect(child,SIGNAL(Interface()),this,SLOT(comeback()));
connect(child,SIGNAL(Inter_delete()),this,SLOT(Delete()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::Init()
{
tcpsocket = new QTcpSocket(this);
connect(tcpsocket,&QTcpSocket::connected,
[=]()
{
}
);
QString ip = "192.168.12.13";
qint16 port = 8888;
tcpsocket->connectToHost(QHostAddress(ip),port);
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"order");
strcpy(F_head.price,"\0");
strcpy(F_head.price,"\0");
strcpy(F_head.post,"\0");
FoodVec.push_back(F_head);
strcpy(F_head.food,"order_up");
FoodVec_no.push_back(F_head);
}
void Widget::client()
{
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"menu");
strcpy(F_head.price,"\0");
strcpy(F_head.price,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
connect(tcpsocket,&QTcpSocket::readyRead,
[=]()
{
QByteArray array = tcpsocket->readAll();
flag(array);
}
);
}
void Widget::flag(QByteArray array)
{
vector<MenuInfo> menuVec;
menuVec.resize(array.size()/sizeof(MenuInfo));
memcpy(menuVec.data(),array.data(),array.size());
qDebug()<<menuVec[0].food;
if(strcmp(menuVec[0].food,"menu")==0)
{
MenuVec = menuVec;
Menu_print();
}
else if(strcmp(menuVec[0].food,"chef_in")==0)
{
Chef_in(menuVec);
}
}
void Widget::Chef_in(vector<MenuInfo> menuVec)
{
for(int i = 0; i < FoodVec_no.size(); i++)
{
if(strcmp(FoodVec_no[i].number,menuVec[1].number) == 0)
{
strcpy(F_head.table,FoodVec_no[i].table);
strcpy(F_head.number,FoodVec_no[i].number);
strcpy(F_head.food,FoodVec_no[i].food);
strcpy(F_head.price,FoodVec_no[i].price);
strcpy(F_head.quatity,FoodVec_no[i].quatity);
strcpy(F_head.post,FoodVec_no[i].post);
FoodVec_in.push_back(F_head);
FoodVec_no.erase(FoodVec_no.begin ()+i);
}
}
for(int i = 1; i < FoodVec.size(); i++)
{
if(strcmp(FoodVec[i].number,menuVec[1].number) == 0)
{
strcpy(FoodVec[i].table,"0");
}
}
child->getvec(FoodVec_no,FoodVec_in);
}
void Widget::Menu_print()
{
QStringList headtext;
headtext<<"序号"<<"餐名"<<"价格"<<"状态";
ui->tableWidget_2->setColumnCount(headtext.count());
ui->tableWidget_2->setHorizontalHeaderLabels(headtext);
ui->tableWidget_2->setRowCount(0);
QStringList headtext1;
headtext1<<"序号"<<"饮品名"<<"价格"<<"状态";
ui->tableWidget_3->setColumnCount(headtext1.count());
ui->tableWidget_3->setHorizontalHeaderLabels(headtext1);
ui->tableWidget_3->setRowCount(0);
for (int j=1;j< MenuVec.size();j++)
{
QString temp = QString(MenuVec[j].number);
int number = temp.toInt();
if( number < 20000)
{
int rowcount = ui->tableWidget_2->rowCount();
ui->tableWidget_2->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(MenuVec[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(MenuVec[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(MenuVec[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(MenuVec[j].state);
ui->tableWidget_2->setItem(rowcount,0,column);
ui->tableWidget_2->setItem(rowcount,1,column1);
ui->tableWidget_2->setItem(rowcount,2,column2);
ui->tableWidget_2->setItem(rowcount,3,column3);
}
else
{
int rowcount = ui->tableWidget_3->rowCount();
ui->tableWidget_3->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(MenuVec[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(MenuVec[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(MenuVec[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(MenuVec[j].state);
ui->tableWidget_3->setItem(rowcount,0,column);
ui->tableWidget_3->setItem(rowcount,1,column1);
ui->tableWidget_3->setItem(rowcount,2,column2);
ui->tableWidget_3->setItem(rowcount,3,column3);
}
}
}
void Widget::on_pushButton_3_clicked()
{
QString S = ui->lineEdit->text();
char s[5];
QByteArray ba = S.toLocal8Bit();
memcpy(s,ba.data(),ba.size()+1);
if(S == "\0")
{
QMessageBox::warning(this,"提示!","请填写桌号!");
}
else
{
strcpy(FoodVec[0].table,s);
int rowcount = ui->tableWidget->rowCount();
for (int j=0;j<rowcount;j++)
{
QString str = ui->tableWidget->item(j,0)->text();
QString str1 = ui->tableWidget->item(j,1)->text();
QString str2 = ui->tableWidget->item(j,2)->text();
QString str3 = ui->tableWidget->item(j,3)->text();
QString str4 = ui->tableWidget->item(j,4)->text();
strcpy(F_head.table,s);
ba = str.toLocal8Bit();
memcpy(F_head.number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1);
ba = str4.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1);
FoodVec.push_back(F_head);
FoodVec_no.push_back(F_head);
}
this->hide();
child->getvec(FoodVec_no,FoodVec_in);
child->show();
QByteArray a1;
a1.resize(sizeof(FoodInfo)*FoodVec.size());
memcpy(a1.data(),FoodVec.data(),sizeof(FoodInfo)*FoodVec.size());
tcpsocket->write(a1);
}
}
void Widget::on_pushButton_4_clicked()
{
exit(-1);
}
void Widget::on_pushButton_clicked()
{
int flag = 0;
char number[10];
QString s = ui->lineEdit_2->text();
QByteArray ba = s.toLocal8Bit();
memcpy(number,ba.data(),ba.size()+1);
QTableWidgetItem *column = new QTableWidgetItem(s);
QString s1;
QString s2;
for(int i = 0; i < MenuVec.size(); i++)
{
if(strcmp(MenuVec[i].number,number) == 0)
{
s1 = QString(MenuVec[i].food);
s2 = QString(MenuVec[i].price);
flag = 1;
}
}
QTableWidgetItem *column1 = new QTableWidgetItem(s1);
QTableWidgetItem *column2 = new QTableWidgetItem(s2);
QString s3 = ui->lineEdit_3->text();
QTableWidgetItem *column3 = new QTableWidgetItem(s3);
QString s4 = ui->lineEdit_4->text();
QTableWidgetItem *column4 = new QTableWidgetItem(s4);
if(flag == 1)
{
int rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
ui->tableWidget->setItem(rowcount,3,column3);
ui->tableWidget->setItem(rowcount,4,column4);
m_sum = m_sum+s2.toFloat()*s3.toInt();
ui->lcdNumber->display(m_sum);
}
else
{
QMessageBox::warning(this,"提示","输入有误!");
}
}
void Widget::on_pushButton_2_clicked()
{
int currow = ui->tableWidget->currentRow();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
ui->tableWidget->removeRow(currow);
}
}
void Widget::comeback()
{
if(FoodVec.begin() != FoodVec.end())
{
QString Table = FoodVec[1].table;
ui->lineEdit->setText(Table);
ui->lineEdit->setFocusPolicy(Qt::NoFocus);
}
ui->tableWidget->setRowCount(0);
m_sum = 0;
this->show();
}
void Widget::Delete()
{
child->Delete_food();
}
childdorm.cpp
#include "childdorm.h"
#include "ui_childdorm.h"
childdorm::childdorm(QWidget *parent) :
QWidget(parent),
ui(new Ui::childdorm)
{
ui->setupUi(this);
this->setWindowTitle(QStringLiteral("点餐窗口"));
this->setFixedSize(1500,800);
this->setWindowIcon(QIcon(":/image/28.png"));
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
setPalette(pal);
}
childdorm::~childdorm()
{
delete ui;
}
void childdorm::on_pushButton_3_clicked()
{
this->hide();
emit Interface();
}
void childdorm::getData(QWidget *parent)
{
Widget * p = (Widget*) parent;
FoodVec = p->getVec();
FoodVec_No = p->getVecNo();
tcpsocket = p->getsocket();
}
void childdorm::getvec(vector<FoodInfo> FoodVec_no,vector<FoodInfo> FoodVec_in)
{
QStringList headtext;
headtext<<"序号"<<"餐名"<<"价格"<<"数量"<<"备注";
ui->tableWidget->setColumnCount(headtext.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext);
ui->tableWidget->setRowCount(0);
ui->lineEdit->setText(FoodVec_no[1].table);
for (int j=1;j<(FoodVec_no).size();j++)
{
int rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(FoodVec_no[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(FoodVec_no[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(FoodVec_no[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(FoodVec_no[j].quatity);
QTableWidgetItem *column4 = new QTableWidgetItem(FoodVec_no[j].post);
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
ui->tableWidget->setItem(rowcount,3,column3);
ui->tableWidget->setItem(rowcount,4,column4);
}
QStringList headtext1;
headtext1<<"序号"<<"餐名"<<"价格"<<"数量"<<"备注";
ui->tableWidget_2->setColumnCount(headtext1.count());
ui->tableWidget_2->setHorizontalHeaderLabels(headtext1);
ui->tableWidget_2->setRowCount(0);
for (int j=0;j<(FoodVec_in).size();j++)
{
int rowcount = ui->tableWidget_2->rowCount();
ui->tableWidget_2->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(FoodVec_in[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(FoodVec_in[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(FoodVec_in[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(FoodVec_in[j].quatity);
QTableWidgetItem *column4 = new QTableWidgetItem(FoodVec_in[j].post);
ui->tableWidget_2->setItem(rowcount,0,column);
ui->tableWidget_2->setItem(rowcount,1,column1);
ui->tableWidget_2->setItem(rowcount,2,column2);
ui->tableWidget_2->setItem(rowcount,3,column3);
ui->tableWidget_2->setItem(rowcount,4,column4);
}
}
void childdorm::Delete_food()
{
int currow = ui->tableWidget->currentRow();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
QString str = ui->tableWidget->item(currow,0)->text();
QString str1 = ui->tableWidget->item(currow,1)->text();
QString str2 = ui->tableWidget->item(currow,2)->text();
QString str3 = ui->tableWidget->item(currow,3)->text();
QString str4 = ui->tableWidget->item(currow,4)->text();
QString S = ui->lineEdit->text();
QByteArray ba = S.toLocal8Bit();
memcpy(F_head.table,ba.data(),ba.size()+1);
ba = str.toLocal8Bit();
memcpy(F_head.number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1);
ba = str4.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1);
ui->tableWidget->removeRow(currow);
}
for(int i = 0; i < FoodVec_No->size(); i++)
{
if((strcmp(FoodVec_No->at(i).number,F_head.number) == 0) && (strcmp(FoodVec_No->at(i).post,F_head.post) == 0))
{
FoodVec_No->erase(FoodVec_No->begin ()+i);
break;
}
}
for(int i = 0; i < FoodVec->size(); i++)
{
if((strcmp(FoodVec->at(i).number,F_head.number) == 0) && (strcmp(FoodVec->at(i).post,F_head.post) == 0))
{
FoodVec->erase(FoodVec->begin ()+i);
break;
}
}
QByteArray a1;
a1.resize(sizeof(FoodInfo)*FoodVec->size());
memcpy(a1.data(),FoodVec->data(),sizeof(FoodInfo)*FoodVec->size());
tcpsocket->write(a1);
}
void childdorm::on_pushButton_clicked()
{
QMessageBox::warning(this,"催餐","催餐成功!\n厨师正在努力中,请耐心等待!");
}
void childdorm::on_pushButton_2_clicked()
{
emit Inter_delete();
}
2、收银端 widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QSqlQuery>
#include <vector>
#include<QString>
#include<QTcpSocket>
#include "childdorm.h"
#include "structural.h"
using namespace std;
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
void comeback();
void comeback_no();
public:
Ui::Widget *ui;
FoodInfo F_head;
vector<FoodInfo> foodVec;
vector<FoodInfo> FoodVec;
childdorm *child ;
};
#endif
childdorm.h
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include <QWidget>
#include<QSqlQuery>
#include <vector>
#include<QString>
#include<QTcpSocket>
#include "structural.h"
using namespace std;
namespace Ui {
class childdorm;
}
class childdorm : public QWidget
{
Q_OBJECT
signals:
void Interface();
void Inter_no();
public:
explicit childdorm(QWidget *parent = 0);
~childdorm();
void Init();
void client();
void flag(QByteArray array);
void log_in(QString name,QString pw);
void cashier_in();
void cashier_no();
void cashier_query();
void cashier_refresh();
private slots:
void on_pushButton_4_clicked();
void on_pushButton_3_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_5_clicked();
private:
Ui::childdorm *ui;
QString m_name;
float m_sum;
QTcpSocket *tcpsocket;
FoodInfo F_head;
vector<FoodInfo> foodVec;
vector<FoodInfo> FoodVec;
};
#endif
structrual.h
#ifndef STRUCTURAL_H
#define STRUCTURAL_H
typedef struct Food
{
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
}FoodInfo;
#endif
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include "childdorm.h"
#include <QDesktopWidget>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QFile>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(400,377);
this->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/5.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/1.jpg")));
setPalette(pal);
child = new childdorm();
child->hide();
connect(child,SIGNAL(Interface()),this,SLOT(comeback()));
connect(child,SIGNAL(Inter_no()),this,SLOT(comeback_no()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_2_clicked()
{
exit(-1);
}
void Widget::on_pushButton_clicked()
{
QString name = ui->lineEdit->text();
QString pw = ui->lineEdit_2->text();
child->log_in(name,pw);
}
void Widget::comeback()
{
this->hide();
}
void Widget::comeback_no()
{
QMessageBox::information(this,"登录失败!","用户名或密码错误!",QMessageBox::Yes,QMessageBox::Yes);
}
childdorm.cpp
#include "childdorm.h"
#include "ui_childdorm.h"
#include "widget.h"
#include <QDesktopWidget>
#include<QSqlQuery>
#include<QDebug>
#include<QString>
#include<cstring>
#include<QMessageBox>
#include<QSqlError>
#include<QHostAddress>
#include<QTableWidgetItem>
#include <QVariant>
#include<unistd.h>
using namespace std;
childdorm::childdorm(QWidget *parent) :
QWidget(parent),
ui(new Ui::childdorm)
{
ui->setupUi(this);
this->setFixedSize(1500,800);
this->setWindowTitle(QStringLiteral("收银界面"));
this->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/5.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
setPalette(pal);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
Init();
client();
}
childdorm::~childdorm()
{
delete ui;
}
void childdorm::Init()
{
tcpsocket = new QTcpSocket(this);
connect(tcpsocket,&QTcpSocket::connected,
[=]()
{
}
);
QString ip = "192.168.12.13";
qint16 port = 8888;
tcpsocket->connectToHost(QHostAddress(ip),port);
}
void childdorm::client()
{
connect(tcpsocket,&QTcpSocket::readyRead,
[=]()
{
QByteArray array = tcpsocket->readAll();
flag(array);
}
);
}
void childdorm::flag(QByteArray array)
{
FoodVec.clear();
FoodVec.resize(array.size()/sizeof(FoodInfo));
memcpy(FoodVec.data(),array.data(),array.size());
qDebug()<<FoodVec[0].food;
if(strcmp(FoodVec[0].food,"cashier_in")==0)
{
cashier_in();
}
else if(strcmp(FoodVec[0].food,"cashier_no")==0)
{
cashier_no();
}
else if(strcmp(FoodVec[0].food,"cashier_query")==0)
{
cashier_query();
}
else if(strcmp(FoodVec[0].food,"cashier_refresh")==0)
{
cashier_refresh();
}
}
void childdorm::log_in(QString name, QString pw)
{
m_name = name;
foodVec.clear();
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"cashier");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray ba = name.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1);
ba = pw.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1);
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
}
void childdorm::cashier_in()
{
emit Interface();
ui->lineEdit_4->setText(m_name);
ui->lineEdit_4->setFocusPolicy(Qt::NoFocus);
ui->lineEdit->setFocusPolicy(Qt::NoFocus);
ui->lineEdit_3->setFocusPolicy(Qt::NoFocus);
this->show();
}
void childdorm::cashier_no()
{
emit Inter_no();
}
void childdorm::cashier_query()
{
m_sum = 0;
QStringList headtext;
headtext<<"桌号"<<"序号"<<"餐名"<<"价格"<<"数量"<<"备注";
ui->tableWidget->setColumnCount(headtext.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext);
ui->tableWidget->setRowCount(0);
for (int j=1; j<FoodVec.size(); j++)
{
int rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(FoodVec[j].table);
QTableWidgetItem *column1 = new QTableWidgetItem(FoodVec[j].number);
QTableWidgetItem *column2 = new QTableWidgetItem(FoodVec[j].food);
QTableWidgetItem *column3 = new QTableWidgetItem(FoodVec[j].price);
QTableWidgetItem *column4 = new QTableWidgetItem(FoodVec[j].quatity);
QTableWidgetItem *column5 = new QTableWidgetItem(FoodVec[j].post);
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
ui->tableWidget->setItem(rowcount,3,column3);
ui->tableWidget->setItem(rowcount,4,column4);
ui->tableWidget->setItem(rowcount,5,column5);
QString price = QString(FoodVec[j].price);
QString quatity = QString(FoodVec[j].quatity);
m_sum += (price.toFloat()) * (quatity.toInt());
QString data = QString("%1").arg(m_sum);
ui->lineEdit_3->setText(data);
}
}
void childdorm::cashier_refresh()
{
QStringList headtext;
headtext<<"餐桌号"<<"使用状态";
ui->tableWidget_2->setColumnCount(headtext.count());
ui->tableWidget_2->setHorizontalHeaderLabels(headtext);
ui->tableWidget_2->setRowCount(0);
for (int j=1; j<FoodVec.size(); j++)
{
int rowcount = ui->tableWidget_2->rowCount();
ui->tableWidget_2->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(FoodVec[j].table);
QTableWidgetItem *column1 = new QTableWidgetItem(FoodVec[j].food);
ui->tableWidget_2->setItem(rowcount,0,column);
ui->tableWidget_2->setItem(rowcount,1,column1);
}
}
void childdorm::on_pushButton_4_clicked()
{
this->hide();
Widget *child = new Widget();
child->show();
}
void childdorm::on_pushButton_3_clicked()
{
exit(-1);
}
void childdorm::on_pushButton_clicked()
{
QString S = ui->lineEdit_2->text();
ui->lineEdit->setText(S);
char s[5];
QByteArray ba = S.toLocal8Bit();
memcpy(s,ba.data(),ba.size()+1);
if(S == "\0")
{
QMessageBox::warning(this,"提示!","请输入查询桌号!");
}
else
{
foodVec.clear();
strcpy(F_head.table,s);
strcpy(F_head.number,"\0");
strcpy(F_head.food,"cashier_query");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
}
}
void childdorm::on_pushButton_2_clicked()
{
QString S = ui->lineEdit->text();
char s[5];
QByteArray ba = S.toLocal8Bit();
memcpy(s,ba.data(),ba.size()+1);
QString Sum = ui->lineEdit_3->text();
char sum[5];
ba = Sum.toLocal8Bit();
memcpy(sum,ba.data(),ba.size()+1);
char name[100];
ba = m_name.toLocal8Bit();
memcpy(name,ba.data(),ba.size()+1);
if(S == "\0")
{
QMessageBox::warning(this,"提示!","请先查询账单!");
}
else
{
foodVec.clear();
strcpy(F_head.table,s);
strcpy(F_head.number,"\0");
strcpy(F_head.food,"cashier_finish");
strcpy(F_head.price,sum);
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,name);
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
QMessageBox::warning(this,"提示!","结算成功!");
ui->tableWidget->setRowCount(0);
ui->lineEdit->clear();
ui->lineEdit_3->clear();
}
}
void childdorm::on_pushButton_5_clicked()
{
foodVec.clear();
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"cashier_refresh");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
}
3、厨房端 widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QSqlQuery>
#include <vector>
#include<QString>
#include<QTcpSocket>
#include "structural.h"
using namespace std;
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void Init();
void client();
void Order_print(QByteArray array);
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
void on_pushButton_3_clicked();
public:
Ui::Widget *ui;
FoodInfo F_head;
vector<FoodInfo> FoodVec;
vector<FoodInfo> foodVec;
QTcpSocket *tcpsocket;
};
#endif
structural.h
#ifndef STRUCTURAL_H
#define STRUCTURAL_H
typedef struct Food
{
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
}FoodInfo;
#endif
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QDesktopWidget>
#include<QSqlQuery>
#include<QDebug>
#include<QString>
#include<cstring>
#include<QMessageBox>
#include<QSqlError>
#include<QHostAddress>
#include<QTcpSocket>
#include<QTableWidgetItem>
#include <QVariant>
using namespace std;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setFixedSize(1500,800);
this->setWindowTitle(QStringLiteral("厨房"));
this->setWindowIcon(QIcon(":/image/3.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QPalette pal = this->palette();
setPalette(pal);
Init();
client();
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_2_clicked()
{
exit(-1);
}
void Widget::Init()
{
tcpsocket = new QTcpSocket;
connect(tcpsocket,&QTcpSocket::connected,
[=]()
{
}
);
QString ip = "192.168.12.13";
qint16 port = 8888;
tcpsocket->connectToHost(QHostAddress(ip),port);
}
void Widget::client()
{
foodVec.clear();
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"chef");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
connect(tcpsocket,&QTcpSocket::readyRead,
[=]()
{
QByteArray array = tcpsocket->readAll();
Order_print(array);
}
);
}
void Widget::Order_print(QByteArray array)
{
FoodVec.clear();
FoodVec.resize(array.size()/sizeof(FoodInfo));
memcpy(FoodVec.data(),array.data(),array.size());
QStringList headtext;
headtext<<"桌号"<<"序号"<<"餐名"<<"价格"<<"数量"<<"备注";
ui->tableWidget->setColumnCount(headtext.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext);
ui->tableWidget->setRowCount(0);
int rowcount;
qDebug()<< FoodVec.size();
for (int j=0;j< FoodVec.size();j++)
{
qDebug()<<FoodVec[j].food;
rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(FoodVec[j].table);
QTableWidgetItem *column1 = new QTableWidgetItem(FoodVec[j].number);
QTableWidgetItem *column2 = new QTableWidgetItem(FoodVec[j].food);
QTableWidgetItem *column3 = new QTableWidgetItem(FoodVec[j].price);
QTableWidgetItem *column4 = new QTableWidgetItem(FoodVec[j].quatity);
QTableWidgetItem *column5 = new QTableWidgetItem(FoodVec[j].post);
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
ui->tableWidget->setItem(rowcount,3,column3);
ui->tableWidget->setItem(rowcount,4,column4);
ui->tableWidget->setItem(rowcount,5,column5);
}
}
void Widget::on_pushButton_clicked()
{
foodVec.clear();
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"chef_in");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
int currow = ui->tableWidget->currentRow();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
QString str = ui->tableWidget->item(currow,0)->text();
QString str1 = ui->tableWidget->item(currow,1)->text();
QString str2 = ui->tableWidget->item(currow,2)->text();
QString str3 = ui->tableWidget->item(currow,3)->text();
QString str4 = ui->tableWidget->item(currow,4)->text();
QString str5 = ui->tableWidget->item(currow,5)->text();
QByteArray ba = str.toLocal8Bit();
memcpy(F_head.table,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(F_head.number,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1);
ba = str4.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1);
ba = str5.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1);
foodVec.push_back(F_head);
ui->tableWidget->removeRow(currow);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
}
}
void Widget::on_pushButton_3_clicked()
{
foodVec.clear();
strcpy(F_head.table,"\0");
strcpy(F_head.number,"\0");
strcpy(F_head.food,"chef");
strcpy(F_head.price,"\0");
strcpy(F_head.quatity,"\0");
strcpy(F_head.post,"\0");
foodVec.push_back(F_head);
QByteArray a1;
a1.resize(sizeof(FoodInfo)*foodVec.size());
memcpy(a1.data(),foodVec.data(),sizeof(FoodInfo)*foodVec.size());
tcpsocket->write(a1);
}
4、管理端 structural.h(结构体)
#ifndef STRUCTURAL_H
#define STRUCTURAL_H
typedef struct Food
{
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
}FoodInfo;
typedef struct Menu
{
char number[10];
char food[100];
char price[10];
char state[20];
}MenuInfo;
#endif
widget.h(登录窗口)
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QTcpServer>
#include<QTcpSocket>
#include "structural.h"
#include"mythread.h"
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void tcp();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Widget *ui;
QSqlDatabase db;
QTcpServer *tcpserver;
QTcpSocket *tcpsocket;
};
#endif
childdorm.h(管理窗口)
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include <QWidget>
#include<QTcpSocket>
#include<QTcpServer>
#include <vector>
#include<QSqlDatabase>
#include <QDesktopWidget>
#include<QSqlError>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include "structural.h"
#include "widget.h"
#include "add_users.h"
#include "change_per.h"
#include "change_pw.h"
#include "add_food.h"
#include "change_price.h"
#include "change_status.h"
#include "add_drinks.h"
#include "modify_drinks.h"
#include "modify_stutus.h"
#include "bill.h"
#include <QDesktopWidget>
using namespace std;
namespace Ui {
class childdorm;
}
class childdorm : public QWidget
{
Q_OBJECT
public:
explicit childdorm(QWidget *parent = 0);
~childdorm();
void Menu_frint();
void User_frint();
void Bill_frint();
void Init();
void getname(QString name);
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
void on_pushButton_3_clicked();
void on_pushButton_5_clicked();
void on_pushButton_6_clicked();
void on_pushButton_8_clicked();
void on_pushButton_10_clicked();
void on_pushButton_11_clicked();
void on_pushButton_13_clicked();
void on_pushButton_15_clicked();
void on_pushButton_16_clicked();
void on_pushButton_18_clicked();
void on_pushButton_7_clicked();
void on_pushButton_19_clicked();
void on_pushButton_17_clicked();
void on_pushButton_12_clicked();
void on_pushButton_4_clicked();
void on_pushButton_9_clicked();
void on_pushButton_14_clicked();
private:
Ui::childdorm *ui;
QTcpServer *Server;
QTcpSocket *Socket;
QSqlDatabase db;
vector<MenuInfo> MenuVec;
MenuInfo M_head;
vector<FoodInfo> Foodvec;
FoodInfo F_head;
};
#endif
add_drinks.h(添加饮品)
#ifndef ADD_DRINKS_H
#define ADD_DRINKS_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class Add_drinks;
}
class Add_drinks : public QWidget
{
Q_OBJECT
public:
explicit Add_drinks(QWidget *parent = 0);
~Add_drinks();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Add_drinks *ui;
QSqlDatabase db;
};
#endif
add_food.h(添加菜品)
#ifndef ADD_FOOD_H
#define ADD_FOOD_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class Add_food;
}
class Add_food : public QWidget
{
Q_OBJECT
public:
explicit Add_food(QWidget *parent = 0);
~Add_food();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::Add_food *ui;
QSqlDatabase db;
};
#endif
add_users.h(添加用户)
#ifndef ADD_USERS_H
#define ADD_USERS_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class add_users;
}
class add_users : public QWidget
{
Q_OBJECT
public:
explicit add_users(QWidget *parent = 0);
~add_users();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::add_users *ui;
QSqlDatabase db;
};
#endif
bill.h(账单详情)
#ifndef BILL_H
#define BILL_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class Bill;
}
class Bill : public QWidget
{
Q_OBJECT
public:
explicit Bill(QWidget *parent = 0);
~Bill();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Bill *ui;
QSqlDatabase db;
};
#endif
change_per(修改用户权限)
#ifndef CHANGE_PER_H
#define CHANGE_PER_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class change_per;
}
class change_per : public QWidget
{
Q_OBJECT
public:
explicit change_per(QWidget *parent = 0);
~change_per();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::change_per *ui;
QSqlDatabase db;
};
#endif
chang_price.h(修改餐品价格)
#ifndef CHANGE_PRICE_H
#define CHANGE_PRICE_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class change_price;
}
class change_price : public QWidget
{
Q_OBJECT
public:
explicit change_price(QWidget *parent = 0);
~change_price();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::change_price *ui;
QSqlDatabase db;
};
#endif
change_pw.h(修改用户密码)
#ifndef CHANGE_PW_H
#define CHANGE_PW_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class change_pw;
}
class change_pw : public QWidget
{
Q_OBJECT
public:
explicit change_pw(QWidget *parent = 0);
~change_pw();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::change_pw *ui;
QSqlDatabase db;
};
#endif
change_status.h(修改菜品状态)
#ifndef CHANGE_STATUS_H
#define CHANGE_STATUS_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class change_status;
}
class change_status : public QWidget
{
Q_OBJECT
public:
explicit change_status(QWidget *parent = 0);
~change_status();
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::change_status *ui;
QSqlDatabase db;
};
#endif
modify_drinks.h(修改饮品价格)
#ifndef MODIFY_DRINKS_H
#define MODIFY_DRINKS_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class Modify_drinks;
}
class Modify_drinks : public QWidget
{
Q_OBJECT
public:
explicit Modify_drinks(QWidget *parent = 0);
~Modify_drinks();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Modify_drinks *ui;
QSqlDatabase db;
};
#endif
modify_status.h(修改饮品状态)
#ifndef MODIFY_STUTUS_H
#define MODIFY_STUTUS_H
#include <QWidget>
#include<QSqlQuery>
#include<QSqlDatabase>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QSqlError>
#include <QDesktopWidget>
namespace Ui {
class Modify_stutus;
}
class Modify_stutus : public QWidget
{
Q_OBJECT
public:
explicit Modify_stutus(QWidget *parent = 0);
~Modify_stutus();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::Modify_stutus *ui;
QSqlDatabase db;
};
#endif
mythread.h(线程)
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include<QThread>
#include<QObject>
#include<QWidget>
#include<QTcpSocket>
#include<QByteArray>
#include<QSqlQuery>
#include<vector>
#include<cstring>
#include<string>
#include<QDateTime>
#include"structural.h"
using namespace std;
class mythread:public QThread
{
Q_OBJECT
public:
mythread(QTcpSocket *socket);
void run();
void Init();
void Flag(QByteArray array);
void order_menu();
void order_food();
void chef_sent();
void chef_in();
void cashier_in();
void cashier_query();
void cashier_refresh();
void cashier_finish();
public:
QTcpSocket *tcpsocket;
static QTcpSocket *order_socket[20];
static QTcpSocket *chef_socket;
static QTcpSocket *cashier_socket;
vector<MenuInfo> MenuVec;
MenuInfo M_head;
vector<FoodInfo> Foodvec;
FoodInfo F_head;
QSqlDatabase db;
};
static vector<FoodInfo> foodvec[20];
#endif
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.cpp(登录)
#include "widget.h"
#include "ui_widget.h"
#include "childdorm.h"
#include <QDesktopWidget>
#include<QLabel>
#include<QPalette>
#include<QMessageBox>
#include<QFile>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(400,377);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/1.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
tcp();
}
Widget::~Widget()
{
delete ui;
}
void Widget::tcp()
{
tcpserver = new QTcpServer(this);
tcpserver->listen(QHostAddress::Any,8888);
connect(tcpserver,&QTcpServer::newConnection,
[=](){
tcpsocket = tcpserver->nextPendingConnection();
QString ip =tcpsocket->peerAddress().toString();
int port = tcpsocket->peerPort();
QString temp = QString::fromUtf8("地址:%1 端口:%2").arg(ip).arg(port);
qDebug()<<temp;
mythread *thread = new mythread(tcpsocket);
thread->start();
});
}
void Widget::on_pushButton_clicked()
{
QSqlQuery query(db);
QString name = ui->lineEdit->text();
QString pwm = ui->lineEdit_2->text();
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() == pwm)
{
temp=QString::fromUtf8("select 权限 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("权限").toString()=="管理员")
{
this->hide();
childdorm *child = new childdorm();
child->getname(name);
child->show();
}
else
{
QMessageBox qm(this);
qm.setText(QStringLiteral("该用户不是管理员!"));
qm.move(this->geometry().center());
qm.exec();
}
}
else
{
QMessageBox qm(this);
qm.setText(QStringLiteral("账号或密码错误!"));
qm.move(this->geometry().center());
qm.exec();
}
}
void Widget::on_pushButton_2_clicked()
{
exit(-1);
}
childdorm.cpp(管理窗口)
#include "childdorm.h"
#include "ui_childdorm.h"
childdorm::childdorm(QWidget *parent) :
QWidget(parent),
ui(new Ui::childdorm)
{
ui->setupUi(this);
this->setFixedSize(1500,800);
this->setWindowTitle(QStringLiteral("管理员界面"));
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
setPalette(pal);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_3->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget_4->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget_4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
Init();
}
childdorm::~childdorm()
{
delete ui;
}
void childdorm::getname(QString name)
{
ui->lineEdit->setText(name);
}
void childdorm::on_pushButton_clicked()
{
this->hide();
Widget *child = new Widget();
child->show();
}
void childdorm::on_pushButton_2_clicked()
{
exit(-1);
}
void childdorm::on_pushButton_3_clicked()
{
add_users *child = new add_users();
child->show();
}
void childdorm::on_pushButton_5_clicked()
{
change_pw *child = new change_pw();
child->show();
}
void childdorm::on_pushButton_6_clicked()
{
change_per *child = new change_per();
child->show();
}
void childdorm::on_pushButton_8_clicked()
{
Add_food *child = new Add_food();
child->show();
}
void childdorm::on_pushButton_10_clicked()
{
change_price *child = new change_price;
child->show();
}
void childdorm::on_pushButton_11_clicked()
{
change_status *child = new change_status;
child->show();
}
void childdorm::on_pushButton_13_clicked()
{
Add_drinks *child = new Add_drinks;
child->show();
}
void childdorm::on_pushButton_15_clicked()
{
Modify_drinks *child = new Modify_drinks;
child->show();
}
void childdorm::on_pushButton_16_clicked()
{
Modify_stutus *child = new Modify_stutus;
child->show();
}
void childdorm::on_pushButton_18_clicked()
{
Bill *child = new Bill;
child->show();
}
void childdorm::Init()
{
QSqlQuery query;
bool ret = query.exec("select *from 菜单");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
while (query.next())
{
QString str = query.value("序号").toString();
QString str1 = query.value("菜名").toString();
QString str2 = query.value("价格").toString();
QString str3 = query.value("状态").toString();
char Number[10];
char food[100];
char Price[10];
char State[20];
QByteArray ba = str.toLocal8Bit();
memcpy(Number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);
strcpy(M_head.number,Number);
strcpy(M_head.food, food);
strcpy(M_head.price ,Price);
strcpy(M_head.state , State);
MenuVec.push_back(M_head);
}
ret = query.exec("select *from 饮品");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
while (query.next())
{
QString str = query.value("序号").toString();
QString str1 = query.value("饮品名").toString();
QString str2 = query.value("价格").toString();
QString str3 = query.value("状态").toString();
char Number[10];
char food[100];
char Price[10];
char State[20];
QByteArray ba = str.toLocal8Bit();
memcpy(Number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);
strcpy(M_head.number,Number);
strcpy(M_head.food, food);
strcpy(M_head.price ,Price);
strcpy(M_head.state , State);
MenuVec.push_back(M_head);
}
Menu_frint();
User_frint();
Bill_frint();
}
void childdorm::Menu_frint()
{
QStringList headtext;
headtext<<"序号"<<"餐名"<<"价格"<<"状态";
ui->tableWidget_3->setColumnCount(headtext.count());
ui->tableWidget_3->setHorizontalHeaderLabels(headtext);
ui->tableWidget_3->setRowCount(0);
QStringList headtext1;
headtext1<<"序号"<<"饮品名"<<"价格"<<"状态";
ui->tableWidget_4->setColumnCount(headtext1.count());
ui->tableWidget_4->setHorizontalHeaderLabels(headtext1);
ui->tableWidget_4->setRowCount(0);
for (int j=0;j< MenuVec.size();j++)
{
QString temp = QString(MenuVec[j].number);
int number = temp.toInt();
if( number < 20000)
{
int rowcount = ui->tableWidget_3->rowCount();
ui->tableWidget_3->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(MenuVec[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(MenuVec[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(MenuVec[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(MenuVec[j].state);
ui->tableWidget_3->setItem(rowcount,0,column);
ui->tableWidget_3->setItem(rowcount,1,column1);
ui->tableWidget_3->setItem(rowcount,2,column2);
ui->tableWidget_3->setItem(rowcount,3,column3);
}
else
{
int rowcount = ui->tableWidget_4->rowCount();
ui->tableWidget_4->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(MenuVec[j].number);
QTableWidgetItem *column1 = new QTableWidgetItem(MenuVec[j].food);
QTableWidgetItem *column2 = new QTableWidgetItem(MenuVec[j].price);
QTableWidgetItem *column3 = new QTableWidgetItem(MenuVec[j].state);
ui->tableWidget_4->setItem(rowcount,0,column);
ui->tableWidget_4->setItem(rowcount,1,column1);
ui->tableWidget_4->setItem(rowcount,2,column2);
ui->tableWidget_4->setItem(rowcount,3,column3);
}
}
}
void childdorm::User_frint()
{
QSqlQuery query(db);
bool ret = query.exec("select *from 用户");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
QStringList headtext;
headtext<<"用户名"<<"密码"<<"权限";
ui->tableWidget->setColumnCount(headtext.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext);
ui->tableWidget->setRowCount(0);
while (query.next())
{
int rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(query.value("用户名").toString());
QTableWidgetItem *column1 = new QTableWidgetItem(query.value("密码").toString());
QTableWidgetItem *column2 = new QTableWidgetItem(query.value("权限").toString());
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
}
}
void childdorm::Bill_frint()
{
QSqlQuery query(db);
bool ret = query.exec("select *from 账单");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
QStringList headtext;
headtext<<"交易号"<<"时间"<<"桌号"<<"消费额"<<"收银人";
ui->tableWidget_2->setColumnCount(headtext.count());
ui->tableWidget_2->setHorizontalHeaderLabels(headtext);
ui->tableWidget_2->setRowCount(0);
while (query.next())
{
int rowcount = ui->tableWidget_2->rowCount();
ui->tableWidget_2->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(query.value("交易号").toString());
QTableWidgetItem *column1 = new QTableWidgetItem(query.value("时间").toString());
QTableWidgetItem *column2 = new QTableWidgetItem(query.value("桌号").toString());
QTableWidgetItem *column3 = new QTableWidgetItem(query.value("消费额").toString());
QTableWidgetItem *column4 = new QTableWidgetItem(query.value("收银人").toString());
ui->tableWidget_2->setItem(rowcount,0,column);
ui->tableWidget_2->setItem(rowcount,1,column1);
ui->tableWidget_2->setItem(rowcount,2,column2);
ui->tableWidget_2->setItem(rowcount,3,column3);
ui->tableWidget_2->setItem(rowcount,4,column4);
}
}
void childdorm::on_pushButton_7_clicked()
{
User_frint();
}
void childdorm::on_pushButton_19_clicked()
{
Bill_frint();
}
void childdorm::on_pushButton_17_clicked()
{
Menu_frint();
}
void childdorm::on_pushButton_12_clicked()
{
Menu_frint();
}
void childdorm::on_pushButton_4_clicked()
{
QSqlQuery query(db);
char str[100];
int currow = ui->tableWidget->currentRow();
QString name= ui->tableWidget->item(currow,0)->text();
std::string s1 = name.toStdString();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
sprintf(str,"delete from 用户 where 用户名 = '%s'",s1.c_str());
query.exec(str);
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() != "\0")
{
QMessageBox::warning(this,"提示","删除失败!");
}
else
{
ui->tableWidget->removeRow(currow);
QMessageBox::warning(this,"提示","删除成功!");
}
}
}
void childdorm::on_pushButton_9_clicked()
{
QSqlQuery query(db);
char str[100];
int currow = ui->tableWidget_3->currentRow();
QString number= ui->tableWidget_3->item(currow,0)->text();
std::string s1 = number.toStdString();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
sprintf(str,"delete from 菜单 where 序号 = '%s'",s1.c_str());
query.exec(str);
QString temp=QString::fromUtf8("select 菜名 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("菜名").toString() != "\0")
{
QMessageBox::warning(this,"提示","删除失败!");
}
else
{
ui->tableWidget_3->removeRow(currow);
QMessageBox::warning(this,"提示","删除成功!");
}
}
}
void childdorm::on_pushButton_14_clicked()
{
QSqlQuery query(db);
char str[100];
int currow = ui->tableWidget_4->currentRow();
QString number= ui->tableWidget_4->item(currow,0)->text();
std::string s1 = number.toStdString();
if(currow == -1)
{
QMessageBox::warning(this,"提示","操作有误!");
}
else
{
sprintf(str,"delete from 饮品 where 序号 = '%s'",s1.c_str());
query.exec(str);
QString temp=QString::fromUtf8("select 饮品名 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("饮品名").toString() != "\0")
{
QMessageBox::warning(this,"提示","删除失败!");
}
else
{
ui->tableWidget_4->removeRow(currow);
QMessageBox::warning(this,"提示","删除成功!");
}
}
}
add_drinks.cpp(添加饮品)
#include "add_drinks.h"
#include "ui_add_drinks.h"
#include <QDesktopWidget>
Add_drinks::Add_drinks(QWidget *parent) :
QWidget(parent),
ui(new Ui::Add_drinks)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
Add_drinks::~Add_drinks()
{
delete ui;
}
void Add_drinks::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
bool ret = query.exec("select *from 饮品");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
int count;
while (query.next())
{
count = query.value("序号").toInt();
}
count++;
QString name = ui->lineEdit->text();
QString price = ui->lineEdit_2->text();
QString limit = ui->comboBox->currentText();
std::string s1 = name.toStdString();
std::string s2 = price.toStdString();
std::string s3 = limit.toStdString();
QString temp=QString::fromUtf8("select 序号 from 饮品 where 饮品名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("序号").toString() != "\0")
{
QMessageBox::warning(this,"提示","已有该饮品!");
}
else
{
sprintf(str,"insert into 饮品 values(%d,'%s','%s','%s')",count,s1.c_str(),s2.c_str(),s3.c_str());
query.exec(str);
temp=QString::fromUtf8("select 序号 from 饮品 where 饮品名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("序号").toString() != "\0")
{
QMessageBox::warning(this,"提示","添加成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","添加失败!");
}
}
}
void Add_drinks::on_pushButton_2_clicked()
{
close();
}
add_dood.cpp(添加菜品)
#include "add_food.h"
#include "ui_add_food.h"
#include <QDesktopWidget>
#include<QDebug>
Add_food::Add_food(QWidget *parent) :
QWidget(parent),
ui(new Ui::Add_food)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
Add_food::~Add_food()
{
delete ui;
}
void Add_food::on_pushButton_2_clicked()
{
close();
}
void Add_food::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
bool ret = query.exec("select *from 菜单");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
int count;
while (query.next())
{
count = query.value("序号").toInt();
}
count++;
QString name = ui->lineEdit->text();
QString price = ui->lineEdit_2->text();
QString limit = ui->comboBox->currentText();
std::string s1 = name.toStdString();
std::string s2 = price.toStdString();
std::string s3 = limit.toStdString();
QString temp=QString::fromUtf8("select 序号 from 菜单 where 菜名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("序号").toString() != "\0")
{
QMessageBox::warning(this,"提示","已有该菜品!");
}
else
{
sprintf(str,"insert into 菜单 values(%d,'%s','%s','%s')",count,s1.c_str(),s2.c_str(),s3.c_str());
query.exec(str);
temp=QString::fromUtf8("select 序号 from 菜单 where 菜名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("序号").toString() != "\0")
{
QMessageBox::warning(this,"提示","添加成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","添加失败!");
}
}
}
add_users.cpp(添加用户)
#include "add_users.h"
#include "ui_add_users.h"
#include <QDesktopWidget>
#include<QComboBox>
#include<QDebug>
add_users::add_users(QWidget *parent) :
QWidget(parent),
ui(new Ui::add_users)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
add_users::~add_users()
{
delete ui;
}
void add_users::on_pushButton_2_clicked()
{
close();
}
void add_users::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString name = ui->lineEdit->text();
QString pwm = ui->lineEdit_2->text();
QString limit = ui->comboBox->currentText();
std::string s1 = name.toStdString();
std::string s2 = pwm.toStdString();
std::string s3 = limit.toStdString();
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() != "\0")
{
QMessageBox qm(this);
qm.setText(QStringLiteral("该用户已被注册!\n请重新输入!"));
qm.move(this->geometry().center());
qm.exec();
}
else
{
sprintf(str,"insert into 用户 values('%s','%s','%s')",s1.c_str(),s2.c_str(),s3.c_str());
query.exec(str);
temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() == pwm)
{
QMessageBox::warning(this,"提示","添加成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","添加失败!");
}
}
}
bill.cpp(账单详情)
#include "bill.h"
#include "ui_bill.h"
#include <QDesktopWidget>
Bill::Bill(QWidget *parent) :
QWidget(parent),
ui(new Ui::Bill)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(1000,700);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
Bill::~Bill()
{
delete ui;
}
void Bill::on_pushButton_clicked()
{
close();
}
void Bill::on_pushButton_2_clicked()
{
QString Num = ui->lineEdit->text();
QSqlQuery query(db);
bool ret = query.exec("select *from 账单详情");
if(!ret)
{
QSqlError error = query.lastError();
QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
QMessageBox::warning(this,"提示",str);
}
QStringList headtext;
headtext<<"交易号"<<"桌号"<<"序号"<<"菜名"<<"价格"<<"数量"<<"备注"<<"收银人";
ui->tableWidget->setColumnCount(headtext.count());
ui->tableWidget->setHorizontalHeaderLabels(headtext);
ui->tableWidget->setRowCount(0);
while (query.next())
{
QString num = query.value("交易号").toString();
if(num == Num)
{
int rowcount = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowcount);
QTableWidgetItem *column = new QTableWidgetItem(query.value("交易号").toString());
QTableWidgetItem *column1 = new QTableWidgetItem(query.value("桌号").toString());
QTableWidgetItem *column2 = new QTableWidgetItem(query.value("序号").toString());
QTableWidgetItem *column3 = new QTableWidgetItem(query.value("菜名").toString());
QTableWidgetItem *column4 = new QTableWidgetItem(query.value("价格").toString());
QTableWidgetItem *column5 = new QTableWidgetItem(query.value("数量").toString());
QTableWidgetItem *column6 = new QTableWidgetItem(query.value("备注").toString());
QTableWidgetItem *column7 = new QTableWidgetItem(query.value("收银人").toString());
ui->tableWidget->setItem(rowcount,0,column);
ui->tableWidget->setItem(rowcount,1,column1);
ui->tableWidget->setItem(rowcount,2,column2);
ui->tableWidget->setItem(rowcount,3,column3);
ui->tableWidget->setItem(rowcount,4,column4);
ui->tableWidget->setItem(rowcount,5,column5);
ui->tableWidget->setItem(rowcount,6,column6);
ui->tableWidget->setItem(rowcount,7,column7);
}
}
}
change_per.cpp(修改用户权限)
#include "change_per.h"
#include "ui_change_per.h"
#include <QDesktopWidget>
change_per::change_per(QWidget *parent) :
QWidget(parent),
ui(new Ui::change_per)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
change_per::~change_per()
{
delete ui;
}
void change_per::on_pushButton_2_clicked()
{
close();
}
void change_per::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString name = ui->lineEdit->text();
QString pw = ui->lineEdit_2->text();
QString limit = ui->comboBox->currentText();
std::string s1 = name.toStdString();
std::string s3 = limit.toStdString();
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() != pw)
{
QMessageBox::warning(this,"提示","用户名或密码错误!");
}
else
{
sprintf(str,"update 用户 set 权限 = '%s' where 用户名 = '%s'",s3.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 权限 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("权限").toString() == limit)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
change_price.cpp(修改菜品价格)
#include "change_price.h"
#include "ui_change_price.h"
#include <QDesktopWidget>
change_price::change_price(QWidget *parent) :
QWidget(parent),
ui(new Ui::change_price)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
change_price::~change_price()
{
delete ui;
}
void change_price::on_pushButton_2_clicked()
{
close();
}
void change_price::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString number = ui->lineEdit->text();
QString price = ui->lineEdit_2->text();
std::string s1 = number.toStdString();
std::string s2 = price.toStdString();
QString temp=QString::fromUtf8("select 菜名 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("菜名").toString() == "\0")
{
QMessageBox::warning(this,"提示","菜品不存在!请重新输入!");
}
else
{
sprintf(str,"update 菜单 set 价格 = '%s' where 序号 = '%s'",s2.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 价格 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("价格").toString() == price)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
change_pw(修改用户密码)
#include "change_pw.h"
#include "ui_change_pw.h"
#include <QDesktopWidget>
change_pw::change_pw(QWidget *parent) :
QWidget(parent),
ui(new Ui::change_pw)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
change_pw::~change_pw()
{
delete ui;
}
void change_pw::on_pushButton_2_clicked()
{
close();
}
void change_pw::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString name = ui->lineEdit->text();
QString pw = ui->lineEdit_2->text();
QString new_pw = ui->lineEdit_3->text();
std::string s1 = name.toStdString();
std::string s3 = new_pw.toStdString();
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() != pw)
{
QMessageBox::warning(this,"提示","用户名或密码错误!");
}
else
{
sprintf(str,"update 用户 set 密码 = '%s' where 用户名 = '%s'",s3.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() == new_pw)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
change_status.cpp(修改菜品状态)
#include "change_status.h"
#include "ui_change_status.h"
#include <QDesktopWidget>
change_status::change_status(QWidget *parent) :
QWidget(parent),
ui(new Ui::change_status)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
change_status::~change_status()
{
delete ui;
}
void change_status::on_pushButton_2_clicked()
{
close();
}
void change_status::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString number = ui->lineEdit->text();
QString limit = ui->comboBox->currentText();
std::string s1 = number.toStdString();
std::string s2 = limit.toStdString();
QString temp=QString::fromUtf8("select 菜名 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("菜名").toString() == "\0")
{
QMessageBox::warning(this,"提示","菜品不存在!请重新输入!");
}
else
{
sprintf(str,"update 菜单 set 状态 = '%s' where 序号 = '%s'",s2.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 状态 from 菜单 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("状态").toString() == limit)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
modify_drinks.cpp(修改饮品价格)
#include "modify_drinks.h"
#include "ui_modify_drinks.h"
#include <QDesktopWidget>
Modify_drinks::Modify_drinks(QWidget *parent) :
QWidget(parent),
ui(new Ui::Modify_drinks)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
Modify_drinks::~Modify_drinks()
{
delete ui;
}
void Modify_drinks::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString number = ui->lineEdit->text();
QString price = ui->lineEdit_2->text();
std::string s1 = number.toStdString();
std::string s2 = price.toStdString();
QString temp=QString::fromUtf8("select 饮品名 from 饮品 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("饮品名").toString() == "\0")
{
QMessageBox::warning(this,"提示","饮品不存在!请重新输入!");
}
else
{
sprintf(str,"update 饮品 set 价格 = '%s' where 序号 = '%s'",s2.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 价格 from 饮品 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("价格").toString() == price)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
void Modify_drinks::on_pushButton_2_clicked()
{
close();
}
modify_status.cpp(修改饮品状态)
#include "modify_stutus.h"
#include "ui_modify_stutus.h"
#include <QDesktopWidget>
Modify_stutus::Modify_stutus(QWidget *parent) :
QWidget(parent),
ui(new Ui::Modify_stutus)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon(":/image/44.png"));
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
QPalette pal = this->palette();
pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/31.jpg")));
setPalette(pal);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
QMessageBox::warning(this,"提示","无法连接数据库");
}
}
Modify_stutus::~Modify_stutus()
{
delete ui;
}
void Modify_stutus::on_pushButton_clicked()
{
QSqlQuery query(db);
char str[100];
QString number = ui->lineEdit->text();
QString limit = ui->comboBox->currentText();
std::string s1 = number.toStdString();
std::string s2 = limit.toStdString();
QString temp=QString::fromUtf8("select 饮品名 from 饮品 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("饮品名").toString() == "\0")
{
QMessageBox::warning(this,"提示","饮品不存在!请重新输入!");
}
else
{
sprintf(str,"update 饮品 set 状态 = '%s' where 序号 = '%s'",s2.c_str(),s1.c_str());
query.exec(str);
temp=QString::fromUtf8("select 状态 from 饮品 where 序号 ='%1'").arg(number);
query.exec(temp);
query.next();
if(query.value("状态").toString() == limit)
{
QMessageBox::warning(this,"提示","修改成功!");
close();
}
else
{
QMessageBox::warning(this,"提示","修改失败!");
}
}
}
void Modify_stutus::on_pushButton_2_clicked()
{
close();
}
mythread.cpp(线程)
#include "mythread.h"
QTcpSocket *mythread::chef_socket=NULL;
QTcpSocket *mythread::cashier_socket=NULL;
QTcpSocket *mythread::order_socket[20] ={NULL};
mythread::mythread(QTcpSocket *socket)
{
tcpsocket=socket;
Init();
}
void mythread::run()
{
connect(tcpsocket,&QTcpSocket::readyRead,
[=](){
QByteArray array= tcpsocket->readAll();
Flag(array);
});
}
void mythread::Flag(QByteArray array)
{
Foodvec.clear();
Foodvec.resize(array.size()/sizeof(FoodInfo));
memcpy(Foodvec.data(),array.data(),array.size());
qDebug()<<Foodvec[0].food;
if(strcmp(Foodvec[0].food,"menu") == 0)
{
order_menu();
}
else if(strcmp(Foodvec[0].food,"order") == 0)
{
order_food();
}
else if(strcmp(Foodvec[0].food,"chef") == 0)
{
chef_socket = tcpsocket;
chef_sent();
}
else if(strcmp(Foodvec[0].food,"chef_in") == 0)
{
chef_in();
}
else if(strcmp(Foodvec[0].food,"cashier") == 0)
{
cashier_socket = tcpsocket;
cashier_in();
}
else if(strcmp(Foodvec[0].food,"cashier_query") == 0)
{
cashier_query();
}
else if(strcmp(Foodvec[0].food,"cashier_refresh") == 0)
{
cashier_refresh();
}
else if(strcmp(Foodvec[0].food,"cashier_finish") == 0)
{
cashier_finish();
}
}
void mythread::cashier_in()
{
QSqlQuery query(db);
QString name = Foodvec[1].food;
QString pw = Foodvec[1].post;
QString temp=QString::fromUtf8("select 密码 from 用户 where 用户名 ='%1'").arg(name);
query.exec(temp);
query.next();
if(query.value("密码").toString() == pw)
{
strcpy(Foodvec[0].food,"cashier_in");
QByteArray a1;
a1.resize(sizeof(FoodInfo)*Foodvec.size());
memcpy(a1.data(),Foodvec.data(),sizeof(MenuInfo)*Foodvec.size());
cashier_socket->write(a1);
}
else
{
strcpy(Foodvec[0].food,"cashier_no");
QByteArray a1;
a1.resize(sizeof(FoodInfo)*Foodvec.size());
memcpy(a1.data(),Foodvec.data(),sizeof(MenuInfo)*Foodvec.size());
cashier_socket->write(a1);
}
}
void mythread::cashier_query()
{
QString temp = QString(Foodvec[0].table);
int n = temp.toInt();
Foodvec = foodvec[n];
strcpy(Foodvec[0].food,"cashier_query");
QByteArray a1;
a1.resize(sizeof(FoodInfo)*Foodvec.size());
memcpy(a1.data(),Foodvec.data(),sizeof(MenuInfo)*Foodvec.size()*2+Foodvec.size()*50);
cashier_socket->write(a1);
}
void mythread::cashier_refresh()
{
QSqlQuery query(db);
bool ret = query.exec("select *from 餐桌");
if(!ret)
{
}
while (query.next())
{
QString str = query.value("桌号").toString();
QString str1 = query.value("状态").toString();
char table[5];
char food[100];
QByteArray ba = str.toLocal8Bit();
memcpy(table,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
strcpy(F_head.table, table);
strcpy(F_head.food, food);
Foodvec.push_back(F_head);
}
QByteArray a1;
a1.resize(sizeof(FoodInfo)*Foodvec.size());
memcpy(a1.data(),Foodvec.data(),sizeof(MenuInfo)*Foodvec.size()*2+Foodvec.size()*50);
cashier_socket->write(a1);
}
void mythread::cashier_finish()
{
QString Table = QString(Foodvec[0].table);
int n = Table.toInt();
QString Price = QString(Foodvec[0].price);
QString Name = QString(Foodvec[0].post);
QSqlQuery query(db);
char str[100];
Foodvec = foodvec[n];
bool ret = query.exec("select *from 账单");
if(!ret)
{
}
int count = 100000;
while (query.next())
{
count = query.value("交易号").toInt();
}
if(count < 100001)
{
count = 100000;
}
count++;
QString Num;
Num=QString::number(count);
QDateTime current_date_time =QDateTime::currentDateTime();
QString Time =current_date_time.toString("yyyy-MM-dd hh:mm:ss ddd");
char num[10];
char time[100];
char table[5];
char sprice[10];
char name[100];
QByteArray ba = Num.toLocal8Bit();
memcpy(num,ba.data(),ba.size()+1);
ba = Time.toLocal8Bit();
memcpy(time,ba.data(),ba.size()+1);
ba = Table.toLocal8Bit();
memcpy(table,ba.data(),ba.size()+1);
ba = Price.toLocal8Bit();
memcpy(sprice,ba.data(),ba.size()+1);
ba = Name.toLocal8Bit();
memcpy(name,ba.data(),ba.size()+1);
sprintf(str,"insert into 账单 values('%s','%s','%s','%s','%s')",num,time,table,sprice,name);
query.exec(str);
for (int j=1;j<(Foodvec).size();j++)
{
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
strcpy(number,Foodvec[j].number);
strcpy(food,Foodvec[j].food);
strcpy(price,Foodvec[j].price);
strcpy(quatity,Foodvec[j].quatity);
strcpy(post,Foodvec[j].post);
sprintf(str,"insert into 账单详情 values('%s','%s','%s','%s','%s','%s','%s','%s')",num,table,number,food,price,quatity,post,name);
query.exec(str);
}
}
void mythread::order_menu()
{
QByteArray a1;
a1.resize(sizeof(MenuInfo)*MenuVec.size());
memcpy(a1.data(),MenuVec.data(),sizeof(MenuInfo)*MenuVec.size());
tcpsocket->write(a1);
}
void mythread::chef_sent()
{
Foodvec.clear();
QSqlQuery query(db);
bool ret = query.exec("select *from 厨房");
if(!ret)
{
}
while (query.next())
{
QString str = query.value("桌号").toString();
QString str1 = query.value("序号").toString();
QString str2 = query.value("菜名").toString();
QString str3 = query.value("价格").toString();
QString str4 = query.value("数量").toString();
QString str5 = query.value("备注").toString();
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
QByteArray ba = str.toLocal8Bit();
memcpy(table,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(number,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(price,ba.data(),ba.size()+1);
ba = str4.toLocal8Bit();
memcpy(quatity,ba.data(),ba.size()+1);
ba = str5.toLocal8Bit();
memcpy(post,ba.data(),ba.size()+1);
strcpy(F_head.table, table);
strcpy(F_head.number, number);
strcpy(F_head.food, food);
strcpy(F_head.price, price);
strcpy(F_head.quatity, quatity);
strcpy(F_head.post, post);
Foodvec.push_back(F_head);
}
QByteArray a1;
a1.resize(sizeof(FoodInfo)*Foodvec.size());
memcpy(a1.data(),Foodvec.data(),(sizeof(MenuInfo)*Foodvec.size()*2+Foodvec.size()*50));
chef_socket->write(a1);
}
void mythread::chef_in()
{
QSqlQuery query(db);
char str[100];
QString table= Foodvec[1].table;
QString number = Foodvec[1].number;
std::string s1 = table.toStdString();
std::string s2 = number.toStdString();
sprintf(str,"delete from 厨房 where 桌号 = '%s' and 序号 = '%s'",s1.c_str(),s2.c_str());
query.exec(str);
qDebug()<<str;
QString temp = QString(Foodvec[1].table);
int n = temp.toInt();
MenuVec.clear();
strcpy(M_head.number,"\0");
strcpy(M_head.food,"chef_in");
strcpy(M_head.price,"\0");
strcpy(M_head.state,"\0");
MenuVec.push_back(M_head);
strcpy(M_head.number,Foodvec[1].number);
strcpy(M_head.food,Foodvec[1].food);
strcpy(M_head.price,Foodvec[1].price);
strcpy(M_head.state,"\0");
MenuVec.push_back(M_head);
QByteArray a1;
a1.resize(sizeof(MenuInfo)*MenuVec.size());
memcpy(a1.data(),MenuVec.data(),sizeof(MenuInfo)*MenuVec.size());
order_socket[n]->write(a1);
}
void mythread::order_food()
{
QString temp = QString(Foodvec[0].table);
int n = temp.toInt();
order_socket[n] = tcpsocket;
foodvec[n] = Foodvec;
QSqlQuery query(db);
char str[100];
QString Table= Foodvec[1].table;
std::string s1 = Table.toStdString();
sprintf(str,"delete from 厨房 where 桌号 = '%s' ",s1.c_str());
query.exec(str);
for (int j=1;j<(Foodvec).size();j++)
{
char table[5];
char number[10];
char food[100];
char price[10];
char quatity[10];
char post[200];
strcpy(table,Foodvec[j].table);
strcpy(number,Foodvec[j].number);
strcpy(food,Foodvec[j].food);
strcpy(price,Foodvec[j].price);
strcpy(quatity,Foodvec[j].quatity);
strcpy(post,Foodvec[j].post);
if(table != "0")
{
sprintf(str,"insert into 厨房 values('%s','%s','%s','%s','%s','%s')",table,number,food,price,quatity,post);
query.exec(str);
}
}
}
void mythread::Init()
{
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.12.13");
db.setUserName("root");
db.setPassword("12345678");
db.setPort(3306);
db.setDatabaseName("Order");
if(!db.open())
{
}
QSqlQuery query;
bool ret = query.exec("select *from 菜单");
if(!ret)
{
}
strcpy(M_head.number,"\0");
strcpy(M_head.food,"menu");
strcpy(M_head.price,"\0");
strcpy(M_head.state,"\0");
MenuVec.push_back(M_head);
while (query.next())
{
QString str = query.value("序号").toString();
QString str1 = query.value("菜名").toString();
QString str2 = query.value("价格").toString();
QString str3 = query.value("状态").toString();
char Number[10];
char food[100];
char Price[10];
char State[20];
QByteArray ba = str.toLocal8Bit();
memcpy(Number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);
strcpy(M_head.number,Number);
strcpy(M_head.food, food);
strcpy(M_head.price ,Price);
strcpy(M_head.state , State);
MenuVec.push_back(M_head);
}
ret = query.exec("select *from 饮品");
if(!ret)
{
}
while (query.next())
{
QString str = query.value("序号").toString();
QString str1 = query.value("饮品名").toString();
QString str2 = query.value("价格").toString();
QString str3 = query.value("状态").toString();
char Number[10];
char food[100];
char Price[10];
char State[20];
QByteArray ba = str.toLocal8Bit();
memcpy(Number,ba.data(),ba.size()+1);
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);
strcpy(M_head.number,Number);
strcpy(M_head.food, food);
strcpy(M_head.price ,Price);
strcpy(M_head.state , State);
MenuVec.push_back(M_head);
}
}
|