mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
264 lines
7.1 KiB
C++
264 lines
7.1 KiB
C++
#include "connectortoserver.h"
|
|
#include <QThread>
|
|
|
|
ConnectorToServer::ConnectorToServer(QObject *parent) :
|
|
QObject(parent),
|
|
connectionThread(nullptr),
|
|
client(nullptr),
|
|
dataParser(nullptr),
|
|
sendSystem(nullptr),
|
|
recognizeSystem(nullptr)
|
|
{
|
|
initialize();
|
|
}
|
|
|
|
bool ConnectorToServer::authorizationInstructorLocal(QString login, QString password)
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientAutorization *autorization = new ClientAutorization;
|
|
autorization->Login = login;
|
|
autorization->Password = password;
|
|
autorization->TypeClient = TypeClientAutorization::TYPE_GUI;
|
|
|
|
dataParser->createAuthMessage(autorization);
|
|
emit sigSendAutorization();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ConnectorToServer::deAuthorizationInstructorLocal(QString login)
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientDeAutorization *deAutorization = new ClientDeAutorization;
|
|
deAutorization->Login = login;
|
|
|
|
dataParser->createDeAuthMessage(deAutorization);
|
|
emit sigSendDeAutorization();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery)
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientQueryToDB *queryToDB = new ClientQueryToDB;
|
|
queryToDB->typeQuery = typeQuery;
|
|
|
|
dataParser->createQueryToDBMessage(queryToDB);
|
|
emit sigSendQueryToDB();
|
|
|
|
return true;
|
|
}
|
|
|
|
QList<Instructor> ConnectorToServer::getListInstructors()
|
|
{
|
|
return listInstructors;
|
|
}
|
|
|
|
QList<Trainee> ConnectorToServer::getListTrainees()
|
|
{
|
|
return listTrainees;
|
|
}
|
|
|
|
QList<Group> ConnectorToServer::getListGroups()
|
|
{
|
|
return listGroups;
|
|
}
|
|
|
|
QList<Computer> ConnectorToServer::getListComputers()
|
|
{
|
|
return listComputers;
|
|
}
|
|
|
|
QList<Classroom> ConnectorToServer::getListClassrooms()
|
|
{
|
|
return listClassrooms;
|
|
}
|
|
|
|
QList<Task> ConnectorToServer::getListTasks()
|
|
{
|
|
return listTasks;
|
|
}
|
|
|
|
bool ConnectorToServer::isArchivedInstructor(int id)
|
|
{
|
|
for(Instructor instructor : listInstructors)
|
|
{
|
|
if(instructor.getID() == id)
|
|
{
|
|
if(instructor.getArchived()) return true; else return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool ConnectorToServer::isAdminInstructor(int id)
|
|
{
|
|
for(Instructor instructor : listInstructors)
|
|
{
|
|
if(instructor.getID() == id)
|
|
{
|
|
if(instructor.getIsAdmin()) return true; else return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool ConnectorToServer::isLoggedInInstructor(int id)
|
|
{
|
|
for(Instructor instructor : listInstructors)
|
|
{
|
|
if(instructor.getID() == id)
|
|
{
|
|
if(instructor.getLoggedIn()) return true; else return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
QList<Trainee> ConnectorToServer::getListTraineesInGroup(int id)
|
|
{
|
|
QList<Trainee> list;
|
|
for(Trainee trainee : listTrainees)
|
|
{
|
|
if(trainee.getGroup().getID() == id)
|
|
list.append(trainee);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
bool ConnectorToServer::isArchivedTrainee(int id)
|
|
{
|
|
for(Trainee trainee : listTrainees)
|
|
{
|
|
if(trainee.getID() == id)
|
|
{
|
|
if(trainee.getArchived()) return true; else return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool ConnectorToServer::isLoggedInTrainee(int id)
|
|
{
|
|
for(Trainee trainee : listTrainees)
|
|
{
|
|
if(trainee.getID() == id)
|
|
{
|
|
if(trainee.getLoggedIn()) return true; else return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors,
|
|
QList<Trainee>* listTrainees,
|
|
QList<Group>* listGroups)
|
|
{
|
|
this->listInstructors = *listInstructors;
|
|
this->listTrainees = *listTrainees;
|
|
this->listGroups = *listGroups;
|
|
emit signal_UpdateDB(true, true);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListInstructors(QList<Instructor> listInstructors)
|
|
{
|
|
this->listInstructors = listInstructors;
|
|
emit signal_UpdateDB(true, false);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListGroups(QList<Group> listGroups)
|
|
{
|
|
this->listGroups = listGroups;
|
|
emit signal_UpdateDB(false, true);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListTrainees(QList<Trainee> listTrainees)
|
|
{
|
|
this->listTrainees = listTrainees;
|
|
emit signal_UpdateDB(false, true);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListComputers(QList<Computer> listComputers)
|
|
{
|
|
this->listComputers = listComputers;
|
|
//emit signal_UpdateDB(false, true);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListClassrooms(QList<Classroom> listClassrooms)
|
|
{
|
|
this->listClassrooms = listClassrooms;
|
|
//emit signal_UpdateDB(false, true);
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB_ListTasks(QList<Task> listTasks)
|
|
{
|
|
this->listTasks = listTasks;
|
|
//emit signal_UpdateDB(false, true);
|
|
}
|
|
|
|
|
|
|
|
void ConnectorToServer::initialize()
|
|
{
|
|
createObjects();
|
|
|
|
bindConnection();
|
|
|
|
emit sigInitializeClient(recognizeSystem,sendSystem,connectionThread);
|
|
|
|
emit sigSetConnect(dataParser->getServerSettings(),connectionThread);
|
|
}
|
|
|
|
void ConnectorToServer::bindConnection()
|
|
{
|
|
connect(this,&ConnectorToServer::sigInitializeClient,client,&TCPClient::initialize,Qt::AutoConnection);
|
|
connect(this,&ConnectorToServer::sigSetConnect,client,&TCPClient::setConnect,Qt::AutoConnection);
|
|
connect(this,&ConnectorToServer::sigSendAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
|
connect(this,&ConnectorToServer::sigSendDeAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
|
|
|
connect(this,&ConnectorToServer::sigSendQueryToDB,sendSystem,&SendSystem::sendClientQueryToDB);
|
|
|
|
connect(recognizeSystem,&RecognizeSystem::sigAuth,this,&ConnectorToServer::sigLoginResult);
|
|
connect(recognizeSystem,&RecognizeSystem::sigDeAuth,this,&ConnectorToServer::sigDeLoginResult);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB,this,&ConnectorToServer::slot_AnswerQueryToDB);
|
|
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListInstructors,this,&ConnectorToServer::slot_AnswerQueryToDB_ListInstructors);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListGroups,this,&ConnectorToServer::slot_AnswerQueryToDB_ListGroups);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListTrainees,this,&ConnectorToServer::slot_AnswerQueryToDB_ListTrainees);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListComputers,this,&ConnectorToServer::slot_AnswerQueryToDB_ListComputers);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListClassrooms,this,&ConnectorToServer::slot_AnswerQueryToDB_ListClassrooms);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB_ListTasks,this,&ConnectorToServer::slot_AnswerQueryToDB_ListTasks);
|
|
}
|
|
|
|
void ConnectorToServer::createObjects()
|
|
{
|
|
connectionThread = new QThread;
|
|
|
|
client = new TCPClient;
|
|
client->moveToThread(connectionThread);
|
|
|
|
dataParser = new DataParser;
|
|
|
|
sendSystem = new SendSystem;
|
|
sendSystem->moveToThread(connectionThread);
|
|
|
|
recognizeSystem = new RecognizeSystem;
|
|
recognizeSystem->moveToThread(connectionThread);
|
|
|
|
connectionThread->start();
|
|
connectionThread->setPriority(QThread::HighestPriority);
|
|
}
|