mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Создание БД из кода. Требуется рефакт.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <QSqlDriver>
|
||||
#include <QMessageBox>
|
||||
#include <QDomDocument>
|
||||
#include <QProcess>
|
||||
|
||||
const QString DataBaseLMS::TypeUserDBInstructor = "instructor";
|
||||
const QString DataBaseLMS::TypeUserDBTrainee = "trainee";
|
||||
@@ -28,25 +29,62 @@ void DataBaseLMS::slot_LanguageChanged(QString language)
|
||||
QCoreApplication::installTranslator(&qtLanguageTranslator);
|
||||
}
|
||||
|
||||
bool DataBaseLMS::createConnection()
|
||||
bool DataBaseLMS::checkDriverQPSQLavailable()
|
||||
{
|
||||
dbSettings = getDataBaseSettings();
|
||||
return QSqlDatabase::isDriverAvailable("QPSQL");
|
||||
}
|
||||
|
||||
dbSettings.connectionName = "Connection_" + dbSettings.dbName;
|
||||
bool DataBaseLMS::checkUserLMSexist()
|
||||
{
|
||||
DataBaseSettings dbSett = getDataBaseSettings();
|
||||
QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL");
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbSettings.dbType, dbSettings.connectionName));
|
||||
dbCheck.setUserName("postgres");
|
||||
dbCheck.setPassword("12345678");
|
||||
dbCheck.setHostName(dbSett.dbHostName);
|
||||
dbCheck.setPort(dbSett.dbPort);
|
||||
|
||||
/*
|
||||
db->setUserName(dbSettings.dbUserName);
|
||||
db->setPassword(dbSettings.dbPassword);
|
||||
//db->setHostName(dbSettings.dbHostName);
|
||||
//db->setPort(dbSettings.dbPort);
|
||||
bool res1 = db->open();
|
||||
if (dbCheck.open())
|
||||
{
|
||||
QSqlQuery query = QSqlQuery(dbCheck);
|
||||
query.prepare("SELECT 1 FROM pg_roles WHERE rolname = :username");
|
||||
query.bindValue(":username", dbSett.dbUserName);
|
||||
|
||||
//Проверка наличия БД
|
||||
if (query.exec() && query.next())
|
||||
{
|
||||
qDebug() << "Пользователь существует.";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Пользователь не существует.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Ошибка подключения к PostreSQL.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DataBaseLMS::checkDataBaseLMSexist()
|
||||
{
|
||||
DataBaseSettings dbSett = getDataBaseSettings();
|
||||
QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL");
|
||||
|
||||
bool flDBexist = false;
|
||||
|
||||
dbCheck.setUserName("postgres");
|
||||
dbCheck.setPassword("12345678");
|
||||
dbCheck.setHostName(dbSett.dbHostName);
|
||||
dbCheck.setPort(dbSett.dbPort);
|
||||
|
||||
if (dbCheck.open())
|
||||
{
|
||||
QString queryStr = QString("SELECT datname FROM pg_database");
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
bool flExist = false;
|
||||
QSqlQuery query = QSqlQuery(dbCheck);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
while (query.next())
|
||||
@@ -54,15 +92,169 @@ bool DataBaseLMS::createConnection()
|
||||
QString nameDB = "";
|
||||
nameDB = query.value(0).toString();
|
||||
if(nameDB == dbSettings.dbName)
|
||||
flExist = true;
|
||||
{
|
||||
flDBexist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Ошибка подключения к PostreSQL.";
|
||||
return false;
|
||||
}
|
||||
return flDBexist;
|
||||
}
|
||||
|
||||
nameDB = query.value(1).toString();
|
||||
nameDB = query.value(2).toString();
|
||||
nameDB = query.value(3).toString();
|
||||
bool DataBaseLMS::createUser(QString name)
|
||||
{
|
||||
DataBaseSettings dbSett = getDataBaseSettings();
|
||||
QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL");
|
||||
|
||||
dbCheck.setUserName("postgres");
|
||||
dbCheck.setPassword("12345678");
|
||||
dbCheck.setHostName(dbSett.dbHostName);
|
||||
dbCheck.setPort(dbSett.dbPort);
|
||||
|
||||
if (dbCheck.open())
|
||||
{
|
||||
QString queryStr = QString("CREATE USER %1 WITH ENCRYPTED PASSWORD '%2'").arg(dbSett.dbUserName, dbSett.dbPassword);
|
||||
QSqlQuery query = QSqlQuery(dbCheck);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
qDebug() << "Пользователь создан.";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Пользователь не создан.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Ошибка подключения к PostreSQL.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DataBaseLMS::createDB(QString name)
|
||||
{
|
||||
DataBaseSettings dbSett = getDataBaseSettings();
|
||||
QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL");
|
||||
|
||||
dbCheck.setUserName("postgres");
|
||||
dbCheck.setPassword("12345678");
|
||||
dbCheck.setHostName(dbSett.dbHostName);
|
||||
dbCheck.setPort(dbSett.dbPort);
|
||||
|
||||
if (dbCheck.open())
|
||||
{
|
||||
//Создание БД
|
||||
QString queryStr = QString("CREATE DATABASE %1").arg(dbSett.dbName);
|
||||
QSqlQuery query = QSqlQuery(dbCheck);
|
||||
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
qDebug() << "БД создана.";
|
||||
|
||||
//Залитие БД
|
||||
|
||||
QProcess process;
|
||||
//QString pgRestorePath = "C:\\restoreDB.bat"; // Замените на актуальный путь
|
||||
QString pgRestorePath = "restoreDB.bat"; // Замените на актуальный путь
|
||||
|
||||
/*
|
||||
QString dbName = "databaselms2";
|
||||
QString user = "postgres";
|
||||
QString backupFile = "C:\\DBLMS_EMPTY_30_09_2025.backup";
|
||||
|
||||
QStringList arguments;
|
||||
arguments << "-d" << dbName;
|
||||
arguments << "-U" << user;
|
||||
arguments << backupFile;
|
||||
*/
|
||||
|
||||
process.start("cmd /C " + pgRestorePath);
|
||||
process.waitForFinished(-1); // Ждать бесконечно, пока процесс не завершится
|
||||
|
||||
|
||||
//Назначение владельца
|
||||
QString queryStr = QString("ALTER DATABASE %1 OWNER TO %2").arg(dbSett.dbName, dbSett.dbUserName);
|
||||
QSqlQuery query = QSqlQuery(dbCheck);
|
||||
if(queryExec(queryStr, &query))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
//return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "БД не создана.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Ошибка подключения к PostreSQL.";
|
||||
return false;
|
||||
}
|
||||
|
||||
dbCheck.close();
|
||||
|
||||
QSqlDatabase dbCheck2 = QSqlDatabase::addDatabase("QPSQL");
|
||||
|
||||
dbCheck2.setUserName("postgres");
|
||||
dbCheck2.setPassword("12345678");
|
||||
dbCheck2.setHostName(dbSett.dbHostName);
|
||||
dbCheck2.setPort(dbSett.dbPort);
|
||||
dbCheck2.setDatabaseName(dbSett.dbName);
|
||||
|
||||
if (dbCheck2.open())
|
||||
{
|
||||
QString newOwner = dbSett.dbUserName;
|
||||
|
||||
// Получаем список таблиц
|
||||
QSqlQuery query(dbCheck2);
|
||||
query.exec("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public';");
|
||||
|
||||
while (query.next())
|
||||
{
|
||||
QString tableName = query.value(0).toString();
|
||||
QString alterQuery = QString("ALTER TABLE %1 OWNER TO %2;").arg(tableName).arg(newOwner);
|
||||
qDebug() << "Executing: " << alterQuery;
|
||||
dbCheck2.exec(alterQuery);
|
||||
/*
|
||||
if (dbCheck2.exec(alterQuery))
|
||||
{
|
||||
qDebug() << "Error changing owner for table " << tableName << ":" << dbCheck2.lastError().text();
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::createConnection()
|
||||
{
|
||||
dbSettings = getDataBaseSettings();
|
||||
|
||||
dbSettings.connectionName = "Connection_" + dbSettings.dbName;
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbSettings.dbType, dbSettings.connectionName));
|
||||
|
||||
db->setDatabaseName(dbSettings.dbName);
|
||||
db->setUserName(dbSettings.dbUserName);
|
||||
|
||||
@@ -39,6 +39,15 @@ public:
|
||||
static const QString TypeUserDBInstructor;
|
||||
static const QString TypeUserDBTrainee;
|
||||
|
||||
public:
|
||||
//PostgreSQL
|
||||
bool checkDriverQPSQLavailable();
|
||||
bool checkUserLMSexist();
|
||||
bool checkDataBaseLMSexist();
|
||||
|
||||
bool createUser(QString name);
|
||||
bool createDB(QString name);
|
||||
|
||||
protected:
|
||||
//Подключение
|
||||
bool createConnection();
|
||||
|
||||
@@ -12,6 +12,9 @@ add_library(ServerLMS SHARED
|
||||
dialogsettingstray.cpp
|
||||
dialogsettingstray.h
|
||||
dialogsettingstray.ui
|
||||
dialogcheckdb.cpp
|
||||
dialogcheckdb.h
|
||||
dialogcheckdb.ui
|
||||
clienthandler.cpp
|
||||
clienthandler.h
|
||||
multithreadserver.cpp
|
||||
|
||||
@@ -16,5 +16,8 @@
|
||||
<file>resources/icons/stop.png</file>
|
||||
<file>resources/icons/settings.png</file>
|
||||
<file>resources/icons/circleGray.png</file>
|
||||
<file>resources/icons/checkDB.png</file>
|
||||
<file>resources/icons/editorDB.png</file>
|
||||
<file>resources/icons/procedure.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
111
ServerLMS/dialogcheckdb.cpp
Normal file
111
ServerLMS/dialogcheckdb.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include "dialogcheckdb.h"
|
||||
#include "ui_dialogcheckdb.h"
|
||||
|
||||
DialogCheckDB::DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogCheckDB),
|
||||
providerDBLMS(providerDBLMS),
|
||||
resDriver(false),
|
||||
resUser(false),
|
||||
resDB(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->btnRepare->setEnabled(false);
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
DialogCheckDB::~DialogCheckDB()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogCheckDB::check()
|
||||
{
|
||||
resDriver = false;
|
||||
resUser = false;
|
||||
resDB = false;
|
||||
|
||||
resDriver = providerDBLMS->checkDriverQPSQLavailable();
|
||||
if(resDriver)
|
||||
{
|
||||
ui->lblDriverRes->setText(tr("Installed"));
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblDriverRes->setText(tr("Not installed"));
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resUser = providerDBLMS->checkUserLMSexist();
|
||||
if(resUser)
|
||||
{
|
||||
ui->lblUserRes->setText(tr("Exist"));
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblUserRes->setText(tr("Not exist"));
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resDB = providerDBLMS->checkDataBaseLMSexist();
|
||||
if(resDB)
|
||||
{
|
||||
ui->lblDBRes->setText(tr("Exist"));
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->lblDBRes->setText(tr("Not exist"));
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
if(!resDriver || !resUser || !resDB)
|
||||
ui->btnRepare->setEnabled(true);
|
||||
else
|
||||
ui->btnRepare->setEnabled(false);
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_btnRepare_clicked()
|
||||
{
|
||||
if(!resDriver)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Warning!"), tr("Install PostgreSQL."));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!resUser)
|
||||
{
|
||||
if(!providerDBLMS->createUser("nameUser"))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(!resDB)
|
||||
{
|
||||
if(!providerDBLMS->createDB("nameDB"))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_toolButton_clicked()
|
||||
{
|
||||
QProcess process;
|
||||
QString program = "cmd.exe";
|
||||
QStringList arguments;
|
||||
arguments << "/C" << "echo Hello from QProcess" << "&&" << "pause";
|
||||
process.start(program, arguments);
|
||||
process.waitForFinished();
|
||||
|
||||
int i = 0;
|
||||
}
|
||||
37
ServerLMS/dialogcheckdb.h
Normal file
37
ServerLMS/dialogcheckdb.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef DIALOGCHECKDB_H
|
||||
#define DIALOGCHECKDB_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "providerdblms.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogCheckDB;
|
||||
}
|
||||
|
||||
class DialogCheckDB : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent = nullptr);
|
||||
~DialogCheckDB();
|
||||
|
||||
private slots:
|
||||
void on_btnRepare_clicked();
|
||||
|
||||
void on_toolButton_clicked();
|
||||
|
||||
private:
|
||||
void check();
|
||||
|
||||
private:
|
||||
Ui::DialogCheckDB *ui;
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
bool resDriver;
|
||||
bool resUser;
|
||||
bool resDB;
|
||||
};
|
||||
|
||||
#endif // DIALOGCHECKDB_H
|
||||
244
ServerLMS/dialogcheckdb.ui
Normal file
244
ServerLMS/dialogcheckdb.ui
Normal file
@@ -0,0 +1,244 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogCheckDB</class>
|
||||
<widget class="QDialog" name="DialogCheckDB">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Database</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_Main">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Driver">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Driver">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Driver PostgreSQL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblDriverRes">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblDriverResIco">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">:/resources/icons/circleGray.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_User">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_User">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>User</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblUserRes">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblUserResIco">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">:/resources/icons/circleGray.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_DB">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_DB">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Database</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblDBRes">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblDBResIco">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">:/resources/icons/circleGray.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Ctrl">
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnRepare">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>58</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Repare</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees/InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/procedure.png</normaloff>:/resources/icons/procedure.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../InstructorsAndTrainees/InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -2,11 +2,13 @@
|
||||
#include "dialogsettingstray.h"
|
||||
#include "Systems/tools.h"
|
||||
#include "ui_dialogsettingstray.h"
|
||||
#include "dialogcheckdb.h"
|
||||
|
||||
DialogSettingsTray::DialogSettingsTray(QWidget *parent) :
|
||||
DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogSettingsTray),
|
||||
settings(nullptr),
|
||||
providerDBLMS(providerDBLMS),
|
||||
flSettingsServerChanged(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -226,3 +228,19 @@ void DialogSettingsTray::on_editPassword_textChanged(const QString &arg1)
|
||||
ui->btnSave->setEnabled(true);
|
||||
flSettingsServerChanged = true;
|
||||
}
|
||||
|
||||
void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
{
|
||||
DialogCheckDB dlgCheckDB(providerDBLMS, this);
|
||||
dlgCheckDB.setWindowFlags(dlgCheckDB.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
switch( dlgCheckDB.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
break;
|
||||
case QDialog::Rejected:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QDialog>
|
||||
#include <QTranslator>
|
||||
#include <QEvent>
|
||||
#include "providerdblms.h"
|
||||
|
||||
class ServerDBSettings{
|
||||
public:
|
||||
@@ -25,7 +26,7 @@ class DialogSettingsTray : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogSettingsTray(QWidget *parent = nullptr);
|
||||
explicit DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *parent = nullptr);
|
||||
~DialogSettingsTray();
|
||||
|
||||
ServerDBSettings getSettings();
|
||||
@@ -55,6 +56,8 @@ private slots:
|
||||
|
||||
void on_editPassword_textChanged(const QString &arg1);
|
||||
|
||||
void on_btnCheckDB_clicked();
|
||||
|
||||
private:
|
||||
bool saveSettings();
|
||||
|
||||
@@ -63,6 +66,8 @@ private:
|
||||
|
||||
ServerDBSettings *settings;
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
bool flSettingsServerChanged;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>324</height>
|
||||
<height>427</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -179,6 +179,36 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Check">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnCheckDB">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>58</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check DB</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="ServerLMS.qrc">
|
||||
<normaloff>:/resources/icons/checkDB.png</normaloff>:/resources/icons/checkDB.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -238,6 +268,7 @@
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../InstructorsAndTrainees/InstructorsAndTrainees.qrc"/>
|
||||
<include location="ServerLMS.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -64,6 +64,31 @@ DataBaseSettings ProviderDBLMS::getDBSettings()
|
||||
return dbLMS->getDataBaseSettings();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::checkDriverQPSQLavailable()
|
||||
{
|
||||
return dbLMS->checkDriverQPSQLavailable();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::checkUserLMSexist()
|
||||
{
|
||||
return dbLMS->checkUserLMSexist();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::checkDataBaseLMSexist()
|
||||
{
|
||||
return dbLMS->checkDataBaseLMSexist();
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::createUser(QString name)
|
||||
{
|
||||
return dbLMS->createUser(name);
|
||||
}
|
||||
|
||||
bool ProviderDBLMS::createDB(QString name)
|
||||
{
|
||||
return dbLMS->createDB(name);
|
||||
}
|
||||
|
||||
QString ProviderDBLMS::getMainInstructorName()
|
||||
{
|
||||
mtxAccess.lock();
|
||||
|
||||
@@ -80,6 +80,14 @@ public:
|
||||
bool DBisConnected();
|
||||
DataBaseSettings getDBSettings();
|
||||
|
||||
//PostgreSQL
|
||||
bool checkDriverQPSQLavailable();
|
||||
bool checkUserLMSexist();
|
||||
bool checkDataBaseLMSexist();
|
||||
|
||||
bool createUser(QString name);
|
||||
bool createDB(QString name);
|
||||
|
||||
private:
|
||||
InterfaceDataBaseLMS* dbLMS;
|
||||
QMutex mtxAccess;
|
||||
|
||||
BIN
ServerLMS/resources/icons/checkDB.png
Normal file
BIN
ServerLMS/resources/icons/checkDB.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
ServerLMS/resources/icons/editorDB.png
Normal file
BIN
ServerLMS/resources/icons/editorDB.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
ServerLMS/resources/icons/procedure.png
Normal file
BIN
ServerLMS/resources/icons/procedure.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -179,7 +179,7 @@ void ServerLMSWidget::on_btnStopServer_clicked()
|
||||
|
||||
void ServerLMSWidget::on_btnSettings_clicked()
|
||||
{
|
||||
DialogSettingsTray dlg(this);
|
||||
DialogSettingsTray dlg(providerDBLMS, this);
|
||||
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
|
||||
|
||||
Reference in New Issue
Block a user