From 582119951a74c37ca2118820f61464b1bca8dac1 Mon Sep 17 00:00:00 2001 From: HOJI Date: Thu, 17 Aug 2023 17:59:05 +0800 Subject: [PATCH] add mysql support and updata login system --- Hotel_Management.pro | 2 +- Hotel_Management.pro.user | 2 +- login.cpp | 66 ++++++++++++++++++++++++++++++++++++++- login.h | 8 ++++- login.ui | 12 +++---- 5 files changed, 80 insertions(+), 10 deletions(-) diff --git a/Hotel_Management.pro b/Hotel_Management.pro index 980cc68..bba7c73 100644 --- a/Hotel_Management.pro +++ b/Hotel_Management.pro @@ -1,4 +1,4 @@ -QT += core gui +QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/Hotel_Management.pro.user b/Hotel_Management.pro.user index ee397a5..9b0b03b 100644 --- a/Hotel_Management.pro.user +++ b/Hotel_Management.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/login.cpp b/login.cpp index 931b280..59069b7 100644 --- a/login.cpp +++ b/login.cpp @@ -17,6 +17,21 @@ login::login(QWidget *parent) bg->setScaledContents(true); bg->setPixmap(QPixmap(":/image/bg/login.png")); bg->lower(); + + 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"); + } + + ui->lineEdit_password->setEchoMode(QLineEdit::Password); + } login::~login() @@ -29,7 +44,7 @@ void login::paintEvent(QPaintEvent*) bg->resize(ui->widget->size()); } -void login::on_pushButton_clicked() +void login::on_btn_info_clicked() { QMessageBox::about(this, tr("关于我们"), tr("《宾馆客房管理系统》\n\n开发团队:\n\n项目总监:\n美术设计:\n程序设计: \n界面设计:\n系统测试:\n\nCopyright© 2023 xxx All Right Reserved.")); } @@ -58,3 +73,52 @@ void login::on_pushButton_4_clicked() admin->show(); } + +void login::on_btn_login_clicked() +{ + bool isfind = false; + QString account = ui->lineEdit_account->text(); + QString password = ui->lineEdit_password->text(); + QSqlQuery query; + query.exec("select * from customer"); + //管理员身份判断 + if(QString::compare(account,"admin")==0&&QString::compare(password,"111111")==0){ + qDebug("login succeed"); + isfind=true; + administration *admin = new administration; + this->hide(); + admin->show(); + }else{ + //客户身份判断 + while(query.next()){ + if(QString::compare(query.value(0).toString(),account)==0&&QString::compare(query.value(1).toString(),password)==0){ + qDebug("login succeed"); + isfind=true; + customer *cus = new customer; + this->hide(); + cus->show(); + break; + } + } + } + //前台身份判断 + if(!isfind){ + query.exec("select * from employee"); + while(query.next()){ + if(QString::compare(query.value(0).toString(),account)==0&&QString::compare(query.value(1).toString(),password)==0){ + qDebug("login succeed"); + isfind=true; + receptionist *rec = new receptionist; + this->hide(); + rec->show(); + break; + } + } + } + //未找到,提示错误 + if(!isfind){ + qDebug("login failed"); + QMessageBox::warning(this,tr("登录提示"),tr("账号或密码错误!请重新输入")); + } +} + diff --git a/login.h b/login.h index 0e2f956..4ed1207 100644 --- a/login.h +++ b/login.h @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include QT_BEGIN_NAMESPACE namespace Ui { class login; } @@ -22,7 +25,7 @@ protected: void paintEvent(QPaintEvent*); private slots: - void on_pushButton_clicked(); + void on_btn_info_clicked(); void on_pushButton_2_clicked(); @@ -30,8 +33,11 @@ private slots: void on_pushButton_4_clicked(); + void on_btn_login_clicked(); + private: Ui::login *ui; QLabel *bg; + QSqlDatabase db; }; #endif // LOGIN_H diff --git a/login.ui b/login.ui index 41b983a..959c172 100644 --- a/login.ui +++ b/login.ui @@ -87,7 +87,7 @@ 注册 - + 1250 @@ -108,7 +108,7 @@ 账号: - + 1250 @@ -129,7 +129,7 @@ 密码: - + 1400 @@ -144,7 +144,7 @@ - + 1400 @@ -159,7 +159,7 @@ - + 1800 @@ -176,7 +176,7 @@ background-color: rgba(0, 0, 0, 0); - + 40