parent
1e222668ae
commit
2d0592906a
@ -1,14 +1,270 @@
|
|||||||
#include "customer.h"
|
#include "customer.h"
|
||||||
|
#include "login.h"
|
||||||
|
#include "registers.h"
|
||||||
#include "ui_customer.h"
|
#include "ui_customer.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ID从数据库的提取
|
||||||
|
*/
|
||||||
|
|
||||||
customer::customer(QWidget *parent) :
|
customer::customer(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::customer)
|
ui(new Ui::customer)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
customer::~customer()
|
customer::~customer()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void customer::paintEvent(QPaintEvent*)
|
||||||
|
{
|
||||||
|
labelone->resize(ui->widget->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::init()//初始化
|
||||||
|
{
|
||||||
|
customer_id = "123";
|
||||||
|
ui->setupUi(this);
|
||||||
|
this->setFixedSize(1920,1080);
|
||||||
|
this->setWindowTitle("用户界面");
|
||||||
|
this->setWindowIcon(QIcon(":image/icon/logo"));//创造本界面
|
||||||
|
lg = new login(this);
|
||||||
|
lg->hide();
|
||||||
|
rm = new ResetMessage(this);
|
||||||
|
rm->hide();//创造副界面
|
||||||
|
labelone = new QLabel(this);
|
||||||
|
labelone->setScaledContents(true);
|
||||||
|
labelone->setPixmap(QPixmap(":/image/bg/login.png"));
|
||||||
|
labelone->lower();
|
||||||
|
|
||||||
|
findall();
|
||||||
|
flush_data(userinfo);//初始显示全部
|
||||||
|
setmousehand();//装饰鼠标
|
||||||
|
|
||||||
|
ui->Reservation1->setEnabled(false);
|
||||||
|
ui->checking_out1->setEnabled(false);//初始退订按钮
|
||||||
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||||
|
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//表格不可编辑
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::setmousehand()//鼠标小手 完成
|
||||||
|
{
|
||||||
|
ui->search->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
ui->pushButton->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
ui->Reservation1->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
ui->checking_out1->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void customer::on_checking_out1_clicked()//退房 完成
|
||||||
|
{
|
||||||
|
int c = row;//总之是获取选中的行
|
||||||
|
if( ui->tableWidget->model()->index(c,6).data().toString() == "123" ){
|
||||||
|
QString QS = "空闲";
|
||||||
|
QSqlQuery query((db));
|
||||||
|
|
||||||
|
|
||||||
|
QString n = 0;
|
||||||
|
n = ui->tableWidget->model()->index(c,0).data().toString();
|
||||||
|
int num = n.toInt();
|
||||||
|
|
||||||
|
query.prepare("UPDATE room set status=:QS where room_num = :num");
|
||||||
|
query.bindValue(":QS",QS);
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();
|
||||||
|
query.prepare("UPDATE room set checkout_time=NULL where room_num = :num");
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();
|
||||||
|
query.prepare("UPDATE room set customer_id=NULL where room_num = :num");
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();//开始操作数据库
|
||||||
|
|
||||||
|
if(c >= 0){
|
||||||
|
QTableWidgetItem *Q1 = new QTableWidgetItem(QS);
|
||||||
|
ui->tableWidget->setItem(c,4,Q1);
|
||||||
|
ui->tableWidget->setItem(c,5,NULL);
|
||||||
|
ui->tableWidget->setItem(c,6,NULL);
|
||||||
|
Q1->setTextAlignment(Qt::AlignCenter);
|
||||||
|
QMessageBox::about(this,"提示","退房成功");
|
||||||
|
ui->Reservation1->setEnabled(true);
|
||||||
|
ui->checking_out1->setEnabled(false);//开始操作表格
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else QMessageBox::about(this,"警告","不是本人操作");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void customer::on_Reservation1_clicked()//订房 id是什么
|
||||||
|
{
|
||||||
|
int c = row;//总之是获取选中的行
|
||||||
|
QString QS = "使用";
|
||||||
|
QSqlQuery query((db));
|
||||||
|
QString n = 0;
|
||||||
|
n = ui->tableWidget->model()->index(c,0).data().toString();
|
||||||
|
QDate d = QDate::currentDate();
|
||||||
|
|
||||||
|
|
||||||
|
int num = n.toInt();
|
||||||
|
query.prepare("UPDATE room set status=:QS where room_num = :num");
|
||||||
|
query.bindValue(":QS",QS);
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();
|
||||||
|
query.prepare("UPDATE room set checkout_time=DATE_ADD(:d, INTERVAL 1 DAY) where room_num = :num");
|
||||||
|
query.bindValue(":d",d);
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();
|
||||||
|
query.prepare("UPDATE room set customer_id=:id where room_num = :num");
|
||||||
|
query.bindValue(":id",123);
|
||||||
|
query.bindValue(":num",num);
|
||||||
|
query.exec();
|
||||||
|
|
||||||
|
if(c>=0){
|
||||||
|
QTableWidgetItem *Q1 = new QTableWidgetItem(QS);
|
||||||
|
ui->tableWidget->setItem(c,4,Q1);
|
||||||
|
Q1->setTextAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
|
QMessageBox::about(this,"提示","订房成功");
|
||||||
|
ui->Reservation1->setEnabled(false);
|
||||||
|
ui->checking_out1->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void customer::on_pushButton_clicked()//修改 完成
|
||||||
|
{
|
||||||
|
rm->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::on_checkBox_clicked(bool checked)//装饰品
|
||||||
|
{
|
||||||
|
if(checked){
|
||||||
|
ui->tableWidget->horizontalHeader()->show();
|
||||||
|
}
|
||||||
|
else ui->tableWidget->horizontalHeader()->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::on_checkBox_2_clicked(bool checked)//装饰品
|
||||||
|
{
|
||||||
|
if(checked){
|
||||||
|
ui->tableWidget->verticalHeader()->show();
|
||||||
|
}
|
||||||
|
else ui->tableWidget->verticalHeader()->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::on_checkBox_3_clicked(bool checked)//装饰品
|
||||||
|
{
|
||||||
|
if(checked){
|
||||||
|
ui->tableWidget->setAlternatingRowColors(true);
|
||||||
|
}
|
||||||
|
else ui->tableWidget->setAlternatingRowColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::findall()//显示全部 完成
|
||||||
|
{
|
||||||
|
userinfo.clear();//清楚存储向量rec的向量的数据
|
||||||
|
QSqlQuery query((db));
|
||||||
|
query.prepare("select * from room");
|
||||||
|
|
||||||
|
if(query.exec())
|
||||||
|
{
|
||||||
|
while (query.next()) {
|
||||||
|
QVector<QString>rec;
|
||||||
|
for(int i=0;i<query.record().count();i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
rec.push_back(query.record().value(i).toString());//将sql搜索到的一行记录塞入rec向量
|
||||||
|
}
|
||||||
|
userinfo.push_back(rec);//将rec向量塞入向量
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::flush_data(QVector<QVector<QString>>&userinfo)//插入数据 完成
|
||||||
|
{
|
||||||
|
ui->tableWidget->clear();
|
||||||
|
if(!userinfo.size())return;
|
||||||
|
ui->tableWidget->setRowCount(userinfo.size());//行
|
||||||
|
ui->tableWidget->setColumnCount(5);//列
|
||||||
|
|
||||||
|
for(int i=0;i<userinfo.size();i++)
|
||||||
|
{
|
||||||
|
for(int j=0;j<userinfo[0].size();j++)
|
||||||
|
{
|
||||||
|
QTableWidgetItem *QW = new QTableWidgetItem(userinfo[i][j]);
|
||||||
|
ui->tableWidget->setItem(i,j,QW);//行 列 内容
|
||||||
|
QW->setTextAlignment(Qt::AlignCenter);//设置中心对齐
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态"});//设置表头
|
||||||
|
}
|
||||||
|
|
||||||
|
void customer::on_tableWidget_itemClicked(QTableWidgetItem *item)//点击表格格子 获取行数 完成
|
||||||
|
{
|
||||||
|
row = item->row();
|
||||||
|
if(ui->tableWidget->model()->index(row,4).data().toString() == "空闲"){
|
||||||
|
ui->Reservation1->setEnabled(true);
|
||||||
|
ui->checking_out1->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(ui->tableWidget->model()->index(row,4).data().toString() == "使用"){
|
||||||
|
ui->checking_out1->setEnabled(true);
|
||||||
|
ui->Reservation1->setEnabled(false);
|
||||||
|
}
|
||||||
|
else QMessageBox::about(this,"警告","未知错误");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void customer::on_search_clicked()//搜索 不能部分找到全部
|
||||||
|
{
|
||||||
|
|
||||||
|
QString number=ui->lineEdit_2->text();
|
||||||
|
if(number == NULL){
|
||||||
|
findall();
|
||||||
|
flush_data(userinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(find_byname(number))
|
||||||
|
{
|
||||||
|
flush_data(userinfo);
|
||||||
|
userinfo.clear();
|
||||||
|
}else QMessageBox::critical(nullptr, "错误", "未知的错误", QMessageBox::Retry);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool customer::find_byname(QString n)//搜索?
|
||||||
|
{
|
||||||
|
int number = n.toInt();
|
||||||
|
userinfo.clear();
|
||||||
|
QSqlQuery query(db);
|
||||||
|
query.prepare("select * from room where room_num like :number;");//以开头搜索 不行
|
||||||
|
query.bindValue(":number",number);
|
||||||
|
if(query.exec())
|
||||||
|
{
|
||||||
|
while (query.next()) {
|
||||||
|
QVector<QString>rec;
|
||||||
|
rec.push_back(query.record().value("room_num").toString());
|
||||||
|
rec.push_back(query.record().value("type").toString());
|
||||||
|
rec.push_back(query.record().value("withwindow").toString());
|
||||||
|
rec.push_back(query.record().value("responsible_person").toString());
|
||||||
|
rec.push_back(query.record().value("status").toString());
|
||||||
|
rec.push_back(query.record().value("checkout_time").toString());
|
||||||
|
rec.push_back(query.record().value("customer_id").toString());
|
||||||
|
|
||||||
|
userinfo.push_back(rec);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue