opencv_mv/QMainPro/QMacVisual/frmLogin.cpp

182 lines
5.8 KiB
C++
Raw Permalink Normal View History

2023-05-22 09:27:46 +00:00
#include "frmLogin.h"
#include <QMessageBox>
#include <QTime>
#include "datavar.h"
using namespace std;
frmLogin::frmLogin(QWidget*parent)
: BaseWindow(parent)
{
ui.setupUi(this);
this->setWindowIcon(QIcon(":/res/ico/user.png"));
connect(this, &frmLogin::sendInStateSignal, dataVar::m_pWindow, &MainWindow::slot_LoginBtnState);
connect(this, &frmLogin::sendOutStateSignal, dataVar::m_pWindow, &MainWindow::slot_LogoutBtnState);
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
initTitleBar();
//<2F><><EFBFBD><EFBFBD>Tab˳<62><CBB3>
ui.txtUserName->setFocus();
setTabOrder(ui.txtUserName, ui.txtUserPW);
setTabOrder(ui.txtUserPW, ui.btnLogout);
setTabOrder(ui.btnLogout, ui.btnLogin);
form_load();
ui.txtUserPW->setEchoMode(QLineEdit::Password);
}
frmLogin::~frmLogin()
{
this->deleteLater();
}
void frmLogin::initTitleBar()
{
m_titleBar->setBackgroundColor(3, 110, 95);
m_titleBar->setStyleSheet("background-color: rgba(0, 0, 0,0);color:white;font-size:16px");
m_titleBar->setTitleIcon(":/res/ico/user.png");
m_titleBar->setTitleContent("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>¼");
m_titleBar->setButtonType(ONLY_CLOSE_BUTTON);
m_titleBar->setTitleWidth(this->width());
}
void frmLogin::paintEvent(QPaintEvent* event)
{
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
QPainter painter(this);
QPainterPath pathBack;
pathBack.setFillRule(Qt::WindingFill);
pathBack.addRoundedRect(QRect(0, 0, this->width(), this->height()), 3, 3);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.fillPath(pathBack, QBrush(QColor("#bcc2bc")));
return QWidget::paintEvent(event);
}
void frmLogin::form_load()
{
//SQLite<74><65><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
QFileInfo file(dataVar::path_DB + "MyDataBase.db");
if (!file.exists())
{
dataVar::bol_connect = dataVar::sqlite.CreateConnectDB(dataVar::soft_key, dataVar::path_DB + "MyDataBase.db", dataVar::database);
if (dataVar::bol_connect == true)
{
dataVar::sqlite.CreateTable(dataVar::soft_key, "LoginTable");
dataVar::sqlite.InsertData(dataVar::soft_key, "LoginTable", "fz_lcl", "666666");
}
}
if (dataVar::login_state == 1)
{
ui.txtUserName->setText(dataVar::user_name);
}
}
void frmLogin::on_btnLogout_clicked()
{
if (dataVar::login_state == 1)
{
dataVar::startTime = QDateTime();
emit sendOutStateSignal();
dataVar::login_state = 0;
dataVar::admin_login_state = 0;
emit dataVar::fProItemTab->sig_InfoClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>: " + dataVar::user_name + "<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
dataVar::user_name = QString();
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/info.png"));
msgBox.exec();
}
else
{
emit dataVar::fProItemTab->sig_WarnClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/warn.png"));
msgBox.exec();
}
}
void frmLogin::on_btnLogout_pressed()
{
ui.btnLogout->setStyleSheet("QPushButton{background-color: rgb(255, 207, 130);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
}
void frmLogin::on_btnLogout_released()
{
ui.btnLogout->setStyleSheet("QPushButton{background-color: rgb(255, 163, 97);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
}
void frmLogin::on_btnLogin_clicked()
{
if (dataVar::login_state == 1)
{
emit dataVar::fProItemTab->sig_WarnClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>: " + dataVar::user_name + "<EFBFBD>ѵ<EFBFBD>¼<EFBFBD><EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>: " + dataVar::user_name + "<EFBFBD>ѵ<EFBFBD>¼<EFBFBD><EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/warn.png"));
msgBox.exec();
return;
}
if (dataVar::bol_connect == false)
{
dataVar::bol_connect = dataVar::sqlite.CreateConnectDB(dataVar::soft_key, dataVar::path_DB + "/MyDataBase.db", dataVar::database);
}
if (dataVar::bol_connect == true)
{
if (ui.txtUserName->text() == "" || ui.txtUserPW->text() == "")
{
emit dataVar::fProItemTab->sig_WarnClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/warn.png"));
msgBox.exec();
return;
}
else
{
QString password;
bol_query = dataVar::sqlite.QueryData(dataVar::soft_key, ui.txtUserName->text(), password);
if (bol_query == true && password == ui.txtUserPW->text() && password != "")
{
emit sendInStateSignal();
dataVar::login_state = 1;
if (ui.txtUserName->text() == "fz_lcl")
{
dataVar::admin_login_state = 1;
}
ui.txtUserPW->setText("");
dataVar::user_name = ui.txtUserName->text();
dataVar::startTime = QDateTime::currentDateTime();
emit dataVar::fProItemTab->sig_InfoClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>: " + dataVar::user_name + "<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/info.png"));
msgBox.exec();
}
else
{
emit dataVar::fProItemTab->sig_ErrorClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/error.png"));
msgBox.exec();
}
}
}
else
{
emit dataVar::fProItemTab->sig_ErrorClick();
emit dataVar::fProItemTab->sig_Log("<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>");
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>");
msgBox.setWindowIcon(QIcon(":/res/ico/error.png"));
msgBox.exec();
}
}
void frmLogin::on_btnLogin_pressed()
{
ui.btnLogin->setStyleSheet("QPushButton{background-color: rgb(146, 217, 108);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
}
void frmLogin::on_btnLogin_released()
{
ui.btnLogin->setStyleSheet("QPushButton{background-color: rgb(85, 170, 127);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
}