mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
Settings DB
This commit is contained in:
@@ -9,11 +9,12 @@
|
||||
const QString DataBaseLMS::TypeUserDBInstructor = "instructor";
|
||||
const QString DataBaseLMS::TypeUserDBTrainee = "trainee";
|
||||
|
||||
QString DataBaseLMS::UserNamePostgres = "";
|
||||
QString DataBaseLMS::PasswordPostgres = "";
|
||||
|
||||
DataBaseLMS::DataBaseLMS(QObject *parent):
|
||||
QObject(parent),
|
||||
db(nullptr),
|
||||
UserNamePostgres(""),
|
||||
PasswordPostgres("")
|
||||
db(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -40,11 +40,14 @@ signals:
|
||||
public:
|
||||
static const QString TypeUserDBInstructor;
|
||||
static const QString TypeUserDBTrainee;
|
||||
protected:
|
||||
static QString UserNamePostgres;
|
||||
static QString PasswordPostgres;
|
||||
|
||||
public:
|
||||
//PostgreSQL
|
||||
bool setUserPasswordPostgres(QString userName, QString password);
|
||||
bool checkDriverQPSQLavailable();
|
||||
static bool checkDriverQPSQLavailable();
|
||||
static bool setUserPasswordPostgres(QString userName, QString password);
|
||||
bool checkUserLMSexist();
|
||||
bool checkDataBaseLMSexist();
|
||||
bool createUser();
|
||||
@@ -118,7 +121,7 @@ protected:
|
||||
int updateReportFIMforTask(TaskAmmFim task);
|
||||
|
||||
public:
|
||||
DataBaseSettings getDataBaseSettings();
|
||||
static DataBaseSettings getDataBaseSettings();
|
||||
private:
|
||||
int queryExecInt(QString queryStr);
|
||||
QString queryExecString(QString queryStr);
|
||||
@@ -129,9 +132,6 @@ private:
|
||||
protected:
|
||||
QSqlDatabase* db;
|
||||
DataBaseSettings dbSettings;
|
||||
|
||||
QString UserNamePostgres;
|
||||
QString PasswordPostgres;
|
||||
};
|
||||
|
||||
#endif // DATABASELMS_H
|
||||
|
||||
@@ -11,4 +11,6 @@ void registerMetaType()
|
||||
|
||||
qRegisterMetaType<EStateServer>("EStateServer");
|
||||
qRegisterMetaType<EStateBlockAutorization>("EStateBlockAutorization");
|
||||
|
||||
qRegisterMetaType<CheckResult>("CheckResult");
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Data/typesDataServerClient.h"
|
||||
#include "Systems/logger.h"
|
||||
#include "databaselms.h"
|
||||
#include "providerdblms.h"
|
||||
|
||||
void registerMetaType();
|
||||
|
||||
@@ -17,4 +18,6 @@ Q_DECLARE_METATYPE(DataBaseSettings)
|
||||
Q_DECLARE_METATYPE(EStateServer)
|
||||
Q_DECLARE_METATYPE(EStateBlockAutorization)
|
||||
|
||||
Q_DECLARE_METATYPE(CheckResult)
|
||||
|
||||
#endif // METATYPES_H
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
#include "specialmessagebox.h"
|
||||
|
||||
ProviderDBLMS::ProviderDBLMS(QObject *parent) :
|
||||
QObject(parent),
|
||||
@@ -25,6 +26,46 @@ void ProviderDBLMS::slot_TryDisConnectionFromDB()
|
||||
DisConnectionFromDB();
|
||||
}
|
||||
|
||||
void ProviderDBLMS::slot_CheckDB()
|
||||
{
|
||||
CheckResult result;
|
||||
|
||||
result.resDriver = ProviderDBLMS::checkDriverQPSQLavailable();
|
||||
|
||||
result.resUser = this->checkUserLMSexist();
|
||||
|
||||
result.resDB = this->checkDataBaseLMSexist();
|
||||
|
||||
emit signal_CheckDBResult(result);
|
||||
}
|
||||
|
||||
void ProviderDBLMS::slot_RepareDB(CheckResult result)
|
||||
{
|
||||
if(!result.resUser)
|
||||
{
|
||||
if(!this->createUser())
|
||||
{
|
||||
result.resUser = false;
|
||||
emit signal_RepareDBResult(result);
|
||||
}
|
||||
else
|
||||
result.resUser = true;
|
||||
}
|
||||
|
||||
if(!result.resDB)
|
||||
{
|
||||
if(!this->createDB())
|
||||
{
|
||||
result.resDB = false;
|
||||
emit signal_RepareDBResult(result);
|
||||
}
|
||||
else
|
||||
result.resDB = true;
|
||||
}
|
||||
|
||||
emit signal_RepareDBResult(result);
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::ConnectionToDB()
|
||||
{
|
||||
mtxAccess.lock();
|
||||
@@ -103,12 +144,12 @@ DataBaseSettings ProviderDBLMS::getDBSettings()
|
||||
|
||||
bool ProviderDBLMS::setUserPasswordPostgres(QString userName, QString password)
|
||||
{
|
||||
return dbLMS->setUserPasswordPostgres(userName, password);
|
||||
return InterfaceDataBaseLMS::setUserPasswordPostgres(userName, password);
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::checkDriverQPSQLavailable()
|
||||
{
|
||||
return dbLMS->checkDriverQPSQLavailable();
|
||||
return InterfaceDataBaseLMS::checkDriverQPSQLavailable();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::checkUserLMSexist()
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
#include "interfacedatabaselms.h"
|
||||
#include "tasksAmmFim.h"
|
||||
|
||||
class CheckResult
|
||||
{
|
||||
public:
|
||||
bool resDriver = false;
|
||||
bool resUser = false;
|
||||
bool resDB = false;
|
||||
};
|
||||
|
||||
class ProviderDBLMS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -80,10 +88,16 @@ signals:
|
||||
void signal_ResultTryConnectDb(bool result);
|
||||
void signal_ResultTryDisConnectDb(bool result);
|
||||
|
||||
void signal_CheckDBResult(CheckResult result);
|
||||
void signal_RepareDBResult(CheckResult result);
|
||||
|
||||
public slots:
|
||||
void slot_TryConnectionToDB();
|
||||
void slot_TryDisConnectionFromDB();
|
||||
|
||||
void slot_CheckDB();
|
||||
void slot_RepareDB(CheckResult result);
|
||||
|
||||
private:
|
||||
bool ConnectionToDB();
|
||||
void DisConnectionFromDB();
|
||||
@@ -93,8 +107,8 @@ public:
|
||||
DataBaseSettings getDBSettings();
|
||||
|
||||
//PostgreSQL
|
||||
bool setUserPasswordPostgres(QString userName, QString password);
|
||||
bool checkDriverQPSQLavailable();
|
||||
static bool checkDriverQPSQLavailable();
|
||||
static bool setUserPasswordPostgres(QString userName, QString password);
|
||||
bool checkUserLMSexist();
|
||||
bool checkDataBaseLMSexist();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QFile>
|
||||
#include <QResizeEvent>
|
||||
#include "specialmessagebox.h"
|
||||
#include "dialogcheckdb.h"
|
||||
#include "ui_dialogcheckdb.h"
|
||||
@@ -8,33 +9,78 @@
|
||||
DialogCheckDB::DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogCheckDB),
|
||||
providerDBLMS(providerDBLMS),
|
||||
resDriver(false),
|
||||
resUser(false),
|
||||
resDB(false)
|
||||
waitAnimationWidget(nullptr),
|
||||
providerDBLMS(providerDBLMS)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(this, &DialogCheckDB::signal_CheckDB, providerDBLMS, &ProviderDBLMS::slot_CheckDB);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_CheckDBResult, this, &DialogCheckDB::slot_CheckDBResult);
|
||||
|
||||
connect(this, &DialogCheckDB::signal_RepareDB, providerDBLMS, &ProviderDBLMS::slot_RepareDB);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_RepareDBResult, this, &DialogCheckDB::slot_RepareDBResult);
|
||||
|
||||
|
||||
waitAnimationWidget = new WaitAnimationWidget;
|
||||
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
||||
waitAnimationWidget->setParent(this);
|
||||
waitAnimationWidget->initialize(movie,this);
|
||||
|
||||
ui->btnRepare->setObjectName("btnRepare");
|
||||
|
||||
ui->btnRepare->setEnabled(false);
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
DialogCheckDB::~DialogCheckDB()
|
||||
{
|
||||
if(waitAnimationWidget)
|
||||
{
|
||||
waitAnimationWidget->hideWithStop();
|
||||
delete waitAnimationWidget;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogCheckDB::initialize()
|
||||
{
|
||||
check();
|
||||
}
|
||||
|
||||
void DialogCheckDB::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QSize size = event->size();
|
||||
waitAnimationWidget->resize(size);
|
||||
}
|
||||
|
||||
void DialogCheckDB::check()
|
||||
{
|
||||
resDriver = false;
|
||||
resUser = false;
|
||||
resDB = false;
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
resDriver = providerDBLMS->checkDriverQPSQLavailable();
|
||||
if(resDriver)
|
||||
emit signal_CheckDB();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_btnRepare_clicked()
|
||||
{
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
if(!checkResult.resDriver)
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
emit signal_RepareDB(checkResult);
|
||||
}
|
||||
|
||||
void DialogCheckDB::slot_CheckDBResult(CheckResult result)
|
||||
{
|
||||
checkResult = result;
|
||||
|
||||
if(result.resDriver)
|
||||
{
|
||||
ui->lblDriverRes->setText(tr("Installed"));
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -45,8 +91,7 @@ void DialogCheckDB::check()
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resUser = providerDBLMS->checkUserLMSexist();
|
||||
if(resUser)
|
||||
if(result.resUser)
|
||||
{
|
||||
ui->lblUserRes->setText(tr("Exist"));
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -57,8 +102,7 @@ void DialogCheckDB::check()
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resDB = providerDBLMS->checkDataBaseLMSexist();
|
||||
if(resDB)
|
||||
if(result.resDB)
|
||||
{
|
||||
ui->lblDBRes->setText(tr("Exist"));
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -69,48 +113,39 @@ void DialogCheckDB::check()
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
if(!resDriver || !resUser || !resDB)
|
||||
if(!result.resDriver || !result.resUser || !result.resDB)
|
||||
{
|
||||
ui->btnRepare->setEnabled(true);
|
||||
}
|
||||
else
|
||||
ui->btnRepare->setEnabled(false);
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_btnRepare_clicked()
|
||||
void DialogCheckDB::slot_RepareDBResult(CheckResult result)
|
||||
{
|
||||
if(!resDriver)
|
||||
checkResult = result;
|
||||
|
||||
if(!checkResult.resUser)
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
|
||||
slot_CheckDBResult(checkResult);
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!resUser)
|
||||
if(!checkResult.resDB)
|
||||
{
|
||||
if(!providerDBLMS->createUser())
|
||||
{
|
||||
check();
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(!resDB)
|
||||
{
|
||||
if(!providerDBLMS->createDB())
|
||||
{
|
||||
check();
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
slot_CheckDBResult(checkResult);
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
check();
|
||||
|
||||
if(resDriver && resUser && resDB)
|
||||
if(checkResult.resDriver && checkResult.resUser && checkResult.resDB)
|
||||
{
|
||||
SpecMsgBox::InfoOk(this, tr("The database has been successfully restored!"));
|
||||
this->accept();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include "providerdblms.h"
|
||||
#include "waitanimationwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogCheckDB;
|
||||
@@ -16,9 +17,22 @@ public:
|
||||
explicit DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent = nullptr);
|
||||
~DialogCheckDB();
|
||||
|
||||
void initialize();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void on_btnRepare_clicked();
|
||||
|
||||
signals:
|
||||
void signal_CheckDB();
|
||||
void signal_RepareDB(CheckResult result);
|
||||
|
||||
public slots:
|
||||
void slot_CheckDBResult(CheckResult result);
|
||||
void slot_RepareDBResult(CheckResult result);
|
||||
|
||||
private:
|
||||
void check();
|
||||
void prepareRestoreDBscript();
|
||||
@@ -26,11 +40,11 @@ private:
|
||||
private:
|
||||
Ui::DialogCheckDB *ui;
|
||||
|
||||
WaitAnimationWidget *waitAnimationWidget;
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
bool resDriver;
|
||||
bool resUser;
|
||||
bool resDB;
|
||||
CheckResult checkResult;
|
||||
};
|
||||
|
||||
#endif // DIALOGCHECKDB_H
|
||||
|
||||
@@ -26,6 +26,12 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
||||
ui->btnUpdateDocs->setVisible(false);
|
||||
#endif
|
||||
|
||||
#ifdef PROJECT_TYPE_DEBUG
|
||||
ui->editNameDB->setEnabled(true);
|
||||
ui->editUserName->setEnabled(true);
|
||||
ui->editPassword->setEnabled(true);
|
||||
#endif
|
||||
|
||||
/* Создаем строку для регулярного выражения */
|
||||
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
|
||||
/* Создаем регулярное выражение с применением строки, как
|
||||
@@ -298,7 +304,7 @@ void DialogSettingsTray::on_checkLocalhost_stateChanged(int arg1)
|
||||
void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
{
|
||||
//Проверяем, установлен ли PostgreSQL
|
||||
if(!providerDBLMS->checkDriverQPSQLavailable())
|
||||
if(!ProviderDBLMS::checkDriverQPSQLavailable())
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Driver PostgreSQL is not installed!"));
|
||||
return;
|
||||
@@ -332,10 +338,11 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
if(providerDBLMS->setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
|
||||
if(ProviderDBLMS::setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
|
||||
{
|
||||
DialogCheckDB dlgCheckDB(providerDBLMS, this);
|
||||
dlgCheckDB.setWindowFlags(dlgCheckDB.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
dlgCheckDB.initialize();
|
||||
|
||||
switch( dlgCheckDB.exec() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user