You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
4.9 KiB
152 lines
4.9 KiB
#include "receptionist.h"
|
|
#include "ui_receptionist.h"
|
|
#include "cellstatus.h"
|
|
#include "checkbtn.h"
|
|
|
|
receptionist::receptionist(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::receptionist)
|
|
{
|
|
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();
|
|
|
|
// 设置主窗口大小为1920x1080
|
|
this->setFixedSize(1920,1080);
|
|
|
|
db = QSqlDatabase::addDatabase("QMYSQL");
|
|
db.setDatabaseName("hotel");
|
|
db.setHostName("localhost");
|
|
db.setPort(3306);
|
|
db.setUserName("root");
|
|
db.setPassword("111111");
|
|
if(db.open()){
|
|
qDebug("database connect succeed");
|
|
}else{
|
|
qDebug("database connect failed");
|
|
}
|
|
|
|
// 创建 QTableWidget 和其他组件
|
|
ui->tableWidget->setRowCount(3);
|
|
ui->tableWidget->setColumnCount(8);
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
|
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()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void receptionist::paintEvent(QPaintEvent *)
|
|
{
|
|
QStyleOption opt;
|
|
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());
|
|
checkbtn* cbtn = new checkbtn;
|
|
cbtn->setroomNum(query.value(0).toInt());
|
|
cbtn->setDB(db);
|
|
cell->setcbtn(cbtn);
|
|
if(QString::compare(ui->tableWidget->model()->index(i,4).data().toString(),"使用")==0){
|
|
cell->setisused(true);
|
|
cbtn->setisused(true);
|
|
}else{
|
|
cell->setisused(false);
|
|
cbtn->setisused(false);
|
|
}
|
|
cell->setbtn();
|
|
cbtn->setbtn();
|
|
|
|
ui->tableWidget->setCellWidget(i,7,cell);
|
|
ui->tableWidget->setCellWidget(i,6,cbtn);
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void receptionist::search(QString str){
|
|
int s = str.toInt();
|
|
ui->tableWidget->setRowCount(1);
|
|
ui->tableWidget->clear();
|
|
ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态","退房时间","客户信息","操作"});
|
|
QSqlQuery query;
|
|
query.prepare("select * from room where room_num like :str;");
|
|
query.bindValue(":str",s);
|
|
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(0,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());
|
|
checkbtn* cbtn = new checkbtn;
|
|
cbtn->setroomNum(query.value(0).toInt());
|
|
cbtn->setDB(db);
|
|
cell->setcbtn(cbtn);
|
|
if(QString::compare(ui->tableWidget->model()->index(0,4).data().toString(),"使用")==0){
|
|
cell->setisused(true);
|
|
cbtn->setisused(true);
|
|
}else{
|
|
cell->setisused(false);
|
|
cbtn->setisused(false);
|
|
}
|
|
cell->setbtn();
|
|
cbtn->setbtn();
|
|
|
|
ui->tableWidget->setCellWidget(0,7,cell);
|
|
ui->tableWidget->setCellWidget(0,6,cbtn);
|
|
}
|
|
}
|
|
}
|
|
|
|
void receptionist::on_pushButton_clicked()
|
|
{
|
|
QString str = ui->lineEdit->text();
|
|
if(str == NULL){
|
|
showall();
|
|
}else{
|
|
search(str);
|
|
}
|
|
}
|
|
|
|
void receptionist::onflash(){
|
|
showall();
|
|
}
|
|
|