до изменения NEW_INSTRUCTOR

This commit is contained in:
krivoshein
2024-12-13 13:07:20 +03:00
parent 1c9e0510a9
commit 14148356e0
30 changed files with 484 additions and 352 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2024-12-11T17:49:41. -->
<!-- Written by QtCreator 4.11.1, 2024-12-12T17:49:55. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -25,7 +25,7 @@ CommonView::CommonView(ConnectorToServer* connectorToServer, TypeView type, QWid
void CommonView::setItemColorArchive(QTreeWidgetItem *item)
{
setItemColor(item,QColor(250, 250, 150));
setItemColor(item,QColor(240, 240, 240));
}
void CommonView::setItemColorNoArchive(QTreeWidgetItem *item)

View File

@@ -31,6 +31,14 @@ EditorInstructors::~EditorInstructors()
void EditorInstructors::on_btnNewInstructor_clicked()
{
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR);
/*
Instructor instructor;
Instructor instructor_edit;
if(editInstructor(instructor, &instructor_edit))
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR, 0, &instructor_edit);
*/
return;
/*
if(int id_instructor = dbLMS->newInstructor())
@@ -173,36 +181,18 @@ void EditorInstructors::on_btnEdit_clicked()
if(connectorToServer->isLoggedInInstructor(id))
{//Инструктор залогирован!
QMessageBox::critical(this, tr("Error!"), tr("You cannot archive a logged-in instructor."));
QMessageBox::critical(this, tr("Error!"), tr("You cannot edit a logged-in instructor."));
return;
}
DialogEditInstructor dlg(this);
Instructor instructor = connectorToServer->getInstructor(id);
if(instructor.getID() == 0)
return;
dlg.setInstructor(instructor);
Instructor instructor_edit;
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Instructor instructor_edit = dlg.getInstructor();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor_edit);
return;
}
case QDialog::Rejected:
return;
break;
default:
return;
break;
}
}
if(editInstructor(instructor, &instructor_edit))
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor_edit);
}
}
@@ -268,4 +258,82 @@ void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *curren
}
}
bool EditorInstructors::verifyInstructor(Instructor instructor)
{
//Проверка корректности логина, имени, пароля
if(instructor.getName() == QStringLiteral("<instructor>"))
{//Имя не корректно!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor name has been entered.\nThe changes will not be accepted."));
return false;
}
if(instructor.getLogin() == QStringLiteral("<login>"))
{//Логин не корректен!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor login has been entered.\nThe changes will not be accepted."));
return false;
}
if(instructor.getPassword() == QStringLiteral("<password>"))
{//Пароль не корректный!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor password has been entered.\nThe changes will not be accepted."));
return false;
}
QList<Instructor> listInstructors = connectorToServer->getListInstructors();
for(Instructor exist_instructor : listInstructors)
{
if(instructor.getName() == exist_instructor.getName() && instructor.getID() != exist_instructor.getID())
{//Имя уже существует
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing instructor name has been entered."));
return false;
}
if(instructor.getLogin() == exist_instructor.getLogin() && instructor.getID() != exist_instructor.getID())
{//Логин уже существует!
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing instructor login has been entered.\nThe changes will not be accepted."));
return false;
}
}
return true;
}
bool EditorInstructors::editInstructor(Instructor instructor, Instructor* instructor_edit)
{
DialogEditInstructor dlg(this);
dlg.setInstructor(instructor);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
*instructor_edit = dlg.getInstructor();
if(! verifyInstructor(*instructor_edit))
{
dlg.setInstructor(*instructor_edit);
continue;
}
return true;
}
case QDialog::Rejected:
return false;
default:
return false;
}
}
}

View File

@@ -29,6 +29,9 @@ private Q_SLOTS:
private:
//void setCurrentInstructor(int id);
bool verifyInstructor(Instructor instructor);
bool editInstructor(Instructor instructor, Instructor* instructor_edit);
private:
Ui::EditorInstructors *ui;

View File

@@ -270,22 +270,14 @@ void EditorTrainees::on_btnEdit_clicked()
{
Group group_edit = dlg.getGroup();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_GROUP, id_group, &group_edit);
return;
/*
if(int id = dbLMS->editGroup(group_edit))
{//Отредактировано
loadTraineesFromDB();
setCurrentGroup(id);
return;
}
else
if(! verifyGroup(group_edit))
{
dlg.setGroup(group_edit);
continue;
}*/
}
break;
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_GROUP, id_group, &group_edit);
return;
}
case QDialog::Rejected:
return;
@@ -303,7 +295,7 @@ void EditorTrainees::on_btnEdit_clicked()
if(connectorToServer->isLoggedInTrainee(id_trainee))
{//Обучаемый залогирован!
QMessageBox::critical(this, tr("Error!"), tr("You cannot archive a logged-in trainee."));
QMessageBox::critical(this, tr("Error!"), tr("You cannot edit a logged-in trainee."));
return;
}
@@ -323,22 +315,14 @@ void EditorTrainees::on_btnEdit_clicked()
{
Trainee trainee_edit = dlg.getTrainee();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE, id_trainee, &trainee_edit);
return;
/*
if(int id = dbLMS->editTrainee(trainee_edit))
{//Отредактировано
loadTraineesFromDB();
setCurrentTrainee(id);
return;
}
else
if(! verifyTrainee(trainee_edit))
{
dlg.setTrainee(trainee_edit);
continue;
}*/
}
break;
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_TRAINEE, id_trainee, &trainee_edit);
return;
}
case QDialog::Rejected:
return;
@@ -457,4 +441,77 @@ void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
}
}
bool EditorTrainees::verifyGroup(Group group)
{
//Проверка корректности имени
if(group.getName() == QStringLiteral("<group>"))
{//Имя не корректно!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable group name has been entered.\nThe changes will not be accepted."));
return false;
}
QList<Group> listGroups = connectorToServer->getListGroups();
for(Group exist_group : listGroups)
{
if(group.getName() == exist_group.getName() && group.getID() != exist_group.getID())
{//Имя уже существует
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing group name has been entered.\nThe changes will not be accepted."));
return false;
}
}
return true;
}
bool EditorTrainees::verifyTrainee(Trainee trainee)
{
//Проверка корректности логина, имени, пароля
if(trainee.getName() == QStringLiteral("<trainee>"))
{//Имя не корректно!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable trainee name has been entered.\nThe changes will not be accepted."));
return false;
}
if(trainee.getLogin() == QStringLiteral("<login>"))
{//Логин не корректен!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable trainee login has been entered.\nThe changes will not be accepted."));
return false;
}
if(trainee.getPassword() == QStringLiteral("<password>"))
{//Пароль не корректный!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable trainee password has been entered.\nThe changes will not be accepted."));
return false;
}
QList<Trainee> listTrainees = connectorToServer->getListTrainees();
for(Trainee exist_trainee : listTrainees)
{
if(trainee.getName() == exist_trainee.getName() && trainee.getID() != exist_trainee.getID())
{//Имя уже существует
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing trainee name has been entered."));
return false;
}
if(trainee.getLogin() == exist_trainee.getLogin() && trainee.getID() != exist_trainee.getID())
{//Логин уже существует!
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing trainee login has been entered.\nThe changes will not be accepted."));
return false;
}
}
return true;
}

View File

@@ -33,6 +33,8 @@ private Q_SLOTS:
private:
//void setCurrentGroup(int id);
//void setCurrentTrainee(int id);
bool verifyGroup(Group group);
bool verifyTrainee(Trainee trainee);
private:
Ui::EditorTrainees *ui;

View File

@@ -107,6 +107,7 @@ void TraineesView::loadTraineesFromDB()
listGroups = connectorToServer->getListGroups();
listTrainees = connectorToServer->getListTrainees();
for(Group group : listGroups)
{
//Группа
@@ -116,6 +117,8 @@ void TraineesView::loadTraineesFromDB()
ItemGroup->setText(ColumnsTreeTrainees::clmn_Trainee, group.getName());
ItemGroup->setIcon(ColumnsTreeTrainees::clmn_Trainee, QIcon(QStringLiteral(":/icons/group.png")));
setItemColor(ItemGroup, QColor(170, 190, 170));
//ItemGroup->set Property("greenButton", QVariant(true));
//((QAbstractItemView*)ItemGroup)->setIconSize(QSize(32, 32));
//Обучаемые
@@ -183,8 +186,8 @@ void TraineesView::loadTraineesFromDB()
ItemTrainee->setHidden(true);
}
if(! archiveVisible && cntChildsNotArchived == 0)
delete ItemGroup;
//if(! archiveVisible && cntChildsNotArchived == 0)
//delete ItemGroup;
}
treeWidget->expandAll();