Files
RRJServer/DB_IaT/InstructorsAndTrainees/instructorsandtraineeswidget.cpp
2024-11-13 17:16:33 +03:00

107 lines
3.0 KiB
C++

#include <QMessageBox>
#include "instructorsandtraineeswidget.h"
#include "ui_instructorsandtraineeswidget.h"
#include "dialogauthorizationinstructor.h"
InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::InstructorsAndTraineesWidget),
adminMode(false),
loginInstructorLoggedInLocal(QStringLiteral(""))
{
ui->setupUi(this);
dbLMS = new InterfaceDataBaseLMS();
//Авторизация Инструктора локальная (Администратора)
authorizationInstructorLocal(this);
m_viewerTrainees = new ViewerTrainees(dbLMS, adminMode);
m_viewerInstructors = new ViewerInstructors(dbLMS, adminMode);
ui->verticalLayout->addWidget(m_viewerTrainees);
ui->verticalLayout->addWidget(m_viewerInstructors);
m_viewerTrainees->setMinimumSize(1600, 700);
m_viewerInstructors->setMinimumSize(1600, 400);
}
InstructorsAndTraineesWidget::~InstructorsAndTraineesWidget()
{
deAuthorizationInstructor(loginInstructorLoggedInLocal);
delete m_viewerInstructors;
delete m_viewerTrainees;
delete dbLMS;
delete ui;
}
bool InstructorsAndTraineesWidget::authorizationInstructorLocal(QWidget* parent)
{
DialogAuthorizationInstructor dlg(parent);
dlg.setWindowTitle(tr("Instructor authorithation"));
do
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
QString login = dlg.getLogin();
QString password = dlg.getPassword();
if(dbLMS->AuthorizationInstructor(login, password))
{
loginInstructorLoggedInLocal = login;
if(login == QStringLiteral("admin"))
adminMode = true;
QMessageBox::information(parent, tr("Instructor authorization"), tr("Successfully!"));
return true;
}
else
QMessageBox::warning(parent, tr("Instructor authorization"), tr("Invalid login or password!"));
break;
}
case QDialog::Rejected:
return false;
default:
return false;
}
}
while(true);
return false;
}
bool InstructorsAndTraineesWidget::authorizationIsCompleted()
{
if(loginInstructorLoggedInLocal == QStringLiteral(""))
return false;
else
return true;
}
bool InstructorsAndTraineesWidget::authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
return dbLMS->AuthorizationTrainee(login, password, classroom_name, computer_name);
}
bool InstructorsAndTraineesWidget::deAuthorizationTrainee(QString login)
{
return dbLMS->deAuthorizationTrainee(login);
}
bool InstructorsAndTraineesWidget::authorizationInstructor(QString login, QString password)
{
return dbLMS->AuthorizationInstructor(login, password);
}
bool InstructorsAndTraineesWidget::deAuthorizationInstructor(QString login)
{
return dbLMS->deAuthorizationInstructor(login);
}