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:
@@ -1,5 +1,6 @@
|
||||
#include "databasetrainees.h"
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
DataBaseTrainees::DataBaseTrainees(DataBaseLMS* dbLMS)
|
||||
{
|
||||
@@ -36,7 +37,7 @@ void DataBaseTrainees::LoadTraineesGroupsPSQL()
|
||||
QApplication::beep();
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString learnClass, QString computer)
|
||||
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
@@ -48,12 +49,12 @@ bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QSt
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setLoggedIn(true);
|
||||
trainee.setLearnClass(learnClass);
|
||||
trainee.setComputer(computer);
|
||||
//trainee.setLearnClass(learnClass);
|
||||
//trainee.setComputer(computer);
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return true;
|
||||
@@ -77,12 +78,12 @@ bool DataBaseTrainees::deAuthorizationTrainee(QString login)
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setLoggedIn(false);
|
||||
trainee.setLearnClass(QStringLiteral(""));
|
||||
trainee.setComputer(QStringLiteral(""));
|
||||
//trainee.setLearnClass(QStringLiteral(""));
|
||||
//trainee.setComputer(QStringLiteral(""));
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return true;
|
||||
@@ -94,6 +95,7 @@ bool DataBaseTrainees::deAuthorizationTrainee(QString login)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
void DataBaseTrainees::setTasks(QString login, QStringList tasks)
|
||||
{
|
||||
//Обучаемые
|
||||
@@ -102,39 +104,43 @@ void DataBaseTrainees::setTasks(QString login, QStringList tasks)
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
listOfTrainees[i].setTasks(tasks);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
QStringList DataBaseTrainees::getTasks(QString login)
|
||||
{
|
||||
QStringList tasks;
|
||||
QStringList tasksStrList;
|
||||
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
{
|
||||
tasks = listOfTrainees[i].getTasks();
|
||||
QList<Task> tasks = listOfTrainees[i].getTasks();
|
||||
for(Task task: tasks)
|
||||
{
|
||||
tasksStrList.append(task.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tasks;
|
||||
return tasksStrList;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer)
|
||||
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer_name)
|
||||
{
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getComputer() == computer)
|
||||
if(trainee.getComputer().getName() == computer_name)
|
||||
return trainee.getName();
|
||||
}
|
||||
return QString(QStringLiteral(""));
|
||||
}
|
||||
|
||||
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer)
|
||||
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer_name)
|
||||
{
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getComputer() == computer)
|
||||
if(trainee.getComputer().getName() == computer_name)
|
||||
return trainee;
|
||||
}
|
||||
return Trainee();
|
||||
@@ -149,7 +155,7 @@ QString DataBaseTrainees::getNameTraineeByLogin(QString login)
|
||||
}
|
||||
return QString(QStringLiteral(""));
|
||||
}
|
||||
|
||||
/*
|
||||
QColor DataBaseTrainees::getColorGroupByLogin(QString login)
|
||||
{
|
||||
QString nameTrainee = getNameTraineeByLogin(login);
|
||||
@@ -157,15 +163,15 @@ QColor DataBaseTrainees::getColorGroupByLogin(QString login)
|
||||
QString nameGroup = trainee.getGroup();
|
||||
Group group = getGroup(nameGroup);
|
||||
return getColorGroup(group.getColor());
|
||||
}
|
||||
}*/
|
||||
|
||||
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(QString nameGroup)
|
||||
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(int id)
|
||||
{
|
||||
QList<Trainee> listTrainees;
|
||||
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getGroup() == nameGroup)
|
||||
if(trainee.getGroup().getID() == id)
|
||||
listTrainees.append(trainee);
|
||||
}
|
||||
|
||||
@@ -176,199 +182,185 @@ QList<Group> DataBaseTrainees::getListGroups()
|
||||
{
|
||||
return listOfGroups;
|
||||
}
|
||||
|
||||
/*
|
||||
QColor DataBaseTrainees::getColorGroup(Group::ColorGroup numColor)
|
||||
{
|
||||
if(numColor > listOfColorGroup.count() - 1)
|
||||
return listOfColorGroup.at(Group::ColorGroup::colorAther);
|
||||
|
||||
return listOfColorGroup.at(numColor);
|
||||
}
|
||||
}*/
|
||||
|
||||
Trainee DataBaseTrainees::getTrainee(QString name)
|
||||
Trainee DataBaseTrainees::getTrainee(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(listOfTrainees[i].getID() == id)
|
||||
return listOfTrainees[i];
|
||||
}
|
||||
return Trainee();
|
||||
}
|
||||
|
||||
Group DataBaseTrainees::getGroup(QString nameGroup)
|
||||
Group DataBaseTrainees::getGroup(int id)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == nameGroup)
|
||||
if(listOfGroups[i].getID() == id)
|
||||
return listOfGroups[i];
|
||||
}
|
||||
return Group();
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::newGroup()
|
||||
int DataBaseTrainees::newGroup()
|
||||
{
|
||||
Group group;
|
||||
group.setName(generateDefaultNameGroup());
|
||||
group.setColor(generateDefaultColorGroup());
|
||||
|
||||
bool result = dbLMS->insertGroup(group);
|
||||
int id = dbLMS->insertGroup(group);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
//listOfGroups.append(group);
|
||||
LoadTraineesGroupsPSQL();
|
||||
return group.getName();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return QStringLiteral("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::deleteGroup(QString name)
|
||||
int DataBaseTrainees::deleteGroup(int id)
|
||||
{
|
||||
if(getListTraineesInGroup(name).count() > 0)
|
||||
{//Группа не пуста
|
||||
return false;
|
||||
}
|
||||
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
if(listOfGroups[i].getID() == id)
|
||||
{
|
||||
int id = listOfGroups[i].getID();
|
||||
int id_del = dbLMS->deleteGroup(id);
|
||||
|
||||
bool result = dbLMS->deleteGroup(id);
|
||||
|
||||
if(result)
|
||||
if(id_del)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
//listOfGroups.removeAt(i);
|
||||
|
||||
break;
|
||||
return id_del;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::editGroup(QString name, Group group)
|
||||
int DataBaseTrainees::editGroup(Group group)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
if(listOfGroups[i].getID() == group.getID())
|
||||
{
|
||||
if(!checkExistNameGroup(group.getName()) || group.getName() == name)
|
||||
if(!checkExistNameGroup(group.getName()) || group.getName() == listOfGroups[i].getName())
|
||||
{
|
||||
//group.setID(listOfGroups[i].getID());
|
||||
int id = dbLMS->updateGroup(group);
|
||||
|
||||
bool result = dbLMS->updateGroup(group);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
/*
|
||||
listOfGroups[i].setName(newName);
|
||||
|
||||
//Меняем имя группы у всех Обучаемых этой группы
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getGroup() == name)
|
||||
listOfTrainees[i].setGroup(newName);
|
||||
}
|
||||
*/
|
||||
LoadTraineesGroupsPSQL();
|
||||
|
||||
return true;
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(nullptr, tr("Editing error!"),
|
||||
tr("An existing group name has been entered.\nThe changes will not be accepted."));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::newTrainee(QString nameGroup)
|
||||
int DataBaseTrainees::newTrainee(int id_group)
|
||||
{
|
||||
Trainee trainee;
|
||||
trainee.setGroup(nameGroup);
|
||||
Group group;
|
||||
group.setID(id_group);
|
||||
trainee.setGroup(group);
|
||||
trainee.setName(generateDefaultNameTrainee());
|
||||
trainee.setLogin(generateDefaultLoginTrainee());
|
||||
trainee.setPassword(QStringLiteral("<password>"));
|
||||
trainee.setLearnClass(QStringLiteral(""));
|
||||
trainee.setComputer(QStringLiteral(""));
|
||||
trainee.setArchived(false);
|
||||
trainee.setLoggedIn(false);
|
||||
//trainee.setWhatItDoes(QStringLiteral(""));
|
||||
|
||||
bool result = dbLMS->insertTrainee(trainee);
|
||||
int id = dbLMS->insertTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
//listOfTrainees.append(trainee);
|
||||
LoadTraineesGroupsPSQL();
|
||||
return trainee.getName();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return QStringLiteral("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DataBaseTrainees::deleteTrainee(QString name)
|
||||
int DataBaseTrainees::deleteTrainee(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(listOfTrainees[i].getID() == id)
|
||||
{
|
||||
int id = listOfTrainees[i].getID();
|
||||
int id_del = dbLMS->deleteTrainee(id);
|
||||
|
||||
bool result = dbLMS->deleteTrainee(id);
|
||||
|
||||
if(result)
|
||||
if(id_del)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
//listOfTrainees.removeAt(i);
|
||||
return id_del;
|
||||
}
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::editTrainee(QString name, Trainee trainee)
|
||||
int DataBaseTrainees::editTrainee(Trainee trainee)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(listOfTrainees[i].getID() == trainee.getID())
|
||||
{
|
||||
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == name) &&
|
||||
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == listOfTrainees[i].getName()) &&
|
||||
(!checkExistLoginTrainee(trainee.getLogin()) || trainee.getLogin() == listOfTrainees[i].getLogin()) )
|
||||
{
|
||||
//trainee.setID(listOfTrainees[i].getID());
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
if(id)
|
||||
{
|
||||
//listOfTrainees.replace(i, trainee);
|
||||
LoadTraineesGroupsPSQL();
|
||||
return true;
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(nullptr, tr("Editing error!"),
|
||||
tr("An existing trainee's name or login has been entered.\nThe changes will not be accepted."));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::isArchived(QString name)
|
||||
bool DataBaseTrainees::isArchived(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(listOfTrainees[i].getID()== id)
|
||||
return listOfTrainees[i].getArchived();
|
||||
}
|
||||
return false;
|
||||
@@ -439,7 +431,7 @@ bool DataBaseTrainees::checkExistLoginTrainee(QString login)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
|
||||
{
|
||||
for(int i = 0; i < Group::ColorGroup::countColor; i++)
|
||||
@@ -449,8 +441,8 @@ Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
|
||||
return color;
|
||||
}
|
||||
return Group::ColorGroup::colorAther;
|
||||
}
|
||||
|
||||
}*/
|
||||
/*
|
||||
bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
|
||||
{
|
||||
//Группы
|
||||
@@ -460,4 +452,4 @@ bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <QColor>
|
||||
#include <QObject>
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT DataBaseTrainees : QObject
|
||||
class DataBaseTrainees : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -21,35 +21,33 @@ public:
|
||||
|
||||
void LoadTraineesGroupsPSQL();
|
||||
|
||||
bool AuthorizationTrainee(QString login, QString password, QString learnClass, QString computer);
|
||||
bool AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name);
|
||||
bool deAuthorizationTrainee(QString login);
|
||||
|
||||
void setTasks(QString login, QStringList tasks);
|
||||
//void setTasks(QString login, QStringList tasks);
|
||||
QStringList getTasks(QString login);
|
||||
|
||||
QString getNameTraineeOnComputer(QString computer);
|
||||
Trainee getTraineeOnComputer(QString computer);
|
||||
QString getNameTraineeOnComputer(QString computer_name);
|
||||
Trainee getTraineeOnComputer(QString computer_name);
|
||||
|
||||
QString getNameTraineeByLogin(QString login);
|
||||
QColor getColorGroupByLogin(QString login);
|
||||
//QColor getColorGroupByLogin(QString login);
|
||||
|
||||
QList<Trainee> getListTraineesInGroup(QString nameGroup);
|
||||
QList<Trainee> getListTraineesInGroup(int id);
|
||||
QList<Group> getListGroups();
|
||||
|
||||
QColor getColorGroup(Group::ColorGroup numColor);
|
||||
Trainee getTrainee(int id);
|
||||
Group getGroup(int id);
|
||||
|
||||
Trainee getTrainee(QString name);
|
||||
Group getGroup(QString nameGroup);
|
||||
int newGroup();
|
||||
int deleteGroup(int id);
|
||||
int editGroup(Group group);
|
||||
|
||||
QString newGroup();
|
||||
bool deleteGroup(QString name);
|
||||
bool editGroup(QString name, Group group);
|
||||
int newTrainee(int id_group);
|
||||
int deleteTrainee(int id);
|
||||
int editTrainee(Trainee trainee);
|
||||
|
||||
QString newTrainee(QString nameGroup);
|
||||
void deleteTrainee(QString name);
|
||||
bool editTrainee(QString name, Trainee trainee);
|
||||
|
||||
bool isArchived(QString name);
|
||||
bool isArchived(int id);
|
||||
|
||||
private:
|
||||
QString generateDefaultNameGroup();
|
||||
@@ -60,9 +58,6 @@ private:
|
||||
QString generateDefaultLoginTrainee();
|
||||
bool checkExistLoginTrainee(QString login);
|
||||
|
||||
Group::ColorGroup generateDefaultColorGroup();
|
||||
bool checkExistColorGroup(Group::ColorGroup color);
|
||||
|
||||
private:
|
||||
QList<Trainee> listOfTrainees;
|
||||
QList<Group> listOfGroups;
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
#include "dialogedittrainee.h"
|
||||
|
||||
EditorTrainees::EditorTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent) :
|
||||
//QDialog(parent),
|
||||
TraineesView(db, CommonView::TypeView::control, parent),
|
||||
TraineesView(db, CommonView::TypeView::control, adminMode, parent),
|
||||
ui(new Ui::EditorTrainees)
|
||||
{
|
||||
ui->setupUi((QDialog*)this);
|
||||
@@ -23,9 +22,9 @@ EditorTrainees::~EditorTrainees()
|
||||
|
||||
void EditorTrainees::on_btnNewGroup_clicked()
|
||||
{
|
||||
QString nameGroup = dbTrainees->newGroup();
|
||||
int id = dbTrainees->newGroup();
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
setCurrentGroup(id);
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnDeleteGroup_clicked()
|
||||
@@ -37,13 +36,24 @@ void EditorTrainees::on_btnDeleteGroup_clicked()
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
QString name = treeItemCurrent->text(0);
|
||||
if(dbTrainees->deleteGroup(name))
|
||||
{//Удалено
|
||||
loadTraineesFromDB();
|
||||
int id_group = treeItemCurrent->text(0).toInt();
|
||||
|
||||
if(dbTrainees->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
|
||||
QMessageBox::critical(this, tr("Editing error!"), tr("The group is not empty.\nIt is not possible to delete a non-empty group."));
|
||||
{//Пустая группа
|
||||
if(int id = dbTrainees->deleteGroup(id_group))
|
||||
{//Удалено
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ошибка удаления
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,10 +67,16 @@ void EditorTrainees::on_btnNewTrainee_clicked()
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа. Можно добавить Обучаемого
|
||||
QString nameGroup = treeItemCurrent->text(0);
|
||||
dbTrainees->newTrainee(nameGroup);
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
int id_group = treeItemCurrent->text(0).toInt();
|
||||
if(int id = dbTrainees->newTrainee(id_group))
|
||||
{
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(id_group);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ошибка добавления
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,14 +91,20 @@ void EditorTrainees::on_btnDeleteTrainee_clicked()
|
||||
if(treeItemParent != nullptr)
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
QString nameGroup = treeItemParent->text(0);
|
||||
int id_trainee = treeItemCurrent->text(0).toInt();
|
||||
int id_group = treeItemParent->text(0).toInt();
|
||||
|
||||
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
{
|
||||
dbTrainees->deleteTrainee(name);
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
if(int id = dbTrainees->deleteTrainee(id_trainee))
|
||||
{//Удалено
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(id_group);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ошибка удаления
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,29 +120,37 @@ void EditorTrainees::on_btnToOrFromArchiveTrainee_clicked()
|
||||
if(treeItemParent != nullptr)
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
int id_trainee = treeItemCurrent->text(0).toInt();
|
||||
|
||||
Trainee trainee = dbTrainees->getTrainee(name);
|
||||
Trainee trainee = dbTrainees->getTrainee(id_trainee);
|
||||
|
||||
if(trainee.getArchived())
|
||||
{//Архивный
|
||||
trainee.setArchived(false);
|
||||
if(dbTrainees->editTrainee(name, trainee))
|
||||
{
|
||||
if(int id = dbTrainees->editTrainee(trainee))
|
||||
{//Отредактировано
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(trainee.getName());
|
||||
setCurrentTrainee(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ошибка редактирования
|
||||
}
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
trainee.setArchived(true);
|
||||
if(dbTrainees->editTrainee(name, trainee))
|
||||
{
|
||||
if(int id = dbTrainees->editTrainee(trainee))
|
||||
{//Отредактировано
|
||||
if(!archiveVisible)
|
||||
ui->btnArchive->click();
|
||||
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(trainee.getName());
|
||||
setCurrentTrainee(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ошибка редактирования
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,23 +168,25 @@ void EditorTrainees::on_btnEdit_clicked()
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
|
||||
QString nameGroup = treeItemCurrent->text(0);
|
||||
int id_group = treeItemCurrent->text(0).toInt();
|
||||
|
||||
DialogEditGroup dlg(this);
|
||||
dlg.setGroup(dbTrainees->getGroup(nameGroup));
|
||||
dlg.setGroup(dbTrainees->getGroup(id_group));
|
||||
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbTrainees->editGroup(nameGroup, dlg.getGroup()))
|
||||
{
|
||||
if(int id = dbTrainees->editGroup(dlg.getGroup()))
|
||||
{//Отредактировано
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(dlg.getGroup().getName());
|
||||
setCurrentGroup(id);
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
tr("An existing group name has been entered.\nThe changes will not be accepted."));
|
||||
{
|
||||
//Ошибка редактирования
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
@@ -166,23 +198,25 @@ void EditorTrainees::on_btnEdit_clicked()
|
||||
else
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
int id_trainee = treeItemCurrent->text(0).toInt();
|
||||
|
||||
DialogEditTrainee dlg(this);
|
||||
dlg.setTrainee(dbTrainees->getTrainee(name));
|
||||
dlg.setTrainee(dbTrainees->getTrainee(id_trainee));
|
||||
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbTrainees->editTrainee(name, dlg.getTrainee()))
|
||||
{
|
||||
if(int id = dbTrainees->editTrainee(dlg.getTrainee()))
|
||||
{//Отредактировано
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(dlg.getTrainee().getName());
|
||||
setCurrentTrainee(id);
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
tr("An existing trainee's name or login has been entered.\nThe changes will not be accepted."));
|
||||
{
|
||||
//Ошибка редактирования
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
@@ -210,8 +244,27 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
QTreeWidgetItem *treeItemParent = current->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
ui->btnNewGroup->setEnabled(true);
|
||||
ui->btnDeleteGroup->setEnabled(true);
|
||||
int id_group = current->text(0).toInt();
|
||||
|
||||
if(adminMode)
|
||||
{
|
||||
ui->btnNewGroup->setEnabled(true);
|
||||
|
||||
if(dbTrainees->getListTraineesInGroup(id_group).count() > 0)
|
||||
{//Группа не пуста
|
||||
ui->btnDeleteGroup->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{//Группа пуста
|
||||
ui->btnDeleteGroup->setEnabled(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnNewGroup->setEnabled(false);
|
||||
ui->btnDeleteGroup->setEnabled(false);
|
||||
}
|
||||
|
||||
ui->btnNewTrainee->setEnabled(true);
|
||||
ui->btnDeleteTrainee->setEnabled(false);
|
||||
ui->btnToOrFromArchiveTrainee->setEnabled(false);
|
||||
@@ -223,13 +276,13 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
}
|
||||
else
|
||||
{//Выбран обучаемый
|
||||
QString name = current->text(0);
|
||||
int id_trainee = current->text(0).toInt();
|
||||
|
||||
ui->btnNewGroup->setEnabled(false);
|
||||
ui->btnDeleteGroup->setEnabled(false);
|
||||
ui->btnNewTrainee->setEnabled(false);
|
||||
|
||||
if(dbTrainees->isArchived(name))
|
||||
if(dbTrainees->isArchived(id_trainee))
|
||||
{//Архивный
|
||||
ui->btnDeleteTrainee->setEnabled(true);
|
||||
|
||||
@@ -251,13 +304,13 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::setCurrentGroup(QString nameGroup)
|
||||
void EditorTrainees::setCurrentGroup(int id)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
if(item->text(0) == nameGroup)
|
||||
if(item->text(0).toInt() == id)
|
||||
{
|
||||
treeWidget->setCurrentItem(item);
|
||||
break;
|
||||
@@ -265,7 +318,7 @@ void EditorTrainees::setCurrentGroup(QString nameGroup)
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::setCurrentTrainee(QString name)
|
||||
void EditorTrainees::setCurrentTrainee(int id)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
@@ -276,7 +329,7 @@ void EditorTrainees::setCurrentTrainee(QString name)
|
||||
{
|
||||
QTreeWidgetItem * itemChild = item->child(j);
|
||||
if(itemChild != nullptr)
|
||||
if(itemChild->text(0) == name)
|
||||
if(itemChild->text(0).toInt() == id)
|
||||
{
|
||||
treeWidget->setCurrentItem(itemChild);
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,7 @@ class EditorTrainees : /*public QDialog,*/ public TraineesView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditorTrainees(DataBaseTrainees* db, bool adminMode = false, QWidget *parent = nullptr);
|
||||
explicit EditorTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent = nullptr);
|
||||
~EditorTrainees();
|
||||
|
||||
private Q_SLOTS:
|
||||
@@ -32,8 +32,8 @@ private Q_SLOTS:
|
||||
void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
private:
|
||||
void setCurrentGroup(QString nameGroup);
|
||||
void setCurrentTrainee(QString name);
|
||||
void setCurrentGroup(int id);
|
||||
void setCurrentTrainee(int id);
|
||||
|
||||
private:
|
||||
Ui::EditorTrainees *ui;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QHeaderView>
|
||||
#include "traineesview.h"
|
||||
|
||||
TraineesView::TraineesView(DataBaseTrainees* db, TypeView type, QWidget *parent):
|
||||
CommonView(type, parent),
|
||||
TraineesView::TraineesView(DataBaseTrainees* db, TypeView type, bool adminMode, QWidget *parent):
|
||||
CommonView(type, adminMode, parent),
|
||||
dbTrainees(db)
|
||||
{
|
||||
|
||||
@@ -15,38 +15,38 @@ void TraineesView::preparationTreeWidget(QTreeWidget *tree)
|
||||
if(treeWidget == nullptr)
|
||||
return;
|
||||
|
||||
treeWidget->setColumnCount(9);
|
||||
treeWidget->setColumnCount(10);
|
||||
|
||||
reSetHeadTreeWidget();
|
||||
|
||||
treeWidget->header()->setStyleSheet(QStringLiteral("font-size: 10pt;"));
|
||||
|
||||
treeWidget->setColumnWidth(0, 250);
|
||||
treeWidget->setColumnWidth(1, 100);
|
||||
treeWidget->setColumnWidth(0, 80);
|
||||
treeWidget->setColumnWidth(1, 250);
|
||||
treeWidget->setColumnWidth(2, 100);
|
||||
treeWidget->setColumnWidth(3, 130);
|
||||
treeWidget->setColumnWidth(3, 100);
|
||||
treeWidget->setColumnWidth(4, 130);
|
||||
treeWidget->setColumnWidth(5, 130);
|
||||
treeWidget->setColumnWidth(6, 80);
|
||||
treeWidget->setColumnWidth(6, 130);
|
||||
treeWidget->setColumnWidth(7, 80);
|
||||
treeWidget->setColumnWidth(8, 100);
|
||||
treeWidget->setColumnWidth(8, 80);
|
||||
treeWidget->setColumnWidth(9, 100);
|
||||
|
||||
if(typeView == TypeView::onlyView)
|
||||
{//onlyView
|
||||
treeWidget->setColumnHidden(1, true);
|
||||
treeWidget->setColumnHidden(2, true);
|
||||
treeWidget->setColumnHidden(6, true);
|
||||
treeWidget->setColumnHidden(8, true);
|
||||
treeWidget->setColumnHidden(3, true);
|
||||
treeWidget->setColumnHidden(7, true);
|
||||
}
|
||||
else
|
||||
{//control
|
||||
treeWidget->setColumnHidden(6, true);
|
||||
treeWidget->setColumnHidden(7, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TraineesView::loadTraineesFromDB()
|
||||
{
|
||||
//dbTrainees->LoadTraineesGroupsPSQL();
|
||||
dbTrainees->LoadTraineesGroupsPSQL();
|
||||
|
||||
if(treeWidget == nullptr)
|
||||
return;
|
||||
@@ -58,56 +58,62 @@ void TraineesView::loadTraineesFromDB()
|
||||
{
|
||||
//Группа
|
||||
QTreeWidgetItem *ItemGroup = new QTreeWidgetItem(treeWidget);
|
||||
ItemGroup->setText(0, group.getName());
|
||||
ItemGroup->setIcon(0, QIcon(QStringLiteral(":/icons/group.png")));
|
||||
QColor color = dbTrainees->getColorGroup(/*group.getColor()*/Group::color0);
|
||||
setItemColor(ItemGroup, color);
|
||||
ItemGroup->setText(0, QString::number(group.getID()));
|
||||
ItemGroup->setText(1, group.getName());
|
||||
ItemGroup->setIcon(1, QIcon(QStringLiteral(":/icons/group.png")));
|
||||
setItemColor(ItemGroup, QColor(170, 190, 170));
|
||||
|
||||
//Обучаемые
|
||||
QList<Trainee> listTrainees;
|
||||
listTrainees = dbTrainees->getListTraineesInGroup(group.getName());
|
||||
listTrainees = dbTrainees->getListTraineesInGroup(group.getID());
|
||||
for(Trainee trainee : listTrainees)
|
||||
{
|
||||
QTreeWidgetItem *ItemTrainee = new QTreeWidgetItem();
|
||||
|
||||
ItemTrainee->setText(0, trainee.getName());
|
||||
ItemTrainee->setText(1, trainee.getLogin());
|
||||
ItemTrainee->setText(2, trainee.getPassword());
|
||||
ItemTrainee->setText(3, trainee.getLearnClass());
|
||||
ItemTrainee->setText(4, trainee.getComputer());
|
||||
ItemTrainee->setText(5, trainee.getIpAddress());
|
||||
ItemTrainee->setText(0, QString::number(trainee.getID()));
|
||||
ItemTrainee->setText(1, trainee.getName());
|
||||
ItemTrainee->setText(2, trainee.getLogin());
|
||||
ItemTrainee->setText(3, trainee.getPassword());
|
||||
ItemTrainee->setText(4, trainee.getComputer().getClassroom().getName());
|
||||
ItemTrainee->setText(5, trainee.getComputer().getName());
|
||||
ItemTrainee->setText(6, trainee.getComputer().getIpAddress());
|
||||
|
||||
if(trainee.getArchived())
|
||||
{//Архивный
|
||||
ItemTrainee->setText(6, tr("yes"));
|
||||
ItemTrainee->setIcon(0, QIcon(QStringLiteral(":/icons/traineeArchive.png")));
|
||||
ItemTrainee->setText(7, tr("yes"));
|
||||
ItemTrainee->setIcon(1, QIcon(QStringLiteral(":/icons/traineeArchive.png")));
|
||||
setItemColorArchive(ItemTrainee);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ItemTrainee->setText(6, tr("no"));
|
||||
ItemTrainee->setIcon(0, QIcon(QStringLiteral(":/icons/trainee.png")));
|
||||
ItemTrainee->setText(7, tr("no"));
|
||||
ItemTrainee->setIcon(1, QIcon(QStringLiteral(":/icons/trainee.png")));
|
||||
setItemColorNoArchive(ItemTrainee);
|
||||
}
|
||||
|
||||
if(trainee.getLoggedIn())
|
||||
{//Залогинен
|
||||
ItemTrainee->setText(7, tr("yes"));
|
||||
ItemTrainee->setIcon(7, QIcon(QStringLiteral(":/icons/circleGreen.png")));
|
||||
ItemTrainee->setText(8, tr("yes"));
|
||||
ItemTrainee->setIcon(8, QIcon(QStringLiteral(":/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{//Не Залогинен
|
||||
ItemTrainee->setText(7, tr("no"));
|
||||
ItemTrainee->setIcon(7, QIcon(QStringLiteral(":/icons/circleGray.png")));
|
||||
ItemTrainee->setText(8, tr("no"));
|
||||
ItemTrainee->setIcon(8, QIcon(QStringLiteral(":/icons/circleGray.png")));
|
||||
}
|
||||
|
||||
ItemTrainee->setText(8, QString(trainee.getTasks().join(QStringLiteral(";"))));
|
||||
QString tasksStr;
|
||||
for(Task task: trainee.getTasks())
|
||||
{
|
||||
tasksStr += task.getName() + QStringLiteral("; ");
|
||||
}
|
||||
ItemTrainee->setText(9, tasksStr);
|
||||
|
||||
ItemGroup->addChild(ItemTrainee);
|
||||
|
||||
//Скрываем архивных (при необходимости)
|
||||
if(trainee.getArchived())
|
||||
if(!archiveVisible)
|
||||
if(! archiveVisible)
|
||||
ItemTrainee->setHidden(true);
|
||||
|
||||
//Скрываем незалогиненых (при необходимости)
|
||||
@@ -118,7 +124,7 @@ void TraineesView::loadTraineesFromDB()
|
||||
}
|
||||
|
||||
treeWidget->setSortingEnabled(true);
|
||||
treeWidget->sortItems(0, Qt::SortOrder::AscendingOrder);
|
||||
treeWidget->sortItems(1, Qt::SortOrder::AscendingOrder);
|
||||
treeWidget->expandAll();
|
||||
|
||||
if(typeView == TypeView::control)
|
||||
@@ -131,6 +137,6 @@ void TraineesView::loadTraineesFromDB()
|
||||
|
||||
void TraineesView::reSetHeadTreeWidget()
|
||||
{
|
||||
QStringList listHeaders = {tr("Trainee"), tr("Login"), tr("Password"), tr("Class"), tr("Computer"), tr("IP address"), tr("Archived"), tr("Logged"), tr("Tasks")};
|
||||
QStringList listHeaders = {tr("ID"), tr("Trainee"), tr("Login"), tr("Password"), tr("Class"), tr("Computer"), tr("IP address"), tr("Archived"), tr("Logged"), tr("Tasks")};
|
||||
treeWidget->setHeaderLabels(listHeaders);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
//Родительский класс представления БД Обучаемых (для просмотра и управления)
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT TraineesView: public CommonView
|
||||
class TraineesView: public CommonView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TraineesView(DataBaseTrainees* db, TypeView type, QWidget *parent = nullptr);
|
||||
TraineesView(DataBaseTrainees* db, TypeView type, bool adminMode, QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void preparationTreeWidget(QTreeWidget* tree);
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "ui_viewertrainees.h"
|
||||
|
||||
ViewerTrainees::ViewerTrainees(DataBaseTrainees* db, bool adminMode, QWidget *parent) :
|
||||
//QWidget(parent),
|
||||
TraineesView(db, CommonView::TypeView::onlyView, parent),
|
||||
TraineesView(db, CommonView::TypeView::onlyView, adminMode, parent),
|
||||
ui(new Ui::ViewerTrainees)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -35,7 +34,7 @@ void ViewerTrainees::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column
|
||||
{
|
||||
if(item->childCount() == 0)
|
||||
{//Выбран обучаемый
|
||||
QString login = item->text(1);
|
||||
QString login = item->text(2);
|
||||
Q_EMIT signal_traineeSelected(login);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +47,7 @@ void ViewerTrainees::slot_tabMessengerChanged(QString login)
|
||||
|
||||
for (int j = 0; j < countChild; j++)
|
||||
{//Проход по обучаемым
|
||||
QString loginChild = ui->treeWidget->topLevelItem(i)->child(j)->text(1);
|
||||
QString loginChild = ui->treeWidget->topLevelItem(i)->child(j)->text(2);
|
||||
if(loginChild == login)
|
||||
{
|
||||
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(i)->child(j));
|
||||
@@ -80,16 +79,12 @@ void ViewerTrainees::slot_LanguageChanged(QString language)
|
||||
void ViewerTrainees::on_btnEditorTrainees_clicked()
|
||||
{
|
||||
EditorTrainees editorTraineesGroups(dbTrainees, adminMode);
|
||||
//dlg.setWindowTitle(tr("List trainees"));
|
||||
//dlg.exec();
|
||||
//dlg.show();
|
||||
QDialog* dialog = new QDialog(this);
|
||||
QHBoxLayout *layout = new QHBoxLayout(dialog);
|
||||
layout->addWidget(&editorTraineesGroups);
|
||||
dialog->setWindowTitle(tr("List trainees"));
|
||||
dialog->setWindowTitle(tr("Editor of trainees"));
|
||||
dialog->setMinimumSize(1400, 800);
|
||||
dialog->exec();
|
||||
|
||||
dbTrainees->LoadTraineesGroupsPSQL();
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class ViewerTrainees;
|
||||
|
||||
//Виджет только для просмотра БД Обучаемых
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT ViewerTrainees : public TraineesView
|
||||
class ViewerTrainees : public TraineesView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user