Перед внедрением списочной модели БД в 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:46. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -1,6 +1,7 @@
#include "Core/recognizesystem.h"
#include <QThread>
#include <QDir>
#include <QDomDocument>
#include "instructor.h"
@@ -17,6 +18,8 @@ RecognizeSystem::RecognizeSystem(QObject *parent):
folderList = new QList<QString>;
listInstructors = new QList<Instructor>;
listTrainees = new QList<Trainee>;
listGroups = new QList<Group>;
}
RecognizeSystem::~RecognizeSystem()
@@ -253,6 +256,20 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
packetType = PacketType::TYPE_NONE;
}
if(packetType == PacketType::TYPE_XMLANSWER_ON_QUERY_TO_DB){ //ответы формата XML на запросы к БД
QByteArray array;
stream.startTransaction();
stream >> array;
if(!stream.commitTransaction()){
continue;
}
xmlParserQueryToDB(array);
packetType = PacketType::TYPE_NONE;
}
packetType = PacketType::TYPE_NONE;
}
}
@@ -355,7 +372,7 @@ void RecognizeSystem::xmlParser(QByteArray array)
emit sigDeAuth(serverDeAuth);
}
if(xmlReader.name() == "ListInstructors"){
if(xmlReader.name() == "AllLists"){
xmlReader.readNext();
name = xmlReader.name().toString();
@@ -417,13 +434,108 @@ void RecognizeSystem::xmlParser(QByteArray array)
i++;
*this->listInstructors = listInstructors;
emit sigAnswerQueryToDB(this->listInstructors);
//emit sigAnswerQueryToDB(this->listInstructors);
}
xmlReader.readNext();
}
}
void RecognizeSystem::xmlParserQueryToDB(QByteArray array)
{
QDomDocument groupsTraineesDOM;
/*
QString xmlFileName = appDirPath + "/groupsTrainees.xml";
QFile xmlInFile(xmlFileName);
if (!xmlInFile.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "LoadTraineesGroupsXML: Не удалось открыть файл " + xmlFileName;
return;
}
else*/
{
QList<Instructor> listInstructors;
QList<Trainee> listTrainees;
QList<Group> listGroups;
listInstructors.clear();
listTrainees.clear();
listGroups.clear();
groupsTraineesDOM.setContent(array);
/*
groupsTraineesDOM.setContent(xmlInFile.readAll());
xmlInFile.close();*/
//QDomNode groupsTraineesNode = groupsTraineesDOM.namedItem("groupsTrainees");
QDomNode allListsNode = groupsTraineesDOM.namedItem("AllLists");
QDomNode groupsTraineesNode = allListsNode.firstChildElement("GroupsTrainees");
QDomNode allInstructorsNode = allListsNode.firstChildElement("Instructors");
for(int i = 0; i < groupsTraineesNode.childNodes().count(); i++)
{
QDomNode groupNode = groupsTraineesNode.childNodes().at(i);
if(groupNode.nodeName().toLower() == "group")
{//Группа
Group group;
group.setName(groupNode.toElement().attribute("group_id"));
group.setName(groupNode.toElement().attribute("name"));
listGroups.append(group);
for(int j = 0; j < groupNode.childNodes().count(); j++)
{
QDomNode traineeNode = groupNode.childNodes().at(j);
if(traineeNode.nodeName().toLower() == "trainee")
{//Обучаемый
Trainee trainee;
trainee.setID(traineeNode.toElement().attribute("trainee_id").toInt());
trainee.setName(traineeNode.toElement().attribute("name"));
trainee.setLogin(traineeNode.toElement().attribute("login"));
trainee.setPassword(traineeNode.toElement().attribute("password"));
trainee.setArchived(traineeNode.toElement().attribute("archived") == QStringLiteral("true") ? true : false);
trainee.setArchived(traineeNode.toElement().attribute("logged_in") == QStringLiteral("true") ? true : false);
trainee.setGroup(group);
listTrainees.append(trainee);
}
}
}
}//for(int i = 0; i < groupsTraineesNode.childNodes().count(); i++)
for(int i = 0; i < allInstructorsNode.childNodes().count(); i++)
{
QDomNode instructorNode = allInstructorsNode.childNodes().at(i);
if(instructorNode.nodeName().toLower() == "instructor")
{//Инструктор
Instructor instructor;
instructor.setID(instructorNode.toElement().attribute("instructor_id").toInt());
instructor.setName(instructorNode.toElement().attribute("name"));
instructor.setLogin(instructorNode.toElement().attribute("login"));
instructor.setPassword(instructorNode.toElement().attribute("password"));
instructor.setIsAdmin(instructorNode.toElement().attribute("is_admin") == QStringLiteral("true") ? true : false);
instructor.setArchived(instructorNode.toElement().attribute("archived") == QStringLiteral("true") ? true : false);
instructor.setLoggedIn(instructorNode.toElement().attribute("logged_in") == QStringLiteral("true") ? true : false);
listInstructors.append(instructor);
}
}//for(int i = 0; i < allInstructorsNode.childNodes().count(); i++)
*this->listInstructors = listInstructors;
*this->listTrainees = listTrainees;
*this->listGroups = listGroups;
emit sigAnswerQueryToDB(this->listInstructors, this->listTrainees, this->listGroups);
}
}
void RecognizeSystem::checkAccessType(QString type)
{
if(type == "instructor")

View File

@@ -8,6 +8,8 @@
#include <Core\tools.h>
#include "dataparser.h"
#include "instructor.h"
#include "trainee.h"
#include "group.h"
class RecognizeSystem : public QObject
@@ -30,7 +32,9 @@ signals:
void sigServerBlocked();
void sigAuth(ServerAuthorization *serverAuth);
void sigDeAuth(ServerDeAuthorization *serverDeAuth);
void sigAnswerQueryToDB(QList<Instructor>* listInstructors);
void sigAnswerQueryToDB(QList<Instructor>* listInstructors,
QList<Trainee>* listTrainees,
QList<Group>* listGroups);
void sigSocketWaitForReadyRead(int waitTime);
void sigStartCompare();
@@ -48,8 +52,11 @@ private:
int countSend;
QList<Instructor>* listInstructors;
QList<Trainee>* listTrainees;
QList<Group>* listGroups;
void xmlParser(QByteArray array);
void xmlParserQueryToDB(QByteArray array);
void checkAccessType(QString type);
};

View File

@@ -32,9 +32,12 @@ enum PacketType{
TYPE_QT = 9,
TYPE_DISABLE = 11,
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:

View File

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

View File

@@ -46,7 +46,7 @@ bool ConnectorToServer::deAuthorizationInstructorLocal(QString login)
return true;
}
bool ConnectorToServer::queryGetListInstructors()
bool ConnectorToServer::sendQueryToDB(TypeQueryToDB typeQuery)
{
if (!client->getIsConnected())
{
@@ -54,10 +54,12 @@ bool ConnectorToServer::queryGetListInstructors()
}
ClientQueryToDB *queryToDB = new ClientQueryToDB;
queryToDB->typeQuery = TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS;
queryToDB->typeQuery = typeQuery;
dataParser->createQueryToDBMessage(queryToDB);
emit sigSendQueryToDB();
return true;
}
QList<Instructor> ConnectorToServer::getListInstructors()
@@ -65,10 +67,24 @@ QList<Instructor> ConnectorToServer::getListInstructors()
return listInstructors;
}
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors)
QList<Trainee> ConnectorToServer::getListTrainees()
{
return listTrainees;
}
QList<Group> ConnectorToServer::getListGroups()
{
return listGroups;
}
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors,
QList<Trainee>* listTrainees,
QList<Group>* listGroups)
{
this->listInstructors = *listInstructors;
emit signal_UpdateDB(true, false);
this->listTrainees = *listTrainees;
this->listGroups = *listGroups;
emit signal_UpdateDB(true, true);
}
void ConnectorToServer::initialize()

View File

@@ -6,6 +6,9 @@
#include "Core\dataparser.h"
#include "Core\sendsystem.h"
#include "Core\recognizesystem.h"
#include "instructor.h"
#include "trainee.h"
#include "group.h"
class ConnectorToServer : public QObject
{
@@ -16,12 +19,16 @@ public:
bool authorizationInstructorLocal(QString login, QString password);
bool deAuthorizationInstructorLocal(QString login);
bool queryGetListInstructors();
bool sendQueryToDB(TypeQueryToDB typeQuery);
QList<Instructor> getListInstructors();
QList<Trainee> getListTrainees();
QList<Group> getListGroups();
public slots:
void slot_AnswerQueryToDB(QList<Instructor>* listInstructors);
void slot_AnswerQueryToDB(QList<Instructor>* listInstructors,
QList<Trainee>* listTrainees,
QList<Group>* listGroups);
signals:
void sigSetConnect(ServerSettings* serverSettings,QThread *thread);
@@ -53,6 +60,8 @@ private:
RecognizeSystem *recognizeSystem;
QList<Instructor> listInstructors;
QList<Trainee> listTrainees;
QList<Group> listGroups;
};
#endif // CONNECTORTOSERVER_H

View File

@@ -19,6 +19,8 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
{
ui->setupUi(this);
qRegisterMetaType<PacketType>("PacketType");
connectorToServer = new ConnectorToServer(this);
connect(connectorToServer,&ConnectorToServer::sigLoginResult,this,&InstructorsAndTraineesWidget::checkLoginResult);
connect(connectorToServer,&ConnectorToServer::sigDeLoginResult,this,&InstructorsAndTraineesWidget::checkDeLoginResult);
@@ -36,6 +38,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
connect(this, &InstructorsAndTraineesWidget::signal_tabMessengerChanged, viewerTrainees, &ViewerTrainees::slot_tabMessengerChanged);
connect(connectorToServer,&ConnectorToServer::signal_UpdateDB,viewerInstructors,&ViewerInstructors::slot_NeedUpdateUI);
connect(connectorToServer,&ConnectorToServer::signal_UpdateDB,viewerTrainees,&ViewerTrainees::slot_NeedUpdateUI);
messangerWidget = new MessangerWidget(this);
@@ -291,7 +294,7 @@ void InstructorsAndTraineesWidget::on_btnUpdateStyleSheet_clicked()
viewerInstructors->updateMyStyleSheet();
}
void InstructorsAndTraineesWidget::on_btnQueryGetListInstructors_clicked()
void InstructorsAndTraineesWidget::on_btnQueryGetAllLists_clicked()
{
connectorToServer->queryGetListInstructors();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS);
}

View File

@@ -53,7 +53,7 @@ private Q_SLOTS:
void on_btnAuthorizationInstructor_clicked();
void on_btnUpdateStyleSheet_clicked();
void on_btnQueryGetListInstructors_clicked();
void on_btnQueryGetAllLists_clicked();
private:
//Авторизация инструктора локальная

View File

@@ -213,7 +213,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="btnQueryGetListInstructors">
<widget class="QToolButton" name="btnQueryGetAllLists">
<property name="minimumSize">
<size>
<width>58</width>
@@ -221,7 +221,7 @@
</size>
</property>
<property name="text">
<string>GET_LIST_INSTRUCTORS</string>
<string>GET_ALL_LISTS</string>
</property>
</widget>
</item>

View File

@@ -108,6 +108,9 @@ void TraineesView::loadTraineesFromDB()
//listGroups = dbLMS->getListGroups();
//listTrainees = dbLMS->getListTrainees();
listGroups = connectorToServer->getListGroups();
listTrainees = connectorToServer->getListTrainees();
for(Group group : listGroups)
{
//Группа