|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#include "customer.h"
|
|
|
|
|
#include "login.h"
|
|
|
|
|
#include "ui_customer.h"
|
|
|
|
|
|
|
|
|
|
customer::customer(QWidget *parent) :
|
|
|
|
@ -6,9 +7,241 @@ customer::customer(QWidget *parent) :
|
|
|
|
|
ui(new Ui::customer)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
this->setFixedSize(1920,1080);
|
|
|
|
|
this->setWindowTitle("用户界面");
|
|
|
|
|
this->setWindowIcon(QIcon());
|
|
|
|
|
QPalette q;//调色板
|
|
|
|
|
q.setBrush(QPalette::Window,QBrush(QPixmap("picture/customerbackground.jpg")));
|
|
|
|
|
this->setPalette(q);
|
|
|
|
|
labelone = new QLabel(this);
|
|
|
|
|
labelone->setScaledContents(true);
|
|
|
|
|
//labelone->setPixmap(QPixmap("picture/customerbackground.jpg"));
|
|
|
|
|
labelone->lower();
|
|
|
|
|
|
|
|
|
|
lg = new login(this);
|
|
|
|
|
lg->hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->setColumnCount(4);//添加四列
|
|
|
|
|
QStringList QL;
|
|
|
|
|
QL << "房间号"<<"房间类型";
|
|
|
|
|
QL << "是否带窗";
|
|
|
|
|
QL << "状态";
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels(QL);//添加列头的内容
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//列自适应,填满
|
|
|
|
|
|
|
|
|
|
addrow("曹坤","男",14,"中国");//测试用
|
|
|
|
|
addrow("曹","男",4,"中国");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customer::~customer()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void customer::addrow(QString name,QString gender,int age,QString bornplace){
|
|
|
|
|
int count = ui->tableWidget->rowCount();//获取行数
|
|
|
|
|
ui->tableWidget->setRowCount(count+1);
|
|
|
|
|
QTableWidgetItem *Q1 = new QTableWidgetItem(name);
|
|
|
|
|
QTableWidgetItem *Q2 = new QTableWidgetItem(gender);
|
|
|
|
|
QTableWidgetItem *Q3 = new QTableWidgetItem(QString::number(age));//将int转为string
|
|
|
|
|
QTableWidgetItem *Q4 = new QTableWidgetItem(bornplace);
|
|
|
|
|
Q1->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
Q2->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
Q3->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
Q4->setTextAlignment(Qt::AlignCenter);//内容居中对齐
|
|
|
|
|
ui->tableWidget->setItem(count,0,Q1);//行数 列 内容
|
|
|
|
|
ui->tableWidget->setItem(count,1,Q2);
|
|
|
|
|
ui->tableWidget->setItem(count,2,Q3);
|
|
|
|
|
ui->tableWidget->setItem(count,3,Q4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_checking_out1_clicked()//要连到数据库
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QString count = ui->lineEdit->text() ;//获取行数
|
|
|
|
|
|
|
|
|
|
QString QS = "空闲";
|
|
|
|
|
|
|
|
|
|
QTableWidgetItem *Q1 = new QTableWidgetItem(QS);
|
|
|
|
|
|
|
|
|
|
int c = count.toInt();
|
|
|
|
|
if(c>=0){
|
|
|
|
|
ui->tableWidget->setItem(c,3,Q1);
|
|
|
|
|
Q1->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
QMessageBox::about(this,"提示","退房成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_Reservation1_clicked()//要连到数据库
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QString count = ui->lineEdit->text() ;//获取行数
|
|
|
|
|
|
|
|
|
|
QString QS = "占用";
|
|
|
|
|
|
|
|
|
|
QTableWidgetItem *Q1 = new QTableWidgetItem(QS);
|
|
|
|
|
|
|
|
|
|
int c = count.toInt();
|
|
|
|
|
if(c>=0){
|
|
|
|
|
ui->tableWidget->setItem(c,3,Q1);
|
|
|
|
|
Q1->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
QMessageBox::about(this,"提示","订房成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_commandLinkButton_clicked()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
this->hide();
|
|
|
|
|
lg->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_toolButton_2_clicked()
|
|
|
|
|
{
|
|
|
|
|
findall();
|
|
|
|
|
flush_data(userinfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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::on_radioButton_clicked(bool checked)
|
|
|
|
|
{
|
|
|
|
|
if(checked){
|
|
|
|
|
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
|
|
|
|
|
ui->radioButton_2->setChecked(false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ui->radioButton_2->setChecked(true);
|
|
|
|
|
on_radioButton_2_clicked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_radioButton_2_clicked(bool checked)
|
|
|
|
|
{
|
|
|
|
|
if(checked) {ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
ui->radioButton->setChecked(false);
|
|
|
|
|
}else {
|
|
|
|
|
ui->radioButton->setChecked(true);
|
|
|
|
|
on_radioButton_clicked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void customer::findall()
|
|
|
|
|
{
|
|
|
|
|
userinfo.clear();
|
|
|
|
|
QSqlQuery query((db));
|
|
|
|
|
query.prepare("select * from hotel;");
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
userinfo.push_back(rec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void customer::flush_data(QVector<QVector<QString>>&userinfo)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->clear();
|
|
|
|
|
if(!userinfo.size())return;
|
|
|
|
|
ui->tableWidget->setRowCount(userinfo.size());
|
|
|
|
|
ui->tableWidget->setColumnCount(4);
|
|
|
|
|
for(int i=0;i<userinfo.size();i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j=0;j<userinfo[0].size();j++)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->setItem(i,j,new QTableWidgetItem(userinfo[i][j]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","状态"});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void customer::on_tableWidget_itemClicked(QTableWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
int row = item->row();
|
|
|
|
|
QString r = QString::number(row);
|
|
|
|
|
ui->lineEdit->setText(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void customer::on_search_clicked()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QString number=ui->search->text();
|
|
|
|
|
if(find_byname(number))
|
|
|
|
|
{
|
|
|
|
|
flush_data(userinfo);
|
|
|
|
|
userinfo.clear();
|
|
|
|
|
}else QMessageBox::critical(nullptr, "错误", "something wrong!", QMessageBox::Retry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool customer::find_byname(QString number)
|
|
|
|
|
{
|
|
|
|
|
userinfo.clear();
|
|
|
|
|
QSqlQuery query(db);
|
|
|
|
|
query.prepare("select * from users where username=:number;");
|
|
|
|
|
query.bindValue(":number",number);
|
|
|
|
|
if(query.exec())
|
|
|
|
|
{
|
|
|
|
|
while (query.next()) {
|
|
|
|
|
QVector<QString>rec;
|
|
|
|
|
rec.push_back(query.record().value("房间").toString());
|
|
|
|
|
rec.push_back(query.record().value("房间类型").toString());
|
|
|
|
|
rec.push_back(query.record().value("是否带窗").toString());
|
|
|
|
|
rec.push_back(query.record().value("状态").toString());
|
|
|
|
|
|
|
|
|
|
userinfo.push_back(rec);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|