mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
before task parser
This commit is contained in:
@@ -8,7 +8,7 @@ DataBaseLMS::DataBaseLMS():
|
||||
db(nullptr),
|
||||
transactionBegined(false)
|
||||
{
|
||||
createConnection();
|
||||
|
||||
}
|
||||
|
||||
DataBaseLMS::~DataBaseLMS()
|
||||
@@ -24,12 +24,11 @@ bool DataBaseLMS::createConnection()
|
||||
db->setPassword(dbPassword);
|
||||
if(!db->open())
|
||||
{
|
||||
QMessageBox::critical(nullptr, dbName, "Connection error: " + db->lastError().text());
|
||||
deleteConnection();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information(nullptr, dbName, "Connection is successful!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -49,18 +48,34 @@ void DataBaseLMS::deleteConnection()
|
||||
}
|
||||
}
|
||||
|
||||
bool DataBaseLMS::isConnected()
|
||||
{
|
||||
if(db == nullptr)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if(db->isOpen())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::transactionBegin()
|
||||
{
|
||||
/*
|
||||
if(transactionBegined)
|
||||
QSqlDatabase::database().rollback();
|
||||
|
||||
transactionBegined = true;
|
||||
|
||||
return QSqlDatabase::database().transaction();
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::transactionEnd()
|
||||
{
|
||||
/*
|
||||
if(transactionBegined)
|
||||
{
|
||||
transactionBegined = false;
|
||||
@@ -68,6 +83,8 @@ bool DataBaseLMS::transactionEnd()
|
||||
return QSqlDatabase::database().commit();
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<Instructor> DataBaseLMS::selectAllInstructors()
|
||||
@@ -236,6 +253,27 @@ int DataBaseLMS::selectInstructorID(QString login, QString password)
|
||||
return queryExecInt(queryStr);
|
||||
}
|
||||
|
||||
QString DataBaseLMS::selectInstructorNameByLogin(QString login)
|
||||
{
|
||||
QString queryStr = QString("SELECT instructors.name "
|
||||
"FROM public.instructors "
|
||||
"WHERE instructors.login = '%1' ").arg(
|
||||
login );
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.first())
|
||||
return query.value(0).toString();
|
||||
}
|
||||
return QStringLiteral("");
|
||||
}
|
||||
|
||||
bool DataBaseLMS::selectInstructorIsAdmin(int id_instructor)
|
||||
{
|
||||
QString queryStr = QString("SELECT instructors.is_admin "
|
||||
@@ -251,7 +289,7 @@ bool DataBaseLMS::selectInstructorIsAdmin(int id_instructor)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.next())
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
return false;
|
||||
@@ -272,7 +310,7 @@ bool DataBaseLMS::selectInstructorLoggedIn(int id_instructor)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.next())
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
return false;
|
||||
@@ -293,7 +331,7 @@ bool DataBaseLMS::selectInstructorArchived(int id_instructor)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.next())
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
return false;
|
||||
@@ -311,6 +349,25 @@ int DataBaseLMS::updateInstructorLoggedIn(int id_instructor, bool loggedIn)
|
||||
return queryExecInt(queryStr);
|
||||
}
|
||||
|
||||
bool DataBaseLMS::updateAllInstructorsLoggedIn(bool loggedIn)
|
||||
{
|
||||
QString queryStr = QString("UPDATE public.instructors "
|
||||
"SET logged_in = %1 ").arg(
|
||||
loggedIn ? "true" : "false");
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int DataBaseLMS::updateInstructorArchived(int id_instructor, bool archived)
|
||||
{
|
||||
QString queryStr = QString("UPDATE public.instructors "
|
||||
@@ -560,6 +617,93 @@ int DataBaseLMS::selectTraineeID(QString login, QString password)
|
||||
return queryExecInt(queryStr);
|
||||
}
|
||||
|
||||
QString DataBaseLMS::selectTraineeNameByLogin(QString login)
|
||||
{
|
||||
QString queryStr = QString("SELECT trainees.name "
|
||||
"FROM public.trainees "
|
||||
"WHERE trainees.login = '%1' ").arg(
|
||||
login );
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.first())
|
||||
return query.value(0).toString();
|
||||
}
|
||||
return QStringLiteral("");
|
||||
}
|
||||
|
||||
QString DataBaseLMS::selectTraineeNameOnComputer(QString computer_name)
|
||||
{
|
||||
QString queryStr = QString("SELECT trainees.name "
|
||||
"FROM public.trainees JOIN public.computers ON computers.computer_id = trainees.computer_trainee "
|
||||
"WHERE computers.name = '%1' ").arg(
|
||||
computer_name);
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.first())
|
||||
return query.value(0).toString();
|
||||
}
|
||||
return QStringLiteral("");
|
||||
}
|
||||
|
||||
Trainee DataBaseLMS::selectTraineeOnComputer(QString computer_name)
|
||||
{
|
||||
Trainee trainee;
|
||||
|
||||
QString queryStr = QString("SELECT trainees.trainee_id, trainees.name, trainees.login, trainees.password, trainees.archived, trainees.logged_in, "
|
||||
"groups.group_id, groups.name, "
|
||||
"computers.computer_id, computers.name, computers.ip_address, "
|
||||
"classrooms.classroom_id, classrooms.name "
|
||||
"FROM public.trainees JOIN public.groups ON groups.group_id = trainees.group_trainee "
|
||||
"LEFT OUTER JOIN public.computers ON computers.computer_id = trainees.computer_trainee "
|
||||
"LEFT OUTER JOIN public.classrooms ON classrooms.classroom_id = computers.classroom_computer "
|
||||
"WHERE computers.name = '%1' ").arg(
|
||||
computer_name);
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (query.first())
|
||||
{//Инструктор
|
||||
trainee.setID(query.value(0).toInt());
|
||||
trainee.setName(query.value(1).toString());
|
||||
trainee.setLogin(query.value(2).toString());
|
||||
trainee.setPassword(query.value(3).toString());
|
||||
trainee.setArchived(query.value(4).toBool());
|
||||
trainee.setLoggedIn(query.value(5).toBool());
|
||||
|
||||
Group group = Group(query.value(6).toInt(), query.value(7).toString());
|
||||
trainee.setGroup(group);
|
||||
|
||||
Classroom classroom = Classroom(query.value(11).toInt(), query.value(12).toString());
|
||||
Computer computer = Computer(query.value(8).toInt(), query.value(9).toString(), query.value(10).toString(), classroom);
|
||||
trainee.setComputer(computer);
|
||||
|
||||
trainee.setTasks(selectTasksOfTrainee(trainee.getID()));
|
||||
}
|
||||
}
|
||||
|
||||
return trainee;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::selectTraineeArchived(int id_trainee)
|
||||
{
|
||||
QString queryStr = QString("SELECT trainees.archived "
|
||||
@@ -575,7 +719,7 @@ bool DataBaseLMS::selectTraineeArchived(int id_trainee)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.next())
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
return false;
|
||||
@@ -596,7 +740,7 @@ bool DataBaseLMS::selectTraineeLoggedIn(int id_trainee)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.next())
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
}
|
||||
return false;
|
||||
@@ -614,6 +758,25 @@ int DataBaseLMS::updateTraineeLoggedIn(int id_trainee, bool loggedIn)
|
||||
return queryExecInt(queryStr);
|
||||
}
|
||||
|
||||
bool DataBaseLMS::updateAllTraineesLoggedIn(bool loggedIn)
|
||||
{
|
||||
QString queryStr = QString("UPDATE public.trainees "
|
||||
"SET logged_in = %1 ").arg(
|
||||
loggedIn ? "true" : "false");
|
||||
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int DataBaseLMS::updateTraineeArchived(int id_trainee, bool archived)
|
||||
{
|
||||
QString queryStr = QString("UPDATE public.trainees "
|
||||
@@ -732,24 +895,6 @@ int DataBaseLMS::queryExecInt(QString queryStr)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
bool DataBaseLMS::queryExecBool(QString queryStr)
|
||||
{
|
||||
QSqlQuery query = QSqlQuery(*db);
|
||||
|
||||
if(!query.exec(queryStr))
|
||||
{
|
||||
messageWarningErrorQuery(queryStr, &query);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(query.first())
|
||||
return query.value(0).toBool();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
void DataBaseLMS::messageWarningErrorQuery(QString queryStr, QSqlQuery* query)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user