сделал newInstructor

This commit is contained in:
krivoshein
2024-12-11 12:50:52 +03:00
parent 4556c07fc9
commit 0cb03e49b1
89 changed files with 1318 additions and 671 deletions

View File

@@ -72,3 +72,10 @@ target_link_libraries(ServerLMS PRIVATE libDataBaseLMS.dll)
target_compile_definitions(ServerLMS PRIVATE SERVERLMS_LIBRARY)
add_custom_command(TARGET ServerLMS
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
d:/LMS/ServerLMS/Debug64/libServerLMS.dll
d:/LMS/TestServerLMS/Debug64)

View File

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

View File

@@ -365,6 +365,134 @@ QByteArray DataParser::xmlAnswer_ClientQueryToDB(bool result, QList<Instructor>*
return groupsTraineesDOM.toByteArray();
}
bool DataParser::loadBlankXML(QString nameFile, QDomDocument *commonDOM)
{
QFile blankFile(":/blankXML/" + nameFile);
if (! blankFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug() << "loadBlankXML: Не удалось считать файл :/blankXML/" + nameFile;
return false;
}
commonDOM->setContent(blankFile.readAll());
blankFile.close();
return true;
}
bool DataParser::saveDOMtoXML(QString nameFile, QDomDocument *commonDOM)
{
QFile xmlOutFile(nameFile);
if (!xmlOutFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << "saveDOMtoXML: Не удалось записать файл " + nameFile;
return false;
}
else
{
QTextStream outFile(&xmlOutFile);
commonDOM->save(outFile, 4);
xmlOutFile.close();
}
return true;
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListInstructors(bool result, QList<Instructor> *listInstructors)
{
QDomDocument commonDOM;
if(! loadBlankXML("ListInstructors.xml", &commonDOM))
return QByteArray();
QDomNode listNode = commonDOM.namedItem("ListInstructors");
for(Instructor instructor : *listInstructors)
{
//Инструктор
QDomNode instructorNode = commonDOM.createElement("Instructor");
listNode.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());
instructorNode.toElement().setAttribute("archived", instructor.getArchived());
instructorNode.toElement().setAttribute("logged_in", instructor.getLoggedIn());
}
saveDOMtoXML("ListInstructors.xml", &commonDOM);
return commonDOM.toByteArray();
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListGroups(bool result, QList<Group> *listGroups)
{
QDomDocument commonDOM;
if(! loadBlankXML("ListGroups.xml", &commonDOM))
return QByteArray();
QDomNode listNode = commonDOM.namedItem("ListGroups");
for(Group group : *listGroups)
{
//Группа
QDomNode groupNode = commonDOM.createElement("Group");
listNode.appendChild(groupNode);
groupNode.toElement().setAttribute("group_id", QString::number(group.getID()));
groupNode.toElement().setAttribute("name", group.getName());
}
saveDOMtoXML("ListGroups.xml", &commonDOM);
return commonDOM.toByteArray();
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListTrainees(bool result, QList<Trainee> *listTrainees)
{
QDomDocument commonDOM;
if(! loadBlankXML("ListTrainees.xml", &commonDOM))
return QByteArray();
QDomNode listNode = commonDOM.namedItem("ListTrainees");
for(Trainee trainee : *listTrainees)
{
//Обучаемый
QDomNode traineeNode = commonDOM.createElement("Trainee");
listNode.appendChild(traineeNode);
traineeNode.toElement().setAttribute("trainee_id", 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());
traineeNode.toElement().setAttribute("logged_in", trainee.getLoggedIn());
traineeNode.toElement().setAttribute("group_trainee", trainee.getGroup().getID());
traineeNode.toElement().setAttribute("computer_trainee", trainee.getComputer().getID());
//trainee.setTasks()
}
saveDOMtoXML("ListTrainees.xml", &commonDOM);
return commonDOM.toByteArray();
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListComputers(bool result, QList<Computer> *listComputers)
{
//TODO
return QByteArray();
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListClassrooms(bool result, QList<Classroom> *listClassrooms)
{
//TODO
return QByteArray();
}
QByteArray DataParser::xmlAnswer_ClientQueryToDB_ListTasks(bool result, QList<Task> *listTasks)
{
//TODO
return QByteArray();
}
QByteArray DataParser::xmlAnswer_message(QString text)
{
QList<SXmlAnswerTag> listTag;

View File

@@ -11,6 +11,7 @@
#include <QByteArray>
#include <QXmlStreamReader>
#include <QDebug>
#include <QDomDocument>
class ProcessingSystem;
class ClientHandler;
@@ -31,6 +32,15 @@ public:
QByteArray xmlAnswer_ClientQueryToDB(bool result, QList<Instructor>* listInstructors = nullptr,
QList<Trainee>* listTrainees = nullptr, QList<Group>* listGroups = nullptr);
bool loadBlankXML(QString nameFile, QDomDocument* commonDOM);
bool saveDOMtoXML(QString nameFile, QDomDocument* commonDOM);
QByteArray xmlAnswer_ClientQueryToDB_ListInstructors(bool result, QList<Instructor>* listInstructors);
QByteArray xmlAnswer_ClientQueryToDB_ListGroups(bool result, QList<Group> *listGroups);
QByteArray xmlAnswer_ClientQueryToDB_ListTrainees(bool result, QList<Trainee> *listTrainees);
QByteArray xmlAnswer_ClientQueryToDB_ListComputers(bool result, QList<Computer> *listComputers);
QByteArray xmlAnswer_ClientQueryToDB_ListClassrooms(bool result, QList<Classroom> *listClassrooms);
QByteArray xmlAnswer_ClientQueryToDB_ListTasks(bool result, QList<Task> *listTasks);
QByteArray xmlAnswer_message(QString text);
QByteArray xmlAnswer_task(QString text);
QByteArray xmlAnswer_notify(QString code);
@@ -41,6 +51,7 @@ public:
QList<FileData> *getDatas() const;
signals:
void sigLogMessage(QString log);

View File

@@ -130,12 +130,26 @@ void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQu
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
QList<Trainee> listTrainees = providerDBLMS->GetListAllTrainees();
QList<Group> listGroups = providerDBLMS->GetListAllGroups();
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB(true, &listInstructors, &listTrainees, &listGroups);
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListInstructors(true, &listInstructors);
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS);
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListGroups(true, &listGroups);
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS);
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB_ListTrainees(true, &listTrainees);
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES);
break;
}
case TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR:
{
providerDBLMS->newInstructor();
emit sigAuthChanged();
break;
}
}
client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_ON_QUERY_TO_DB);
//client->sendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER_QUERY_DB_LIST_INSTRUCTORS);
//QString str = QString(arrayAnswer);
//logger->addTextToLogger("To Client: " + str);

View File

@@ -32,8 +32,13 @@ enum PacketType
TYPE_DISABLE = 11,
TYPE_FILESIZE = 20,
TYPE_GET_LIST_INSTRUCTORS = 100,
TYPE_XMLANSWER_ON_QUERY_TO_DB = 101 //xml-ответ на запрос к БД
//xml-ответы на запросы к БД
TYPE_XMLANSWER_QUERY_DB__LIST_INSTRUCTORS = 100,
TYPE_XMLANSWER_QUERY_DB__LIST_GROUPS = 101,
TYPE_XMLANSWER_QUERY_DB__LIST_TRAINEES = 102,
TYPE_XMLANSWER_QUERY_DB__LIST_COMPUTERS = 103,
TYPE_XMLANSWER_QUERY_DB__LIST_CLASSROOMS = 104,
TYPE_XMLANSWER_QUERY_DB__LIST_TASKS = 105
};
Q_DECLARE_METATYPE(PacketType)

View File

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

View File

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

View File

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

View File

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

View File

@@ -252,3 +252,8 @@ QList<Group> ProviderDBLMS::GetListAllGroups()
mtxAccess.unlock();
return listGroups;
}
int ProviderDBLMS::newInstructor()
{
return dbLMS->newInstructor();
}

View File

@@ -28,6 +28,8 @@ public:
QList<Trainee> GetListAllTrainees();
QList<Group> GetListAllGroups();
int newInstructor();
Q_SIGNALS:
//сигнал о блокировке авторизации
void signal_BlockAutorization(bool block);

View File

@@ -5,7 +5,8 @@
<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>
<file>blankXML/ListInstructors.xml</file>
<file>blankXML/ListGroups.xml</file>
<file>blankXML/ListTrainees.xml</file>
</qresource>
</RCC>

View File

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