add mysql support and updata login system

master
HOJI 2 years ago
parent 3d733ea220
commit 582119951a

@ -1,4 +1,4 @@
QT += core gui
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 9.0.2, 2023-08-15T17:53:25. -->
<!-- Written by QtCreator 9.0.2, 2023-08-17T17:27:20. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

@ -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("账号或密码错误!请重新输入"));
}
}

@ -5,6 +5,9 @@
#include <QLabel>
#include <QMessageBox>
#include <QIcon>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
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

@ -87,7 +87,7 @@
<string>注册</string>
</property>
</widget>
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_account">
<property name="geometry">
<rect>
<x>1250</x>
@ -108,7 +108,7 @@
<string>账号:</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_password">
<property name="geometry">
<rect>
<x>1250</x>
@ -129,7 +129,7 @@
<string>密码:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="lineEdit_account">
<property name="geometry">
<rect>
<x>1400</x>
@ -144,7 +144,7 @@
</font>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<widget class="QLineEdit" name="lineEdit_password">
<property name="geometry">
<rect>
<x>1400</x>
@ -159,7 +159,7 @@
</font>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="btn_info">
<property name="geometry">
<rect>
<x>1800</x>
@ -176,7 +176,7 @@ background-color: rgba(0, 0, 0, 0);</string>
<string/>
</property>
</widget>
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>

Loading…
Cancel
Save