Add login window, move database open from SelectFormWidget to login window.
This commit is contained in:
@@ -65,7 +65,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
table->verticalHeader()->setDefaultSectionSize(38);
|
table->verticalHeader()->setDefaultSectionSize(38);
|
||||||
table->horizontalHeader()->setStretchLastSection(true);
|
table->horizontalHeader()->setStretchLastSection(true);
|
||||||
//dat from SQLITE
|
//dat from SQLITE
|
||||||
SQLHelper::Open();
|
|
||||||
auto model = SQLHelper::getTable("Patient");
|
auto model = SQLHelper::getTable("Patient");
|
||||||
model->select();
|
model->select();
|
||||||
model->setHeaderData(1,Qt::Horizontal,"ID");
|
model->setHeaderData(1,Qt::Horizontal,"ID");
|
||||||
|
|||||||
184
src/loginwindow.cpp
Normal file
184
src/loginwindow.cpp
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
#include "loginwindow.h"
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <qDebug>
|
||||||
|
#include <QInputMethodEvent>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include "guimacros.h"
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include "db/SQLHelper.h"
|
||||||
|
#define splitFlag QString("-")
|
||||||
|
|
||||||
|
LoginWindow::LoginWindow(QWidget* parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_pLoginButton(nullptr)
|
||||||
|
, m_pVMainLayout(nullptr)
|
||||||
|
, m_pUserCodeFrame(nullptr)
|
||||||
|
, m_pUserCodeLayout(nullptr)
|
||||||
|
, m_pUserCodeEdit(nullptr)
|
||||||
|
, m_pPassWordEdit(nullptr)
|
||||||
|
{
|
||||||
|
initUi();
|
||||||
|
init();
|
||||||
|
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
||||||
|
//Dialog::Instance()->InitForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginWindow::~LoginWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void LoginWindow::initUi()
|
||||||
|
{
|
||||||
|
QString style = "*{background-color:#3c3c3c; font-family:Microsoft YaHei; color:white;margin:0;font-size:16px;}"
|
||||||
|
"QLabel#title{font-Size:98px;color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
||||||
|
"stop: 0.0 darkgray, stop: 0.5 lightgray, stop: 1.0 darkgray);}"
|
||||||
|
"QLabel#warn{color:#930000;background:transparent;font-size:20px;}"
|
||||||
|
"QFrame#login_frame_username{min-width:700px;max-width:700px;max-height:500px;min-height:500px;"
|
||||||
|
"border:1px solid #0078d8;border-radius:20px;"
|
||||||
|
"background:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\n"
|
||||||
|
" stop: 0.0 darkgray, stop: 0.5 gray, stop: 1.0 darkgray);"
|
||||||
|
"}"
|
||||||
|
"QLineEdit{min-height:100px;max-height:100px; border:1px solid silver;border-radius:10px;font-size:26px;}"
|
||||||
|
"QLineEdit:enabled{background-color: #515151}"
|
||||||
|
"QComboBox{text-align:center;min-height:100px;max-height:100px; "
|
||||||
|
"border:1px solid silver;border-radius:10px;padding:3px}"
|
||||||
|
"QComboBox:enabled{background-color: #515151}"
|
||||||
|
"QComboBox::drop-down{width:80px;border-radius:10px}"
|
||||||
|
"QComboBox QAbstractItemView{min-width:120px;}"
|
||||||
|
"QComboBox QAbstractItemView::item {min-height:60px;max-height:60px; border:1px solid white;}"
|
||||||
|
"QToolButton{min-height:100px;max-height:100px;border:1px solid #505050;"
|
||||||
|
"border-radius:10%;font-size:26px; font-weight:Bold;padding:5px;}"
|
||||||
|
"QToolButton:hover{background:#505050;}";
|
||||||
|
setStyleSheet(style);
|
||||||
|
|
||||||
|
m_pVMainLayout = new QVBoxLayout(this);
|
||||||
|
m_pVMainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_pVMainLayout->setSpacing(0);
|
||||||
|
m_pVMainLayout->addSpacerItem(new QSpacerItem(20,20,QSizePolicy::Minimum,QSizePolicy::Expanding));
|
||||||
|
|
||||||
|
QLabel* title = new QLabel(this);
|
||||||
|
title->setObjectName("title");
|
||||||
|
title->setText("U S C T");
|
||||||
|
m_pVMainLayout->addWidget(title,0,Qt::AlignCenter);
|
||||||
|
m_pUserCodeFrame = new QFrame(this);
|
||||||
|
m_pUserCodeFrame->setObjectName("login_frame_username");
|
||||||
|
m_pUserCodeLayout = new QVBoxLayout(m_pUserCodeFrame);
|
||||||
|
m_pUserCodeLayout->setSpacing(30);
|
||||||
|
m_pUserCodeLayout->setContentsMargins(20,60,20,20);
|
||||||
|
warn = new QLabel(this);
|
||||||
|
warn->setObjectName("warn");
|
||||||
|
warn->setText("Login failed, username or password error!");
|
||||||
|
warn->setVisible(false);
|
||||||
|
m_pUserCodeLayout->addWidget(warn,0,Qt::AlignCenter);
|
||||||
|
m_pUserCodeEdit = new QLineEdit(m_pUserCodeFrame);
|
||||||
|
m_pUserCodeEdit->setObjectName("combobox_UserName");
|
||||||
|
|
||||||
|
//m_pUserCodeEdit->setLineEdit(new QLineEdit(m_pUserCodeFrame));
|
||||||
|
|
||||||
|
m_pUserCodeEdit->setPlaceholderText(tr("Username"));
|
||||||
|
m_pUserCodeLayout->addWidget(m_pUserCodeEdit);
|
||||||
|
m_pVMainLayout->addWidget(m_pUserCodeFrame,0,Qt::AlignCenter);
|
||||||
|
|
||||||
|
m_pPassWordEdit = new QLineEdit(this);
|
||||||
|
m_pPassWordEdit->setObjectName("edt_Password");
|
||||||
|
m_pPassWordEdit->setEchoMode(QLineEdit::Password);
|
||||||
|
m_pPassWordEdit->setPlaceholderText(tr("Password"));
|
||||||
|
m_pUserCodeLayout->addWidget(m_pPassWordEdit);
|
||||||
|
|
||||||
|
ADD_TOOL_BTN_TO_LAYOUT(login,":/icons/login.png",m_pUserCodeLayout);
|
||||||
|
m_pUserCodeLayout->removeWidget(btnlogin);
|
||||||
|
m_pUserCodeLayout->addWidget(btnlogin,0,Qt::AlignCenter);
|
||||||
|
m_pLoginButton = btnlogin;
|
||||||
|
// m_pUserCodeLayout->addWidget(m_pLoginButton, 0, Qt::AlignCenter);
|
||||||
|
m_pVMainLayout->addSpacerItem(new QSpacerItem(20,20,QSizePolicy::Minimum,QSizePolicy::Expanding));
|
||||||
|
|
||||||
|
initUserList();
|
||||||
|
SQLHelper::Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginWindow::init()
|
||||||
|
{
|
||||||
|
connect(m_pLoginButton, SIGNAL(clicked()), this, SLOT(doLogin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginWindow::initUserList()
|
||||||
|
{
|
||||||
|
// userList = UserService::queryUserInfo("");
|
||||||
|
// for (int i = 0; i < userList.count(); i++)
|
||||||
|
// {
|
||||||
|
// QString userCode = userList.at(i)->getUserCode();
|
||||||
|
// //QString userName = userList.at(i)->getUserName();
|
||||||
|
// //m_pUserCodeEdit->addItem(userCode + splitFlag + userName);
|
||||||
|
// m_pUserCodeEdit->addItem(userCode);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginWindow::clearInputData()
|
||||||
|
{
|
||||||
|
m_pUserCodeEdit->clear();
|
||||||
|
m_pPassWordEdit->clear();
|
||||||
|
//m_pUserCodeEdit->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString getEncryptedPassword(const QString& password)
|
||||||
|
{
|
||||||
|
QByteArray bytePwd = password.toLatin1();
|
||||||
|
QByteArray bytePwdMd5 = QCryptographicHash::hash(bytePwd, QCryptographicHash::Md5);
|
||||||
|
return bytePwdMd5.toHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void LoginWindow::doLogin()
|
||||||
|
{
|
||||||
|
QString strUserCode = m_pUserCodeEdit->text();
|
||||||
|
QString strPassWord = m_pPassWordEdit->text();
|
||||||
|
|
||||||
|
QString encryptedPassword = strPassWord;
|
||||||
|
strPassWord = "12345678";
|
||||||
|
|
||||||
|
|
||||||
|
QString encryptPwd = getEncryptedPassword(strPassWord);
|
||||||
|
qDebug()<<encryptPwd;
|
||||||
|
QString sql = QString("select UserCode from Account where UserCode='%1' and Password='%2'")
|
||||||
|
.arg(strUserCode).arg(encryptPwd);
|
||||||
|
qDebug()<<sql;
|
||||||
|
if (SQLHelper::QueryCount(sql)>0)
|
||||||
|
{
|
||||||
|
accept();
|
||||||
|
} else{
|
||||||
|
warn->setVisible(true);
|
||||||
|
}
|
||||||
|
// bool isLoginSuccess = UserService::ValidateAccount(strUserCode, encryptedPassword);
|
||||||
|
// if (isLoginSuccess)
|
||||||
|
// {
|
||||||
|
// accept();
|
||||||
|
// emit sigUserLoginSuccessful(strUserCode);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// EQ9MessageBox box;
|
||||||
|
// box.setMessage(tr("login failed, please check input data"));
|
||||||
|
// box.exec();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
//void LoginWindow::onUserCodeFocusOut(QFocusEvent* e)
|
||||||
|
//{
|
||||||
|
// Q_UNUSED(e);
|
||||||
|
//
|
||||||
|
// QString wholeText = m_pUserCodeEdit->currentText();
|
||||||
|
// int flagPosition = wholeText.indexOf(splitFlag);
|
||||||
|
// if(flagPosition > 0)
|
||||||
|
// {
|
||||||
|
// QString userCode = wholeText.left(flagPosition);
|
||||||
|
// m_pUserCodeEdit->setCurrentText(userCode);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
48
src/loginwindow.h
Normal file
48
src/loginwindow.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef LOGINWINDOW_H
|
||||||
|
#define LOGINWINDOW_H
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
|
||||||
|
class QVBoxLayout;
|
||||||
|
class QLineEdit;
|
||||||
|
class QToolButton;
|
||||||
|
class QFrame;
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
|
class LoginWindow : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
LoginWindow(QWidget* parent = nullptr);
|
||||||
|
~LoginWindow() override;
|
||||||
|
|
||||||
|
void initUi();
|
||||||
|
void init();
|
||||||
|
void clearInputData();
|
||||||
|
signals:
|
||||||
|
void sigUserLoginSuccessful(const QString& userCode);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void doLogin();
|
||||||
|
//void onUserCodeFocusOut(QFocusEvent* e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initUserList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QVBoxLayout* m_pVMainLayout;
|
||||||
|
QFrame* m_pUserCodeFrame;
|
||||||
|
QVBoxLayout* m_pUserCodeLayout;
|
||||||
|
QLineEdit* m_pUserCodeEdit;
|
||||||
|
QLineEdit* m_pPassWordEdit;
|
||||||
|
QToolButton* m_pLoginButton;
|
||||||
|
QLabel* warn;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGINWINDOW_H
|
||||||
Reference in New Issue
Block a user