mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
194 lines
4.5 KiB
C++
194 lines
4.5 KiB
C++
#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);
|
|
}
|