after interface 13.11.2024

This commit is contained in:
krivoshein
2024-11-13 17:16:33 +03:00
parent 61aaac2b1c
commit 2ed1eac956
80 changed files with 1734 additions and 1379 deletions

View File

@@ -1,103 +0,0 @@
#include <QMessageBox>
#include <QApplication>
#include "databaseinstructors.h"
DataBaseInstructors::DataBaseInstructors(DataBaseLMS* dbLMS):
adminMode(false)
{
this->dbLMS = dbLMS;
}
DataBaseInstructors::~DataBaseInstructors()
{
}
bool DataBaseInstructors::AuthorizationInstructor(QString login, QString password)
{
if(! dbLMS->transactionBegin())
return false;
if(int id = dbLMS->selectInstructorID(login, password))
{
if(dbLMS->updateInstructorLoggedIn(id, true))
return dbLMS->transactionEnd();
}
dbLMS->transactionEnd();
return false;
}
bool DataBaseInstructors::deAuthorizationInstructor(QString login)
{
if(! dbLMS->transactionBegin())
return false;
if(int id = dbLMS->selectInstructorID(login))
{
if(dbLMS->updateInstructorLoggedIn(id, false))
return dbLMS->transactionEnd();
}
dbLMS->transactionEnd();
return false;
}
QList<Instructor> DataBaseInstructors::getListInstructors()
{
return dbLMS->selectAllInstructors();
}
Instructor DataBaseInstructors::getInstructor(int id)
{
return dbLMS->selectInstructor(id);
}
int DataBaseInstructors::newInstructor()
{
return dbLMS->insertInstructor();
}
int DataBaseInstructors::deleteInstructor(int id)
{
return dbLMS->deleteInstructor(id);
}
int DataBaseInstructors::editInstructor(Instructor instructor)
{
//Проверка дублирования логина и имени
QList<Instructor> listInstructors = dbLMS->selectAllInstructors();
for(Instructor exist_instructor : listInstructors)
{
if(instructor.getLogin() == exist_instructor.getLogin() && instructor.getID() != exist_instructor.getID())
{//Логин уже существует!
QMessageBox::critical(nullptr, tr("Editing error!"),
tr("An existing instructor login has been entered.\nThe changes will not be accepted."));
return 0;
}
if(instructor.getName() == exist_instructor.getName() && instructor.getID() != exist_instructor.getID())
{//Имя уже существует
QMessageBox::warning(nullptr, tr("Editing warning!"),
tr("An existing instructor name has been entered."));
//return 0;
}
}
return dbLMS->updateInstructor(instructor);
}
bool DataBaseInstructors::isAdmin(int id)
{
return dbLMS->selectInstructorIsAdmin(id);
}
bool DataBaseInstructors::isArchived(int id)
{
return dbLMS->selectInstructorArchived(id);
}
bool DataBaseInstructors::existLogin(QString login)
{
}

View File

@@ -1,38 +0,0 @@
#ifndef DATABASEINSTRUCTORS_H
#define DATABASEINSTRUCTORS_H
#include <QList>
#include <QObject>
#include "instructorsAndTrainees_global.h"
#include "instructor.h"
#include "databaselms.h"
class DataBaseInstructors : QObject
{
Q_OBJECT
public:
DataBaseInstructors(DataBaseLMS* dbLMS);
~DataBaseInstructors();
bool AuthorizationInstructor(QString login, QString password);
bool deAuthorizationInstructor(QString login);
QList<Instructor> getListInstructors();
Instructor getInstructor(int id);
int newInstructor();
int deleteInstructor(int id);
int editInstructor(Instructor instructor);
bool isAdmin(int id);
bool isArchived(int id);
bool existLogin(QString login);
private:
bool adminMode;
DataBaseLMS* dbLMS;
};
#endif // DATABASEINSTRUCTORS_H

View File

@@ -3,8 +3,8 @@
#include "dialogeditinstructor.h"
#include "ui_editorinstructors.h"
EditorInstructors::EditorInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent) :
InstructorsView(db, CommonView::TypeView::control, adminMode, parent),
EditorInstructors::EditorInstructors(InterfaceDataBaseLMS* dbLMS, bool adminMode, QWidget *parent) :
InstructorsView(dbLMS, CommonView::TypeView::control, adminMode, parent),
ui(new Ui::EditorInstructors)
{
ui->setupUi((QDialog*)this);
@@ -24,10 +24,49 @@ EditorInstructors::~EditorInstructors()
void EditorInstructors::on_btnNewInstructor_clicked()
{
if(int id = dbInstructors->newInstructor())
if(int id_instructor = dbLMS->newInstructor())
{
loadInstructorsFromDB();
setCurrentInstructor(id);
setCurrentInstructor(id_instructor);
DialogEditInstructor dlg(this);
Instructor instructor = dbLMS->getInstructor(id_instructor);
if(instructor.getID() == 0)
return;
dlg.setInstructor(instructor);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Instructor instructor_edit = dlg.getInstructor();
if(int id_edit = dbLMS->editInstructor(instructor_edit))
{//Отредактировано
loadInstructorsFromDB();
setCurrentInstructor(id_edit);
return;
}
else
{
dlg.setInstructor(instructor_edit);
continue;
}
}
case QDialog::Rejected:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
default:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
}
}
}
}
@@ -43,7 +82,7 @@ void EditorInstructors::on_btnDeleteInstructor_clicked()
int id = treeItemCurrent->text(ColumnsTreeInsructors::clmn_ID).toInt();
if(dbInstructors->isAdmin(id))
if(dbLMS->isAdminInstructor(id))
{//Это Админ!
QMessageBox::critical(this, tr("Error!"), tr("You cannot delete the Administrator."));
return;
@@ -51,7 +90,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)
{
if(dbInstructors->deleteInstructor(id))
if(dbLMS->delInstructor(id))
loadInstructorsFromDB();
}
}
@@ -70,14 +109,14 @@ void EditorInstructors::on_btnToOrFromArchive_clicked()
int id = treeItemCurrent->text(ColumnsTreeInsructors::clmn_ID).toInt();
Instructor instructor = dbInstructors->getInstructor(id);
Instructor instructor = dbLMS->getInstructor(id);
if(instructor.getID() == 0)
return;
if(instructor.getArchived())
{//Архивный
instructor.setArchived(false);
if(int id_edit = dbInstructors->editInstructor(instructor))
if(int id_edit = dbLMS->editInstructor(instructor))
{
loadInstructorsFromDB();
setCurrentInstructor(id_edit);
@@ -86,7 +125,7 @@ void EditorInstructors::on_btnToOrFromArchive_clicked()
else
{//Не Архивный
instructor.setArchived(true);
if(int id_edit = dbInstructors->editInstructor(instructor))
if(int id_edit = dbLMS->editInstructor(instructor))
{
if(!archiveVisible)
ui->btnArchive->click();
@@ -114,7 +153,7 @@ void EditorInstructors::on_btnEdit_clicked()
DialogEditInstructor dlg(this);
Instructor instructor = dbInstructors->getInstructor(id);
Instructor instructor = dbLMS->getInstructor(id);
if(instructor.getID() == 0)
return;
@@ -128,7 +167,7 @@ void EditorInstructors::on_btnEdit_clicked()
{
Instructor instructor_edit = dlg.getInstructor();
if(int id_edit = dbInstructors->editInstructor(instructor_edit))
if(int id_edit = dbLMS->editInstructor(instructor_edit))
{//Отредактировано
loadInstructorsFromDB();
setCurrentInstructor(id_edit);
@@ -173,7 +212,7 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
int id = current->text(ColumnsTreeInsructors::clmn_ID).toInt();
if(dbInstructors->isArchived(id))
if(dbLMS->isArchivedInstructor(id))
{//Архивный
ui->btnToOrFromArchive->setText(tr("From archive"));
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/icons/instructorFromArchive.png")));
@@ -186,7 +225,7 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
ui->btnNewInstructor->setEnabled(true);
if(dbInstructors->isAdmin(id))
if(dbLMS->isAdminInstructor(id))
{//Это Админ! Удалять/Архивировать нельзя!
ui->btnDeleteInstructor->setEnabled(false);
ui->btnToOrFromArchive->setEnabled(false);
@@ -195,7 +234,7 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
{
ui->btnToOrFromArchive->setEnabled(true);
if(dbInstructors->isArchived(id))
if(dbLMS->isArchivedInstructor(id))
ui->btnDeleteInstructor->setEnabled(true);
else
ui->btnDeleteInstructor->setEnabled(false);

View File

@@ -3,7 +3,6 @@
#include <QDialog>
#include <QTreeWidget>
#include "databaseinstructors.h"
#include "instructorsview.h"
namespace Ui {
@@ -17,7 +16,7 @@ class EditorInstructors : public InstructorsView
Q_OBJECT
public:
explicit EditorInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent = nullptr);
explicit EditorInstructors(InterfaceDataBaseLMS* dbLMS, bool adminMode, QWidget *parent = nullptr);
~EditorInstructors();
private Q_SLOTS:

View File

@@ -2,9 +2,9 @@
#include <QTranslator>
#include "instructorsview.h"
InstructorsView::InstructorsView(DataBaseInstructors* dbInstructors, TypeView type, bool adminMode, QWidget *parent):
InstructorsView::InstructorsView(InterfaceDataBaseLMS* dbLMS, TypeView type, bool adminMode, QWidget *parent):
CommonView(type, adminMode, parent),
dbInstructors(dbInstructors)
dbLMS(dbLMS)
{
}
@@ -51,6 +51,9 @@ void InstructorsView::preparationTreeWidget(QTreeWidget* tree)
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Archived, true);
}
}
treeWidget->setSortingEnabled(true);
treeWidget->sortItems(ColumnsTreeInsructors::clmn_Instructor, Qt::SortOrder::AscendingOrder);
}
void InstructorsView::loadInstructorsFromDB()
@@ -63,7 +66,7 @@ void InstructorsView::loadInstructorsFromDB()
//Инструкторы
QList<Instructor> listInstructors;
listInstructors = dbInstructors->getListInstructors();
listInstructors = dbLMS->getListInstructors();
for(Instructor instructor : listInstructors)
{
QTreeWidgetItem *ItemInstructor = new QTreeWidgetItem(treeWidget);
@@ -121,8 +124,6 @@ void InstructorsView::loadInstructorsFromDB()
ItemInstructor->setHidden(true);
}
treeWidget->setSortingEnabled(true);
treeWidget->sortItems(ColumnsTreeInsructors::clmn_Instructor, Qt::SortOrder::AscendingOrder);
treeWidget->expandAll();
if(typeView == TypeView::control)

View File

@@ -2,7 +2,7 @@
#define INSTRUCTORSVIEW_H
#include "instructorsAndTrainees_global.h"
#include "databaseinstructors.h"
#include "interfacedatabaselms.h"
#include "commonview.h"
//Родительский класс представления БД Инструкторов (для просмотра и управления)
@@ -12,7 +12,7 @@ class InstructorsView: public CommonView
Q_OBJECT
public:
InstructorsView(DataBaseInstructors* dbInstructors, TypeView type, bool adminMode, QWidget *parent = nullptr);
InstructorsView(InterfaceDataBaseLMS* dbLMS, TypeView type, bool adminMode, QWidget *parent = nullptr);
protected:
enum ColumnsTreeInsructors{
@@ -32,7 +32,7 @@ protected:
void reSetHeadTreeWidget();
protected:
DataBaseInstructors* dbInstructors;
InterfaceDataBaseLMS* dbLMS;
};
#endif // INSTRUCTORSVIEW_H

View File

@@ -3,7 +3,7 @@
#include "viewerinstructors.h"
#include "ui_viewerinstructors.h"
ViewerInstructors::ViewerInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent) :
ViewerInstructors::ViewerInstructors(InterfaceDataBaseLMS* db, bool adminMode, QWidget *parent) :
InstructorsView(db, CommonView::TypeView::onlyView, adminMode, parent),
ui(new Ui::ViewerInstructors)
{
@@ -61,7 +61,7 @@ void ViewerInstructors::on_btnEditorInstructors_clicked()
return;
}
EditorInstructors editorInstructors(dbInstructors, adminMode);
EditorInstructors editorInstructors(dbLMS, adminMode);
QDialog* dialog = new QDialog(this);
QHBoxLayout *layout = new QHBoxLayout(dialog);
layout->addWidget(&editorInstructors);

View File

@@ -3,7 +3,7 @@
#include <QWidget>
#include "instructorsAndTrainees_global.h"
#include "databaseinstructors.h"
#include "interfacedatabaselms.h"
#include "instructorsview.h"
namespace Ui {
@@ -17,7 +17,7 @@ class ViewerInstructors : public InstructorsView
Q_OBJECT
public:
explicit ViewerInstructors(DataBaseInstructors* db, bool adminMode, QWidget *parent = nullptr);
explicit ViewerInstructors(InterfaceDataBaseLMS* db, bool adminMode, QWidget *parent = nullptr);
~ViewerInstructors();
protected: