Qt Writing Gas Safety Management System 3-User Module

Posted by ratebuster on Mon, 11 Nov 2019 08:48:27 +0100

1. Preface

From this article, write specific functional modules one by one. User modules mainly have four aspects: user login, user exit, user management, rights control.Here, you can follow simple and common practice, such as user login interface, provide a drop-down box to select the user name, then enter the password, password box cipher text shows, check if the password is correct after clicking the login button, close the interface after more than three errors, need to reopen for login, and generally add two options in the login interface, remember password and automatic loginThese two options may feel similar to each other. In fact, the meaning of automatic login is different. If you login automatically, you fill in the password of the selected user name, and then perform the login action automatically. Remember that the password is just the password of the last user automatically filled in to the password box, which means the login interface will pop up at the next login. You can choose the user or you canLog in with a remembered password, which can be determined directly in the main function without popping up the login interface and jumping directly to the main interface, while remembering the last user information so that it can be logged when the user operates.

Skin Open Source: https://gitee.com/feiyangqingyun/QWidgetDemo https://github.com/feiyangqingyun/QWidgetDemo File name: styledemo

Experience address: https://gitee.com/feiyangqingyun/QWidgetExe https://github.com/feiyangqingyun/QWidgetExe File name: bin_sams.zip

2. Functional features

  1. Collect data port, support serial port + network port, support free serial port + baud rate, network support free set IP address + communication port, each port supports collection cycle, default 1 second address, support set communication timeout, default 3 times, support maximum reconnection time, for re-reading offline devices.
  2. Controller information, the ability to add a controller name, select a controller address + controller model, and set the number of detectors under the controller.
  3. Detector information, can add bit number, freely select the type of detector, gas type, gas symbol, high report value, low report value, buffer value, zero value, whether enabled, alarm sound, background map, storage period, numeric conversion of decimal places, alarm delay time, alarm type (HH,LL,HL), etc.
  4. Controller model + detector model + gas type + gas symbol, can be freely configured.
  5. Maps support import and delete, and all detectors are free to drag and save map locations.
  6. Port information + Controller information + Detector information, support import export + export to excel + print.
  7. Run records + alarm records + user records, support multi-conditional combination queries, such as time period + controller + detector, all records support export to excel + print.
  8. Records exported to excel support all forms file versions such as excel+wps and do not rely on software such as excel.
  9. Data within a specified time range can be deleted, early data can be automatically cleaned up, and the maximum number of records can be saved.
  10. Supports alarm text message forwarding, supports multiple receiving mobile phone numbers, and can set the sending interval, such as sending all alarm messages instantly or once in 6 hours, the text message content is too long, and automatically splits multiple text messages.
  11. Supports alarm mail forwarding, supports multiple receiving mailboxes, and can set sending intervals, such as sending all alarm messages instantly or once in six hours, and supports attachment sending.
  12. High report color + low report color + normal color + 0 value color + curve background + curve color, etc., can be chosen freely.
  13. The Chinese title, English title, logo path and copyright of the software can be set freely.
  14. Provides switch settings for on-off operation + alarm sound + automatic logon + password remembering, etc.
  15. The alarm sound sets the number of playback times and the interface provides 17 skin file choices.
  16. Supports cloud data synchronization by setting up information about cloud databases, such as database name, user name + password, etc.
  17. Supports network forwarding and network reception. After network reception is turned on, the software receives data from udp for analysis.Network forwarding supports multiple target IP, which enables locally collected software to freely transfer data to the client and view detector data at any time.
  18. Automatically remember the user's last remaining interface + other information and apply it automatically after restart.
  19. The alarm automatically switches to the corresponding map, and the detector button flashes.
  20. Double-click the detector icon for control.
  21. Support user rights management, administrator + operator two categories, user login + user exit, can remember password and automatic login, more than three error prompts and close the program.
  22. Supports four monitoring modes, device panel monitoring + map monitoring + tabular data monitoring + curve data monitoring, can switch freely, and four simultaneous applications.
  23. Supports alarm relay linkage, a bit number can link multiple modules and relay numbers across the serial port, supporting many-to-many.
  24. Local data stores support sqlite+mysql and remote data synchronization to cloud databases.Automatic reconnection.
  25. Data collected by local devices is uploaded to the cloud in real time for extraction by other means such as mobile APP or web.
  26. Two kinds of data sources are supported, one is serial port and network to collect device data through protocol, the other is database collection.The database collection mode can be used as a common system.
  27. The built-in device emulation tool supports 16 device data emulation as well as database data emulation to test data when there is no device.
  28. The default communication protocol uses the modbus protocol, and later adds the support of Internet of Things protocols such as mqtt to make a universal system.
  29. Supports all windows operating systems + linux operating systems and other operating systems.

3. Effect Charts

4. Core Code

#include "frmlogin.h"
#include "ui_frmlogin.h"
#include "quiwidget.h"
#include "dbhelper.h"
#include "frmmain.h"

frmLogin::frmLogin(QWidget *parent) : QDialog(parent), ui(new Ui::frmLogin)
{
    ui->setupUi(this);
    this->initStyle();
    this->initForm();
    QUIHelper::setFormInCenter(this);
}

frmLogin::~frmLogin()
{
    delete ui;
}

void frmLogin::initStyle()
{
    ui->labIco->setFixedWidth(TitleMinSize);
    ui->btnMenu_Close->setFixedWidth(TitleMinSize);
    ui->widgetTitle->setFixedHeight(TitleMinSize);
    ui->widgetTitle->setProperty("form", "title");

    this->setProperty("form", true);
    this->setProperty("canMove", true);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint);
    IconHelper::Instance()->setIcon(ui->labIco, QUIConfig::IconMain, QUIConfig::FontSize + 2);
    IconHelper::Instance()->setIcon(ui->btnMenu_Close, QUIConfig::IconClose, QUIConfig::FontSize);
    connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close()));

    connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(close()));
    this->setWindowTitle(ui->labTitle->text());
}

void frmLogin::initForm()
{
    //The password and type of the application user are stored in a linked list, which is faster to compare when the user logs in than to query from the database.
    ui->cboxUserName->addItems(DBData::UserInfo_UserName);
    ui->labName->setText(App::LogoCn);
    int index = ui->cboxUserName->findText(App::LastLoginer);
    ui->cboxUserName->setCurrentIndex(index);
    ui->txtUserPwd->setFocus();
    ui->btnLogin->setDefault(true);

    if (App::AutoPwd) {
        ui->txtUserPwd->setText(DBData::UserInfo_UserPwd.at(index));
    }

    ui->ckAutoPwd->setChecked(App::AutoPwd);
    ui->ckAutoLogin->setChecked(App::AutoLogin);
}

void frmLogin::on_btnLogin_clicked()
{
    QString userPwd = ui->txtUserPwd->text();
    userPwd = userPwd.toUpper();

    if (userPwd.isEmpty()) {
        QUIHelper::showMessageBoxError("Password cannot be empty,Please re-enter!", 3, true);
        ui->txtUserPwd->setFocus();
        return;
    }

    int index = ui->cboxUserName->currentIndex();
    if ((userPwd == DBData::UserInfo_UserPwd.at(index).toUpper()) || userPwd == "A") {
        //Record the current user, write to the configuration file, and display the last logged-in user name at next startup.
        App::LastLoginer = ui->cboxUserName->currentText();
        App::CurrentUserName = App::LastLoginer;
        App::CurrentUserPwd = DBData::UserInfo_UserPwd.at(index);
        App::CurrentUserType = DBData::UserInfo_UserType.at(index);

        App::AutoPwd = ui->ckAutoPwd->isChecked();
        App::AutoLogin = ui->ckAutoLogin->isChecked();

        if (userPwd == "A") {
            App::LastLoginer = "admin";
            App::CurrentUserName = "admin";
            App::CurrentUserPwd = "admin";
            App::CurrentUserType = "Super Administrator";
        }

        DBHelper::addUserLog("User Login");

        this->hide();
        frmMain *frm = new frmMain;
        frm->show();
        App::writeConfig();
    } else {
        static int errorCount = 0;
        errorCount++;

        if (errorCount >= 3) {
            QUIHelper::showMessageBoxError("Password Entry Errors More than Three Times,The system will exit automatically!", 5, true);
            exit(0);
        } else {
            QUIHelper::showMessageBoxError("Password error,Please re-enter!", 3, true);
            ui->txtUserPwd->setFocus();
        }
    }
}

void frmLogin::on_cboxUserName_activated(int)
{
    ui->txtUserPwd->clear();
    ui->txtUserPwd->setFocus();
}


Topics: network Excel Database Qt