mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
306 lines
8.5 KiB
C++
306 lines
8.5 KiB
C++
#include <QMessageBox>
|
|
#include "interfacedatabaselms.h"
|
|
|
|
InterfaceDataBaseLMS::InterfaceDataBaseLMS():
|
|
DataBaseLMS()
|
|
{
|
|
|
|
}
|
|
|
|
//Инструкторы
|
|
|
|
bool InterfaceDataBaseLMS::AuthorizationInstructor(QString login, QString password)
|
|
{
|
|
if(! transactionBegin())
|
|
return false;
|
|
|
|
if(int id = selectInstructorID(login, password))
|
|
{
|
|
if(updateInstructorLoggedIn(id, true))
|
|
return transactionEnd();
|
|
}
|
|
|
|
transactionEnd();
|
|
return false;
|
|
}
|
|
|
|
bool InterfaceDataBaseLMS::deAuthorizationInstructor(QString login)
|
|
{
|
|
if(! transactionBegin())
|
|
return false;
|
|
|
|
if(int id = selectInstructorID(login))
|
|
{
|
|
if(updateInstructorLoggedIn(id, false))
|
|
return transactionEnd();
|
|
}
|
|
|
|
transactionEnd();
|
|
return false;
|
|
}
|
|
|
|
QList<Instructor> InterfaceDataBaseLMS::getListInstructors()
|
|
{
|
|
return selectAllInstructors();
|
|
}
|
|
|
|
Instructor InterfaceDataBaseLMS::getInstructor(int id)
|
|
{
|
|
return selectInstructor(id);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::newInstructor()
|
|
{
|
|
return insertInstructor();
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::delInstructor(int id)
|
|
{
|
|
return deleteInstructor(id);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::editInstructor(Instructor instructor)
|
|
{
|
|
//Проверка корректности логина, имени, пароля
|
|
QList<Instructor> listInstructors = selectAllInstructors();
|
|
for(Instructor exist_instructor : listInstructors)
|
|
{
|
|
if(instructor.getName() == QStringLiteral("<instructor>"))
|
|
{//Имя не корректно!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable instructor name has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(instructor.getLogin() == QStringLiteral("<login>"))
|
|
{//Логин не корректен!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable instructor login has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(instructor.getPassword() == QStringLiteral("<password>"))
|
|
{//Пароль не корректный!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable instructor password has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(instructor.getName() == exist_instructor.getName() && instructor.getID() != exist_instructor.getID())
|
|
{//Имя уже существует
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("An existing instructor name has been entered."));
|
|
return 0;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
return updateInstructor(instructor);
|
|
}
|
|
|
|
bool InterfaceDataBaseLMS::isAdminInstructor(int id)
|
|
{
|
|
return selectInstructorIsAdmin(id);
|
|
}
|
|
|
|
bool InterfaceDataBaseLMS::isArchivedInstructor(int id)
|
|
{
|
|
return selectInstructorArchived(id);
|
|
}
|
|
|
|
|
|
//Инструкторы
|
|
|
|
bool InterfaceDataBaseLMS::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
|
|
{
|
|
if(! transactionBegin())
|
|
return false;
|
|
|
|
if(int id = selectTraineeID(login, password))
|
|
{
|
|
if(updateTraineeLoggedIn(id, true))
|
|
return transactionEnd();
|
|
}
|
|
|
|
transactionEnd();
|
|
return false;
|
|
}
|
|
|
|
bool InterfaceDataBaseLMS::deAuthorizationTrainee(QString login)
|
|
{
|
|
if(! transactionBegin())
|
|
return false;
|
|
|
|
if(int id = selectTraineeID(login))
|
|
{
|
|
if(updateTraineeLoggedIn(id, false))
|
|
return transactionEnd();
|
|
}
|
|
|
|
transactionEnd();
|
|
return false;
|
|
}
|
|
|
|
QList<Task> InterfaceDataBaseLMS::getTasksTrainee(int id)
|
|
{
|
|
return selectTasksOfTrainee(id);
|
|
}
|
|
|
|
QString InterfaceDataBaseLMS::getNameTraineeOnComputer(QString computer_name)
|
|
{
|
|
/*
|
|
for(Trainee trainee : listOfTrainees)
|
|
{
|
|
if(trainee.getComputer().getName() == computer_name)
|
|
return trainee.getName();
|
|
}*/
|
|
return QString(QStringLiteral(""));
|
|
}
|
|
|
|
Trainee InterfaceDataBaseLMS::getTraineeOnComputer(QString computer_name)
|
|
{
|
|
/*
|
|
for(Trainee trainee : listOfTrainees)
|
|
{
|
|
if(trainee.getComputer().getName() == computer_name)
|
|
return trainee;
|
|
}*/
|
|
return Trainee();
|
|
}
|
|
|
|
QString InterfaceDataBaseLMS::getNameTraineeByLogin(QString login)
|
|
{
|
|
/*
|
|
for(Trainee trainee : listOfTrainees)
|
|
{
|
|
if(trainee.getLogin() == login)
|
|
return trainee.getName();
|
|
}*/
|
|
return QString(QStringLiteral(""));
|
|
}
|
|
|
|
QList<Trainee> InterfaceDataBaseLMS::getListTraineesInGroup(int id)
|
|
{
|
|
return selectAllTraineesInGroup(id);
|
|
}
|
|
|
|
QList<Group> InterfaceDataBaseLMS::getListGroups()
|
|
{
|
|
return selectAllGroups();
|
|
}
|
|
|
|
QList<Trainee> InterfaceDataBaseLMS::getListTrainees()
|
|
{
|
|
return selectAllTrainees();
|
|
}
|
|
|
|
Trainee InterfaceDataBaseLMS::getTrainee(int id)
|
|
{
|
|
return selectTrainee(id);
|
|
}
|
|
|
|
Group InterfaceDataBaseLMS::getGroup(int id)
|
|
{
|
|
return selectGroup(id);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::newGroup()
|
|
{
|
|
return insertGroup();
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::delGroup(int id)
|
|
{
|
|
return deleteGroup(id);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::editGroup(Group group)
|
|
{
|
|
//Проверка корректности имени
|
|
QList<Group> listGroups = selectAllGroups();
|
|
for(Group exist_group : listGroups)
|
|
{
|
|
if(group.getName() == QStringLiteral("<group>"))
|
|
{//Имя не корректно!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable 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 updateGroup(group);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::newTrainee(int id_group)
|
|
{
|
|
return insertTrainee(id_group);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::delTrainee(int id)
|
|
{
|
|
return deleteTrainee(id);
|
|
}
|
|
|
|
int InterfaceDataBaseLMS::editTrainee(Trainee trainee)
|
|
{
|
|
//Проверка корректности логина, имени, пароля
|
|
QList<Trainee> listTrainees = selectAllTrainees();
|
|
for(Trainee exist_trainee : listTrainees)
|
|
{
|
|
if(trainee.getName() == QStringLiteral("<trainee>"))
|
|
{//Имя не корректно!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable trainee name has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(trainee.getLogin() == QStringLiteral("<login>"))
|
|
{//Логин не корректен!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable trainee login has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(trainee.getPassword() == QStringLiteral("<password>"))
|
|
{//Пароль не корректный!
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("Unacceptable trainee password has been entered.\nThe changes will not be accepted."));
|
|
return 0;
|
|
}
|
|
|
|
if(trainee.getName() == exist_trainee.getName() && trainee.getID() != exist_trainee.getID())
|
|
{//Имя уже существует
|
|
QMessageBox::critical(nullptr, tr("Editing error!"),
|
|
tr("An existing trainee name has been entered."));
|
|
return 0;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
return updateTrainee(trainee);
|
|
}
|
|
|
|
bool InterfaceDataBaseLMS::isArchivedTrainee(int id)
|
|
{
|
|
return selectTraineeArchived(id);
|
|
}
|