├── .gitignore ├── MyUtil.cpp ├── MyUtil.h ├── README.md ├── first draft.png ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── menu.cpp ├── menu.h ├── order_client.pro ├── static.qrc └── static ├── bilibili.ico ├── food ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg └── 5.jpg ├── insert.ini ├── qq.ico ├── shy.jpg ├── steam.ico ├── tables.sql └── unknown.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /MyUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "MyUtil.h" 2 | 3 | 4 | namespace UTILS 5 | { 6 | QString FileUtil::ReadFileToQString(const char *path) 7 | { 8 | QFile f(path); 9 | 10 | if (!f.exists() | !f.open(QIODevice::ReadOnly | QIODevice::Text)) {//打开指定文件 11 | qDebug() << "打开失败"; 12 | return nullptr; 13 | } 14 | QTextStream in(&f); 15 | 16 | in.setCodec("UTF-8"); 17 | return in.readAll(); 18 | } 19 | 20 | bool SqliteUtil::CreateTablesBySQL(QString qs, QSqlQuery *qq) 21 | { 22 | QStringList qlist = qs.split(";"); 23 | 24 | for (int i = 0; i < qlist.size() - 1; i++) { 25 | QString qs1 = qlist.at(i).toUtf8(); 26 | try { 27 | qq->exec(qs1); 28 | } catch (...) { 29 | qDebug() << "创建失败" << qs1; 30 | } 31 | } 32 | 33 | return true; 34 | } 35 | // 占位符:imgData 36 | bool SqliteUtil::InsertDataWithBinaryBySQL(QString qs, QSqlQuery *qq) 37 | { 38 | QStringList qlist = qs.split(";"); 39 | QString qs2; 40 | 41 | qDebug() << "size:" << qlist.size(); 42 | for (int i = 0; i < qlist.size() - 1; i++) { 43 | QString qs1 = qlist.at(i).toUtf8(); 44 | try { 45 | QFile file(qs2.asprintf(":/static/food/%d.jpg", i + 1)); 46 | if (!file.open(QIODevice::ReadOnly)) return false; 47 | QByteArray byte = file.readAll(); 48 | qq->prepare(qs1); 49 | qq->bindValue(":imgData", byte); 50 | qq->exec(); 51 | } catch (...) { 52 | qDebug() << "创建失败" << qs1; 53 | return false; 54 | } 55 | } 56 | return true; 57 | } 58 | 59 | void SqliteUtil::SelectAndShowByRange(QString tablename, QSqlQuery *qq, int range) 60 | { 61 | QString qs("select * from " + tablename + ";"); 62 | 63 | qq->exec(qs); 64 | while (qq->next()) { 65 | QString tqs; 66 | for (int i = 0; i < range; i++) 67 | tqs = tqs.append(qq->value(i).toString() + ";"); 68 | qDebug() << tqs; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MyUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef MYUTILS_H 2 | #define MYUTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace UTILS 10 | { 11 | class FileUtil { 12 | public: 13 | // 读取文件并返回一个Qstring对象 14 | static QString ReadFileToQString(const char *path); 15 | }; 16 | 17 | class SqliteUtil { 18 | public: 19 | // 用QString字符串中的表信息来创建表;建表语句之间用';'分割,其他地方不能出现';' 20 | static bool CreateTablesBySQL(QString, QSqlQuery *); 21 | 22 | // 读取文件,每行内容为预编译语句,有且仅有一个":imgData"占位符存在。 23 | static bool InsertDataWithBinaryBySQL(QString, QSqlQuery *); 24 | 25 | // 查询数据库表的字段以及列(需要指定要查看的列数0-range) 26 | static void SelectAndShowByRange(QString tablename, QSqlQuery *qq, int range); 27 | }; 28 | } 29 | 30 | #endif // MYUTILS_H 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 电子点菜系统客户端 2 | 3 | 相关数据库表(sqlite3) 4 | 5 | ````sqlite 6 | -- 菜单表 7 | create table IF NOT EXISTS menu( 8 | id INTEGER PRIMARY KEY, 9 | name TEXT NOT NULL, 10 | price REAL NOT NULL, 11 | pic BLOB, -- 展示图片 12 | type INTEGER -- 类型: 1. 主食 2. 小吃 3. 甜点 4. 汤 等等 13 | ); 14 | INSERT INTO menu(name,price,type) VALUES("番茄炒马铃薯","10.0",1); 15 | INSERT INTO menu(name,price,type) VALUES("土豆炒西红柿","11.0",1); 16 | 17 | -- 菜品订单表 18 | create table IF NOT EXISTS order_dishes( 19 | id INTEGER PRIMARY KEY, 20 | seat INTEGER NOT NULL, -- 座位号 21 | menu_id INTEGER NOT NULL, -- 菜品id 22 | status INTEGER DEFAULT 1, -- 菜品状态:1. 未确认 2.烹饪中 3. 完成 23 | create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 24 | update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP 25 | ); 26 | INSERT INTO order_dishes(seat,menu_id) VALUES(5,1); 27 | INSERT INTO order_dishes(seat,menu_id) VALUES(5,2); 28 | INSERT INTO order_dishes(seat,menu_id) VALUES(7,2); 29 | 30 | -- 营业数据表 31 | create table IF NOT EXISTS business_data( 32 | id INTEGER PRIMARY KEY, 33 | money REAL NOT NULL, -- 金额费用 34 | type INTEGER DEFAULT 1, -- 类型: 1. 结账 2. 其他待定 35 | create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP 36 | ); 37 | 38 | ```` 39 | 40 | 41 | 42 | 43 | 44 | ## 参考 45 | 46 | 1. Qt教程,Qt5编程入门教程 http://c.biancheng.net/qt/ 47 | 2. Qt中文文档 https://www.qtdoc.cn/ 48 | 3. Qt5之使用sqlite3数据库 https://blog.csdn.net/hk_5788/article/details/80959076 49 | 4. C++引用10分钟入门教程 http://c.biancheng.net/view/2251.html 50 | 5. 51 | 52 | -------------------------------------------------------------------------------- /first draft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/first draft.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | // 建立数据库对象 10 | // QSqlDatabase database = QSqlDatabase::contains("qt_sql_default_connection") 11 | // ?QSqlDatabase::database("qt_sql_default_connection") 12 | // :QSqlDatabase::addDatabase("QSQLITE"); 13 | QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE"); 14 | 15 | // 设置数据库文件的路径并打开数据库 16 | database.setDatabaseName("MyOrder.db"); 17 | database.open()? qDebug() << "open success": qDebug() << database.lastError(); 18 | 19 | // 读取数据库文件 20 | QSqlQuery *sql_query = new QSqlQuery(database); 21 | QString sql_str = UTILS::FileUtil::ReadFileToQString(":/static/tables.sql"); 22 | 23 | // 根据sql语句建立数据表并查看创建的表(建表语句有`IF NOT EXISTS`) 24 | UTILS::SqliteUtil::CreateTablesBySQL(sql_str, sql_query); 25 | qDebug() << "当前表:" << database.tables(); 26 | 27 | // menu表里没数据则读取文件自动创建数据记录 28 | sql_query->exec("select count(*) from menu"); 29 | if (sql_query->next() && sql_query->value(0) == "0") { 30 | QString sql_str = UTILS::FileUtil::ReadFileToQString(":/static/insert.ini"); 31 | UTILS::SqliteUtil::InsertDataWithBinaryBySQL(sql_str, sql_query); 32 | qDebug() << "创建内置数据完成"; 33 | } 34 | 35 | // 查看menu表里的数据 从0-range列 36 | UTILS::SqliteUtil::SelectAndShowByRange("menu", sql_query, 5); 37 | 38 | 39 | QApplication a(argc, argv); 40 | MainWindow w; 41 | 42 | w.setWindowTitle("当前桌号 No.1 点菜系统v0.1-LYQ"); 43 | w.setWindowIcon(QIcon(":/static/bilibili.ico")); 44 | w.show(); 45 | return a.exec(); 46 | } 47 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent) 6 | , ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | init(); 10 | iniTreeWidget(); 11 | connect(ui->menuTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), 12 | this, SLOT(menuTree_clicked(QTreeWidgetItem*))); 13 | connect(ui->addToOrderBtn, SIGNAL(clicked()), 14 | this, SLOT(addToOrderBtn1_clicked())); 15 | } 16 | 17 | MainWindow::~MainWindow() 18 | { 19 | delete ui; 20 | } 21 | 22 | // 初始化窗口 23 | void MainWindow::init() 24 | { 25 | if (timer!=nullptr&&timer->isActive()) 26 | timer->stop(); 27 | this->ui->addToOrderBtn->setStyleSheet("padding:8px;background:#028090;color:#B5838D;border-radius:5px;"); 28 | this->ui->statusbar->showMessage("当前没有客户使用 等待中"); 29 | this->ui->addToOrderBtn->setDisabled(true); 30 | this->money = 2; 31 | this->used = false; 32 | setPicToPicShowLableAdaptive(*new QPixmap(":/static/unknown.jpg")); 33 | 34 | 35 | } 36 | //把当前选中的Menu项添加到右侧已点列表 37 | void MainWindow::addToOrderBtn1_clicked() 38 | { 39 | Menu *m = this->checkedMenu; 40 | 41 | if (m == nullptr) { 42 | qDebug() << "null"; 43 | } else { 44 | qDebug() << m->name; 45 | // 具体操作 46 | QListWidgetItem *item = new QListWidgetItem(); 47 | item->setCheckState(Qt::Checked); //设置为选中状态 48 | item->setData(Qt::UserRole, m->price); 49 | QString qs; 50 | item->setText(qs.asprintf("%d_", m->id) + m->name); 51 | item->setToolTip(QDateTime::currentDateTime().toString("加入时间:hh:mm:ss 单价(元/份):" + m->price.toUtf8())); 52 | this->money += m->price.toFloat(); 53 | this->ui->order_list->addItem(item); 54 | } 55 | } 56 | 57 | // 设置图片到pic_show并且自适应大小 58 | void MainWindow::setPicToPicShowLableAdaptive(QPixmap& pixmap) 59 | { 60 | pixmap.scaled(ui->pic_show->size(), Qt::KeepAspectRatio); 61 | ui->pic_show->setScaledContents(true); 62 | ui->pic_show->setPixmap(pixmap); 63 | } 64 | 65 | // 当点击Tree的Item的事件 1001是自定义的type,为TreeWidget的二级item 66 | void MainWindow::menuTree_clicked(QTreeWidgetItem *item) 67 | { 68 | if (item->type() == 1001) { 69 | QPixmap pixmap; 70 | Menu menu = item->data(0, Qt::UserRole).value(); 71 | this->checkedMenu = new Menu(item->data(0, Qt::UserRole).value()); 72 | pixmap.loadFromData(menu.pic); 73 | setPicToPicShowLableAdaptive(pixmap); 74 | if (used == true) ui->addToOrderBtn->setEnabled(true); 75 | } 76 | } 77 | 78 | // 初始化TreeWidget [一级节点的名字可设置从配置文件中读取] 79 | void MainWindow::iniTreeWidget() 80 | { 81 | int i = 0; 82 | int size = 0; 83 | QIcon icon; 84 | Menu *menus = Menu::getMenusFromDB(sql_query, size); 85 | QStringList qs_arr = { "主食", "小吃", "甜点", "汤" }; // 一级节点的名字 86 | 87 | ui->menuTree->clear(); //清除目录树所有节点item 88 | ui->menuTree->setColumnWidth(0, 250); 89 | icon.addFile(":/static/bilibili.ico"); //设置ICON的图标 90 | 91 | // 遍历Menu表的数据,生成一级节点 92 | for (const QString& qs : qs_arr) { 93 | i++; 94 | QTreeWidgetItem *item = new QTreeWidgetItem(1000); //新建节点时设定类型 95 | item->setIcon(0, icon); //设置第0列的图标 96 | item->setText(0, qs); //设置第0列的文字 97 | // 生成二级节点根据类型挂载到不同的一级节点上,绑定点击事件 98 | for (int j = 0; j < size; j++) { 99 | if (menus[j].type == i) { 100 | QVariant t; 101 | t.setValue(menus[j]); 102 | QTreeWidgetItem *item1 = new QTreeWidgetItem(1001); //新建节点时设定类型 103 | item1->setData(0, Qt::UserRole, t); //给节点带一个数据:为图片 104 | item1->setText(0, menus[j].name); //设置第1列的文字 105 | item1->setText(1, menus[j].price + " 元"); //设置第2列的文字 106 | item->addChild(item1); //添加成item的子节点 107 | } 108 | } 109 | ui->menuTree->addTopLevelItem(item); 110 | } 111 | ui->menuTree->expandAll(); 112 | } 113 | 114 | // 入座 115 | void MainWindow::on_seatConfirmBtn_clicked() 116 | { 117 | if (used == true) { 118 | QString dlgTitle = "对话框"; 119 | QString strInfo = "当前正在使用中"; 120 | QMessageBox::critical(this, dlgTitle, strInfo); 121 | } else { 122 | QString dlgTitle = "消息框"; 123 | QString strInfo = "欢迎使用~"; 124 | QMessageBox::information(this, dlgTitle, strInfo, 125 | QMessageBox::Ok, QMessageBox::NoButton); 126 | if ((timer) == nullptr) 127 | timer = new QTimer(this); 128 | timer->start(1000); //每隔1000ms发送timeout的信号触发状态栏更新 129 | connect(timer, SIGNAL(timeout()), this, SLOT(time_update())); 130 | this->used = true; 131 | this->ui->addToOrderBtn->setStyleSheet("padding:8px;background:#02C39A;color:white;border-radius:5px;"); 132 | } 133 | } 134 | 135 | // 结账 136 | void MainWindow::on_payBtn_clicked() 137 | { 138 | if (used == false) { 139 | QString dlgTitle = "对话框"; 140 | QString strInfo = "当前设备未在使用,结账失败"; 141 | QMessageBox::critical(this, dlgTitle, strInfo); 142 | } else { 143 | QString dlgTitle = "是否结账"; 144 | QString strInfo = strInfo.asprintf("本次累计消费%.2lf元,是否现在结账", this->money); 145 | QMessageBox::StandardButton defaultBtn = QMessageBox::NoButton; //缺省按钮 146 | QMessageBox::StandardButton result = QMessageBox::question(this, dlgTitle, strInfo, 147 | QMessageBox::Yes | QMessageBox::No, defaultBtn); 148 | if (result == QMessageBox::Yes) { 149 | QString dlgTitle = "对话框"; 150 | QString strInfo = "正在通知服务员过来结账!"; 151 | QMessageBox::information(this, dlgTitle, strInfo); 152 | // 收尾工作 153 | disconnect(timer, SIGNAL(timeout()), this, SLOT(time_update())); 154 | // clear ordered_list 155 | int cnt = ui->order_list->count();//项个数 156 | for (int i = 2; i < cnt; i++) { 157 | QListWidgetItem *aItem = ui->order_list->item(2); 158 | delete aItem; 159 | } 160 | init(); 161 | } 162 | } 163 | } 164 | 165 | // 状态栏时间更新 166 | void MainWindow::time_update() 167 | { 168 | QDateTime current_time = QDateTime::currentDateTime(); 169 | QString timestr = current_time.toString(timestr.asprintf("yyyy年MM月dd日 hh:mm:ss 预计消费:%.2lf元", this->money)); //设置显示的格式 170 | 171 | ui->statusbar->showMessage(timestr); //设置label的文本内容为时间 172 | } 173 | // 删除未选 虾机霸写的 174 | void MainWindow::on_deleteBtn_clicked() 175 | { 176 | while (1) { 177 | if (ui->order_list->count() == 2) break; 178 | bool deleted = false;; 179 | for (int i = 2; i < ui->order_list->count(); i++) { 180 | QListWidgetItem *a = ui->order_list->item(i); 181 | // qDebug() << a->checkState(); 182 | if (a->checkState() == Qt::CheckState::Unchecked) { 183 | this->money -= a->data(Qt::UserRole).toFloat(); 184 | delete a; 185 | deleted = true; 186 | break; 187 | } 188 | } 189 | if (deleted == false) break; 190 | } 191 | } 192 | // 通知服务员 [[随意] 193 | void MainWindow::on_callWaiterBtn_clicked() 194 | { 195 | QString dlgTitle = "是否呼叫服务员"; 196 | QString strInfo = "确定?"; 197 | QMessageBox::StandardButton defaultBtn = QMessageBox::NoButton; //缺省按钮 198 | QMessageBox::StandardButton result; //返回选择的按钮 199 | 200 | result = QMessageBox::question(this, dlgTitle, strInfo, QMessageBox::Yes | QMessageBox::Cancel, defaultBtn); 201 | if (result == QMessageBox::Yes) { 202 | QString dlgTitle = "对话框"; 203 | QString strInfo = "正在通知服务员"; 204 | QMessageBox::information(this, dlgTitle, strInfo); 205 | } 206 | } 207 | // 完成点单并通知后厨 [随意] 208 | void MainWindow::on_orderConfirmBtn_clicked() 209 | { 210 | QString dlgTitle = "对话框"; 211 | QString strInfo = "后厨已经收到本次订单了"; 212 | 213 | QMessageBox::information(this, dlgTitle, strInfo); 214 | } 215 | 216 | void MainWindow::on_action_triggered() 217 | { 218 | QString dlgTitle = "About"; 219 | QString strInfo = "Qt 5.14.c++11 sqlite3 \n by Lyq"; 220 | 221 | QMessageBox::information(this, dlgTitle, strInfo); 222 | } 223 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "menu.h" 12 | 13 | QT_BEGIN_NAMESPACE 14 | namespace Ui { class MainWindow; } 15 | QT_END_NAMESPACE 16 | 17 | 18 | class MainWindow : public QMainWindow 19 | { 20 | // 一个宏: 定义了一个静态的元对象 开启信号和槽机制 21 | Q_OBJECT 22 | 23 | public: 24 | // 深拷贝构造函数 25 | MainWindow(QWidget *parent = nullptr); 26 | ~MainWindow(); 27 | 28 | //定义槽 29 | private slots: 30 | 31 | // 点击Tree的Item 32 | void menuTree_clicked(QTreeWidgetItem *item); 33 | // 把当前选中的Menu项添加到右侧已点列表中 34 | void addToOrderBtn1_clicked(); 35 | // 时间更新槽函数,状态栏显示时间 36 | void time_update(); 37 | // 点击付款按钮 38 | void on_payBtn_clicked(); 39 | // 右侧已点菜单中删除未选中的菜单 40 | void on_deleteBtn_clicked(); 41 | // 通知服务员 42 | void on_callWaiterBtn_clicked(); 43 | // 入座确认 44 | void on_seatConfirmBtn_clicked(); 45 | // 点菜完毕确认 46 | void on_orderConfirmBtn_clicked(); 47 | 48 | void on_action_triggered(); 49 | 50 | private: 51 | Ui::MainWindow *ui; 52 | QSqlQuery sql_query; 53 | 54 | // 状态栏更新定时器 55 | QTimer *timer = nullptr; 56 | // App使用状态 默认未使用 57 | bool used = false; 58 | // 预计花费金额 59 | float money = 0.0; 60 | // 当前预览的菜单 61 | Menu *checkedMenu; 62 | 63 | // 窗口初始化 64 | void init(); 65 | // 目录树初始化 66 | void iniTreeWidget(); 67 | // 显示图片到Label中并自动适应大小 68 | void setPicToPicShowLableAdaptive(QPixmap& pixmap); 69 | }; 70 | 71 | #endif // MAINWINDOW_H 72 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1248 10 | 523 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 0 23 | 24 | 25 | 0 26 | 27 | 28 | 0 29 | 30 | 31 | 0 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 0 41 | 0 42 | 43 | 44 | 45 | 46 | 50 47 | 10 48 | 49 | 50 | 51 | true 52 | 53 | 54 | 55 | 56 | 57 | QFrame::StyledPanel 58 | 59 | 60 | QFrame::Raised 61 | 62 | 63 | 64 | 0 65 | 66 | 67 | 0 68 | 69 | 70 | 0 71 | 72 | 73 | 0 74 | 75 | 76 | 0 77 | 78 | 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 0 86 | 0 87 | 88 | 89 | 90 | 91 | border-radius:5%; 92 | 93 | 94 | 95 | 已点菜单🍽 96 | 97 | 98 | 99 | 100 | 51 101 | 216 102 | 253 103 | 104 | 105 | 106 | 107 | ItemIsSelectable|ItemIsEnabled|ItemIsTristate 108 | 109 | 110 | 111 | 112 | 0_餐位费 2¥/ 桌 113 | 114 | 115 | Checked 116 | 117 | 118 | ItemIsSelectable|ItemIsEnabled 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 0 131 | 0 132 | 133 | 134 | 135 | 136 | 137 | 138 | Qt::Horizontal 139 | 140 | 141 | 142 | 40 143 | 20 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | padding:8px;background:rgb(166,169,173);color:white;border-radius:7px; 152 | 153 | 154 | 删除未选 155 | 156 | 157 | 158 | 159 | 160 | 161 | Qt::Horizontal 162 | 163 | 164 | 165 | 40 166 | 20 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | padding:8px;background:rgb(166,169,173);color:white;border-radius:7px; 175 | 176 | 177 | 确认操作 178 | 179 | 180 | 181 | 182 | 183 | 184 | Qt::Horizontal 185 | 186 | 187 | 188 | 40 189 | 20 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 200 205 | 0 206 | 207 | 208 | 209 | 210 | 250 211 | 10 212 | 213 | 214 | 215 | false 216 | 217 | 218 | false 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | false 228 | 229 | 230 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 #ECE9E6, stop:1 #FFFFFF ); 231 | border:1px solid gray; 232 | border-bottom-right-radius:5%; 233 | border-bottom-left-radius:5%; 234 | 235 | 236 | 237 | 菜单 238 | 239 | 240 | 241 | 12 242 | 243 | 244 | 245 | 246 | 255 247 | 170 248 | 127 249 | 250 | 251 | 252 | 253 | 254 | 价格 255 | 256 | 257 | 258 | 12 259 | 260 | 261 | 262 | 263 | 255 264 | 200 265 | 123 266 | 267 | 268 | 269 | 270 | 271 | 主食 272 | 273 | 274 | 275 | 12 276 | 277 | 278 | 279 | 280 | 西红柿炒鸡蛋 281 | 282 | 283 | 284 | 285 | 286 | 小吃 287 | 288 | 289 | 290 | 12 291 | 292 | 293 | 294 | 295 | 酒鬼花生 296 | 297 | 298 | 299 | 300 | 301 | 甜点 302 | 303 | 304 | 305 | 12 306 | 307 | 308 | 309 | 310 | 甜筒 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 250 321 | 16777215 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 0 330 | 0 331 | 332 | 333 | 334 | 335 | 200 336 | 200 337 | 338 | 339 | 340 | 341 | 250 342 | 200 343 | 344 | 345 | 346 | border:1px solid gray;border-radius:5%; 347 | 348 | 349 | 预览图 350 | 351 | 352 | 353 | 354 | 355 | 356 | Qt::Vertical 357 | 358 | 359 | QSizePolicy::Preferred 360 | 361 | 362 | 363 | 20 364 | 40 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 50 374 | 0 375 | 376 | 377 | 378 | 379 | 380 | 381 | Qt::Horizontal 382 | 383 | 384 | 385 | 40 386 | 20 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | false 395 | 396 | 397 | padding:8px;background:rgb(68,185,186);color:white;border-radius:5px; 398 | 399 | 400 | 添加到右侧菜单栏>>> 401 | 402 | 403 | false 404 | 405 | 406 | false 407 | 408 | 409 | false 410 | 411 | 412 | false 413 | 414 | 415 | 416 | 417 | 418 | 419 | Qt::Horizontal 420 | 421 | 422 | 423 | 40 424 | 20 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 16777215 446 | 50 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | Qt::Horizontal 457 | 458 | 459 | 460 | 40 461 | 20 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | padding:8px;background-color:rgb(102,177,255);color:white;border-radius:7px; 471 | 472 | 473 | 474 | 入座确认 475 | 476 | 477 | false 478 | 479 | 480 | 481 | 482 | 483 | 484 | Qt::Horizontal 485 | 486 | 487 | 488 | 40 489 | 20 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | padding:8px;background:rgb(102,177,255);color:white;border-radius:7px; 498 | 499 | 500 | 确认点菜 501 | 502 | 503 | 504 | 505 | 506 | 507 | Qt::Horizontal 508 | 509 | 510 | 511 | 40 512 | 20 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | padding:8px;background:rgb(102,177,255);color:white;border-radius:7px; 521 | 522 | 523 | 呼叫服务员 524 | 525 | 526 | 527 | 528 | 529 | 530 | Qt::Horizontal 531 | 532 | 533 | 534 | 40 535 | 20 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | padding:8px;background:rgb(102,177,255);color:white;border-radius:7px; 544 | 545 | 546 | 结账付款 547 | 548 | 549 | 550 | 551 | 552 | 553 | Qt::Horizontal 554 | 555 | 556 | 557 | 141 558 | 20 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 0 572 | 0 573 | 1248 574 | 28 575 | 576 | 577 | 578 | 579 | 文件(&F) 580 | 581 | 582 | 583 | 584 | 关于(&A) 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 作品介绍 596 | 597 | 598 | 599 | 600 | 601 | 602 | -------------------------------------------------------------------------------- /menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | Menu::Menu() 3 | { 4 | } 5 | 6 | Menu::Menu(Menu *_menu) 7 | { 8 | this->id = _menu->id; 9 | this->name = _menu->name; 10 | this->pic = _menu->pic; 11 | this->price = _menu->price; 12 | this->type = _menu->type; 13 | } 14 | 15 | Menu *Menu::getMenusFromDB(QSqlQuery qq, int& size) 16 | { 17 | QString qs("select * from menu"); 18 | QString tqs; 19 | Menu *ms = nullptr; 20 | int i = 0; 21 | 22 | // 不能直接用.size()获取大小 用sqlite数据库会返回-1 23 | qq.exec(qs); 24 | if (qq.last()) { 25 | size = qq.at() + 1; 26 | qq.first(); 27 | qq.previous(); 28 | } 29 | ms = new Menu[size]; 30 | while (qq.next()) { 31 | ms[i].id = qq.value("id").toInt(); 32 | ms[i].name = qq.value("name").toString(); 33 | ms[i].price = qq.value("price").toString(); 34 | ms[i].pic = qq.value("pic").toByteArray(); 35 | ms[i].type = qq.value("type").toInt(); 36 | i++; 37 | } 38 | return ms; 39 | } 40 | -------------------------------------------------------------------------------- /menu.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_H 2 | #define MENU_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | //菜单表Entity 9 | class Menu 10 | { 11 | public: 12 | Menu(); 13 | Menu(Menu *_menu); 14 | int id; 15 | int type; 16 | QString name; 17 | QString price; 18 | QByteArray pic; 19 | static Menu *getMenusFromDB(QSqlQuery, int&); 20 | }; 21 | Q_DECLARE_METATYPE(Menu) 22 | // QVariant存储自定义类型↑ 23 | 24 | #endif // MENU_H 25 | -------------------------------------------------------------------------------- /order_client.pro: -------------------------------------------------------------------------------- 1 | QT += core gui sql 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | SOURCES += \ 8 | MyUtil.cpp \ 9 | main.cpp \ 10 | mainwindow.cpp \ 11 | menu.cpp 12 | 13 | HEADERS += \ 14 | MyUtil.h \ 15 | mainwindow.h \ 16 | menu.h 17 | 18 | FORMS += \ 19 | mainwindow.ui 20 | 21 | RESOURCES += \ 22 | static.qrc 23 | 24 | # 部署的默认规则 25 | qnx: target.path = /tmp/$${TARGET}/bin 26 | else: unix:!android: target.path = /opt/$${TARGET}/bin 27 | !isEmpty(target.path): INSTALLS += target 28 | -------------------------------------------------------------------------------- /static.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | static/bilibili.ico 4 | static/shy.jpg 5 | static/tables.sql 6 | static/insert.ini 7 | static/unknown.jpg 8 | static/qq.ico 9 | static/steam.ico 10 | static/food/1.jpg 11 | static/food/2.jpg 12 | static/food/3.jpg 13 | static/food/4.jpg 14 | static/food/5.jpg 15 | 16 | 17 | -------------------------------------------------------------------------------- /static/bilibili.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/bilibili.ico -------------------------------------------------------------------------------- /static/food/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/food/1.jpg -------------------------------------------------------------------------------- /static/food/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/food/2.jpg -------------------------------------------------------------------------------- /static/food/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/food/3.jpg -------------------------------------------------------------------------------- /static/food/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/food/4.jpg -------------------------------------------------------------------------------- /static/food/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/food/5.jpg -------------------------------------------------------------------------------- /static/insert.ini: -------------------------------------------------------------------------------- 1 | INSERT INTO menu(name,price,type,pic) VALUES("番茄炒马铃薯","10.0",1,:imgData); 2 | INSERT INTO menu(name,price,type,pic) VALUES("土豆炒西红柿","11.0",1,:imgData); 3 | INSERT INTO menu(name,price,type,pic) VALUES("绝了红烧肉","22.0",1,:imgData); 4 | INSERT INTO menu(name,price,type,pic) VALUES("酒鬼花生","7.0",2,:imgData); 5 | INSERT INTO menu(name,price,type,pic) VALUES("重庆冰粉","6.0",3,:imgData); -------------------------------------------------------------------------------- /static/qq.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/qq.ico -------------------------------------------------------------------------------- /static/shy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/shy.jpg -------------------------------------------------------------------------------- /static/steam.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/steam.ico -------------------------------------------------------------------------------- /static/tables.sql: -------------------------------------------------------------------------------- 1 | create table menu( 2 | id INTEGER PRIMARY KEY, 3 | name TEXT NOT NULL, 4 | price REAL NOT NULL, 5 | pic BLOB, -- 展示图片 6 | type INTEGER -- 类型: 1. 主食 2. 小吃 3. 甜点 4. 汤 等等 7 | ); 8 | create table order_dishes( 9 | id INTEGER PRIMARY KEY, 10 | seat INTEGER NOT NULL, -- 座位号 11 | menu_id INTEGER NOT NULL, -- 菜品id 12 | status INTEGER DEFAULT 1, -- 菜品状态:1. 未确认 2.烹饪中 3. 完成 13 | create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 14 | update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP 15 | ); 16 | create table business_data( 17 | id INTEGER PRIMARY KEY, 18 | money REAL NOT NULL, -- 金额费用 19 | type INTEGER DEFAULT 1, -- 类型: 1. 结账 2. 其他待定 20 | create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP 21 | ); 22 | -------------------------------------------------------------------------------- /static/unknown.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someGenki/OrderDishesClient-qt5/e84d9ee589980ec3fb3bfd731960f50fd7e4f945/static/unknown.jpg --------------------------------------------------------------------------------