mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
PSQL id 06.11.2024
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
#include "ui_editorinstructors.h"
|
||||
|
||||
EditorInstructors::EditorInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent) :
|
||||
//QDialog(parent),
|
||||
InstructorsView(db, CommonView::TypeView::control, parent),
|
||||
InstructorsView(db, CommonView::TypeView::control, adminMode, parent),
|
||||
ui(new Ui::EditorInstructors)
|
||||
{
|
||||
ui->setupUi((QDialog*)this);
|
||||
@@ -22,9 +21,9 @@ EditorInstructors::~EditorInstructors()
|
||||
|
||||
void EditorInstructors::on_btnNewInstructor_clicked()
|
||||
{
|
||||
QString name = dbInstructors->newInstructor();
|
||||
int id = dbInstructors->newInstructor();
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(name);
|
||||
setCurrentInstructor(id);
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnDeleteInstructor_clicked()
|
||||
@@ -37,9 +36,9 @@ void EditorInstructors::on_btnDeleteInstructor_clicked()
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
int id = treeItemCurrent->text(0).toInt();
|
||||
|
||||
if(dbInstructors->isAdmin(name))
|
||||
if(dbInstructors->isAdmin(id))
|
||||
{//Это Админ!
|
||||
QMessageBox::critical(this, tr("Error!"), tr("You cannot delete the Administrator."));
|
||||
return;
|
||||
@@ -47,7 +46,7 @@ void EditorInstructors::on_btnDeleteInstructor_clicked()
|
||||
|
||||
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete it anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
{
|
||||
dbInstructors->deleteInstructor(name);
|
||||
dbInstructors->deleteInstructor(id);
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
}
|
||||
@@ -64,29 +63,29 @@ void EditorInstructors::on_btnToOrFromArchive_clicked()
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
int id = treeItemCurrent->text(0).toInt();
|
||||
|
||||
Instructor instructor = dbInstructors->getInstructor(name);
|
||||
Instructor instructor = dbInstructors->getInstructor(id);
|
||||
|
||||
if(instructor.getArchived())
|
||||
{//Архивный
|
||||
instructor.setArchived(false);
|
||||
if(dbInstructors->editInstructor(name, instructor))
|
||||
if(int id_edit = dbInstructors->editInstructor(instructor))
|
||||
{
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(instructor.getName());
|
||||
setCurrentInstructor(id_edit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
instructor.setArchived(true);
|
||||
if(dbInstructors->editInstructor(name, instructor))
|
||||
if(int id_edit = dbInstructors->editInstructor(instructor))
|
||||
{
|
||||
if(!archiveVisible)
|
||||
ui->btnArchive->click();
|
||||
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(instructor.getName());
|
||||
setCurrentInstructor(id_edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,19 +103,19 @@ void EditorInstructors::on_btnEdit_clicked()
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
int id = treeItemCurrent->text(0).toInt();
|
||||
|
||||
DialogEditInstructor dlg(this);
|
||||
dlg.setInstructor(dbInstructors->getInstructor(name));
|
||||
dlg.setInstructor(dbInstructors->getInstructor(id));
|
||||
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbInstructors->editInstructor(name, dlg.getInstructor()))
|
||||
if(int id_edit = dbInstructors->editInstructor(dlg.getInstructor()))
|
||||
{
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(dlg.getInstructor().getName());
|
||||
setCurrentInstructor(id_edit);
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
@@ -149,9 +148,9 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран инструктор
|
||||
|
||||
QString name = current->text(0);
|
||||
int id = current->text(0).toInt();
|
||||
|
||||
if(dbInstructors->isArchived(name))
|
||||
if(dbInstructors->isArchived(id))
|
||||
{//Архивный
|
||||
ui->btnToOrFromArchive->setText(tr("From archive"));
|
||||
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/icons/instructorFromArchive.png")));
|
||||
@@ -164,7 +163,7 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
|
||||
|
||||
ui->btnNewInstructor->setEnabled(true);
|
||||
|
||||
if(dbInstructors->isAdmin(name))
|
||||
if(dbInstructors->isAdmin(id))
|
||||
{//Это Админ! Удалять/Архивировать нельзя!
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
@@ -173,7 +172,7 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
|
||||
{
|
||||
ui->btnToOrFromArchive->setEnabled(true);
|
||||
|
||||
if(dbInstructors->isArchived(name))
|
||||
if(dbInstructors->isArchived(id))
|
||||
ui->btnDeleteInstructor->setEnabled(true);
|
||||
else
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
@@ -184,13 +183,13 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::setCurrentInstructor(QString name)
|
||||
void EditorInstructors::setCurrentInstructor(int id)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
if(item->text(0) == name)
|
||||
if(item->text(0).toInt() == id)
|
||||
{
|
||||
treeWidget->setCurrentItem(item);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user