Рефакт Администрирование БД 3

This commit is contained in:
2025-11-06 16:46:41 +03:00
parent 2d91b18bfb
commit 2d1e17627b
11 changed files with 308 additions and 184 deletions

View File

@@ -81,6 +81,7 @@ void DialogCheckDB::on_btnRepare_clicked()
if(!resDriver)
{
QMessageBox::critical(this, tr("Error!"), tr("Install PostgreSQL."));
this->reject();
return;
}
@@ -88,8 +89,9 @@ void DialogCheckDB::on_btnRepare_clicked()
{
if(!providerDBLMS->createUser())
{
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
check();
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
this->reject();
return;
}
}
@@ -98,8 +100,9 @@ void DialogCheckDB::on_btnRepare_clicked()
{
if(!providerDBLMS->createDB())
{
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
check();
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
this->reject();
return;
}
}

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>250</height>
</rect>
</property>
<property name="windowTitle">
@@ -45,7 +45,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -229,6 +229,9 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_Result"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@@ -34,7 +34,7 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
/* Устанавливаем Валидатор на QLineEdit */
ui->editHostName->setValidator(ipValidator);
settings = new ServerDBSettings;
settings = new ServerDBSettings();
//Задаём два пункта с текстом локалей в комбобоксе
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
@@ -50,7 +50,17 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
ui->cmbLanguage->setCurrentText("Русский");
ui->editNameDB->setText(settings->NameDB);
if(settings->HostName == "localhost")
{
ui->checkLocalhost->setChecked(true);
}
else
{
ui->checkLocalhost->setChecked(false);
}
ui->editHostName->setText(settings->HostName);
ui->editPort->setText(settings->Port);
ui->editUserName->setText(settings->UserName);
ui->editPassword->setText(settings->Password);
@@ -240,6 +250,20 @@ void DialogSettingsTray::on_editPassword_textChanged(const QString &arg1)
flSettingsServerChanged = true;
}
void DialogSettingsTray::on_checkLocalhost_stateChanged(int arg1)
{
if(arg1)
{
ui->editHostName->setText("localhost");
ui->editHostName->setEnabled(false);
}
else
{
ui->editHostName->setText("0.0.0.0");
ui->editHostName->setEnabled(true);
}
}
void DialogSettingsTray::on_btnCheckDB_clicked()
{
//Проверяем, установлен ли PostgreSQL
@@ -249,7 +273,7 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
return;
}
//TODO Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
//Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
QString UserNamePostgres;
QString PasswordPostgres;
@@ -296,7 +320,17 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
}
else
{
QMessageBox::critical(this, tr("Error!"), tr("The superuser login or password is incorrect!"));
if(settings->HostName == "localhost")
QMessageBox::critical(this, tr("Error!"), tr("Error connecting to PostgreSQL!") + "\n\n" +
tr("Possible reasons:") + "\n" +
tr("*superuser PostgreSQL login or password is incorrect;") + "\n" +
tr("*Port is incorrect."));
else
QMessageBox::critical(this, tr("Error!"), tr("Error connecting to PostgreSQL!") + "\n\n" +
tr("Possible reasons:") + "\n" +
tr("*superuser PostgreSQL login or password is incorrect;") + "\n" +
tr("*Port is incorrect;") + "\n" +
tr("*file 'pg_hba.conf' does not contain an entry for the IP address:") + settings->HostName + ".");
return;
}
}

View File

@@ -58,6 +58,8 @@ private slots:
void on_btnCheckDB_clicked();
void on_checkLocalhost_stateChanged(int arg1);
private:
bool saveSettings();

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>427</height>
<width>450</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
@@ -51,38 +51,24 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_DB">
<property name="title">
<string>Data Base</string>
<string>Database</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_DB">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_NameDB">
<item>
<widget class="QLabel" name="label_NameDB">
<property name="text">
<string>DB name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editNameDB">
<property name="maximumSize">
<size>
<width>170</width>
<height>16777215</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_HostName">
<item>
@@ -92,6 +78,26 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkLocalhost">
<property name="text">
<string>Localhost</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editHostName">
<property name="maximumSize">
@@ -131,6 +137,33 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_NameDB">
<item>
<widget class="QLabel" name="label_NameDB">
<property name="text">
<string>Database name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editNameDB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>170</width>
<height>16777215</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_UserName">
<item>
@@ -142,6 +175,9 @@
</item>
<item>
<widget class="QLineEdit" name="editUserName">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>170</width>
@@ -160,12 +196,15 @@
<item>
<widget class="QLabel" name="label_Password">
<property name="text">
<string>Password</string>
<string>User password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>170</width>

View File

@@ -110,6 +110,8 @@ void ServerLMSWidget::slot_AddMessageToLog(QString message)
void ServerLMSWidget::start()
{
startInitialization();
if(hasError() == 100)
return;
tryConnectionToDB();
}
@@ -172,7 +174,7 @@ void ServerLMSWidget::on_btnSettings_clicked()
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet);
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &ServerLMSWidget::slot_UpdateStyleSheet);
switch( dlg.exec() )