master
2290867136 2 years ago
parent d317218856
commit 08ede05b40

@ -1,14 +1,402 @@
#include "administration.h"
#include "qmessagebox.h"
#include "ui_administration.h"
#include <QDebug>
administration::administration(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::administration)
ui(new Ui::administration){
init();
}
void administration::paintEvent(QPaintEvent*)
{
labels->resize(ui->widget->size());
}
void administration::init()
{
ui->setupUi(this);
this->setFixedSize(1920,1080);
this->setWindowTitle("用户界面");
this->setWindowIcon(QIcon(":image/icon/logo"));
labels = new QLabel(this);
labels->setScaledContents(true);
labels->setFixedSize(1920,1080);
labels->setPixmap(QPixmap(":/image/bg/login.png"));
labels->lower();
ui->HotelTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->AcounTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->AcounTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//表头透明度
ui->AcounTable->verticalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//行头透明度
ui->HotelTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//表头透明度
ui->HotelTable->verticalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(0, 0, 0,30);}");//行头透明度
ui->Add->setEnabled(false);//初始退订按钮灰色
ui->Del->setEnabled(false);//初始退订按钮灰色
ui->Modify->setEnabled(false);//初始退订按钮灰色
ui->Search->setEnabled(false);//初始退订按钮灰色
ui->AcounTable->hide();
ui->HotelTable->hide();
}
void administration::init_account(){
findall2();
flush_data2(userinfo);
ui->AcounTable->setHorizontalHeaderLabels({"客户账号","密码","姓名","性别","身份证"});
}
void administration::init_hotel(){
findall();
flush_data(userinfo);
ui->HotelTable->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态"});
}
administration::~administration()
{
delete ui;
}
//切换到Hotel table,同时关闭Acount table
void administration::on_Hman_clicked()
{
ui->Add->setEnabled(true);//初始退订按钮灰色
ui->Del->setEnabled(true);//初始退订按钮灰色
ui->Modify->setEnabled(true);//初始退订按钮灰色
ui->Search->setEnabled(true);//初始退订按钮灰色
init_hotel();
ui->HotelTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->HotelTable->setSelectionBehavior(QAbstractItemView::SelectRows); //整行选中的方式
ui->HotelTable->setSelectionMode(QAbstractItemView::SingleSelection); //设置可以选中单个
ui->HotelTable->show();
ui->AcounTable->hide();
tool = 1;
}
//切换到Acount table,同时关闭Hotel table
void administration::on_Aman_clicked()
{
ui->Add->setEnabled(true);//初始退订按钮灰色
ui->Del->setEnabled(true);//初始退订按钮灰色
ui->Modify->setEnabled(true);//初始退订按钮灰色
ui->Search->setEnabled(true);//初始退订按钮灰色
init_account();
ui->AcounTable->setSelectionBehavior(QAbstractItemView::SelectRows); //整行选中的方式
ui->AcounTable->setSelectionMode(QAbstractItemView::SingleSelection); //设置可以选中单个
ui->HotelTable->hide();
ui->AcounTable->show();
tool = 0;
}
//增加行 完成
void administration::on_Add_clicked()
{
if(tool == 0){
int cols=ui->AcounTable->columnCount();
int rows=ui->AcounTable->rowCount();
qDebug()<<rows;
ui->AcounTable->insertRow(rows);
for(int i=0;i<cols;i++)
{
ui->AcounTable->setItem(rows,i,new QTableWidgetItem(""));
}
ui->AcounTable->selectRow(rows);
QSqlQuery query((db));
query.prepare("INSERT into customer VALUES(:n,1,1,1,1,NULL);");
query.bindValue(":n",QRandomGenerator::global()->bounded(10000));//随机数 一万以内正整数
query.exec();
QMessageBox::information(this,tr("提示"),("添加成功"));
init_account();
}
else if(tool == 1){
int cols=ui->HotelTable->columnCount();
int rows=ui->HotelTable->rowCount();
qDebug()<<rows;
ui->HotelTable->insertRow(rows);
for(int i=0;i<cols;i++)
{
ui->HotelTable->setItem(rows,i,new QTableWidgetItem(""));
}
ui->HotelTable->selectRow(rows);
QSqlQuery query((db));
query.prepare("INSERT into room VALUES(:n,1,1,1,1,NULL,NULL);");
query.bindValue(":n",QRandomGenerator::global()->bounded(10000));
query.exec();
QMessageBox::information(this,tr("提示"),("添加成功"));
init_hotel();
}
else QMessageBox::about(this,"警告","出错");
}
//删除操作 完成
void administration::on_Del_clicked()
{
if(tool == 0){
QSqlQuery query((db));
QTableWidgetItem *item = ui->AcounTable->currentItem();
QString n = 0;
n = ui->AcounTable->model()->index(item->row(),0).data().toString();//n是房间号
int num = n.toInt();
query.prepare("DELETE from customer where account = :num ");
query.bindValue(":num",num);
query.exec();
if(item==Q_NULLPTR)return;
ui->AcounTable->removeRow(item->row());
QMessageBox::information(this,tr("提示"),("删除成功"));
}
else if(tool == 1){
QSqlQuery query((db));
QTableWidgetItem *item = ui->HotelTable->currentItem();
QString n = 0;
n = ui->HotelTable->model()->index(item->row(),0).data().toString();//n是房间号
int num = n.toInt();
query.prepare("DELETE from room where room_num = :num ");
query.bindValue(":num",num);
query.exec();
if(item==Q_NULLPTR)return;
ui->HotelTable->removeRow(item->row());
QMessageBox::information(this,tr("提示"),("删除成功"));
}
else QMessageBox::about(this,"警告","出错");
}
//修改操作//???
void administration::on_Modify_clicked()
{
int c = row;
if(tool == 0){
QSqlQuery query((db));
QString n1 = 0;
n1 = ui->AcounTable->model()->index(c,0).data().toString();//n是房间号
num = n1.toInt();
QString n2 = "0";
n2 = ui->AcounTable->model()->index(c,1).data().toString();
query.prepare("UPDATE customer set password=:QS where account = :num");
query.bindValue(":QS",n2);
query.bindValue(":num",num);
query.exec();
QString n3 = 0;
n3 = ui->AcounTable->model()->index(c,2).data().toString();
query.prepare("UPDATE customer set name=:QS where account = :num");
query.bindValue(":QS",n3);
query.bindValue(":num",num);
query.exec();
QString n4 = 0;
n4 = ui->AcounTable->model()->index(c,3).data().toString();
query.prepare("UPDATE customer set gender=:QS where account = :num");
query.bindValue(":QS",n4);
query.bindValue(":num",num);
query.exec();
QString n5 = 0;
n5 = ui->AcounTable->model()->index(c,4).data().toString();
query.prepare("UPDATE customer set id=:QS where account = :num");
query.bindValue(":QS",n5);
query.bindValue(":num",num);
query.exec();
init_account();
}
else if(tool == 1){
QSqlQuery query((db));
QString n1 = 0;
n1 = ui->HotelTable->model()->index(c,0).data().toString();//n是房间号
num = n1.toInt();
QString n2 = "0";
n2 = ui->HotelTable->model()->index(c,1).data().toString();
query.prepare("UPDATE room set type=:QS where room_num = :num");
query.bindValue(":QS",n2);
query.bindValue(":num",num);
query.exec();
QString n3 = 0;
n3 = ui->HotelTable->model()->index(c,2).data().toString();
query.prepare("UPDATE room set withwindow=:QS where room_num = :num");
query.bindValue(":QS",n3);
query.bindValue(":num",num);
query.exec();
QString n4 = 0;
n4 = ui->HotelTable->model()->index(c,3).data().toString();
query.prepare("UPDATE room set responsible_person=:QS where room_num = :num");
query.bindValue(":QS",n4);
query.bindValue(":num",num);
query.exec();
QString n5 = 0;
n5 = ui->HotelTable->model()->index(c,4).data().toString();
query.prepare("UPDATE room set status=:QS where room_num = :num");
query.bindValue(":QS",n5);
query.bindValue(":num",num);
query.exec();
init_hotel();
}
QMessageBox::information(this,tr("提示"),("修改成功"));
}
//插入账号数据
void administration::flush_data2(QVector<QVector<QString>>&userinfo)//插入数据 完成
{
ui->AcounTable->clear();
if(!userinfo.size())return;
ui->AcounTable->setRowCount(userinfo.size());//行
ui->AcounTable->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->AcounTable->setItem(i,j,QW);//行 列 内容
QW->setTextAlignment(Qt::AlignCenter);//设置中心对齐
}
}
}
//插入客房数据
void administration::flush_data(QVector<QVector<QString>>&userinfo)//插入数据 完成
{
ui->HotelTable->clear();
if(!userinfo.size())return;
ui->HotelTable->setRowCount(userinfo.size());//行
ui->HotelTable->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->HotelTable->setItem(i,j,QW);//行 列 内容
QW->setTextAlignment(Qt::AlignCenter);//设置中心对齐
}
}
}
//搜索
void administration::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 administration::findall2()//显示全部 完成
{
userinfo.clear();//清楚存储向量rec的向量的数据
QSqlQuery query((db));
query.prepare("select * from customer");
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 administration::on_Search_clicked()
{
QString number=ui->lineEdit->text();
if(number == NULL && tool == 0){
findall2();
flush_data2(userinfo);
}
else if(number == NULL && tool == 1){
findall();
flush_data(userinfo);
}
else if(find_byname2(number) && tool == 0)
{
flush_data2(userinfo);
userinfo.clear();
}
else if(find_byname(number) && tool == 1){
flush_data(userinfo);
userinfo.clear();
}
else QMessageBox::critical(nullptr, "错误", "未知的错误", QMessageBox::Retry);
ui->AcounTable->setHorizontalHeaderLabels({"客户账号","密码","姓名","性别","身份证"});
ui->HotelTable->setHorizontalHeaderLabels({"房间号","房间类型","是否带窗","负责人","状态"});//设置表头
}
bool administration::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;
}
bool administration::find_byname2(QString n)//搜索
{
userinfo.clear();
QSqlQuery query(db);
query.prepare("select * from customer where account like :number;");//以开头搜索 不行
query.bindValue(":number",n);
if(query.exec())
{
while (query.next()) {
QVector<QString>rec;
rec.push_back(query.record().value("account").toString());
rec.push_back(query.record().value("password").toString());
rec.push_back(query.record().value("name").toString());
rec.push_back(query.record().value("gender").toString());
rec.push_back(query.record().value("id").toString());
userinfo.push_back(rec);
}
return true;
}
return false;
}
void administration::on_AcounTable_itemClicked(QTableWidgetItem *item)
{
row = item->row();
qDebug() << "当前选中行: " << row;
}
void administration::on_HotelTable_itemClicked(QTableWidgetItem *item)
{
row = item->row();
qDebug() << "当前选中行: " << row;
}

@ -1,7 +1,20 @@
#ifndef ADMINISTRATION_H
#define ADMINISTRATION_H
#include "login.h"
#include <QLabel>
#include <QTableWidget>
#include <QStringList>
#include <QApplication>
#include <QMainWindow>
#include <QIcon>
#include <QMessageBox>
#include <QTableWidgetItem>
#include <QSqlRecord>
#include <resetmessage.h>
#include <QDate>
#include <QRandomGenerator>
namespace Ui {
class administration;
@ -14,9 +27,46 @@ class administration : public QMainWindow
public:
explicit administration(QWidget *parent = nullptr);
~administration();
void init();
void findall();
void findall2();
void init_hotel();
void init_account();
private slots:
void on_Aman_clicked();
void on_Add_clicked();
void on_Del_clicked();
void on_Hman_clicked();
void on_Modify_clicked();
void on_Search_clicked();
void on_AcounTable_itemClicked(QTableWidgetItem *item);
void on_HotelTable_itemClicked(QTableWidgetItem *item);
protected:
void paintEvent(QPaintEvent*);
private:
Ui::administration *ui;
QTableWidget *TableWidget;
QLabel *labels;
void flush_data(QVector<QVector<QString>>&userinfo);
void flush_data2(QVector<QVector<QString>>&userinfo);
QVector<QVector<QString>>userinfo;
bool find_byname(QString name);
bool find_byname2(QString name);
QSqlDatabase db;
int row;
int n = 1000;
int m =1000;
int tool = 0;
int num;
};
#endif // ADMINISTRATION_H

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>2079</width>
<height>1453</height>
</rect>
</property>
<property name="windowTitle">
@ -17,12 +17,257 @@
<widget class="QWidget" name="widget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<x>50</x>
<y>-20</y>
<width>1920</width>
<height>1080</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>-10</x>
<y>-20</y>
<width>531</width>
<height>321</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>70</pointsize>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:72pt; font-weight:700; color:#00ffff;&quot;&gt;宜客酒店&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="Hman">
<property name="geometry">
<rect>
<x>980</x>
<y>90</y>
<width>291</width>
<height>61</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>客房管理</string>
</property>
</widget>
<widget class="QPushButton" name="Aman">
<property name="geometry">
<rect>
<x>1290</x>
<y>90</y>
<width>271</width>
<height>61</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>账号管理</string>
</property>
</widget>
<widget class="QTableWidget" name="AcounTable">
<property name="geometry">
<rect>
<x>120</x>
<y>290</y>
<width>1531</width>
<height>731</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0,50);
color: rgb(255, 255, 255);</string>
</property>
<column>
<property name="text">
<string>1</string>
</property>
</column>
<column>
<property name="text">
<string>2</string>
</property>
</column>
<column>
<property name="text">
<string>3</string>
</property>
</column>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>1290</x>
<y>200</y>
<width>161</width>
<height>71</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="Modify">
<property name="geometry">
<rect>
<x>1680</x>
<y>510</y>
<width>161</width>
<height>101</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>更改</string>
</property>
</widget>
<widget class="QPushButton" name="Search">
<property name="geometry">
<rect>
<x>1450</x>
<y>200</y>
<width>111</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>搜索</string>
</property>
</widget>
<widget class="QPushButton" name="Add">
<property name="geometry">
<rect>
<x>1680</x>
<y>290</y>
<width>161</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>添加</string>
</property>
</widget>
<widget class="QPushButton" name="Del">
<property name="geometry">
<rect>
<x>1680</x>
<y>400</y>
<width>161</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<property name="text">
<string>删除</string>
</property>
</widget>
<widget class="QTableWidget" name="HotelTable">
<property name="geometry">
<rect>
<x>120</x>
<y>290</y>
<width>1531</width>
<height>731</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0,50);
color: rgb(255, 255, 255);</string>
</property>
<column>
<property name="text">
<string>1</string>
</property>
</column>
<column>
<property name="text">
<string>2</string>
</property>
</column>
<column>
<property name="text">
<string>3</string>
</property>
</column>
<column>
<property name="text">
<string>4</string>
</property>
</column>
<column>
<property name="text">
<string>5</string>
</property>
</column>
</widget>
<zorder>label</zorder>
<zorder>lineEdit</zorder>
<zorder>Aman</zorder>
<zorder>Hman</zorder>
<zorder>Modify</zorder>
<zorder>AcounTable</zorder>
<zorder>Search</zorder>
<zorder>Add</zorder>
<zorder>Del</zorder>
<zorder>HotelTable</zorder>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
@ -30,8 +275,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>17</height>
<width>2079</width>
<height>18</height>
</rect>
</property>
</widget>

Loading…
Cancel
Save