mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
PSQL 01.11.2024
This commit is contained in:
189
DB_IaT/InstructorsAndTrainees/instructors/editorinstructors.cpp
Normal file
189
DB_IaT/InstructorsAndTrainees/instructors/editorinstructors.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include <QMessageBox>
|
||||
#include "editorinstructors.h"
|
||||
#include "dialogeditinstructor.h"
|
||||
#include "ui_editorinstructors.h"
|
||||
|
||||
EditorInstructors::EditorInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent) :
|
||||
//QDialog(parent),
|
||||
InstructorsView(db, CommonView::TypeView::control, parent),
|
||||
ui(new Ui::EditorInstructors)
|
||||
{
|
||||
ui->setupUi((QDialog*)this);
|
||||
|
||||
preparationTreeWidget(ui->treeWidget);
|
||||
setNotLoggedInVisible(true);
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
|
||||
EditorInstructors::~EditorInstructors()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnNewInstructor_clicked()
|
||||
{
|
||||
QString name = dbInstructors->newInstructor();
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(name);
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnDeleteInstructor_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
|
||||
if(dbInstructors->isAdmin(name))
|
||||
{//Это Админ!
|
||||
QMessageBox::critical(this, tr("Error!"), tr("You cannot delete the Administrator."));
|
||||
return;
|
||||
}
|
||||
|
||||
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete it anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
{
|
||||
dbInstructors->deleteInstructor(name);
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnToOrFromArchive_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
|
||||
if(dbInstructors->isArchived(name))
|
||||
{//Архивный
|
||||
dbInstructors->fromeArchiveInstructor(name);
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(name);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
dbInstructors->toArchiveInstructor(name);
|
||||
loadInstructorsFromDB();
|
||||
if(archiveVisible)
|
||||
setCurrentInstructor(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnEdit_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent == nullptr)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
|
||||
DialogEditInstructor dlg(this);
|
||||
dlg.setInstructor(dbInstructors->getInstructor(name));
|
||||
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbInstructors->editInstructor(name, dlg.getInstructor()))
|
||||
{
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(dlg.getInstructor().getName());
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
tr("An existing instructor name or login has been entered.\nThe changes will not be accepted."));
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnArchive_clicked()
|
||||
{
|
||||
bool state = ui->btnArchive->isChecked();
|
||||
setArchiveVisible(state);
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
|
||||
void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
{
|
||||
//Определяем доступность и функционал кнопок для выбранного элемента
|
||||
|
||||
if(current == nullptr)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *treeItemParent = current->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран инструктор
|
||||
|
||||
QString name = current->text(0);
|
||||
|
||||
if(dbInstructors->isArchived(name))
|
||||
{//Архивный
|
||||
ui->btnToOrFromArchive->setText(tr("From archive"));
|
||||
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/icons/instructorFromArchive.png")));
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ui->btnToOrFromArchive->setText(tr("To archive"));
|
||||
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/icons/instructorArchive.png")));
|
||||
}
|
||||
|
||||
ui->btnNewInstructor->setEnabled(true);
|
||||
|
||||
if(dbInstructors->isAdmin(name))
|
||||
{//Это Админ! Удалять/Архивировать нельзя!
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnToOrFromArchive->setEnabled(true);
|
||||
|
||||
if(dbInstructors->isArchived(name))
|
||||
ui->btnDeleteInstructor->setEnabled(true);
|
||||
else
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
}
|
||||
|
||||
ui->btnEdit->setEnabled(true);
|
||||
ui->btnArchive->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::setCurrentInstructor(QString name)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
if(item->text(0) == name)
|
||||
{
|
||||
treeWidget->setCurrentItem(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user