QMutexLocker

This commit is contained in:
2025-08-13 10:50:55 +03:00
parent 7466e33599
commit 93fe4a94b2
4 changed files with 69 additions and 80 deletions

View File

@@ -21,6 +21,7 @@ void InterfaceDataBaseLMS::slot_LanguageChanged(QString language)
bool InterfaceDataBaseLMS::ConnectionToDB()
{
QMutexLocker mtxLocker(&mtxAccess);
if(!createConnection())
{
QMessageBox::critical(ownerWidget, dbSettings.dbName, tr("Connection error: ") + db->lastError().text());
@@ -34,7 +35,8 @@ bool InterfaceDataBaseLMS::ConnectionToDB()
}
bool InterfaceDataBaseLMS::DisConnectionFromDB()
{
{
QMutexLocker mtxLocker(&mtxAccess);
deleteConnection();
//QMessageBox::information(ownerWidget, dbName, tr("Disconnection is successful!"));
return true;
@@ -42,6 +44,7 @@ bool InterfaceDataBaseLMS::DisConnectionFromDB()
bool InterfaceDataBaseLMS::DBisConnected()
{
QMutexLocker mtxLocker(&mtxAccess);
return isConnected();
}
@@ -50,76 +53,77 @@ bool InterfaceDataBaseLMS::DBisConnected()
bool InterfaceDataBaseLMS::AuthorizationInstructor(QString login, QString password)
{
if(! transactionBegin())
return false;
QMutexLocker mtxLocker(&mtxAccess);
if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login, password))
{
if(isArchivedInstructor(id) || isLoggedInInstructor(id))
{
transactionEnd();
if(selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id))
return false;
}
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, true))
return transactionEnd();
}
transactionEnd();
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, true))
return true;
}
return false;
}
bool InterfaceDataBaseLMS::deAuthorizationInstructor(QString login)
{
if(! transactionBegin())
return false;
QMutexLocker mtxLocker(&mtxAccess);
if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login))
{
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, false))
return transactionEnd();
return true;
}
transactionEnd();
return false;
}
bool InterfaceDataBaseLMS::deAuthorizationAllInstructors()
{
QMutexLocker mtxLocker(&mtxAccess);
return updateAllUsersLoggedIn(DataBaseLMS::TypeUserDBInstructor,false);
}
QString InterfaceDataBaseLMS::getNameInstructorByLogin(QString login)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserNameByLogin(DataBaseLMS::TypeUserDBInstructor, login);
}
int InterfaceDataBaseLMS::getIdInstructorByLogin(QString login)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserID(DataBaseLMS::TypeUserDBInstructor, login);
}
QList<Instructor> InterfaceDataBaseLMS::getListInstructors()
{
QMutexLocker mtxLocker(&mtxAccess);
return selectAllInstructors();
}
Instructor InterfaceDataBaseLMS::getInstructor(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectInstructor(id);
}
int InterfaceDataBaseLMS::newInstructor()
{
QMutexLocker mtxLocker(&mtxAccess);
return insertInstructor();
}
int InterfaceDataBaseLMS::delInstructor(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return deleteInstructor(id);
}
int InterfaceDataBaseLMS::editInstructor(Instructor instructor)
{
QMutexLocker mtxLocker(&mtxAccess);
//Проверка корректности логина, имени, пароля
QList<Instructor> listInstructors = selectAllInstructors();
for(Instructor exist_instructor : listInstructors)
@@ -165,16 +169,19 @@ int InterfaceDataBaseLMS::editInstructor(Instructor instructor)
bool InterfaceDataBaseLMS::isAdminInstructor(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectInstructorIsAdmin(id);
}
bool InterfaceDataBaseLMS::isArchivedInstructor(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id);
}
bool InterfaceDataBaseLMS::isLoggedInInstructor(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id);
}
@@ -183,46 +190,41 @@ bool InterfaceDataBaseLMS::isLoggedInInstructor(int id)
bool InterfaceDataBaseLMS::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
if(! transactionBegin())
return false;
QMutexLocker mtxLocker(&mtxAccess);
if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login, password))
{
if(isArchivedTrainee(id) || isLoggedInTrainee(id))
{
transactionEnd();
if(selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id))
return false;
}
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, true))
return transactionEnd();
}
transactionEnd();
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, true))
return true;
}
return false;
}
bool InterfaceDataBaseLMS::deAuthorizationTrainee(QString login)
{
if(! transactionBegin())
return false;
QMutexLocker mtxLocker(&mtxAccess);
if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login))
{
if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, false))
return transactionEnd();
return true;
}
transactionEnd();
return false;
}
bool InterfaceDataBaseLMS::deAuthorizationAllTrainees()
{
QMutexLocker mtxLocker(&mtxAccess);
return updateAllUsersLoggedIn(DataBaseLMS::TypeUserDBTrainee, false);
}
int InterfaceDataBaseLMS::entryTraineeOnSimulator(int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
TimingOfTrainee timing(id_trainee);
timing = selectTimingTrainee(id_trainee);
@@ -243,6 +245,8 @@ int InterfaceDataBaseLMS::entryTraineeOnSimulator(int id_trainee)
int InterfaceDataBaseLMS::exitTraineeFromSimulator(int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
TimingOfTrainee timing(id_trainee);
timing = selectTimingTrainee(id_trainee);
@@ -263,61 +267,74 @@ int InterfaceDataBaseLMS::exitTraineeFromSimulator(int id_trainee)
QString InterfaceDataBaseLMS::getNameTraineeOnComputer(QString computer_name)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTraineeNameOnComputer(computer_name);
}
Trainee InterfaceDataBaseLMS::getTraineeOnComputer(QString computer_name)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTraineeOnComputer(computer_name);
}
QString InterfaceDataBaseLMS::getNameTraineeByLogin(QString login)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserNameByLogin(DataBaseLMS::TypeUserDBTrainee, login);
}
int InterfaceDataBaseLMS::getIdTraineeByLogin(QString login)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserID(DataBaseLMS::TypeUserDBTrainee, login);
}
QList<Trainee> InterfaceDataBaseLMS::getListTraineesInGroup(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectAllTraineesInGroup(id);
}
QList<Group> InterfaceDataBaseLMS::getListGroups()
{
QMutexLocker mtxLocker(&mtxAccess);
return selectAllGroups();
}
QList<Trainee> InterfaceDataBaseLMS::getListTrainees()
{
QMutexLocker mtxLocker(&mtxAccess);
return selectAllTrainees();
}
Trainee InterfaceDataBaseLMS::getTrainee(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTrainee(id);
}
Group InterfaceDataBaseLMS::getGroup(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectGroup(id);
}
int InterfaceDataBaseLMS::newGroup()
{
QMutexLocker mtxLocker(&mtxAccess);
return insertGroup();
}
int InterfaceDataBaseLMS::delGroup(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return deleteGroup(id);
}
int InterfaceDataBaseLMS::editGroup(Group group)
{
QMutexLocker mtxLocker(&mtxAccess);
//Проверка корректности имени
QList<Group> listGroups = selectAllGroups();
for(Group exist_group : listGroups)
@@ -342,57 +359,68 @@ int InterfaceDataBaseLMS::editGroup(Group group)
int InterfaceDataBaseLMS::newTaskAMM(TaskAmmFim task, int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
return insertTaskAMM(task, id_trainee);
}
int InterfaceDataBaseLMS::delTaskAMM(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return deleteTaskAMM(id);
}
int InterfaceDataBaseLMS::editTaskAMM(TaskAmmFim task)
{
QMutexLocker mtxLocker(&mtxAccess);
return updateTaskAMM(task);
}
QList<TaskAmmFim> InterfaceDataBaseLMS::getListTasksAMMofTrainee(int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTasksAMMofTrainee(id_trainee);
}
QList<TaskAmmFim> InterfaceDataBaseLMS::getListTasksFIMofTrainee(int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTasksFIMofTrainee(id_trainee);
}
TaskAmmFim InterfaceDataBaseLMS::getTaskAMMbyID(int id_task)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTaskAMMbyID(id_task);
}
TaskAmmFim InterfaceDataBaseLMS::getTaskFIMbyID(int id_task)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectTaskFIMbyID(id_task);
}
int InterfaceDataBaseLMS::newTaskFIM(TaskAmmFim task, int id_trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
return insertTaskFIM(task, id_trainee);
}
int InterfaceDataBaseLMS::delTaskFIM(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
deleteReportFIM(id);
return deleteTaskFIM(id);
}
int InterfaceDataBaseLMS::editTaskFIM(TaskAmmFim task)
{
QMutexLocker mtxLocker(&mtxAccess);
return updateTaskFIM(task);
}
int InterfaceDataBaseLMS::replaceReportFIM(TaskAmmFim task)
{
QMutexLocker mtxLocker(&mtxAccess);
deleteReportFIM(task.getID());
if(int report_id = insertReportFIM(task))
@@ -406,26 +434,32 @@ int InterfaceDataBaseLMS::replaceReportFIM(TaskAmmFim task)
int InterfaceDataBaseLMS::changeStatusTaskFIM(int id_task, QString status)
{
QMutexLocker mtxLocker(&mtxAccess);
return updateStatusTaskFIM(id_task, status);
}
int InterfaceDataBaseLMS::changeStatusTaskAMM(int id_task, QString status)
{
QMutexLocker mtxLocker(&mtxAccess);
return updateStatusTaskAMM(id_task, status);
}
int InterfaceDataBaseLMS::newTrainee(int id_group)
{
QMutexLocker mtxLocker(&mtxAccess);
return insertTrainee(id_group);
}
int InterfaceDataBaseLMS::delTrainee(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return deleteTrainee(id);
}
int InterfaceDataBaseLMS::editTrainee(Trainee trainee)
{
QMutexLocker mtxLocker(&mtxAccess);
//Проверка корректности логина, имени, пароля
QList<Trainee> listTrainees = selectAllTrainees();
for(Trainee exist_trainee : listTrainees)
@@ -471,10 +505,12 @@ int InterfaceDataBaseLMS::editTrainee(Trainee trainee)
bool InterfaceDataBaseLMS::isArchivedTrainee(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id);
}
bool InterfaceDataBaseLMS::isLoggedInTrainee(int id)
{
QMutexLocker mtxLocker(&mtxAccess);
return selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id);
}