mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
до изменения NEW_INSTRUCTOR
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user