mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
before interface 13.11.2024
This commit is contained in:
@@ -2,23 +2,10 @@
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
DataBaseTrainees::DataBaseTrainees(DataBaseLMS* dbLMS)
|
||||
DataBaseTrainees::DataBaseTrainees(DataBaseLMS* dbLMS):
|
||||
adminMode(false)
|
||||
{
|
||||
listOfColorGroup.append(QColor(170, 190, 170));
|
||||
listOfColorGroup.append(QColor(180, 180, 220));
|
||||
listOfColorGroup.append(QColor(240, 220, 230));
|
||||
listOfColorGroup.append(QColor(85, 170, 127));
|
||||
listOfColorGroup.append(QColor(170, 115, 120));
|
||||
listOfColorGroup.append(QColor(110, 160, 170));
|
||||
listOfColorGroup.append(QColor(110, 170, 130));
|
||||
listOfColorGroup.append(QColor(170, 170, 120));
|
||||
listOfColorGroup.append(QColor(160, 170, 45));
|
||||
listOfColorGroup.append(QColor(170, 140, 60));
|
||||
listOfColorGroup.append(QColor(200, 200, 200));
|
||||
|
||||
this->dbLMS = dbLMS;
|
||||
|
||||
LoadTraineesGroupsPSQL();
|
||||
}
|
||||
|
||||
DataBaseTrainees::~DataBaseTrainees()
|
||||
@@ -26,430 +13,181 @@ DataBaseTrainees::~DataBaseTrainees()
|
||||
|
||||
}
|
||||
|
||||
void DataBaseTrainees::LoadTraineesGroupsPSQL()
|
||||
void DataBaseTrainees::transactionBegin()
|
||||
{
|
||||
listOfTrainees.clear();
|
||||
listOfGroups.clear();
|
||||
dbLMS->transactionBegin();
|
||||
}
|
||||
|
||||
listOfTrainees = dbLMS->selectAllTrainees();
|
||||
listOfGroups = dbLMS->selectAllGroups();
|
||||
|
||||
QApplication::beep();
|
||||
void DataBaseTrainees::transactionEnd()
|
||||
{
|
||||
dbLMS->transactionEnd();
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
if(! dbLMS->transactionBegin())
|
||||
return false;
|
||||
|
||||
if(int id = dbLMS->selectTraineeID(login, password))
|
||||
{
|
||||
if(listOfTrainees[i].getArchived())
|
||||
continue;
|
||||
|
||||
if(listOfTrainees[i].getLogin() == login && listOfTrainees[i].getPassword() == password)
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setLoggedIn(true);
|
||||
//trainee.setLearnClass(learnClass);
|
||||
//trainee.setComputer(computer);
|
||||
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if(dbLMS->updateTraineeLoggedIn(id, true))
|
||||
return dbLMS->transactionEnd();
|
||||
}
|
||||
|
||||
dbLMS->transactionEnd();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::deAuthorizationTrainee(QString login)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
if(! dbLMS->transactionBegin())
|
||||
return false;
|
||||
|
||||
if(int id = dbLMS->selectTraineeID(login))
|
||||
{
|
||||
if(listOfTrainees[i].getArchived())
|
||||
continue;
|
||||
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setLoggedIn(false);
|
||||
//trainee.setLearnClass(QStringLiteral(""));
|
||||
//trainee.setComputer(QStringLiteral(""));
|
||||
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if(dbLMS->updateTraineeLoggedIn(id, false))
|
||||
return dbLMS->transactionEnd();
|
||||
}
|
||||
|
||||
dbLMS->transactionEnd();
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
void DataBaseTrainees::setTasks(QString login, QStringList tasks)
|
||||
QList<Task> DataBaseTrainees::getTasks(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
listOfTrainees[i].setTasks(tasks);
|
||||
}
|
||||
}*/
|
||||
|
||||
QStringList DataBaseTrainees::getTasks(QString login)
|
||||
{
|
||||
QStringList tasksStrList;
|
||||
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
{
|
||||
QList<Task> tasks = listOfTrainees[i].getTasks();
|
||||
for(Task task: tasks)
|
||||
{
|
||||
tasksStrList.append(task.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tasksStrList;
|
||||
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(""));
|
||||
}
|
||||
/*
|
||||
QColor DataBaseTrainees::getColorGroupByLogin(QString login)
|
||||
{
|
||||
QString nameTrainee = getNameTraineeByLogin(login);
|
||||
Trainee trainee = getTrainee(nameTrainee);
|
||||
QString nameGroup = trainee.getGroup();
|
||||
Group group = getGroup(nameGroup);
|
||||
return getColorGroup(group.getColor());
|
||||
}*/
|
||||
|
||||
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 listOfGroups;
|
||||
return dbLMS->selectAllGroups();
|
||||
}
|
||||
/*
|
||||
QColor DataBaseTrainees::getColorGroup(Group::ColorGroup numColor)
|
||||
{
|
||||
if(numColor > listOfColorGroup.count() - 1)
|
||||
return listOfColorGroup.at(Group::ColorGroup::colorAther);
|
||||
|
||||
return listOfColorGroup.at(numColor);
|
||||
}*/
|
||||
QList<Trainee> DataBaseTrainees::getListTrainees()
|
||||
{
|
||||
return dbLMS->selectAllTrainees();
|
||||
}
|
||||
|
||||
Trainee DataBaseTrainees::getTrainee(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getID() == id)
|
||||
return listOfTrainees[i];
|
||||
}
|
||||
return Trainee();
|
||||
return dbLMS->selectTrainee(id);
|
||||
}
|
||||
|
||||
Group DataBaseTrainees::getGroup(int id)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getID() == id)
|
||||
return listOfGroups[i];
|
||||
}
|
||||
return Group();
|
||||
return dbLMS->selectGroup(id);
|
||||
}
|
||||
|
||||
int DataBaseTrainees::newGroup()
|
||||
{
|
||||
Group group;
|
||||
group.setName(generateDefaultNameGroup());
|
||||
|
||||
int id = dbLMS->insertGroup(group);
|
||||
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return dbLMS->insertGroup();
|
||||
}
|
||||
|
||||
int DataBaseTrainees::deleteGroup(int id)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getID() == id)
|
||||
{
|
||||
int id_del = dbLMS->deleteGroup(id);
|
||||
|
||||
if(id_del)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id_del;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return dbLMS->deleteGroup(id);
|
||||
}
|
||||
|
||||
int DataBaseTrainees::editGroup(Group group)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
//Проверка дублирования имени
|
||||
QList<Group> listGroups = dbLMS->selectAllGroups();
|
||||
for(Group exist_group : listGroups)
|
||||
{
|
||||
if(listOfGroups[i].getID() == group.getID())
|
||||
{
|
||||
if(!checkExistNameGroup(group.getName()) || group.getName() == listOfGroups[i].getName())
|
||||
{
|
||||
int id = dbLMS->updateGroup(group);
|
||||
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
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;
|
||||
}
|
||||
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 0;
|
||||
|
||||
return dbLMS->updateGroup(group);
|
||||
}
|
||||
|
||||
int DataBaseTrainees::newTrainee(int id_group)
|
||||
{
|
||||
Trainee trainee;
|
||||
Group group;
|
||||
group.setID(id_group);
|
||||
trainee.setGroup(group);
|
||||
trainee.setName(generateDefaultNameTrainee());
|
||||
trainee.setLogin(generateDefaultLoginTrainee());
|
||||
trainee.setPassword(QStringLiteral("<password>"));
|
||||
trainee.setArchived(false);
|
||||
trainee.setLoggedIn(false);
|
||||
|
||||
int id = dbLMS->insertTrainee(trainee);
|
||||
|
||||
if(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return dbLMS->insertTrainee(id_group);
|
||||
}
|
||||
|
||||
int DataBaseTrainees::deleteTrainee(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getID() == id)
|
||||
{
|
||||
int id_del = dbLMS->deleteTrainee(id);
|
||||
|
||||
if(id_del)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id_del;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return dbLMS->deleteTrainee(id);
|
||||
}
|
||||
|
||||
int DataBaseTrainees::editTrainee(Trainee trainee)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
//Проверка дублирования логина и имени
|
||||
QList<Trainee> listTrainees = dbLMS->selectAllTrainees();
|
||||
for(Trainee exist_trainee : listTrainees)
|
||||
{
|
||||
if(listOfTrainees[i].getID() == trainee.getID())
|
||||
{
|
||||
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == listOfTrainees[i].getName()) &&
|
||||
(!checkExistLoginTrainee(trainee.getLogin()) || trainee.getLogin() == listOfTrainees[i].getLogin()) )
|
||||
{
|
||||
int id = dbLMS->updateTrainee(trainee);
|
||||
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(id)
|
||||
{
|
||||
LoadTraineesGroupsPSQL();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
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;
|
||||
}
|
||||
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 0;
|
||||
|
||||
return dbLMS->updateTrainee(trainee);
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::isArchived(int id)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getID()== id)
|
||||
return listOfTrainees[i].getArchived();
|
||||
}
|
||||
return false;
|
||||
return dbLMS->selectTraineeArchived(id);
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultNameGroup()
|
||||
{
|
||||
int numGroup = 0;
|
||||
QString name;
|
||||
do
|
||||
{
|
||||
name = tr("Group") + QStringLiteral(" ") + QString::number(++numGroup);
|
||||
}while(checkExistNameGroup(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultNameTrainee()
|
||||
{
|
||||
int numTrainee = 0;
|
||||
QString name;
|
||||
do
|
||||
{
|
||||
name = QStringLiteral("<") + tr("Trainee") + QStringLiteral(" ") + QString::number(++numTrainee) + QStringLiteral(">");
|
||||
}while(checkExistNameTrainee(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistNameGroup(QString name)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistNameTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultLoginTrainee()
|
||||
{
|
||||
int numTrainee = 0;
|
||||
QString login;
|
||||
do
|
||||
{
|
||||
login = QStringLiteral("<O") + QString::number(++numTrainee) + QStringLiteral(">");
|
||||
}while(checkExistLoginTrainee(login));
|
||||
return login;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistLoginTrainee(QString login)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
|
||||
{
|
||||
for(int i = 0; i < Group::ColorGroup::countColor; i++)
|
||||
{
|
||||
Group::ColorGroup color = (Group::ColorGroup)i;
|
||||
if(!checkExistColorGroup(color))
|
||||
return color;
|
||||
}
|
||||
return Group::ColorGroup::colorAther;
|
||||
}*/
|
||||
/*
|
||||
bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getColor() == color)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user