mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
104 lines
2.6 KiB
C++
104 lines
2.6 KiB
C++
#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)
|
|
{
|
|
|
|
}
|