mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Начал реализовывать обмен запросами к БД
This commit is contained in:
@@ -60,8 +60,28 @@ void DataParser::createAuthMessage(ClientAutorization *auth)
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("ClientAutorization");
|
||||
|
||||
xmlWriter.writeAttribute("Login",auth->Login);
|
||||
xmlWriter.writeAttribute("Password",auth->Password);
|
||||
xmlWriter.writeAttribute("Login", auth->Login);
|
||||
xmlWriter.writeAttribute("Password", auth->Password);
|
||||
xmlWriter.writeAttribute("TypeClient", QString::number(auth->TypeClient));
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void DataParser::createQueryToDBMessage(ClientQueryToDB *queryToDB)
|
||||
{
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("QueryToDB");
|
||||
|
||||
xmlWriter.writeAttribute("TypeQuery", QString::number(queryToDB->typeQuery));
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeEndElement();
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void saveClientSettrings(QString language,bool isAutoStart);
|
||||
void createFileDataList(QList<FileData> fileDataList,QString filename);
|
||||
void createAuthMessage(ClientAutorization *auth);
|
||||
void createQueryToDBMessage(ClientQueryToDB *queryToDB);
|
||||
void createDeAuthMessage(ClientDeAutorization *deAuth);
|
||||
void createAuthData(ServerAuthorization *serverAuth);
|
||||
void createAuthDataOffline(QString username,QString pass);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Core/recognizesystem.h"
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
#include "instructor.h"
|
||||
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
@@ -14,6 +15,8 @@ RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
tmpBlock.clear();
|
||||
countSend = 0;
|
||||
folderList = new QList<QString>;
|
||||
|
||||
listInstructors = new QList<Instructor>;
|
||||
}
|
||||
|
||||
RecognizeSystem::~RecognizeSystem()
|
||||
@@ -25,7 +28,7 @@ void RecognizeSystem::initialize(DataParser *dataParser/*,MainWindow *mainWindow
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
//this->mainWindow = mainWindow;
|
||||
connect(this,&RecognizeSystem::sigSaveLoginData,dataParser,&DataParser::createAuthData);
|
||||
connect(this,&RecognizeSystem::sigAuth,dataParser,&DataParser::createAuthData);
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
@@ -259,9 +262,12 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext();
|
||||
QString name = xmlReader.name().toString();
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
name = xmlReader.name().toString();
|
||||
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
@@ -325,7 +331,7 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
}
|
||||
}
|
||||
|
||||
emit sigSaveLoginData(serverAuth);
|
||||
emit sigAuth(serverAuth);
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerDeAuthorization"){
|
||||
@@ -349,6 +355,71 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
emit sigDeAuth(serverDeAuth);
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ListInstructors"){
|
||||
|
||||
xmlReader.readNext();
|
||||
name = xmlReader.name().toString();
|
||||
|
||||
QList<Instructor> listInstructors;
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
name = xmlReader.name().toString();
|
||||
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "Instructor")
|
||||
{
|
||||
Instructor instructor;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if (name == "instructor_id"){
|
||||
instructor.setID(value.toInt());
|
||||
}
|
||||
if (name == "name"){
|
||||
instructor.setName(value);
|
||||
}
|
||||
if (name == "login"){
|
||||
instructor.setLogin(value);
|
||||
}
|
||||
if (name == "password"){
|
||||
instructor.setPassword(value);
|
||||
}
|
||||
if (name == "is_admin"){
|
||||
instructor.setIsAdmin(value == "true" ? true : false);
|
||||
}
|
||||
if (name == "archived"){
|
||||
instructor.setArchived(value == "true" ? true : false);
|
||||
}
|
||||
if (name == "logged_in"){
|
||||
instructor.setLoggedIn(value == "true" ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
listInstructors.append(instructor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//emit sigDeAuth(serverDeAuth);
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
i++;
|
||||
|
||||
*this->listInstructors = listInstructors;
|
||||
emit sigAnswerQueryToDB(this->listInstructors);
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//#include <mainwindow.h>
|
||||
#include <Core\tools.h>
|
||||
#include "dataparser.h"
|
||||
#include "instructor.h"
|
||||
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
@@ -27,8 +28,9 @@ signals:
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigSocketDisabled();
|
||||
void sigServerBlocked();
|
||||
void sigSaveLoginData(ServerAuthorization *serverAuth);
|
||||
void sigAuth(ServerAuthorization *serverAuth);
|
||||
void sigDeAuth(ServerDeAuthorization *serverDeAuth);
|
||||
void sigAnswerQueryToDB(QList<Instructor>* listInstructors);
|
||||
void sigSocketWaitForReadyRead(int waitTime);
|
||||
void sigStartCompare();
|
||||
|
||||
@@ -45,6 +47,8 @@ private:
|
||||
qint64 fileSize;
|
||||
int countSend;
|
||||
|
||||
QList<Instructor>* listInstructors;
|
||||
|
||||
void xmlParser(QByteArray array);
|
||||
|
||||
void checkAccessType(QString type);
|
||||
|
||||
@@ -129,6 +129,23 @@ void SendSystem::sendFinish()
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
void SendSystem::sendClientQueryToDB()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray array = file.readAll();
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
void sendXMLAnswer(QByteArray array);
|
||||
~SendSystem();
|
||||
void sendFinish();
|
||||
|
||||
void sendClientQueryToDB();
|
||||
signals:
|
||||
void sigSend();
|
||||
QByteArray sigGetXmlAnswer(QString);
|
||||
|
||||
@@ -30,7 +30,9 @@ enum PacketType{
|
||||
TYPE_NEEDUPDATE = 7,
|
||||
TYPE_XMLANSWER = 8,
|
||||
TYPE_QT = 9,
|
||||
TYPE_DISABLE = 11
|
||||
TYPE_DISABLE = 11,
|
||||
|
||||
TYPE_GET_LIST_INSTRUCTORS = 100
|
||||
};
|
||||
|
||||
class Tools {
|
||||
|
||||
@@ -25,10 +25,16 @@ public:
|
||||
QString Login;
|
||||
};
|
||||
|
||||
enum TypeClientAutorization{
|
||||
TYPE_SIMPLE = 0,
|
||||
TYPE_GUI = 10
|
||||
};
|
||||
|
||||
class ClientAutorization{
|
||||
public:
|
||||
QString Login;
|
||||
QString Password;
|
||||
TypeClientAutorization TypeClient;
|
||||
};
|
||||
|
||||
class ClientDeAutorization{
|
||||
@@ -36,6 +42,15 @@ public:
|
||||
QString Login;
|
||||
};
|
||||
|
||||
enum TypeQueryToDB{
|
||||
TYPE_QUERY_GET_LIST_INSTRUCTORS
|
||||
};
|
||||
|
||||
class ClientQueryToDB{
|
||||
public:
|
||||
TypeQueryToDB typeQuery;
|
||||
};
|
||||
|
||||
class ServerMessage
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -22,6 +22,7 @@ bool ConnectorToServer::authorizationInstructorLocal(QString login, QString pass
|
||||
ClientAutorization *autorization = new ClientAutorization;
|
||||
autorization->Login = login;
|
||||
autorization->Password = password;
|
||||
autorization->TypeClient = TypeClientAutorization::TYPE_GUI;
|
||||
|
||||
dataParser->createAuthMessage(autorization);
|
||||
emit sigSendAutorization();
|
||||
@@ -45,6 +46,31 @@ bool ConnectorToServer::deAuthorizationInstructorLocal(QString login)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConnectorToServer::queryGetListInstructors()
|
||||
{
|
||||
if (!client->getIsConnected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ClientQueryToDB *queryToDB = new ClientQueryToDB;
|
||||
queryToDB->typeQuery = TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS;
|
||||
|
||||
dataParser->createQueryToDBMessage(queryToDB);
|
||||
emit sigSendQueryToDB();
|
||||
}
|
||||
|
||||
QList<Instructor> ConnectorToServer::getListInstructors()
|
||||
{
|
||||
return listInstructors;
|
||||
}
|
||||
|
||||
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors)
|
||||
{
|
||||
this->listInstructors = *listInstructors;
|
||||
emit signal_UpdateDB(true, false);
|
||||
}
|
||||
|
||||
void ConnectorToServer::initialize()
|
||||
{
|
||||
createObjects();
|
||||
@@ -63,8 +89,11 @@ void ConnectorToServer::bindConnection()
|
||||
connect(this,&ConnectorToServer::sigSendAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
||||
connect(this,&ConnectorToServer::sigSendDeAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
||||
|
||||
connect(recognizeSystem,&RecognizeSystem::sigSaveLoginData,this,&ConnectorToServer::sigLoginResult);
|
||||
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);
|
||||
}
|
||||
|
||||
void ConnectorToServer::createObjects()
|
||||
|
||||
@@ -16,7 +16,12 @@ public:
|
||||
bool authorizationInstructorLocal(QString login, QString password);
|
||||
bool deAuthorizationInstructorLocal(QString login);
|
||||
|
||||
private slots:
|
||||
bool queryGetListInstructors();
|
||||
|
||||
QList<Instructor> getListInstructors();
|
||||
|
||||
public slots:
|
||||
void slot_AnswerQueryToDB(QList<Instructor>* listInstructors);
|
||||
|
||||
signals:
|
||||
void sigSetConnect(ServerSettings* serverSettings,QThread *thread);
|
||||
@@ -25,9 +30,16 @@ signals:
|
||||
QThread *thread);
|
||||
void sigSendAutorization();
|
||||
void sigSendDeAutorization();
|
||||
|
||||
void sigSendQueryToDB();
|
||||
|
||||
|
||||
void sigLoginResult(ServerAuthorization * serverAuth);
|
||||
void sigDeLoginResult(ServerDeAuthorization * serverDeAuth);
|
||||
|
||||
void signal_UpdateDB(bool treeInstructor, bool treeTrainee);
|
||||
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void bindConnection();
|
||||
@@ -40,6 +52,7 @@ private:
|
||||
SendSystem *sendSystem;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
|
||||
QList<Instructor> listInstructors;
|
||||
};
|
||||
|
||||
#endif // CONNECTORTOSERVER_H
|
||||
|
||||
Reference in New Issue
Block a user