Доделал остальные операции по редактированию

This commit is contained in:
krivoshein
2024-12-12 10:27:18 +03:00
parent 1569df7d94
commit d28453440f
56 changed files with 725 additions and 540 deletions

View File

@@ -3,6 +3,10 @@
#include "FileData.h"
#include "tools.h"
#include "instructor.h"
#include "trainee.h"
#include "group.h"
#include <QDir>
DataParser::DataParser(QObject *parent) :
@@ -71,7 +75,7 @@ void DataParser::createAuthMessage(ClientAutorization *auth)
file.close();
}
void DataParser::createQueryToDBMessage(ClientQueryToDB *queryToDB, int id)
void DataParser::createQueryToDBMessage(ClientQueryToDB *queryToDB, int id, void* data)
{
QFile file(tempName);
file.open(QIODevice::WriteOnly);
@@ -86,6 +90,48 @@ void DataParser::createQueryToDBMessage(ClientQueryToDB *queryToDB, int id)
if(id)
xmlWriter.writeAttribute("id", QString::number(id));
if(data)
{
if(queryToDB->typeQuery == TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR)
{
Instructor* instructor = (Instructor*)data;
if(instructor)
{
xmlWriter.writeAttribute("instructor_id", QString::number(instructor->getID()));
xmlWriter.writeAttribute("name", instructor->getName());
xmlWriter.writeAttribute("login", instructor->getLogin());
xmlWriter.writeAttribute("password", instructor->getPassword());
xmlWriter.writeAttribute("is_admin", QString::number(instructor->getIsAdmin()));
xmlWriter.writeAttribute("archived", QString::number(instructor->getArchived()));
xmlWriter.writeAttribute("logged_in", QString::number(instructor->getLoggedIn()));
}
}
else if(queryToDB->typeQuery == TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE)
{
Trainee* trainee = (Trainee*)data;
if(trainee)
{
xmlWriter.writeAttribute("trainee_id", QString::number(trainee->getID()));
xmlWriter.writeAttribute("name", trainee->getName());
xmlWriter.writeAttribute("login", trainee->getLogin());
xmlWriter.writeAttribute("password", trainee->getPassword());
xmlWriter.writeAttribute("archived", QString::number(trainee->getArchived()));
xmlWriter.writeAttribute("logged_in", QString::number(trainee->getLoggedIn()));
xmlWriter.writeAttribute("group_trainee", QString::number(trainee->getGroup().getID()));
xmlWriter.writeAttribute("computer_trainee", QString::number(trainee->getComputer().getID()));
}
}
else if(queryToDB->typeQuery == TypeQueryToDB::TYPE_QUERY_EDIT_GROUP)
{
Group* group = (Group*)data;
if(group)
{
xmlWriter.writeAttribute("group_id", QString::number(group->getID()));
xmlWriter.writeAttribute("name", group->getName());
}
}
}
xmlWriter.writeEndElement();
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();

View File

@@ -2,6 +2,7 @@
#define DATAPARSER_H
#include "FileData.h"
#include "instructor.h"
#include <QObject>
#include <Datas.h>
@@ -21,7 +22,7 @@ public:
void saveClientSettrings(QString language,bool isAutoStart);
void createFileDataList(QList<FileData> fileDataList,QString filename);
void createAuthMessage(ClientAutorization *auth);
void createQueryToDBMessage(ClientQueryToDB *queryToDB, int id = 0);
void createQueryToDBMessage(ClientQueryToDB *queryToDB, int id = 0, void* data = nullptr);
void createDeAuthMessage(ClientDeAutorization *deAuth);
void createAuthData(ServerAuthorization *serverAuth);
void createAuthDataOffline(QString username,QString pass);

View File

@@ -46,7 +46,14 @@ enum TypeQueryToDB{
TYPE_QUERY_GET_LIST_INSTRUCTORS,
TYPE_QUERY_GET_ALL_LISTS,
TYPE_QUERY_NEW_INSTRUCTOR,
TYPE_QUERY_DEL_INSTRUCTOR
TYPE_QUERY_DEL_INSTRUCTOR,
TYPE_QUERY_EDIT_INSTRUCTOR,
TYPE_QUERY_NEW_GROUP,
TYPE_QUERY_DEL_GROUP,
TYPE_QUERY_EDIT_GROUP,
TYPE_QUERY_NEW_TRAINEE,
TYPE_QUERY_DEL_TRAINEE,
TYPE_QUERY_EDIT_TRAINEE
};
class ClientQueryToDB{

View File

@@ -46,7 +46,7 @@ bool ConnectorToServer::deAuthorizationInstructorLocal(QString login)
return true;
}
bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery, int id)
bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery, int id, void* data)
{
if (!client->getIsConnected())
{
@@ -56,7 +56,7 @@ bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery, int id)
ClientQueryToDB *queryToDB = new ClientQueryToDB;
queryToDB->typeQuery = typeQuery;
dataParser->createQueryToDBMessage(queryToDB, id);
dataParser->createQueryToDBMessage(queryToDB, id, data);
emit sigSendQueryToDB();
return true;
@@ -128,6 +128,16 @@ bool ConnectorToServer::isLoggedInInstructor(int id)
return false;
}
Instructor ConnectorToServer::getInstructor(int id)
{
for(Instructor instructor : listInstructors)
{
if(instructor.getID() == id)
return instructor;
}
return Instructor();
}
QList<Trainee> ConnectorToServer::getListTraineesInGroup(int id)
{
QList<Trainee> list;
@@ -163,6 +173,26 @@ bool ConnectorToServer::isLoggedInTrainee(int id)
return false;
}
Trainee ConnectorToServer::getTrainee(int id)
{
for(Trainee trainee : listTrainees)
{
if(trainee.getID() == id)
return trainee;
}
return Trainee();
}
Group ConnectorToServer::getGroup(int id)
{
for(Group group : listGroups)
{
if(group.getID() == id)
return group;
}
return Group();
}
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors,
QList<Trainee>* listTrainees,
QList<Group>* listGroups)

View File

@@ -22,7 +22,8 @@ public:
bool authorizationInstructorLocal(QString login, QString password);
bool deAuthorizationInstructorLocal(QString login);
bool sendQueryToDB(TypeQueryToDB typeQuery, int id = 0);
//bool sendQueryToDB(TypeQueryToDB typeQuery, int id = 0, Instructor* instructor = nullptr);
bool sendQueryToDB(TypeQueryToDB typeQuery, int id = 0, void* data = nullptr);
public:
//Запросы к БД (локальной)
@@ -36,10 +37,13 @@ public:
bool isArchivedInstructor(int id);
bool isAdminInstructor(int id);
bool isLoggedInInstructor(int id);
Instructor getInstructor(int id);
QList<Trainee> getListTraineesInGroup(int id);
bool isArchivedTrainee(int id);
bool isLoggedInTrainee(int id);
Trainee getTrainee(int id);
Group getGroup(int id);
public slots:
void slot_AnswerQueryToDB(QList<Instructor>* listInstructors,