mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
Создание БД из кода. Требуется рефакт.
This commit is contained in:
@@ -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