源码下载:https://download.csdn.net/download/G1842965496/83970347
源码连接
管理员及收银员的注册登录、人员信息管理、账单查看、餐品信息管理、顾客点餐、厨房上菜、收银结账。
1、项目采用 C/S 架构,利用 TCP 协议进行通信,采用了多线程的方法解决服务端与多个客服端的通信。
2、通过vector容器来存放顾客的订单信息,顾客提交订单时,将容器发送给管理端和厨房。
3、通过MySQL数据库来储存用户信息、菜单信息、账单信息,及厨房待做餐品清单。
4、采用中介者模式和状态模式,实现不同客服端间的信息交互。
5、顾客提交订单后可随时进行加餐,对未上餐品可进行催餐和退餐。
6、收银员可查询相应桌号的消费详情和消费总额并进行结账。
7、管理员可进行对用户信息和菜单信息的修改、添加和删除,并可查看账单及账单详情。
点餐系统
1、顾客端(客户端)
2、厨房端(客户端)
3、收银端(客户端)
1、表
2、菜单
3、饮品
4、用户
5、餐桌状态
6、厨房待做菜品
7、账单
8、账单详情
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
#include
#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);//上菜
// friend class childdorm;
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 // WIDGET_H
childdrom.h
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include
#include
#include
#include
#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); //通过this把父窗口的指针传到子窗口当中
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;
//Widget *child;
};
#endif // CHILDDORM_H
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 // STRUCTURAL_H
main.cpp
#include "widget.h"
#include
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/28.png"));//APP图标
//居中显示
QDesktopWidget* desktop = QApplication::desktop();
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
//add back picture
QPalette pal = this->palette();
//pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/27.jpg")));//背景图
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());//列表设置为和headtext相等
ui->tableWidget->setHorizontalHeaderLabels(headtext2);//插入表头
ui->tableWidget->setRowCount(0);
m_sum = 0;
child = new childdorm();
child->hide();
child->getData(this); //通过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,//请求连接信号
[=]()
{
//ui->textEdit->setText("成功连接服务器");
}
);
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()); //列表设置为和headtext相等
ui->tableWidget_2->setHorizontalHeaderLabels(headtext); //插入表头
ui->tableWidget_2->setRowCount(0);
QStringList headtext1;
headtext1<<"序号"<<"饮品名"<<"价格"<<"状态";
ui->tableWidget_3->setColumnCount(headtext1.count()); //列表设置为和headtext相等
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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
if(S == "\0")
{
QMessageBox::warning(this,"提示!","请填写桌号!");
}
else
{
// qDebug()<< MenuVec[0].food;
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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str4.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1); //加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);//加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)
{
//获取父窗口变量
//p = (Widget*) parent; //获取父窗口指针
ui->setupUi(this);
this->setWindowTitle(QStringLiteral("点餐窗口"));
//this->move(QPoint(100,100));
this->setFixedSize(1500,800);//背景图尺寸
this->setWindowIcon(QIcon(":/image/28.png"));//APP图标
//设置为只读模式
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);
//add back picture
QPalette pal = this->palette();//yunxu yong bi
// pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/27.jpg")));//背景图
setPalette(pal);
//child = new Widget;
//child->hide();
}
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());//列表设置为和headtext相等
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());//列表设置为和headtext相等
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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str.toLocal8Bit();
memcpy(F_head.number,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str4.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1); //加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();
}
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
#include
#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 // WIDGET_H
childdorm.h
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include
#include
#include
#include
#include
#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 // CHILDDORM_H
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 // STRUCTURAL_H
main.cpp
#include "widget.h"
#include
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
#include //自己添加
#include //自己添加
#include //对话框
#include
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"));//APP图标
//窗口居住显示
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();
//child->getData(this); //通过this把父窗口的指针传到子窗口当中
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
childdorm::childdorm(QWidget *parent) :
QWidget(parent),
ui(new Ui::childdorm)
{
ui->setupUi(this);
this->setFixedSize(1500,800);//背景图尺寸
// this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
this->setWindowTitle(QStringLiteral("收银界面"));
this->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/5.png"));//APP图标
//窗口居住显示
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/27.jpg")));//背景图
setPalette(pal);
//ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // 使表宽度自适应
ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // 使表宽度自适应
Init();
client();
}
childdorm::~childdorm()
{
delete ui;
}
void childdorm::Init()//初始化
{
tcpsocket = new QTcpSocket(this);//创建客户端套接字
connect(tcpsocket,&QTcpSocket::connected,//请求连接信号
[=]()
{
//ui->textEdit->setText("成功连接服务器");
}
);
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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = pw.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1); //加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());//列表设置为和headtext相等
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());//列表设置为和headtext相等
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); //加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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
QString Sum = ui->lineEdit_3->text(); //消费额
char sum[5];
ba = Sum.toLocal8Bit();
memcpy(sum,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
char name[100];
ba = m_name.toLocal8Bit();
memcpy(name,ba.data(),ba.size()+1); //加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->clearContents(); //清空表中数据
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);
}
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
#include
#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;
//QSqlDatabase db;
FoodInfo F_head;//订单结构体
vector<FoodInfo> FoodVec;//订单容器
vector<FoodInfo> foodVec;//通用容器
QTcpSocket *tcpsocket;
};
#endif // WIDGET_H
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 // STRUCTURAL_H
main.cpp
#include "widget.h"
#include
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->setFixedSize(1500,800);//背景图尺寸
this->setWindowTitle(QStringLiteral("厨房"));
// this->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/3.png"));//APP图标
//居中显示
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); // 使表宽度自适应
//add back picture
QPalette pal = this->palette();//yunxu yong bi
//pal.setBrush(QPalette::Background,QBrush(QPixmap(":/image/27.jpg")));//背景图
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,//请求连接信号
[=]()
{
//ui->textEdit->setText("成功连接服务器");
}
);
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();
//qDebug()<< array;
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()); //列表设置为和headtext相等
ui->tableWidget->setHorizontalHeaderLabels(headtext); //插入表头
ui->tableWidget->setRowCount(0);
int rowcount;
qDebug()<< FoodVec.size();
//qDebug()<
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); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(F_head.number,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(F_head.food,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(F_head.price,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str4.toLocal8Bit();
memcpy(F_head.quatity,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str5.toLocal8Bit();
memcpy(F_head.post,ba.data(),ba.size()+1); //加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);
}
#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 // STRUCTURAL_H
widget.h(登录窗口)
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include //监听套接字的类
#include //建立套接字的类
#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 // WIDGET_H
childdorm.h(管理窗口)
#ifndef CHILDDORM_H
#define CHILDDORM_H
#include
#include //建立套接字的类
#include //监听套接字的类
#include
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#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
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 // CHILDDORM_H
add_drinks.h(添加饮品)
#ifndef ADD_DRINKS_H
#define ADD_DRINKS_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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_DRINKS_H
add_food.h(添加菜品)
#ifndef ADD_FOOD_H
#define ADD_FOOD_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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_FOOD_H
add_users.h(添加用户)
#ifndef ADD_USERS_H
#define ADD_USERS_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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 // ADD_USERS_H
bill.h(账单详情)
#ifndef BILL_H
#define BILL_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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 // BILL_H
change_per(修改用户权限)
#ifndef CHANGE_PER_H
#define CHANGE_PER_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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 // CHANGE_PER_H
chang_price.h(修改餐品价格)
#ifndef CHANGE_PRICE_H
#define CHANGE_PRICE_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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_PRICE_H
change_pw.h(修改用户密码)
#ifndef CHANGE_PW_H
#define CHANGE_PW_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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_PW_H
change_status.h(修改菜品状态)
#ifndef CHANGE_STATUS_H
#define CHANGE_STATUS_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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 // CHANGE_STATUS_H
modify_drinks.h(修改饮品价格)
#ifndef MODIFY_DRINKS_H
#define MODIFY_DRINKS_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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_DRINKS_H
modify_status.h(修改饮品状态)
#ifndef MODIFY_STUTUS_H
#define MODIFY_STUTUS_H
#include
#include
#include
#include //自己添加
#include //自己添加
#include //对话框
#include
#include
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 // MODIFY_STUTUS_H
mythread.h(线程)
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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 // MYTHREAD_H
main.cpp
#include "widget.h"
#include
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
#include //自己添加
#include //自己添加
#include //对话框
#include
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/44.png"));//APP图标
//窗口居中显示
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);//binf + listen
//捕获新连接
connect(tcpserver,&QTcpServer::newConnection, //lambda表达式:accept函数
[=](){
//新建新的套接字:客服端套接字
tcpsocket = tcpserver->nextPendingConnection();//最近一个接进来的客服端
QString ip =tcpsocket->peerAddress().toString();//得到地址
int port = tcpsocket->peerPort();
QString temp = QString::fromUtf8("地址:%1 端口:%2").arg(ip).arg(port);
//ui->textEdit->setText(temp);
qDebug()<<temp;
mythread *thread = new mythread(tcpsocket); //创建线程
thread->start();
// connect(tcpsocket,&QTcpSocket::readyRead,
// [=]()
// {
// QByteArray array = tcpsocket->readAll();
// ui->textEdit->append(array);
// }
// );
});
}
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->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
this->setWindowTitle(QStringLiteral("管理员界面"));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居住显示
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/27.jpg")));//背景图
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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);//加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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);//加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());//列表设置为和headtext相等
ui->tableWidget_3->setHorizontalHeaderLabels(headtext);//插入表头
ui->tableWidget_3->setRowCount(0);
QStringList headtext1;
headtext1<<"序号"<<"饮品名"<<"价格"<<"状态";
ui->tableWidget_4->setColumnCount(headtext1.count());//列表设置为和headtext相等
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);
}
//tablewifget操作
QStringList headtext;
headtext<<"用户名"<<"密码"<<"权限";
ui->tableWidget->setColumnCount(headtext.count());//列表设置为和headtext相等
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);
}
//tablewifget操作
QStringList headtext;
headtext<<"交易号"<<"时间"<<"桌号"<<"消费额"<<"收银人";
ui->tableWidget_2->setColumnCount(headtext.count());//列表设置为和headtext相等
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];
//char str1[10];
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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);
// qDebug()<
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
#include
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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);
//qDebug()<
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
#include
#include
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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();
// CDA_Plot = new FrequencyPlot();
// CDA_Plot->setAttribute(Qt::WA_DeleteOnClose); //设置子窗口属性,在子窗口关闭之后,释放子窗口的资源(释放指针)
}
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
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"));//APP图标
//窗口居中显示
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);
}
//tablewifget操作
QStringList headtext;
headtext<<"交易号"<<"桌号"<<"序号"<<"菜名"<<"价格"<<"数量"<<"备注"<<"收银人";
ui->tableWidget->setColumnCount(headtext.count());//列表设置为和headtext相等
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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 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() != pw)
{
QMessageBox::warning(this,"提示","用户名或密码错误!");
}
else
{
sprintf(str,"update 用户 set 权限 = '%s' where 用户名 = '%s'",s3.c_str(),s1.c_str());
query.exec(str);
//qDebug()<
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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);
//qDebug()<
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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 s2 = pw.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);
//qDebug()<
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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);
//qDebug()<
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标
//窗口居中显示
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);
//qDebug()<
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
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->move(QPoint(100,100));
this->setWindowIcon(QIcon(":/image/44.png"));//APP图标图标
//窗口居中显示
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);
//qDebug()<
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, //read函数
[=](){
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)
{
// 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();
char table[5]; //桌号
char food[100]; //餐桌状态
QByteArray ba = str.toLocal8Bit();
memcpy(table,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加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)
{
// QSqlError error = query.lastError();
// QString str = QString("错误信息:%1,%2").arg(error.driverText()).arg(error.databaseText());
// QMessageBox::warning(this,"提示",str);
}
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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = Time.toLocal8Bit();
memcpy(time,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = Table.toLocal8Bit();
memcpy(table,ba.data(),ba.size()+1); //加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = Price.toLocal8Bit();
memcpy(sprice,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = Name.toLocal8Bit();
memcpy(name,ba.data(),ba.size()+1); //加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)
{
// 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();
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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(number,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(price,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str4.toLocal8Bit();
memcpy(quatity,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str5.toLocal8Bit();
memcpy(post,ba.data(),ba.size()+1);//加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()//初始化
{
//tcpsocket=socket;
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,"提示","无法连接数据库");
}
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);
}
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);//菜单信息放入容器中首元素
// qDebug()<< MenuVec[0].food;
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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);//加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);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str1.toLocal8Bit();
memcpy(food,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str2.toLocal8Bit();
memcpy(Price,ba.data(),ba.size()+1);//加1是为了最后的终结符,否则转换回来的时候不知道什么时候截止
ba = str3.toLocal8Bit();
memcpy(State,ba.data(),ba.size()+1);//加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);//菜单信息放入容器中
}
}