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

@@ -39,8 +39,6 @@ add_library(InstructorsAndTrainees SHARED
trainees/dialogedittrainee.ui
trainees/computersLocations.h
trainees/computersLocations.cpp
trainees/databasetrainees.h
trainees/databasetrainees.cpp
trainees/viewertrainees.cpp
trainees/viewertrainees.h
trainees/viewertrainees.ui
@@ -49,8 +47,6 @@ add_library(InstructorsAndTrainees SHARED
instructors/viewerinstructors.cpp
instructors/viewerinstructors.h
instructors/viewerinstructors.ui
instructors/databaseinstructors.cpp
instructors/databaseinstructors.h
instructors/editorinstructors.cpp
instructors/editorinstructors.h
instructors/editorinstructors.ui

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2024-11-13T09:53:44. -->
<!-- Written by QtCreator 4.11.1, 2024-11-13T17:15:54. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

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:

View File

@@ -11,16 +11,13 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
{
ui->setupUi(this);
dbLMS = new DataBaseLMS();
dataBaseTrainees = new DataBaseTrainees(dbLMS);
dataBaseInstructors = new DataBaseInstructors(dbLMS);
dbLMS = new InterfaceDataBaseLMS();
//Авторизация Инструктора локальная (Администратора)
authorizationInstructorLocal(this);
m_viewerTrainees = new ViewerTrainees(dataBaseTrainees, adminMode);
m_viewerInstructors = new ViewerInstructors(dataBaseInstructors, adminMode);
m_viewerTrainees = new ViewerTrainees(dbLMS, adminMode);
m_viewerInstructors = new ViewerInstructors(dbLMS, adminMode);
ui->verticalLayout->addWidget(m_viewerTrainees);
ui->verticalLayout->addWidget(m_viewerInstructors);
@@ -35,8 +32,6 @@ InstructorsAndTraineesWidget::~InstructorsAndTraineesWidget()
delete m_viewerInstructors;
delete m_viewerTrainees;
delete dataBaseInstructors;
delete dataBaseTrainees;
delete dbLMS;
delete ui;
}
@@ -55,7 +50,7 @@ bool InstructorsAndTraineesWidget::authorizationInstructorLocal(QWidget* parent)
QString login = dlg.getLogin();
QString password = dlg.getPassword();
if(dataBaseInstructors->AuthorizationInstructor(login, password))
if(dbLMS->AuthorizationInstructor(login, password))
{
loginInstructorLoggedInLocal = login;
@@ -92,20 +87,20 @@ bool InstructorsAndTraineesWidget::authorizationIsCompleted()
bool InstructorsAndTraineesWidget::authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
return dataBaseTrainees->AuthorizationTrainee(login, password, classroom_name, computer_name);
return dbLMS->AuthorizationTrainee(login, password, classroom_name, computer_name);
}
bool InstructorsAndTraineesWidget::deAuthorizationTrainee(QString login)
{
return dataBaseTrainees->deAuthorizationTrainee(login);
return dbLMS->deAuthorizationTrainee(login);
}
bool InstructorsAndTraineesWidget::authorizationInstructor(QString login, QString password)
{
return dataBaseInstructors->AuthorizationInstructor(login, password);
return dbLMS->AuthorizationInstructor(login, password);
}
bool InstructorsAndTraineesWidget::deAuthorizationInstructor(QString login)
{
return dataBaseInstructors->deAuthorizationInstructor(login);
return dbLMS->deAuthorizationInstructor(login);
}

View File

@@ -3,8 +3,6 @@
#include <QWidget>
#include "instructorsAndTrainees_global.h"
#include "databasetrainees.h"
#include "databaseinstructors.h"
#include "viewertrainees.h"
#include "viewerinstructors.h"
#include "interfacedatabaselms.h"
@@ -37,10 +35,7 @@ public:
private:
Ui::InstructorsAndTraineesWidget *ui;
DataBaseLMS* dbLMS;
DataBaseTrainees* dataBaseTrainees;
DataBaseInstructors* dataBaseInstructors;
InterfaceDataBaseLMS* dbLMS;
ViewerTrainees* m_viewerTrainees;
ViewerInstructors* m_viewerInstructors;

View File

@@ -1,10 +1,10 @@
#include "taskswidget.h"
#include "ui_taskswidget.h"
TasksWidget::TasksWidget(DataBaseTrainees* db, QWidget *parent) :
TasksWidget::TasksWidget(InterfaceDataBaseLMS* dbLMS, QWidget *parent) :
QWidget(parent),
ui(new Ui::TasksWidget),
pDbTrainees(db)
dbLMS(dbLMS)
{
ui->setupUi(this);
}

View File

@@ -4,7 +4,7 @@
#include <QWidget>
#include <QTranslator>
#include "instructorsAndTrainees_global.h"
#include "databasetrainees.h"
#include "interfacedatabaselms.h"
namespace Ui {
class TasksWidget;
@@ -15,7 +15,7 @@ class INSTRUCTORSANDTRAINEES_EXPORT TasksWidget : public QWidget
Q_OBJECT
public:
explicit TasksWidget(DataBaseTrainees* db, QWidget *parent = nullptr);
explicit TasksWidget(InterfaceDataBaseLMS* dbLMS, QWidget *parent = nullptr);
~TasksWidget();
protected:
@@ -35,7 +35,7 @@ private:
Ui::TasksWidget *ui;
QTranslator qtLanguageTranslator;
DataBaseTrainees* pDbTrainees;
InterfaceDataBaseLMS* dbLMS;
};
#endif // TASKSWIDGET_H

View File

@@ -1,193 +0,0 @@
#include "databasetrainees.h"
#include <QApplication>
#include <QMessageBox>
DataBaseTrainees::DataBaseTrainees(DataBaseLMS* dbLMS):
adminMode(false)
{
this->dbLMS = dbLMS;
}
DataBaseTrainees::~DataBaseTrainees()
{
}
void DataBaseTrainees::transactionBegin()
{
dbLMS->transactionBegin();
}
void DataBaseTrainees::transactionEnd()
{
dbLMS->transactionEnd();
}
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
if(! dbLMS->transactionBegin())
return false;
if(int id = dbLMS->selectTraineeID(login, password))
{
if(dbLMS->updateTraineeLoggedIn(id, true))
return dbLMS->transactionEnd();
}
dbLMS->transactionEnd();
return false;
}
bool DataBaseTrainees::deAuthorizationTrainee(QString login)
{
if(! dbLMS->transactionBegin())
return false;
if(int id = dbLMS->selectTraineeID(login))
{
if(dbLMS->updateTraineeLoggedIn(id, false))
return dbLMS->transactionEnd();
}
dbLMS->transactionEnd();
return false;
}
QList<Task> DataBaseTrainees::getTasks(int id)
{
return dbLMS->selectTasksOfTrainee(id);
}
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer_name)
{
/*
for(Trainee trainee : listOfTrainees)
{
if(trainee.getComputer().getName() == computer_name)
return trainee.getName();
}*/
return QString(QStringLiteral(""));
}
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer_name)
{
/*
for(Trainee trainee : listOfTrainees)
{
if(trainee.getComputer().getName() == computer_name)
return trainee;
}*/
return Trainee();
}
QString DataBaseTrainees::getNameTraineeByLogin(QString login)
{
/*
for(Trainee trainee : listOfTrainees)
{
if(trainee.getLogin() == login)
return trainee.getName();
}*/
return QString(QStringLiteral(""));
}
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(int id)
{
QList<Trainee> listTrainees;
/*
for(Trainee trainee : listOfTrainees)
{
if(trainee.getGroup().getID() == id)
listTrainees.append(trainee);
}
*/
return listTrainees;
}
QList<Group> DataBaseTrainees::getListGroups()
{
return dbLMS->selectAllGroups();
}
QList<Trainee> DataBaseTrainees::getListTrainees()
{
return dbLMS->selectAllTrainees();
}
Trainee DataBaseTrainees::getTrainee(int id)
{
return dbLMS->selectTrainee(id);
}
Group DataBaseTrainees::getGroup(int id)
{
return dbLMS->selectGroup(id);
}
int DataBaseTrainees::newGroup()
{
return dbLMS->insertGroup();
}
int DataBaseTrainees::deleteGroup(int id)
{
return dbLMS->deleteGroup(id);
}
int DataBaseTrainees::editGroup(Group group)
{
//Проверка дублирования имени
QList<Group> listGroups = dbLMS->selectAllGroups();
for(Group exist_group : listGroups)
{
if(group.getName() == exist_group.getName() && group.getID() != exist_group.getID())
{//Имя уже существует
QMessageBox::critical(nullptr, tr("Editing error!"),
tr("An existing group name has been entered."));
return 0;
}
}
return dbLMS->updateGroup(group);
}
int DataBaseTrainees::newTrainee(int id_group)
{
return dbLMS->insertTrainee(id_group);
}
int DataBaseTrainees::deleteTrainee(int id)
{
return dbLMS->deleteTrainee(id);
}
int DataBaseTrainees::editTrainee(Trainee trainee)
{
//Проверка дублирования логина и имени
QList<Trainee> listTrainees = dbLMS->selectAllTrainees();
for(Trainee exist_trainee : listTrainees)
{
if(trainee.getLogin() == exist_trainee.getLogin() && trainee.getID() != exist_trainee.getID())
{//Логин уже существует!
QMessageBox::critical(nullptr, tr("Editing error!"),
tr("An existing trainee login has been entered.\nThe changes will not be accepted."));
return 0;
}
if(trainee.getName() == exist_trainee.getName() && trainee.getID() != exist_trainee.getID())
{//Имя уже существует
QMessageBox::warning(nullptr, tr("Editing warning!"),
tr("An existing trainee name has been entered."));
//return 0;
}
}
return dbLMS->updateTrainee(trainee);
}
bool DataBaseTrainees::isArchived(int id)
{
return dbLMS->selectTraineeArchived(id);
}

View File

@@ -1,60 +0,0 @@
#ifndef DATABASETRAINEES_H
#define DATABASETRAINEES_H
#include "instructorsAndTrainees_global.h"
#include "trainee.h"
#include "group.h"
#include "databaselms.h"
#include <QList>
#include <QColor>
#include <QObject>
class DataBaseTrainees : QObject
{
Q_OBJECT
public:
DataBaseTrainees(DataBaseLMS* dbLMS);
~DataBaseTrainees();
//void LoadTraineesGroupsPSQL();
void transactionBegin();
void transactionEnd();
bool AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name);
bool deAuthorizationTrainee(QString login);
//void setTasks(QString login, QStringList tasks);
QList<Task> getTasks(int id);
QString getNameTraineeOnComputer(QString computer_name);
Trainee getTraineeOnComputer(QString computer_name);
QString getNameTraineeByLogin(QString login);
QList<Trainee> getListTraineesInGroup(int id);
QList<Group> getListGroups();
QList<Trainee> getListTrainees();
Trainee getTrainee(int trainee_id);
Group getGroup(int group_id);
int newGroup();
int deleteGroup(int id);
int editGroup(Group group);
int newTrainee(int id_group);
int deleteTrainee(int id);
int editTrainee(Trainee trainee);
bool isArchived(int id);
private:
bool adminMode;
DataBaseLMS* dbLMS;
};
#endif // DATABASETRAINEES_H

View File

@@ -4,8 +4,8 @@
#include "dialogeditgroup.h"
#include "dialogedittrainee.h"
EditorTrainees::EditorTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent) :
TraineesView(db, CommonView::TypeView::control, adminMode, parent),
EditorTrainees::EditorTrainees(InterfaceDataBaseLMS* dbLMS, bool adminMode, QWidget *parent) :
TraineesView(dbLMS, CommonView::TypeView::control, adminMode, parent),
ui(new Ui::EditorTrainees)
{
ui->setupUi((QDialog*)this);
@@ -25,10 +25,50 @@ EditorTrainees::~EditorTrainees()
void EditorTrainees::on_btnNewGroup_clicked()
{
if(int id = dbTrainees->newGroup())
if(int id_group = dbLMS->newGroup())
{
loadTraineesFromDB();
setCurrentGroup(id);
setCurrentGroup(id_group);
DialogEditGroup dlg(this);
Group group = dbLMS->getGroup(id_group);
if(group.getID() == 0)
return;
dlg.setGroup(group);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Group group_edit = dlg.getGroup();
if(int id_edit = dbLMS->editGroup(group_edit))
{//Отредактировано
loadTraineesFromDB();
setCurrentGroup(id_edit);
return;
}
else
{
dlg.setGroup(group_edit);
continue;
}
}
case QDialog::Rejected:
dbLMS->delGroup(id_group);
loadTraineesFromDB();
return;
default:
dbLMS->delGroup(id_group);
loadTraineesFromDB();
return;
}
}
}
}
@@ -43,14 +83,14 @@ void EditorTrainees::on_btnDeleteGroup_clicked()
{//Выбрана группа
int id_group = treeItemCurrent->text(ColumnsTreeTrainees::clmn_ID).toInt();
if(dbTrainees->getListTraineesInGroup(id_group).count() > 0)
if(dbLMS->getListTraineesInGroup(id_group).count() > 0)
{
QMessageBox::critical(this, tr("Editing error!"), tr("The group is not empty.\nIt is not possible to delete a non-empty group."));
return;
}
else
{//Пустая группа
if(int id = dbTrainees->deleteGroup(id_group))
if(int id = dbLMS->delGroup(id_group))
{//Удалено
loadTraineesFromDB();
}
@@ -73,14 +113,54 @@ void EditorTrainees::on_btnNewTrainee_clicked()
if(treeItemParent == nullptr)
{//Выбрана группа. Можно добавить Обучаемого
int id_group = treeItemCurrent->text(ColumnsTreeTrainees::clmn_ID).toInt();
if(int id = dbTrainees->newTrainee(id_group))
if(int id_trainee = dbLMS->newTrainee(id_group))
{
loadTraineesFromDB();
setCurrentGroup(id_group);
}
else
{
//Ошибка добавления
DialogEditTrainee dlg(this);
Trainee trainee = dbLMS->getTrainee(id_trainee);
if(trainee.getID() == 0)
return;
dlg.setTrainee(trainee);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Trainee trainee_edit = dlg.getTrainee();
if(int id_edit = dbLMS->editTrainee(trainee_edit))
{//Отредактировано
loadTraineesFromDB();
//setCurrentTrainee(id_edit);
setCurrentGroup(id_group);
return;
}
else
{
dlg.setTrainee(trainee_edit);
continue;
}
break;
}
case QDialog::Rejected:
dbLMS->delTrainee(id_trainee);
loadTraineesFromDB();
setCurrentGroup(id_group);
return;
default:
dbLMS->delTrainee(id_trainee);
loadTraineesFromDB();
setCurrentGroup(id_group);
return;
}
}
}
}
}
@@ -101,7 +181,7 @@ void EditorTrainees::on_btnDeleteTrainee_clicked()
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
{
if(int id = dbTrainees->deleteTrainee(id_trainee))
if(int id = dbLMS->delTrainee(id_trainee))
{//Удалено
loadTraineesFromDB();
setCurrentGroup(id_group);
@@ -127,14 +207,14 @@ void EditorTrainees::on_btnToOrFromArchiveTrainee_clicked()
int id_trainee = treeItemCurrent->text(ColumnsTreeTrainees::clmn_ID).toInt();
Trainee trainee = dbTrainees->getTrainee(id_trainee);
Trainee trainee = dbLMS->getTrainee(id_trainee);
if(trainee.getID() == 0)
return;
if(trainee.getArchived())
{//Архивный
trainee.setArchived(false);
if(int id = dbTrainees->editTrainee(trainee))
if(int id = dbLMS->editTrainee(trainee))
{//Отредактировано
loadTraineesFromDB();
setCurrentTrainee(id);
@@ -147,7 +227,7 @@ void EditorTrainees::on_btnToOrFromArchiveTrainee_clicked()
else
{//Не Архивный
trainee.setArchived(true);
if(int id = dbTrainees->editTrainee(trainee))
if(int id = dbLMS->editTrainee(trainee))
{//Отредактировано
if(!archiveVisible)
ui->btnArchive->click();
@@ -179,7 +259,7 @@ void EditorTrainees::on_btnEdit_clicked()
DialogEditGroup dlg(this);
Group group = dbTrainees->getGroup(id_group);
Group group = dbLMS->getGroup(id_group);
if(group.getID() == 0)
return;
@@ -193,7 +273,7 @@ void EditorTrainees::on_btnEdit_clicked()
{
Group group_edit = dlg.getGroup();
if(int id = dbTrainees->editGroup(group_edit))
if(int id = dbLMS->editGroup(group_edit))
{//Отредактировано
loadTraineesFromDB();
setCurrentGroup(id);
@@ -223,7 +303,7 @@ void EditorTrainees::on_btnEdit_clicked()
DialogEditTrainee dlg(this);
Trainee trainee = dbTrainees->getTrainee(id_trainee);
Trainee trainee = dbLMS->getTrainee(id_trainee);
if(trainee.getID() == 0)
return;
@@ -237,7 +317,7 @@ void EditorTrainees::on_btnEdit_clicked()
{
Trainee trainee_edit = dlg.getTrainee();
if(int id = dbTrainees->editTrainee(trainee_edit))
if(int id = dbLMS->editTrainee(trainee_edit))
{//Отредактировано
loadTraineesFromDB();
setCurrentTrainee(id);
@@ -285,7 +365,7 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
{
ui->btnNewGroup->setEnabled(true);
if(dbTrainees->getListTraineesInGroup(id_group).count() > 0)
if(dbLMS->getListTraineesInGroup(id_group).count() > 0)
{//Группа не пуста
ui->btnDeleteGroup->setEnabled(false);
}
@@ -317,7 +397,7 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
ui->btnDeleteGroup->setEnabled(false);
ui->btnNewTrainee->setEnabled(false);
if(dbTrainees->isArchived(id_trainee))
if(dbLMS->isArchivedTrainee(id_trainee))
{//Архивный
ui->btnDeleteTrainee->setEnabled(true);

View File

@@ -4,7 +4,7 @@
#include <QDialog>
#include <QTreeWidget>
//#include "computersLocations.h"
#include "databasetrainees.h"
#include "interfacedatabaselms.h"
#include "traineesview.h"
namespace Ui {
@@ -18,7 +18,7 @@ class EditorTrainees : /*public QDialog,*/ public TraineesView
Q_OBJECT
public:
explicit EditorTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent = nullptr);
explicit EditorTrainees(InterfaceDataBaseLMS* dbLMS, bool adminMode, QWidget *parent = nullptr);
~EditorTrainees();
private Q_SLOTS:

View File

@@ -1,9 +1,9 @@
#include <QHeaderView>
#include "traineesview.h"
TraineesView::TraineesView(DataBaseTrainees* dbTrainees, TypeView type, bool adminMode, QWidget *parent):
TraineesView::TraineesView(InterfaceDataBaseLMS* dbLMS, TypeView type, bool adminMode, QWidget *parent):
CommonView(type, adminMode, parent),
dbTrainees(dbTrainees)
dbLMS(dbLMS)
{
}
@@ -57,16 +57,18 @@ void TraineesView::preparationTreeWidget(QTreeWidget *tree)
}
}
treeWidget->setSortingEnabled(true);
treeWidget->sortItems(ColumnsTreeTrainees::clmn_Trainee, Qt::SortOrder::AscendingOrder);
}
void TraineesView::loadTraineesFromDB()
{
QList <Group> listGroups;
QList <Trainee> listTrainees;
dbTrainees->transactionBegin();
listGroups = dbTrainees->getListGroups();
listTrainees = dbTrainees->getListTrainees();
dbTrainees->transactionEnd();
//dbTrainees->transactionBegin();
listGroups = dbLMS->getListGroups();
listTrainees = dbLMS->getListTrainees();
//dbTrainees->transactionEnd();
if(treeWidget == nullptr)
return;
@@ -147,8 +149,6 @@ void TraineesView::loadTraineesFromDB()
}
}
treeWidget->setSortingEnabled(true);
treeWidget->sortItems(ColumnsTreeTrainees::clmn_Trainee, Qt::SortOrder::AscendingOrder);
treeWidget->expandAll();
if(typeView == TypeView::control)

View File

@@ -2,7 +2,7 @@
#define TRAINEESVIEW_H
#include "instructorsAndTrainees_global.h"
#include "databasetrainees.h"
#include "interfacedatabaselms.h"
#include "commonview.h"
//Родительский класс представления БД Обучаемых (для просмотра и управления)
@@ -12,7 +12,7 @@ class TraineesView: public CommonView
Q_OBJECT
public:
TraineesView(DataBaseTrainees* dbTrainees, TypeView type, bool adminMode, QWidget *parent = nullptr);
TraineesView(InterfaceDataBaseLMS* dbLMS, TypeView type, bool adminMode, QWidget *parent = nullptr);
protected:
enum ColumnsTreeTrainees{
@@ -35,7 +35,7 @@ protected:
void reSetHeadTreeWidget();
protected:
DataBaseTrainees* dbTrainees;
InterfaceDataBaseLMS* dbLMS;
};
#endif // TRAINEESVIEW_H

View File

@@ -2,7 +2,7 @@
#include "viewertrainees.h"
#include "ui_viewertrainees.h"
ViewerTrainees::ViewerTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent) :
ViewerTrainees::ViewerTrainees(InterfaceDataBaseLMS* db, bool adminMode, QWidget *parent) :
TraineesView(db, CommonView::TypeView::onlyView, adminMode, parent),
ui(new Ui::ViewerTrainees)
{
@@ -78,7 +78,7 @@ void ViewerTrainees::slot_LanguageChanged(QString language)
void ViewerTrainees::on_btnEditorTrainees_clicked()
{
EditorTrainees editorTraineesGroups(dbTrainees, adminMode);
EditorTrainees editorTraineesGroups(dbLMS, adminMode);
QDialog* dialog = new QDialog(this);
QHBoxLayout *layout = new QHBoxLayout(dialog);
layout->addWidget(&editorTraineesGroups);

View File

@@ -5,7 +5,7 @@
#include <QObject>
#include <QEvent>
#include "instructorsAndTrainees_global.h"
#include "databasetrainees.h"
#include "interfacedatabaselms.h"
#include "traineesview.h"
namespace Ui {
@@ -19,7 +19,7 @@ class ViewerTrainees : public TraineesView
Q_OBJECT
public:
explicit ViewerTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent = nullptr);
explicit ViewerTrainees(InterfaceDataBaseLMS* db, bool adminMode, QWidget *parent = nullptr);
~ViewerTrainees();
protected: