Рефакт

This commit is contained in:
2025-08-12 17:52:32 +03:00
parent bcd58e9631
commit 7466e33599
7 changed files with 150 additions and 245 deletions

View File

@@ -6,7 +6,6 @@
#include "interfacedatabaselms.h"
InterfaceDataBaseLMS::InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent):
//QWidget(parent),
QObject(parent),
DataBaseLMS(ownerWidget),
ownerWidget(ownerWidget)
@@ -24,12 +23,12 @@ bool InterfaceDataBaseLMS::ConnectionToDB()
{
if(!createConnection())
{
QMessageBox::critical(nullptr, dbSettings.dbName, tr("Connection error: ") + db->lastError().text());
QMessageBox::critical(ownerWidget, dbSettings.dbName, tr("Connection error: ") + db->lastError().text());
return false;
}
else
{
//QMessageBox::information(nullptr, dbName, tr("Connection is successful!"));
//QMessageBox::information(ownerWidget, dbName, tr("Connection is successful!"));
return true;
}
}
@@ -37,7 +36,7 @@ bool InterfaceDataBaseLMS::ConnectionToDB()
bool InterfaceDataBaseLMS::DisConnectionFromDB()
{
deleteConnection();
//QMessageBox::information(nullptr, dbName, tr("Disconnection is successful!"));
//QMessageBox::information(ownerWidget, dbName, tr("Disconnection is successful!"));
return true;
}
@@ -54,14 +53,14 @@ bool InterfaceDataBaseLMS::AuthorizationInstructor(QString login, QString passwo
if(! transactionBegin())
return false;
if(int id = selectInstructorID(login, password))
if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login, password))
{
if(isArchivedInstructor(id) || isLoggedInInstructor(id))
{
transactionEnd();
return false;
}
if(updateInstructorLoggedIn(id, true))
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, true))
return transactionEnd();
}
@@ -74,9 +73,9 @@ bool InterfaceDataBaseLMS::deAuthorizationInstructor(QString login)
if(! transactionBegin())
return false;
if(int id = selectInstructorID(login))
if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login))
{
if(updateInstructorLoggedIn(id, false))
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, false))
return transactionEnd();
}
@@ -86,17 +85,17 @@ bool InterfaceDataBaseLMS::deAuthorizationInstructor(QString login)
bool InterfaceDataBaseLMS::deAuthorizationAllInstructors()
{
return updateAllInstructorsLoggedIn(false);
return updateAllUsersLoggedIn(DataBaseLMS::TypeUserDBInstructor,false);
}
QString InterfaceDataBaseLMS::getNameInstructorByLogin(QString login)
{
return selectInstructorNameByLogin(login);
return selectUserNameByLogin(DataBaseLMS::TypeUserDBInstructor, login);
}
int InterfaceDataBaseLMS::getIdInstructorByLogin(QString login)
{
return selectInstructorID(login);
return selectUserID(DataBaseLMS::TypeUserDBInstructor, login);
}
QList<Instructor> InterfaceDataBaseLMS::getListInstructors()
@@ -127,35 +126,35 @@ int InterfaceDataBaseLMS::editInstructor(Instructor instructor)
{
if(instructor.getName() == QStringLiteral("<instructor>"))
{//Имя не корректно!
QMessageBox::critical(nullptr, tr("Editing error!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, tr("Editing error!"),
tr("An existing instructor login has been entered.\nThe changes will not be accepted."));
return 0;
}
@@ -171,12 +170,12 @@ bool InterfaceDataBaseLMS::isAdminInstructor(int id)
bool InterfaceDataBaseLMS::isArchivedInstructor(int id)
{
return selectInstructorArchived(id);
return selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id);
}
bool InterfaceDataBaseLMS::isLoggedInInstructor(int id)
{
return selectInstructorLoggedIn(id);
return selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id);
}
@@ -187,14 +186,14 @@ bool InterfaceDataBaseLMS::AuthorizationTrainee(QString login, QString password,
if(! transactionBegin())
return false;
if(int id = selectTraineeID(login, password))
if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login, password))
{
if(isArchivedTrainee(id) || isLoggedInTrainee(id))
{
transactionEnd();
return false;
}
if(updateTraineeLoggedIn(id, true))
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, true))
return transactionEnd();
}
@@ -207,9 +206,9 @@ bool InterfaceDataBaseLMS::deAuthorizationTrainee(QString login)
if(! transactionBegin())
return false;
if(int id = selectTraineeID(login))
if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login))
{
if(updateTraineeLoggedIn(id, false))
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, false))
return transactionEnd();
}
@@ -219,7 +218,7 @@ bool InterfaceDataBaseLMS::deAuthorizationTrainee(QString login)
bool InterfaceDataBaseLMS::deAuthorizationAllTrainees()
{
return updateAllTraineesLoggedIn(false);
return updateAllUsersLoggedIn(DataBaseLMS::TypeUserDBTrainee, false);
}
int InterfaceDataBaseLMS::entryTraineeOnSimulator(int id_trainee)
@@ -274,12 +273,12 @@ Trainee InterfaceDataBaseLMS::getTraineeOnComputer(QString computer_name)
QString InterfaceDataBaseLMS::getNameTraineeByLogin(QString login)
{
return selectTraineeNameByLogin(login);
return selectUserNameByLogin(DataBaseLMS::TypeUserDBTrainee, login);
}
int InterfaceDataBaseLMS::getIdTraineeByLogin(QString login)
{
return selectTraineeID(login);
return selectUserID(DataBaseLMS::TypeUserDBTrainee, login);
}
QList<Trainee> InterfaceDataBaseLMS::getListTraineesInGroup(int id)
@@ -325,14 +324,14 @@ int InterfaceDataBaseLMS::editGroup(Group group)
{
if(group.getName() == QStringLiteral("<group>"))
{//Имя не корректно!
QMessageBox::critical(nullptr, tr("Editing error!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, tr("Editing error!"),
tr("An existing group name has been entered.\nThe changes will not be accepted."));
return 0;
}
@@ -433,35 +432,35 @@ int InterfaceDataBaseLMS::editTrainee(Trainee trainee)
{
if(trainee.getName() == QStringLiteral("<trainee>"))
{//Имя не корректно!
QMessageBox::critical(nullptr, tr("Editing error!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, 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!"),
QMessageBox::critical(ownerWidget, tr("Editing error!"),
tr("An existing trainee login has been entered.\nThe changes will not be accepted."));
return 0;
}
@@ -472,10 +471,10 @@ int InterfaceDataBaseLMS::editTrainee(Trainee trainee)
bool InterfaceDataBaseLMS::isArchivedTrainee(int id)
{
return selectTraineeArchived(id);
return selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id);
}
bool InterfaceDataBaseLMS::isLoggedInTrainee(int id)
{
return selectTraineeLoggedIn(id);
return selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id);
}