#include #include #include #include #include #include "interfacedatabaselms.h" InterfaceDataBaseLMS::InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent): QObject(parent), DataBaseLMS(ownerWidget), ownerWidget(ownerWidget) { } void InterfaceDataBaseLMS::slot_LanguageChanged(QString language) { qtLanguageTranslator.load(QString(QStringLiteral("translations/DataBaseLMS_")) + language, QStringLiteral(".")); QCoreApplication::installTranslator(&qtLanguageTranslator); } bool InterfaceDataBaseLMS::ConnectionToDB() { QMutexLocker mtxLocker(&mtxAccess); if(!createConnection()) { QMessageBox::critical(ownerWidget, dbSettings.dbName, tr("Connection error: ") + db->lastError().text()); return false; } else { //QMessageBox::information(ownerWidget, dbName, tr("Connection is successful!")); return true; } } bool InterfaceDataBaseLMS::DisConnectionFromDB() { QMutexLocker mtxLocker(&mtxAccess); deleteConnection(); //QMessageBox::information(ownerWidget, dbName, tr("Disconnection is successful!")); return true; } bool InterfaceDataBaseLMS::DBisConnected() { QMutexLocker mtxLocker(&mtxAccess); return isConnected(); } //Инструкторы bool InterfaceDataBaseLMS::AuthorizationInstructor(QString login, QString password) { QMutexLocker mtxLocker(&mtxAccess); if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login, password)) { if(selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id)) return false; if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, true)) return true; } return false; } bool InterfaceDataBaseLMS::deAuthorizationInstructor(QString login) { QMutexLocker mtxLocker(&mtxAccess); if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login)) { if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, false)) return true; } 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 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 listInstructors = selectAllInstructors(); for(Instructor exist_instructor : listInstructors) { if(instructor.getName() == QStringLiteral("")) {//Имя не корректно! 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("")) {//Логин не корректен! 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("")) {//Пароль не корректный! 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(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(ownerWidget, 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) { 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); } //Инструкторы bool InterfaceDataBaseLMS::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name) { QMutexLocker mtxLocker(&mtxAccess); if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login, password)) { if(selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id)) return false; if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, true)) return true; } return false; } bool InterfaceDataBaseLMS::deAuthorizationTrainee(QString login) { QMutexLocker mtxLocker(&mtxAccess); if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login)) { if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, false)) return true; } 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); if(!timing.getID()) {//Еще нет записи int timing_id = insertTimingTrainee(id_trainee); timing.setID(timing_id); if(!timing_id) return 0; } timing.fixEntry(); return updateTimingTrainee(id_trainee, timing); } int InterfaceDataBaseLMS::exitTraineeFromSimulator(int id_trainee) { QMutexLocker mtxLocker(&mtxAccess); TimingOfTrainee timing(id_trainee); timing = selectTimingTrainee(id_trainee); if(!timing.getID()) {//Еще нет записи int timing_id = insertTimingTrainee(id_trainee); timing.setID(timing_id); if(!timing_id) return 0; } timing.fixExit(); return updateTimingTrainee(id_trainee, timing); } 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 InterfaceDataBaseLMS::getListTraineesInGroup(int id) { QMutexLocker mtxLocker(&mtxAccess); return selectAllTraineesInGroup(id); } QList InterfaceDataBaseLMS::getListGroups() { QMutexLocker mtxLocker(&mtxAccess); return selectAllGroups(); } QList 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 listGroups = selectAllGroups(); for(Group exist_group : listGroups) { if(group.getName() == QStringLiteral("")) {//Имя не корректно! 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(ownerWidget, tr("Editing error!"), tr("An existing group name has been entered.\nThe changes will not be accepted.")); return 0; } } return updateGroup(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 InterfaceDataBaseLMS::getListTasksAMMofTrainee(int id_trainee) { QMutexLocker mtxLocker(&mtxAccess); return selectTasksAMMofTrainee(id_trainee); } QList 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)) { updateStatusTaskFIM(task.getID(), "checkup"); return report_id; } return 0; } 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 listTrainees = selectAllTrainees(); for(Trainee exist_trainee : listTrainees) { if(trainee.getName() == QStringLiteral("")) {//Имя не корректно! 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("")) {//Логин не корректен! 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("")) {//Пароль не корректный! 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(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(ownerWidget, 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) { QMutexLocker mtxLocker(&mtxAccess); return selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id); } bool InterfaceDataBaseLMS::isLoggedInTrainee(int id) { QMutexLocker mtxLocker(&mtxAccess); return selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id); }