diff --git a/Hotel_Management.pro b/Hotel_Management.pro index bba7c73..b38907d 100644 --- a/Hotel_Management.pro +++ b/Hotel_Management.pro @@ -13,19 +13,22 @@ SOURCES += \ customer.cpp \ main.cpp \ login.cpp \ - receptionist.cpp + receptionist.cpp \ + registers.cpp HEADERS += \ administration.h \ customer.h \ login.h \ - receptionist.h + receptionist.h \ + registers.h FORMS += \ administration.ui \ customer.ui \ login.ui \ - receptionist.ui + receptionist.ui \ + registers.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/Hotel_Management.pro.user b/Hotel_Management.pro.user index 9b0b03b..56394a9 100644 --- a/Hotel_Management.pro.user +++ b/Hotel_Management.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/customer.cpp b/customer.cpp index 05b2314..49d0cc7 100644 --- a/customer.cpp +++ b/customer.cpp @@ -1,5 +1,4 @@ #include "customer.h" -#include "login.h" #include "ui_customer.h" customer::customer(QWidget *parent) : @@ -7,241 +6,9 @@ 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()) { - QVectorrec; - for(int i=0;i>&userinfo) -{ - ui->tableWidget->clear(); - if(!userinfo.size())return; - ui->tableWidget->setRowCount(userinfo.size()); - ui->tableWidget->setColumnCount(4); - for(int i=0;itableWidget->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()) { - QVectorrec; - 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; -} diff --git a/customer.h b/customer.h index ad60c12..ea9f291 100644 --- a/customer.h +++ b/customer.h @@ -1,12 +1,7 @@ #ifndef CUSTOMER_H #define CUSTOMER_H -#include "login.h" #include -#include -#include -#include -#include namespace Ui { class customer; @@ -19,44 +14,9 @@ class customer : public QMainWindow public: explicit customer(QWidget *parent = nullptr); ~customer(); - void addrow(QString name,QString gender,int age,QString bornplace); - void findall(); - void flush_data(QVector>&userinfo); - bool find_byname(QString name); -private slots: - - - void on_checking_out1_clicked(); - - - void on_Reservation1_clicked(); - - - - void on_commandLinkButton_clicked(); - - void on_toolButton_2_clicked(); - - void on_checkBox_clicked(bool checked); - - void on_checkBox_2_clicked(bool checked); - - void on_checkBox_3_clicked(bool checked); - - void on_radioButton_clicked(bool checked); - - void on_radioButton_2_clicked(bool checked); - - void on_tableWidget_itemClicked(QTableWidgetItem *item); - - void on_search_clicked(); private: Ui::customer *ui; - QLabel *labelone; - login *lg; - QSqlDatabase db; - QVector>userinfo; }; #endif // CUSTOMER_H diff --git a/customer.ui b/customer.ui index f1b32fd..8aa8121 100644 --- a/customer.ui +++ b/customer.ui @@ -6,8 +6,8 @@ 0 0 - 1920 - 1080 + 800 + 600 @@ -17,293 +17,12 @@ - 20 - -50 + 0 + 0 1920 1080 - - - - 1620 - 400 - 40 - 40 - - - - - - - - - - 1620 - 310 - 40 - 40 - - - - 退 - - - - - - 1600 - 230 - 80 - 40 - - - - - 20 - - - - 操作 - - - Qt::AlignCenter - - - - - - 10 - 70 - 281 - 151 - - - - - 70 - - - - color: rgb(85, 255, 255); - - - 宜客酒店 - - - Qt::AlignCenter - - - - - - 1280 - 100 - 160 - 60 - - - - - 20 - - - - 显示全部 - - - - - - 1580 - 100 - 160 - 60 - - - - - - - 1470 - 100 - 81 - 41 - - - - - 20 - - - - 房间号: - - - Qt::AlignCenter - - - - - - 20 - 980 - 201 - 81 - - - - - 30 - - - - 返回 - - - - 40 - 40 - - - - - - - 150 - 300 - 1400 - 600 - - - - - - - 1570 - 600 - 131 - 221 - - - - - - - - - 行表头 - - - true - - - - - - - 列表头 - - - true - - - - - - - 交替背景色 - - - true - - - - - - - - - - - 1760 - 100 - 100 - 60 - - - - - 20 - - - - 搜索 - - - - - - 1350 - 190 - 211 - 101 - - - - - - - - 15 - - - - 当前选中的行: - - - Qt::AlignCenter - - - - - - - true - - - - - - - - - 1570 - 440 - 151 - 151 - - - - - - - 选择单格 - - - true - - - - - - - 选择行 - - - - - @@ -311,8 +30,8 @@ 0 0 - 1920 - 18 + 800 + 17 diff --git a/login.cpp b/login.cpp index 59069b7..c7f519c 100644 --- a/login.cpp +++ b/login.cpp @@ -3,6 +3,7 @@ #include "customer.h" #include "administration.h" #include "receptionist.h" +#include "registers.h" login::login(QWidget *parent) : QMainWindow(parent) @@ -122,3 +123,10 @@ void login::on_btn_login_clicked() } } + +void login::on_btn_register_clicked() +{ + registers *reg = new registers; + reg->show(); +} + diff --git a/login.h b/login.h index 4ed1207..55d1774 100644 --- a/login.h +++ b/login.h @@ -35,6 +35,8 @@ private slots: void on_btn_login_clicked(); + void on_btn_register_clicked(); + private: Ui::login *ui; QLabel *bg; diff --git a/register.jpg b/register.jpg new file mode 100644 index 0000000..9659e45 Binary files /dev/null and b/register.jpg differ diff --git a/registers.cpp b/registers.cpp new file mode 100644 index 0000000..1d9657a --- /dev/null +++ b/registers.cpp @@ -0,0 +1,129 @@ +#include "registers.h" +#include "ui_registers.h" + +registers::registers(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::registers) +{ + ui->setupUi(this); + QIcon logo(":/image/icon/logo.png"); + this->setWindowIcon(logo); + setWindowTitle("宜客酒店"); + this->setFixedSize(800,600); + bg = new QLabel(this); + bg->setScaledContents(true); + bg->setPixmap(QPixmap(":/image/bg/register.jpg")); + bg->lower(); + ui->lineEdit_password->setEchoMode(QLineEdit::Password); + ui->lineEdit_password_r->setEchoMode(QLineEdit::Password); + ui->radioButton_M->setChecked(1); + + 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"); + } +} + +registers::~registers() +{ + delete ui; +} + +void registers::paintEvent(QPaintEvent*) +{ + bg->resize(ui->widget->size()); +} + +bool registers::verify(int x){ + if(x==1){//账号(手机号)判别 + if(ui->lineEdit_account->text().size()!=11){ + return false; + }else{ + QString str = ui->lineEdit_account->text(); + for(int i=0;i<11;i++){ + if(str.at(i)!='1'&&str.at(i)!='2'&&str.at(i)!='3'&&str.at(i)!='4'&&str.at(i)!='5'&&str.at(i)!='6'&&str.at(i)!='7'&&str.at(i)!='8'&&str.at(i)!='9'&&str.at(i)!='0'){ + return false; + } + } + return true; + } + }else if(x==2){//密码判别 + if(ui->lineEdit_password->text().size()<6||ui->lineEdit_password->text().size()>16){ + return false; + }else{ + QString str = ui->lineEdit_password->text(); + int num = str.size(); + for(int i=0;ilineEdit_password->text(),ui->lineEdit_password_r->text())==0){ + return true; + }else{ + return false; + } + }else if(x==4){//姓名判别 + if(ui->lineEdit_name->text().size()>14||ui->lineEdit_name->text()==NULL){ + return false; + }else{ + return true; + } + }else if(x==5){//身份证号判别 + if(ui->lineEdit_id->text().size()!=18){ + return false; + }else{ + QString str = ui->lineEdit_id->text(); + int num = str.size(); + for(int i=0;ihide(); + } +} + +void registers::sign_in(){ + QString gender; + if(ui->radioButton_M->isChecked()){ + gender = "男"; + }else{ + gender = "女"; + } + QString sql = QString("INSERT INTO customer VALUES('%1','%2','%3','%4','%5',NULL);").arg(ui->lineEdit_account->text()).arg(ui->lineEdit_password->text()).arg(ui->lineEdit_name->text()).arg(gender).arg(ui->lineEdit_id->text()); + QSqlQuery query; + query.exec(sql); +} diff --git a/registers.h b/registers.h new file mode 100644 index 0000000..d26df2e --- /dev/null +++ b/registers.h @@ -0,0 +1,38 @@ +#ifndef REGISTERS_H +#define REGISTERS_H + +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class registers; +} + +class registers : public QMainWindow +{ + Q_OBJECT + +public: + explicit registers(QWidget *parent = nullptr); + ~registers(); + +protected: + void paintEvent(QPaintEvent*); + +private slots: + void on_pushButton_clicked(); + +private: + bool verify(int x); + void sign_in(); + Ui::registers *ui; + QLabel *bg; + QSqlDatabase db; +}; + +#endif // REGISTERS_H diff --git a/registers.ui b/registers.ui new file mode 100644 index 0000000..acf1106 --- /dev/null +++ b/registers.ui @@ -0,0 +1,277 @@ + + + registers + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 0 + 0 + 800 + 600 + + + + + + 50 + 50 + 700 + 400 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 确认密码: + + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 身份证: + + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 账号(手机号): + + + + + + + + 12 + + + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 密码: + + + + + + + + 12 + + + + + + + + + 12 + + + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 姓名: + + + + + + + + 12 + + + + + + + + + 12 + + + + + + + + + + 350 + 525 + 100 + 50 + + + + + Microsoft YaHei UI + 14 + false + + + + 注册 + + + + + + 50 + 450 + 700 + 50 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Microsoft YaHei UI + 12 + true + + + + color: rgb(255, 255, 255); + + + 性别: + + + + + + + + 12 + true + + + + color: rgb(255, 255, 255); + + + + + + + + + + + 12 + true + + + + color: rgb(255, 255, 255); + + + + + + + + + + + + + + 0 + 0 + 800 + 17 + + + + + + + + diff --git a/res.qrc b/res.qrc index 8cebefd..f9707c1 100644 --- a/res.qrc +++ b/res.qrc @@ -1,9 +1,11 @@ login.png + register.jpg info.png logo.png + return.png diff --git a/return.png b/return.png new file mode 100644 index 0000000..90266b3 Binary files /dev/null and b/return.png differ