PSQL id 06.11.2024

This commit is contained in:
krivoshein
2024-11-06 16:06:32 +03:00
parent 0f1fa71c33
commit f4ca58ce91
89 changed files with 1131 additions and 763 deletions

View File

@@ -1,5 +1,6 @@
#include "databasetrainees.h"
#include <QApplication>
#include <QMessageBox>
DataBaseTrainees::DataBaseTrainees(DataBaseLMS* dbLMS)
{
@@ -36,7 +37,7 @@ void DataBaseTrainees::LoadTraineesGroupsPSQL()
QApplication::beep();
}
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString learnClass, QString computer)
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
@@ -48,12 +49,12 @@ bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QSt
{
Trainee trainee = listOfTrainees[i];
trainee.setLoggedIn(true);
trainee.setLearnClass(learnClass);
trainee.setComputer(computer);
//trainee.setLearnClass(learnClass);
//trainee.setComputer(computer);
bool result = dbLMS->updateTrainee(trainee);
int id = dbLMS->updateTrainee(trainee);
if(result)
if(id)
{
LoadTraineesGroupsPSQL();
return true;
@@ -77,12 +78,12 @@ bool DataBaseTrainees::deAuthorizationTrainee(QString login)
{
Trainee trainee = listOfTrainees[i];
trainee.setLoggedIn(false);
trainee.setLearnClass(QStringLiteral(""));
trainee.setComputer(QStringLiteral(""));
//trainee.setLearnClass(QStringLiteral(""));
//trainee.setComputer(QStringLiteral(""));
bool result = dbLMS->updateTrainee(trainee);
int id = dbLMS->updateTrainee(trainee);
if(result)
if(id)
{
LoadTraineesGroupsPSQL();
return true;
@@ -94,6 +95,7 @@ bool DataBaseTrainees::deAuthorizationTrainee(QString login)
return false;
}
/*
void DataBaseTrainees::setTasks(QString login, QStringList tasks)
{
//Обучаемые
@@ -102,39 +104,43 @@ void DataBaseTrainees::setTasks(QString login, QStringList tasks)
if(listOfTrainees[i].getLogin() == login)
listOfTrainees[i].setTasks(tasks);
}
}
}*/
QStringList DataBaseTrainees::getTasks(QString login)
{
QStringList tasks;
QStringList tasksStrList;
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getLogin() == login)
{
tasks = listOfTrainees[i].getTasks();
QList<Task> tasks = listOfTrainees[i].getTasks();
for(Task task: tasks)
{
tasksStrList.append(task.getName());
}
}
}
return tasks;
return tasksStrList;
}
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer)
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer_name)
{
for(Trainee trainee : listOfTrainees)
{
if(trainee.getComputer() == computer)
if(trainee.getComputer().getName() == computer_name)
return trainee.getName();
}
return QString(QStringLiteral(""));
}
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer)
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer_name)
{
for(Trainee trainee : listOfTrainees)
{
if(trainee.getComputer() == computer)
if(trainee.getComputer().getName() == computer_name)
return trainee;
}
return Trainee();
@@ -149,7 +155,7 @@ QString DataBaseTrainees::getNameTraineeByLogin(QString login)
}
return QString(QStringLiteral(""));
}
/*
QColor DataBaseTrainees::getColorGroupByLogin(QString login)
{
QString nameTrainee = getNameTraineeByLogin(login);
@@ -157,15 +163,15 @@ QColor DataBaseTrainees::getColorGroupByLogin(QString login)
QString nameGroup = trainee.getGroup();
Group group = getGroup(nameGroup);
return getColorGroup(group.getColor());
}
}*/
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(QString nameGroup)
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(int id)
{
QList<Trainee> listTrainees;
for(Trainee trainee : listOfTrainees)
{
if(trainee.getGroup() == nameGroup)
if(trainee.getGroup().getID() == id)
listTrainees.append(trainee);
}
@@ -176,199 +182,185 @@ QList<Group> DataBaseTrainees::getListGroups()
{
return listOfGroups;
}
/*
QColor DataBaseTrainees::getColorGroup(Group::ColorGroup numColor)
{
if(numColor > listOfColorGroup.count() - 1)
return listOfColorGroup.at(Group::ColorGroup::colorAther);
return listOfColorGroup.at(numColor);
}
}*/
Trainee DataBaseTrainees::getTrainee(QString name)
Trainee DataBaseTrainees::getTrainee(int id)
{
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getName() == name)
if(listOfTrainees[i].getID() == id)
return listOfTrainees[i];
}
return Trainee();
}
Group DataBaseTrainees::getGroup(QString nameGroup)
Group DataBaseTrainees::getGroup(int id)
{
//Группы
for(int i = 0; i < listOfGroups.count(); i++)
{
if(listOfGroups[i].getName() == nameGroup)
if(listOfGroups[i].getID() == id)
return listOfGroups[i];
}
return Group();
}
QString DataBaseTrainees::newGroup()
int DataBaseTrainees::newGroup()
{
Group group;
group.setName(generateDefaultNameGroup());
group.setColor(generateDefaultColorGroup());
bool result = dbLMS->insertGroup(group);
int id = dbLMS->insertGroup(group);
if(result)
if(id)
{
//listOfGroups.append(group);
LoadTraineesGroupsPSQL();
return group.getName();
return id;
}
else
return QStringLiteral("");
return 0;
}
bool DataBaseTrainees::deleteGroup(QString name)
int DataBaseTrainees::deleteGroup(int id)
{
if(getListTraineesInGroup(name).count() > 0)
{//Группа не пуста
return false;
}
//Группы
for(int i = 0; i < listOfGroups.count(); i++)
{
if(listOfGroups[i].getName() == name)
if(listOfGroups[i].getID() == id)
{
int id = listOfGroups[i].getID();
int id_del = dbLMS->deleteGroup(id);
bool result = dbLMS->deleteGroup(id);
if(result)
if(id_del)
{
LoadTraineesGroupsPSQL();
//listOfGroups.removeAt(i);
break;
return id_del;
}
else
return 0;
}
}
return true;
return 0;
}
bool DataBaseTrainees::editGroup(QString name, Group group)
int DataBaseTrainees::editGroup(Group group)
{
//Группы
for(int i = 0; i < listOfGroups.count(); i++)
{
if(listOfGroups[i].getName() == name)
if(listOfGroups[i].getID() == group.getID())
{
if(!checkExistNameGroup(group.getName()) || group.getName() == name)
if(!checkExistNameGroup(group.getName()) || group.getName() == listOfGroups[i].getName())
{
//group.setID(listOfGroups[i].getID());
int id = dbLMS->updateGroup(group);
bool result = dbLMS->updateGroup(group);
if(result)
if(id)
{
/*
listOfGroups[i].setName(newName);
//Меняем имя группы у всех Обучаемых этой группы
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getGroup() == name)
listOfTrainees[i].setGroup(newName);
}
*/
LoadTraineesGroupsPSQL();
return true;
return id;
}
else
return false;
return 0;
}
else
{
QMessageBox::critical(nullptr, tr("Editing error!"),
tr("An existing group name has been entered.\nThe changes will not be accepted."));
return 0;
}
}
}
return false;
return 0;
}
QString DataBaseTrainees::newTrainee(QString nameGroup)
int DataBaseTrainees::newTrainee(int id_group)
{
Trainee trainee;
trainee.setGroup(nameGroup);
Group group;
group.setID(id_group);
trainee.setGroup(group);
trainee.setName(generateDefaultNameTrainee());
trainee.setLogin(generateDefaultLoginTrainee());
trainee.setPassword(QStringLiteral("<password>"));
trainee.setLearnClass(QStringLiteral(""));
trainee.setComputer(QStringLiteral(""));
trainee.setArchived(false);
trainee.setLoggedIn(false);
//trainee.setWhatItDoes(QStringLiteral(""));
bool result = dbLMS->insertTrainee(trainee);
int id = dbLMS->insertTrainee(trainee);
if(result)
if(id)
{
//listOfTrainees.append(trainee);
LoadTraineesGroupsPSQL();
return trainee.getName();
return id;
}
else
return QStringLiteral("");
return 0;
}
void DataBaseTrainees::deleteTrainee(QString name)
int DataBaseTrainees::deleteTrainee(int id)
{
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getName() == name)
if(listOfTrainees[i].getID() == id)
{
int id = listOfTrainees[i].getID();
int id_del = dbLMS->deleteTrainee(id);
bool result = dbLMS->deleteTrainee(id);
if(result)
if(id_del)
{
LoadTraineesGroupsPSQL();
//listOfTrainees.removeAt(i);
return id_del;
}
return;
return 0;
}
}
return 0;
}
bool DataBaseTrainees::editTrainee(QString name, Trainee trainee)
int DataBaseTrainees::editTrainee(Trainee trainee)
{
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getName() == name)
if(listOfTrainees[i].getID() == trainee.getID())
{
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == name) &&
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == listOfTrainees[i].getName()) &&
(!checkExistLoginTrainee(trainee.getLogin()) || trainee.getLogin() == listOfTrainees[i].getLogin()) )
{
//trainee.setID(listOfTrainees[i].getID());
int id = dbLMS->updateTrainee(trainee);
bool result = dbLMS->updateTrainee(trainee);
if(result)
if(id)
{
//listOfTrainees.replace(i, trainee);
LoadTraineesGroupsPSQL();
return true;
return id;
}
else
return false;
return 0;
}
else
{
QMessageBox::critical(nullptr, tr("Editing error!"),
tr("An existing trainee's name or login has been entered.\nThe changes will not be accepted."));
return 0;
}
}
}
return false;
return 0;
}
bool DataBaseTrainees::isArchived(QString name)
bool DataBaseTrainees::isArchived(int id)
{
//Обучаемые
for(int i = 0; i < listOfTrainees.count(); i++)
{
if(listOfTrainees[i].getName() == name)
if(listOfTrainees[i].getID()== id)
return listOfTrainees[i].getArchived();
}
return false;
@@ -439,7 +431,7 @@ bool DataBaseTrainees::checkExistLoginTrainee(QString login)
}
return false;
}
/*
Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
{
for(int i = 0; i < Group::ColorGroup::countColor; i++)
@@ -449,8 +441,8 @@ Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
return color;
}
return Group::ColorGroup::colorAther;
}
}*/
/*
bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
{
//Группы
@@ -460,4 +452,4 @@ bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
return true;
}
return false;
}
}*/