diff --git a/Hotel_Management.pro.user b/Hotel_Management.pro.user index 7b68e85..57fd86e 100644 --- a/Hotel_Management.pro.user +++ b/Hotel_Management.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/cellstatus.cpp b/cellstatus.cpp index b883088..5a540b9 100644 --- a/cellstatus.cpp +++ b/cellstatus.cpp @@ -1,15 +1,14 @@ #include "cellstatus.h" #include "ui_cellstatus.h" -#include cellstatus::cellstatus(QWidget *parent) : QWidget(parent), ui(new Ui::cellstatus) { ui->setupUi(this); - ui->pushButton->setStyleSheet("border:2px groove gray; background-color: rgb(225, 225, 225);" + ui->pushButton->setStyleSheet("border:2px groove gray;background-color: rgb(0, 0, 0,30);color: rgb(255, 255, 255);" "border-radius:5px;"); - ui->pushButton_2->setStyleSheet("border:2px groove gray; background-color: rgb(225, 225, 225);" + ui->pushButton_2->setStyleSheet("border:2px groove gray;background-color: rgb(0, 0, 0,30);color: rgb(255, 255, 255);" "border-radius:5px;"); @@ -27,6 +26,15 @@ cellstatus::~cellstatus() delete ui; } +void cellstatus::setisused(bool i){ + isused = i; +} + +void cellstatus::setbtn(){ + ui->pushButton->setEnabled(!isused); + ui->pushButton_2->setEnabled(isused); +} + void cellstatus::setroomNum(int roomNum) { this->roomNum = roomNum; @@ -39,22 +47,41 @@ void cellstatus::setDB(QSqlDatabase db) void cellstatus::on_pushButton_clicked() { - m_order->setDB(db); m_order->setrootNum(roomNum); + m_order->setDB(db); m_order->show(); } void cellstatus::on_pushButton_2_clicked() { - QMessageBox::information(this, QString::fromLocal8Bit(" 预定信息 "), QString::fromLocal8Bit(" 退房成功 ")); + QSqlQuery query; + query.prepare("select * from customer where room_num like :num;"); + query.bindValue(":str",roomNum); + query.exec(); + QString account = query.value(0).toString(); + query.prepare("UPDATE customer set room_num=NULL where account = :a"); + query.bindValue(":a",account); + query.exec(); + query.prepare("UPDATE room set status=:QS where room_num = :num"); + query.bindValue(":QS","空闲"); + query.bindValue(":num",roomNum); + query.exec(); + query.prepare("UPDATE room set checkout_time=NULL where room_num = :num"); + query.bindValue(":num",roomNum); + query.exec(); + query.prepare("UPDATE room set customer_id=NULL where room_num = :num"); + query.bindValue(":num",roomNum); + query.exec(); + QMessageBox::information(this," 预定信息 "," 退房成功 "); ui->pushButton->setEnabled(true); ui->pushButton_2->setEnabled(false); - + emit flash(); } void cellstatus::onordersuccess() { - QMessageBox::information(this, QString::fromLocal8Bit("预定信息"), QString::fromLocal8Bit("订房成功")); + QMessageBox::information(this,"预定信息","订房成功"); ui->pushButton->setEnabled(false); ui->pushButton_2->setEnabled(true); + emit flash(); } diff --git a/cellstatus.h b/cellstatus.h index a720086..a948293 100644 --- a/cellstatus.h +++ b/cellstatus.h @@ -6,6 +6,8 @@ #include #include #include +#include + namespace Ui { class cellstatus; } @@ -19,6 +21,8 @@ public: ~cellstatus(); void setroomNum(int roomNum); void setDB(QSqlDatabase db); + void setisused(bool i); + void setbtn(); private slots: void on_pushButton_clicked(); @@ -32,6 +36,9 @@ private: int roomNum; orderoom *m_order; QSqlDatabase db; + bool isused; +signals: + void flash(); }; #endif // CELLSTATUS_H diff --git a/login.cpp b/login.cpp index c7f519c..49dd4ce 100644 --- a/login.cpp +++ b/login.cpp @@ -12,7 +12,7 @@ login::login(QWidget *parent) ui->setupUi(this); QIcon logo(":/image/icon/logo.png"); this->setWindowIcon(logo); - setWindowTitle("宜客酒店"); + this->setWindowTitle("宜客酒店"); this->setFixedSize(1920,1080); bg = new QLabel(this); bg->setScaledContents(true); diff --git a/order.png b/order.png new file mode 100644 index 0000000..a88b63b Binary files /dev/null and b/order.png differ diff --git a/orderoom.cpp b/orderoom.cpp index dd3aa63..cb5f309 100644 --- a/orderoom.cpp +++ b/orderoom.cpp @@ -1,14 +1,37 @@ #include "orderoom.h" #include "ui_orderoom.h" -#include -#include -#include -#include +#include "registers.h" + orderoom::orderoom(QWidget *parent) : QWidget(parent), ui(new Ui::orderoom) { ui->setupUi(this); + QIcon logo(":/image/icon/logo.png"); + this->setWindowIcon(logo); + this->setWindowTitle("订房页面"); + this->setFixedSize(800,600); + bg = new QLabel(this); + bg->setScaledContents(true); + bg->setPixmap(QPixmap(":/image/bg/order.png")); + bg->lower(); + + ui->tableWidget->setRowCount(0); + ui->tableWidget->setColumnCount(4); + ui->tableWidget->setHorizontalHeaderLabels({"手机号","姓名","性别","身份证号"}); + ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//表头透明度 + ui->tableWidget->setStyleSheet("QTableWidget{border:2px groove gray;border-radius:15px;background-color: rgb(0, 0, 0,30);color: rgb(255, 255, 255);}"); + ui->tableWidget->verticalHeader()->setVisible(false); + ui->tableWidget->setColumnWidth(0,200); + ui->tableWidget->setColumnWidth(1,100); + ui->tableWidget->setColumnWidth(2,100); + ui->tableWidget->setColumnWidth(3,375); + + findcustomer = false; + + + + } orderoom::~orderoom() @@ -21,33 +44,66 @@ void orderoom::setrootNum(int rootNum) this->rootNum = rootNum; } -void orderoom::setDB(QSqlDatabase db) -{ +void orderoom::setDB(QSqlDatabase db){ this->db = db; } -void orderoom::on_pushButton_2_clicked() +void orderoom::on_btn_search_clicked() { - - QString phone = ui->lineEdit_2->text(); - QString name = ui->lineEdit_3->text(); - QString gender = ui->lineEdit_4->text(); - QString user_id = ui->lineEdit_5->text(); - - //插入记录 - QString sql = QString("insert into customer(account, name, gender,id ,room_num) " - "VALUES ('%1','%2', '%3','%4','%5')") - .arg(phone).arg(name).arg(gender).arg(user_id).arg(rootNum); + QString str = ui->lineEdit->text(); + ui->tableWidget->setRowCount(1); + ui->tableWidget->clear(); + ui->tableWidget->setHorizontalHeaderLabels({"手机号","姓名","性别","身份证号"}); QSqlQuery query; - if(query.exec(sql)) //执行sql语句是否成功 - { + query.prepare("select * from customer where account like :str;"); + query.bindValue(":str",str); - qDebug()<<"insert success"; + if(query.exec()){ + while (query.next()){ + QTableWidgetItem *twi = new QTableWidgetItem(query.value(0).toString()); + twi->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(0,0,twi); + for(int j = 2;j<5;j++){ + QTableWidgetItem *twi = new QTableWidgetItem(query.value(j).toString()); + twi->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(0,j-1,twi); + } + } + } + if(ui->tableWidget->model()->index(0,0).data().toString() == NULL){ + findcustomer = false; + ui->tableWidget->setRowCount(0); + }else{ + findcustomer = true; + } +} - }else - { - qDebug()<tableWidget->model()->index(0,0).data().toString().toInt(); + QString sql1 = QString("UPDATE room set customer_id = %1 where room_num = %2").arg(account).arg(rootNum); + QString sql2 = QString("UPDATE room set status='使用' where room_num = %1").arg(rootNum); + QSqlQuery query; + query.exec(sql1); + query.exec(sql2); + query.prepare("UPDATE room set checkout_time=DATE_ADD(:date, INTERVAL 1 DAY) where room_num = :num"); + query.bindValue(":date",date); + query.bindValue(":num",rootNum); + query.exec(); + emit ordersuccess(); + this->close(); + }else{ + QMessageBox::warning(this,tr("提示"),("请选择入住客户!")); } - emit ordersuccess(); - this->close(); } + + +void orderoom::on_btn_registers_clicked() +{ + registers *reg = new registers; + reg->show(); +} + diff --git a/orderoom.h b/orderoom.h index 15bc98f..b8a6994 100644 --- a/orderoom.h +++ b/orderoom.h @@ -2,9 +2,14 @@ #define ORDEROOM_H #include +#include #include #include #include +#include +#include +#include + namespace Ui { class orderoom; } @@ -20,12 +25,19 @@ public: void setDB(QSqlDatabase db); private slots: - void on_pushButton_2_clicked(); + + + void on_btn_search_clicked(); + void on_btn_order_clicked(); + + void on_btn_registers_clicked(); private: Ui::orderoom *ui; + QLabel *bg; int rootNum; QSqlDatabase db; + bool findcustomer; signals: void ordersuccess(); diff --git a/orderoom.ui b/orderoom.ui index f78e2dc..064403e 100644 --- a/orderoom.ui +++ b/orderoom.ui @@ -6,112 +6,163 @@ 0 0 - 563 - 432 + 800 + 600 Form - - - - - 性别: - - - - - - - 新建客户 - - - - - - - 手机号: - - - - - - - - - - - - - - 姓名: - - - - - - - - 800 - 600 - - - - - - - - - - - 身份证: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 订房 - - - - + + + + 0 + 0 + 800 + 600 + + + + + + 200 + 60 + 461 + 41 + + + + + + + 670 + 60 + 121 + 41 + + + + + 12 + + + + 检索 + + + + + + 10 + 10 + 341 + 131 + + + + + 15 + + + + 检索客户信息: + + + + + + -1 + 489 + 801 + 111 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 新建客户 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 订房 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 10 + 130 + 781 + 341 + + + + + 12 + + + + background-color: rgb(0, 0, 0,50); +color: rgb(255, 255, 255); + + + diff --git a/receptionist.cpp b/receptionist.cpp index 67eb8a0..17302a3 100644 --- a/receptionist.cpp +++ b/receptionist.cpp @@ -1,77 +1,44 @@ #include "receptionist.h" #include "ui_receptionist.h" #include "cellstatus.h" -#include -#include -#include -#include -#include -#include -#include -#include // 添加这一行 receptionist::receptionist(QWidget *parent) : QMainWindow(parent), ui(new Ui::receptionist) { - // 设置主窗口大小为1920x1080 + ui->setupUi(this); + QIcon logo(":/image/icon/logo.png"); + this->setWindowIcon(logo); + this->setWindowTitle("宜客酒店"); this->setFixedSize(1920,1080); + bg = new QLabel(this); + bg->setScaledContents(true); + bg->setPixmap(QPixmap(":/image/bg/login.png")); + bg->lower(); - // 创建一个垂直布局管理器 - QVBoxLayout *layout = new QVBoxLayout(this); + // 设置主窗口大小为1920x1080 + this->setFixedSize(1920,1080); - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("127.0.0.1"); - db.setPort(3306); + db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("hotel"); + db.setHostName("localhost"); + db.setPort(3306); db.setUserName("root"); db.setPassword("111111"); - qDebug() << db.open(); - ui->setupUi(this); + if(db.open()){ + qDebug("database connect succeed"); + }else{ + qDebug("database connect failed"); + } // 创建 QTableWidget 和其他组件 - ui->tableWidget->setRowCount(4); + ui->tableWidget->setRowCount(3); + ui->tableWidget->setColumnCount(8); ui->tableWidget->verticalHeader()->setVisible(false); - QStringList strs = {QString::fromLocal8Bit(u8"房间号"), QString::fromLocal8Bit(u8" 房间类型 "), QString::fromLocal8Bit(u8" 是否带窗 "), - QString::fromLocal8Bit(u8" 负责人 "),QString::fromLocal8Bit(u8" 状态 "),QString::fromLocal8Bit(u8" 退房时间 "), - QString::fromLocal8Bit(u8"客户信息"),QString::fromLocal8Bit(u8"操作")}; - ui->tableWidget->setColumnCount(strs.size()); - ui->tableWidget->setStyleSheet("QTableWidget{border:2px groove gray;border-radius:15px;background-color:rgba(255, 255, 255, 30%);}"); - ui->tableWidget->horizontalHeader()->setVisible(false); - ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - - for(int i = 0; i < strs.size();i++) - { - ui->tableWidget->setItem(0,i,new QTableWidgetItem(strs[i])); - } - - QSqlQuery query; - query.exec("select * from room"); - int i = 1; - while(query.next()){ - //数据 - ui->tableWidget->setItem(i,0,new QTableWidgetItem(QString::fromLocal8Bit(query.value(0).toString().toUtf8().data()))); - ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::fromLocal8Bit(query.value(1).toString().toUtf8().data()))); - ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::fromLocal8Bit(query.value(2).toString().toUtf8().data()))); - ui->tableWidget->setItem(i,3,new QTableWidgetItem(QString::fromLocal8Bit(query.value(3).toString().toUtf8().data()))); - ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::fromLocal8Bit(query.value(4).toString().toUtf8().data()))); - ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::fromLocal8Bit(query.value(5).toString().toUtf8().data()))); - cellstatus* cell = new cellstatus(); - cell->setroomNum(query.value(0).toInt()); - cell->setDB(db); - ui->tableWidget->setCellWidget(i,7,cell); - ui->tableWidget->setCellWidget(i,6,new QPushButton(QString::fromLocal8Bit("查看"))); - i++; - } - - // 将 QTableWidget 和其他组件添加到布局管理器中 - layout->addWidget(ui->tableWidget); // 例如,添加您的表格 - layout->addStretch(); // 添加伸缩项,将组件推到窗口中央 - - // 将布局管理器设置为主窗口的布局 - QWidget *centralWidget = new QWidget(this); - centralWidget->setLayout(layout); - setCentralWidget(centralWidget); + ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态","退房时间","客户信息","操作"}); + ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//表头透明度 + ui->tableWidget->setStyleSheet("QTableWidget{border:2px groove gray;border-radius:15px;background-color: rgb(0, 0, 0,30);color: rgb(255, 255, 255);}"); + showall(); } receptionist::~receptionist() @@ -85,4 +52,76 @@ void receptionist::paintEvent(QPaintEvent *) opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + bg->resize(ui->widget->size()); } + +void receptionist::showall(){ + QSqlQuery query; + query.exec("select * from room"); + ui->tableWidget->setRowCount(query.size()); + int i = 0; + if(query.exec()){ + while(query.next()){ + //数据 + for(int j = 0;j<6;j++){ + QTableWidgetItem *twi = new QTableWidgetItem(query.value(j).toString()); + twi->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(i,j,twi); + ui->tableWidget->setColumnWidth(j,259); + } + cellstatus* cell = new cellstatus(); + connect(cell,&cellstatus::flash,this,&receptionist::onflash); + cell->setDB(db); + cell->setroomNum(query.value(0).toInt()); + if(QString::compare(ui->tableWidget->model()->index(i,4).data().toString(),"使用")==0){ + cell->setisused(true); + }else{ + cell->setisused(false); + } + cell->setbtn(); + ui->tableWidget->setCellWidget(i,7,cell); + ui->tableWidget->setCellWidget(i,6,new QPushButton("查看")); + i++; + } + } +} + +void receptionist::search(QString str){ + int s = str.toInt(); + ui->tableWidget->clear(); + ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态","退房时间","客户信息","操作"}); + QSqlQuery query; + query.prepare("select * from room where room_num like :str;"); + query.bindValue(":str",s); + int i = 0; + if(query.exec()){ + while (query.next()){ + for(int j = 0;j<6;j++){ + QTableWidgetItem *twi = new QTableWidgetItem(query.value(j).toString()); + twi->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(i,j,twi); + ui->tableWidget->setColumnWidth(j,259); + } + cellstatus* cell = new cellstatus(); + cell->setroomNum(query.value(0).toInt()); + cell->setDB(db); + ui->tableWidget->setCellWidget(i,7,cell); + ui->tableWidget->setCellWidget(i,6,new QPushButton("查看")); + } + } +} + +void receptionist::on_pushButton_clicked() +{ + QString str = ui->lineEdit->text(); + if(str == NULL){ + showall(); + }else{ + search(str); + } +} + +void receptionist::onflash(){ + showall(); +} + diff --git a/receptionist.h b/receptionist.h index daae95f..936a772 100644 --- a/receptionist.h +++ b/receptionist.h @@ -2,6 +2,17 @@ #define RECEPTIONIST_H #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // 添加这一行 + namespace Ui { class receptionist; } @@ -16,9 +27,16 @@ public: private: Ui::receptionist *ui; + QLabel *bg; + QSqlDatabase db; + void search(QString str); + void showall(); protected: void paintEvent(QPaintEvent *e); +private slots: + void on_pushButton_clicked(); + void onflash(); }; #endif // RECEPTIONIST_H diff --git a/receptionist.ui b/receptionist.ui index bc22828..69bd92b 100644 --- a/receptionist.ui +++ b/receptionist.ui @@ -20,46 +20,107 @@ MainWindow - - - - - 房间检索: - - - - - - - - - - - 20 - - - - 宜客酒店 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + + + 0 + 0 + 1920 + 1080 + + + + + + 10 + 20 + 711 + 181 + + + + + 70 + + + + color: rgb(85, 255, 255); + + + 宜客酒店 + + + + + + 30 + 220 + 1861 + 831 + + + + + 12 + + + + background-color: rgb(0, 0, 0,50); +color: rgb(255, 255, 255); + + + + + + 1230 + 110 + 411 + 71 + + + + + 25 + + + + 房间检索: + + + + + + 1470 + 130 + 321 + 41 + + + + + 14 + + + + + + + 1809 + 127 + 81 + 41 + + + + + 12 + + + + 查找 + + + @@ -67,7 +128,7 @@ 0 0 1920 - 21 + 17 diff --git a/res.qrc b/res.qrc index 6e7d3e1..d4ca0c0 100644 --- a/res.qrc +++ b/res.qrc @@ -5,6 +5,7 @@ sea.jpg stone.jpg register.jpg + order.png info.png