|
|
@ -1,77 +1,44 @@
|
|
|
|
#include "receptionist.h"
|
|
|
|
#include "receptionist.h"
|
|
|
|
#include "ui_receptionist.h"
|
|
|
|
#include "ui_receptionist.h"
|
|
|
|
#include "cellstatus.h"
|
|
|
|
#include "cellstatus.h"
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
|
|
|
#include <QSqlQuery>
|
|
|
|
|
|
|
|
#include <QSqlError>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <QVBoxLayout> // 添加这一行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
receptionist::receptionist(QWidget *parent) :
|
|
|
|
receptionist::receptionist(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::receptionist)
|
|
|
|
ui(new Ui::receptionist)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 设置主窗口大小为1920x1080
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
QIcon logo(":/image/icon/logo.png");
|
|
|
|
|
|
|
|
this->setWindowIcon(logo);
|
|
|
|
|
|
|
|
this->setWindowTitle("宜客酒店");
|
|
|
|
this->setFixedSize(1920,1080);
|
|
|
|
this->setFixedSize(1920,1080);
|
|
|
|
|
|
|
|
bg = new QLabel(this);
|
|
|
|
|
|
|
|
bg->setScaledContents(true);
|
|
|
|
|
|
|
|
bg->setPixmap(QPixmap(":/image/bg/login.png"));
|
|
|
|
|
|
|
|
bg->lower();
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个垂直布局管理器
|
|
|
|
// 设置主窗口大小为1920x1080
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
this->setFixedSize(1920,1080);
|
|
|
|
|
|
|
|
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
|
|
|
|
db = QSqlDatabase::addDatabase("QMYSQL");
|
|
|
|
db.setHostName("127.0.0.1");
|
|
|
|
|
|
|
|
db.setPort(3306);
|
|
|
|
|
|
|
|
db.setDatabaseName("hotel");
|
|
|
|
db.setDatabaseName("hotel");
|
|
|
|
|
|
|
|
db.setHostName("localhost");
|
|
|
|
|
|
|
|
db.setPort(3306);
|
|
|
|
db.setUserName("root");
|
|
|
|
db.setUserName("root");
|
|
|
|
db.setPassword("111111");
|
|
|
|
db.setPassword("111111");
|
|
|
|
qDebug() << db.open();
|
|
|
|
if(db.open()){
|
|
|
|
ui->setupUi(this);
|
|
|
|
qDebug("database connect succeed");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
qDebug("database connect failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建 QTableWidget 和其他组件
|
|
|
|
// 创建 QTableWidget 和其他组件
|
|
|
|
ui->tableWidget->setRowCount(4);
|
|
|
|
ui->tableWidget->setRowCount(3);
|
|
|
|
|
|
|
|
ui->tableWidget->setColumnCount(8);
|
|
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
QStringList strs = {QString::fromLocal8Bit(u8"房间号"), QString::fromLocal8Bit(u8" 房间类型 "), QString::fromLocal8Bit(u8" 是否带窗 "),
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态","退房时间","客户信息","操作"});
|
|
|
|
QString::fromLocal8Bit(u8" 负责人 "),QString::fromLocal8Bit(u8" 状态 "),QString::fromLocal8Bit(u8" 退房时间 "),
|
|
|
|
ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//表头透明度
|
|
|
|
QString::fromLocal8Bit(u8"客户信息"),QString::fromLocal8Bit(u8"操作")};
|
|
|
|
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->setColumnCount(strs.size());
|
|
|
|
showall();
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
receptionist::~receptionist()
|
|
|
|
receptionist::~receptionist()
|
|
|
@ -85,4 +52,76 @@ void receptionist::paintEvent(QPaintEvent *)
|
|
|
|
opt.init(this);
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|