Перед внедрением списочной модели БД в GUI

This commit is contained in:
krivoshein
2024-12-10 10:27:00 +03:00
parent e6da40c4e7
commit 4556c07fc9
96 changed files with 1044 additions and 444 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2024-12-06T12:00:51. -->
<!-- Written by QtCreator 4.11.1, 2024-12-09T17:51:45. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -1,6 +1,7 @@
#include "dataparser.h"
#include <QFile>
#include <QDomDocument>
DataParser::DataParser(ProcessingSystem *processingSystem,QObject *parent) :
QObject(parent)
@@ -290,26 +291,78 @@ QByteArray DataParser::xmlAnswer_deAuthorization(bool result, QString login)
return xmlAnswer(listTag);
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB(bool result, QList<Instructor> listInstructors)
QByteArray DataParser::xmlAnswer_ClientQueryToDB(bool result, QList<Instructor>* listInstructors,
QList<Trainee>* listTrainees, QList<Group>* listGroups)
{
QList<SXmlAnswerTag> listTag;
QDomDocument groupsTraineesDOM;
QFile blankFile(":/blankXML/groupsTrainees.xml");
for(Instructor instructor : listInstructors)
{
SAttribute attribute1 = {"instructor_id", QString::number(instructor.getID())};
SAttribute attribute2 = {"name", instructor.getName()};
SAttribute attribute3 = {"login", instructor.getLogin()};
SAttribute attribute4 = {"password", instructor.getPassword()};
SAttribute attribute5 = {"is_admin", instructor.getIsAdmin() ? "true" : "false"};
SAttribute attribute6 = {"archived", instructor.getArchived() ? "true" : "false"};
SAttribute attribute7 = {"logged_in", instructor.getLoggedIn() ? "true" : "false"};
QList<SAttribute> listAttr = {attribute1, attribute2, attribute3, attribute4, attribute5, attribute6, attribute7};
SXmlAnswerTag tag = {"Instructor", listAttr};
listTag.append(tag);
if (! blankFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug() << "SaveTraineesGroupsXML: Не удалось считать файл :/blankXML/groupsTrainees.xml";
return QByteArray();
}
return xmlAnswer(listTag, "ListInstructors");
groupsTraineesDOM.setContent(blankFile.readAll());
blankFile.close();
QDomNode allListsNode = groupsTraineesDOM.namedItem("AllLists");
QDomNode groupsTraineesNode = allListsNode.firstChildElement("GroupsTrainees");
QDomNode allInstructorsNode = allListsNode.firstChildElement("Instructors");
for(Group group : *listGroups)
{
//Группа
QDomNode groupNode = groupsTraineesDOM.createElement("group");
groupsTraineesNode.appendChild(groupNode);
groupNode.toElement().setAttribute("group_id", group.getID());
groupNode.toElement().setAttribute("name", group.getName());
//Обучаемые
for(Trainee trainee : *listTrainees)
{
if(group.getID() != trainee.getGroup().getID())
continue;
QDomNode traineeNode = groupsTraineesDOM.createElement("trainee");
groupNode.appendChild(traineeNode);
traineeNode.toElement().setAttribute("trainee_id", QString::number(trainee.getID()));
traineeNode.toElement().setAttribute("name", trainee.getName());
traineeNode.toElement().setAttribute("login", trainee.getLogin());
traineeNode.toElement().setAttribute("password", trainee.getPassword());
traineeNode.toElement().setAttribute("archived", trainee.getArchived() ? QStringLiteral("true") : QStringLiteral("false"));
traineeNode.toElement().setAttribute("logged_in", trainee.getLoggedIn() ? QStringLiteral("true") : QStringLiteral("false"));
traineeNode.toElement().setAttribute("group_trainee", QString::number(trainee.getGroup().getID()));
traineeNode.toElement().setAttribute("computer_trainee", QString::number(trainee.getComputer().getID()));
}
}
for(Instructor instructor : *listInstructors)
{
//Инструктор
QDomNode instructorNode = groupsTraineesDOM.createElement("instructor");
allInstructorsNode.appendChild(instructorNode);
instructorNode.toElement().setAttribute("instructor_id", QString::number(instructor.getID()));
instructorNode.toElement().setAttribute("name", instructor.getName());
instructorNode.toElement().setAttribute("login", instructor.getLogin());
instructorNode.toElement().setAttribute("password", instructor.getPassword());
instructorNode.toElement().setAttribute("is_admin", instructor.getIsAdmin() ? QStringLiteral("true") : QStringLiteral("false"));
instructorNode.toElement().setAttribute("archived", instructor.getArchived() ? QStringLiteral("true") : QStringLiteral("false"));
instructorNode.toElement().setAttribute("logged_in", instructor.getLoggedIn() ? QStringLiteral("true") : QStringLiteral("false"));
}
QString xmlFileName = /*appDirPath +*/ "GroupsTrainees.xml";
QFile xmlOutFile(xmlFileName);
if (!xmlOutFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << "SaveTraineesGroupsXML: Не удалось записать файл " + xmlFileName;
return QByteArray();
}
QTextStream outFile(&xmlOutFile);
groupsTraineesDOM.save(outFile, 4);
xmlOutFile.close();
return groupsTraineesDOM.toByteArray();
}
QByteArray DataParser::xmlAnswer_message(QString text)

View File

@@ -28,7 +28,8 @@ public:
QByteArray xmlAnswer_authorization(bool result, QString instructorName, QString clientName, QString accessType, QString login);
QByteArray xmlAnswer_deAuthorization(bool result, QString login);
QByteArray xmlAnswer_ClientQueryToDB(bool result, QList<Instructor> listInstructors);
QByteArray xmlAnswer_ClientQueryToDB(bool result, QList<Instructor>* listInstructors = nullptr,
QList<Trainee>* listTrainees = nullptr, QList<Group>* listGroups = nullptr);
QByteArray xmlAnswer_message(QString text);
QByteArray xmlAnswer_task(QString text);

View File

@@ -119,13 +119,23 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
switch (clientQueryToDB.typeQuery)
{
case TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS:
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB(true, listInstructors);
break;
case TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS:
{
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB(true, &listInstructors);
break;
}
case TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS:
{
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
QList<Trainee> listTrainees = providerDBLMS->GetListAllTrainees();
QList<Group> listGroups = providerDBLMS->GetListAllGroups();
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB(true, &listInstructors, &listTrainees, &listGroups);
break;
}
}
client->sendXmlAnswer(arrayAnswer);
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_ON_QUERY_TO_DB);
//QString str = QString(arrayAnswer);
//logger->addTextToLogger("To Client: " + str);

View File

@@ -182,7 +182,7 @@ void SendSystem::sendNotify(QString notify)
sendXmlAnswer(answer);
}
void SendSystem::sendXmlAnswer(QByteArray array)
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
{
qDebug() << "SendSystemThread: " << QThread::currentThreadId();
if(!client->getIsUnity())
@@ -190,7 +190,7 @@ void SendSystem::sendXmlAnswer(QByteArray array)
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
stream << PacketType::TYPE_XMLANSWER;
stream << /*PacketType::TYPE_XMLANSWER*/packetType;
stream << array;
}
else

View File

@@ -28,7 +28,7 @@ public:
void sendFinish();
void sendNotify(QString notify);
void sendStop();
void sendXmlAnswer(QByteArray array);
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount);
void updateFiles(QList<FileData> fileSendList, QList<FileData> clientDataList);
bool getIsSendStopped() const;

View File

@@ -32,9 +32,12 @@ enum PacketType
TYPE_DISABLE = 11,
TYPE_FILESIZE = 20,
TYPE_GET_LIST_INSTRUCTORS = 100
TYPE_GET_LIST_INSTRUCTORS = 100,
TYPE_XMLANSWER_ON_QUERY_TO_DB = 101 //xml-ответ на запрос к БД
};
Q_DECLARE_METATYPE(PacketType)
class Tools {
public:
static void printTime();

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<AllLists>
<GroupsTrainees>
</GroupsTrainees>
<Instructors>
</Instructors>
</AllLists>

View File

@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='utf-8'?>
<allInstructors>
</allInstructors>

View File

@@ -69,9 +69,9 @@ void ClientHandler::sendHash()
//emit sigSendNotify("HASHSENDCOMPLETE");
}
void ClientHandler::sendXmlAnswer(QByteArray array)
void ClientHandler::sendXmlAnswer(QByteArray array, PacketType packetType)
{
emit sigSendXmlAnswer(array);
emit sigSendXmlAnswer(array, packetType);
}
void ClientHandler::sendFolderBlock(QString path)
@@ -110,11 +110,10 @@ void ClientHandler::sendNeedUpdate(bool flag, quint64 size, quint64 fileCount)
}
void ClientHandler::sendDisable()
{
{
thread->exit();
thread->wait();
emit sigClientDisconnected(client->getAddress(),client->getPort());
}
Client *ClientHandler::getClient() const

View File

@@ -6,6 +6,7 @@
#include "Client.h"
#include <QTcpSocket>
#include <QThread>
#include "Systems/tools.h"
class SendSystem;
class DataParser;
@@ -21,7 +22,7 @@ class ClientHandler : public QObject
public:
ClientHandler(QObject* parent = nullptr);
void initSender(DataParser *dataParser,Logger *logger);
void sendXmlAnswer(QByteArray array);
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
void sendFolderBlock(QString path);
void sendFileBlock(QString path);
bool getIsSendStopped();
@@ -41,7 +42,7 @@ public:
QTcpSocket *getSocket() const;
signals:
void sigSendXmlAnswer(QByteArray array);
void sigSendXmlAnswer(QByteArray array, PacketType packetType);
void sigInitSender (DataParser *dataParse,Logger *logger);
void sigFolderBlock(QString path);
void sigFileBlock(QString path);

View File

@@ -40,6 +40,11 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo
if(client->getClient()->getAddress() == peerAddress && client->getClient()->getPort() == peerPort)
{
login = client->getClient()->getLogin();
ClientDeAutorization clientDeAutorization;
clientDeAutorization.Login = login;
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(client, clientDeAutorization);
serverLmsWidget->removeClient(idSocket);
delete client;
continue;

View File

@@ -216,3 +216,39 @@ QList<Instructor> ProviderDBLMS::GetListAllInstructors()
mtxAccess.unlock();
return listInstructors;
}
QList<Trainee> ProviderDBLMS::GetListAllTrainees()
{
QList<Trainee> listTrainees;
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return listTrainees;
}
listTrainees = dbLMS->getListTrainees();
mtxAccess.unlock();
return listTrainees;
}
QList<Group> ProviderDBLMS::GetListAllGroups()
{
QList<Group> listGroups;
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return listGroups;
}
listGroups = dbLMS->getListGroups();
mtxAccess.unlock();
return listGroups;
}

View File

@@ -24,7 +24,9 @@ public:
QString getNameInstructorByLogin(QString login);
//
QList<Instructor> GetListAllInstructors();
QList<Instructor> GetListAllInstructors();
QList<Trainee> GetListAllTrainees();
QList<Group> GetListAllGroups();
Q_SIGNALS:
//сигнал о блокировке авторизации

View File

@@ -5,5 +5,7 @@
<file>icons/trainee.png</file>
<file>icons/switchOff.png</file>
<file>icons/switchOn.png</file>
<file>blankXML/groupsTrainees.xml</file>
<file>blankXML/instructors.xml</file>
</qresource>
</RCC>

View File

@@ -25,6 +25,8 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
{
ui->setupUi(this);
qRegisterMetaType<PacketType>("PacketType");
ui->comboTasks->addItem("Задача 1");
ui->comboTasks->addItem("Задача 2");
ui->comboTasks->addItem("Задача 3");
@@ -200,7 +202,7 @@ void ServerLMSWidget::slot_AuthChanged()
if(clientsMap[idSocket]->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS;
processingSystem->processingClientQueryToDB(clientsMap[idSocket], queryToDB);
}
}

View File

@@ -82,6 +82,11 @@ public:
return stateBlockAutorization;
}
ProcessingSystem* getProcessingSystem()
{
return processingSystem;
}
QMap<int, ClientHandler *> getClientsMap() const;
private slots:

View File

@@ -57,7 +57,8 @@ public:
};
enum TypeQueryToDB{
TYPE_QUERY_GET_LIST_INSTRUCTORS
TYPE_QUERY_GET_LIST_INSTRUCTORS,
TYPE_QUERY_GET_ALL_LISTS
};
class ClientQueryToDB{