a lot of stuff
This commit is contained in:
@@ -9,6 +9,13 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
add_compile_options(-Wall -Wextra -pedantic)
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4)
|
||||
endif()
|
||||
|
||||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Svg Core Sql)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Svg Core Sql)
|
||||
|
||||
@@ -31,3 +38,18 @@ target_link_libraries(EinsatzplanQT PRIVATE
|
||||
pqxx
|
||||
stdc++fs
|
||||
)
|
||||
|
||||
install(TARGETS EinsatzplanQT DESTINATION /usr/bin)
|
||||
|
||||
set(DESKTOP_FILE_CONTENT "
|
||||
[Desktop Entry]
|
||||
Name=EinsatzplanQT
|
||||
Exec=/usr/bin/EinsatzplanQT
|
||||
Icon=calendar
|
||||
Type=Application
|
||||
Categories=Utility
|
||||
;")
|
||||
|
||||
set(DESKTOP_FILE_PATH "${CMAKE_BINARY_DIR}/EinsatzplanQT.desktop")
|
||||
file(WRITE ${DESKTOP_FILE_PATH} ${DESKTOP_FILE_CONTENT})
|
||||
install(FILES ${DESKTOP_FILE_PATH} DESTINATION /usr/share/applications)
|
||||
|
||||
24
script.sql
24
script.sql
@@ -92,18 +92,18 @@ CREATE TABLE Veranstalter (
|
||||
);
|
||||
|
||||
INSERT INTO Veranstalter (name, email, passwort, admin) VALUES
|
||||
('tech_guru', 'admin@example.com', 'password123', TRUE),
|
||||
('code_master', 'user1@example.com', 'password1', FALSE),
|
||||
('binary_hero', 'user2@example.com', 'password2', FALSE),
|
||||
('debug_ninja', 'user3@example.com', 'password3', FALSE),
|
||||
('data_wizard', 'user4@example.com', 'password4', FALSE),
|
||||
('script_samurai', 'user5@example.com', 'password5', FALSE),
|
||||
('dev_genius', 'user6@example.com', 'password6', FALSE),
|
||||
('cyber_maven', 'user7@example.com', 'password7', FALSE),
|
||||
('net_knight', 'user8@example.com', 'password8', FALSE),
|
||||
('bit_boss', 'user9@example.com', 'password9', FALSE),
|
||||
('sys_sensei', 'user10@example.com', 'password10', FALSE),
|
||||
('crypto_champ', 'user11@example.com', 'password11', FALSE);
|
||||
('Davids', 'admin@example.com', 'password123', TRUE),
|
||||
('Dalitz', 'user1@example.com', 'password1', FALSE),
|
||||
('Tipp', 'user2@example.com', 'password2', FALSE),
|
||||
('Quix', 'user3@example.com', 'password3', FALSE),
|
||||
('Nietsche', 'user4@example.com', 'password4', FALSE),
|
||||
('Ueberholz', 'user5@example.com', 'password5', FALSE),
|
||||
('Rethmann', 'user6@example.com', 'password6', FALSE),
|
||||
('Pohle-Fröhlich', 'user7@example.com', 'password7', FALSE),
|
||||
('Stockmann', 'user8@example.com', 'password8', FALSE),
|
||||
('Gref', 'user9@example.com', 'password9', FALSE),
|
||||
('Naroska', 'user10@example.com', 'password10', FALSE),
|
||||
('Grothe', 'user11@example.com', 'supersicherespasswort123', FALSE);
|
||||
|
||||
|
||||
INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
EinsatzplanFrameController::EinsatzplanFrameController(QString id, bool admin)
|
||||
:m_id(id),
|
||||
m_admin(admin) {
|
||||
const std::map<std::string, std::string> config = load_config("../config.cfg");
|
||||
const std::map<std::string, std::string> config = load_config( );
|
||||
|
||||
m_connectionString = fmt::format(
|
||||
"host={} port={} dbname={} user={} password={}",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "../../Core/DBHandler/DBPlan/DBPlan.hpp"
|
||||
#include "../../Core/config/config.hpp"
|
||||
#include "../PlanGridController/PlanGridController.hpp"
|
||||
|
||||
class EinsatzplanFrameController {
|
||||
private:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "LoginFrameController.hpp"
|
||||
|
||||
LoginFrameController::LoginFrameController( ) {
|
||||
auto config = load_config("../config.cfg");
|
||||
auto config = load_config( );
|
||||
|
||||
m_connectionString = fmt::format(
|
||||
"host={} port={} dbname={} user={} password={}",
|
||||
|
||||
@@ -15,7 +15,7 @@ PlanGridController::PlanGridController( ) {
|
||||
|
||||
planMap = new QMap<QPair<QString, QString>, QWidget*>( );
|
||||
|
||||
const std::map<std::string, std::string> config = load_config("../config.cfg");
|
||||
const std::map<std::string, std::string> config = load_config( );
|
||||
|
||||
m_connectionString = fmt::format(
|
||||
"host={} port={} dbname={} user={} password={}",
|
||||
@@ -30,7 +30,6 @@ PlanGridController::PlanGridController( ) {
|
||||
QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen( ) {
|
||||
DBPlan* db = new DBPlan(m_connectionString);
|
||||
|
||||
// stringFormat = tag , anfangszeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID
|
||||
std::vector<std::string> planData = db->getPlan( );
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
@@ -57,7 +56,7 @@ QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen(
|
||||
while (std::getline(ss, str, ','))
|
||||
infoVector.push_back(str);
|
||||
|
||||
//Wochentag, Uhrzeit,Uhrzeitende, Campus, Veranstaltung, ProfName,raum, veranstaltungs dauer
|
||||
//Wochentag, Uhrzeit,Uhrzeitende, Campus, Veranstaltung, ProfName,raum, prof id
|
||||
QFrame* container = new QFrame( );
|
||||
|
||||
container->setObjectName("container");
|
||||
@@ -71,13 +70,13 @@ QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen(
|
||||
|
||||
QPushButton* widget = new QPushButton(QString::fromStdString(infoVector.at(4) + " - " + infoVector.at(5) + "\n" + infoVector.at(3) + infoVector.at(6)));
|
||||
layout->addWidget(widget);
|
||||
//widget->setAlignment(Qt::AlignCenter);
|
||||
widget->setObjectName("widget");
|
||||
widget->setProperty("MitarbeiterName", QString::fromStdString(infoVector.at(5)));
|
||||
widget->setProperty("MitarbeiterID", QString::fromStdString(infoVector.at(7)));
|
||||
widget->setObjectName("eintragung");
|
||||
widget->setFixedSize(210, 70);
|
||||
widget->setToolTip(QString::fromStdString(infoVector.at(7)));
|
||||
widget->setCursor(Qt::PointingHandCursor);
|
||||
layout->setAlignment(Qt::AlignCenter);
|
||||
connect(widget, &QPushButton::clicked, this, [infoVector]( ) {
|
||||
fmt::print("clicked on " + infoVector.at(4) + '\n');
|
||||
});
|
||||
|
||||
if (infoVector.at(4) == "THI") {
|
||||
color = "#9FA8DA";
|
||||
@@ -99,12 +98,16 @@ QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen(
|
||||
color = "#80CBC4";
|
||||
} else if (infoVector.at(4) == "SWE") {
|
||||
color = "#80DEEA";
|
||||
} else if (infoVector.at(4) == "MA1") {
|
||||
color = "#B39DDB";
|
||||
} else if (infoVector.at(4) == "PE1") {
|
||||
color = "#FFAB91";
|
||||
} else {
|
||||
color = "#313131";
|
||||
color = "#D8D8D8";
|
||||
}
|
||||
|
||||
widget->setStyleSheet(QString::fromStdString(R"(
|
||||
#widget{
|
||||
#eintragung{
|
||||
border: 0px solid #313131;
|
||||
background-color: )" + color + R"(;
|
||||
color: #212121;
|
||||
@@ -123,3 +126,9 @@ QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen(
|
||||
|
||||
return planMap;
|
||||
}
|
||||
|
||||
void PlanGridController::Krankmelden(const int id, int tag, int stunde) {
|
||||
DBPlan db(m_connectionString);
|
||||
|
||||
db.meldeKrank(std::to_string(id), std::to_string(tag), std::to_string(stunde));
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ class PlanGridController : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::string m_connectionString;
|
||||
|
||||
protected:
|
||||
QString weekdays[5];
|
||||
QString times[5];
|
||||
@@ -23,4 +22,5 @@ public:
|
||||
PlanGridController( );
|
||||
|
||||
QMap<QPair<QString, QString>, QWidget*>* getVeranstaltungen( );
|
||||
void Krankmelden(const int id, const int tag, const int stunde);
|
||||
};
|
||||
|
||||
@@ -2,570 +2,474 @@
|
||||
|
||||
DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { };
|
||||
|
||||
void DBPlan::vertretung(std::string tag, std::string stunde, std::string dauer) {
|
||||
try {
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
std::string cap = std::to_string(18 - std::stoi(dauer));
|
||||
std::string nextStunde;
|
||||
std::string nextTag = tag;
|
||||
std::string prevTag = tag;
|
||||
if (dauer == "4") {
|
||||
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 2);
|
||||
|
||||
}
|
||||
else {
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
}
|
||||
void DBPlan::vertretung(std::string tag, std::string stunde) {
|
||||
try {
|
||||
std::string dauer = getDauer(tag, stunde);
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
std::string cap = std::to_string(18 - std::stoi(dauer));
|
||||
std::string nextStunde;
|
||||
std::string nextTag = tag;
|
||||
std::string prevTag = tag;
|
||||
(dauer == "4") ? nextStunde = std::to_string(std::stoi(stunde) + 2) :
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
if (prevStunde == "0") {
|
||||
prevStunde = "5";
|
||||
prevTag = std::to_string(std::stoi(tag) - 1);
|
||||
if (prevTag == "0") {
|
||||
prevTag = "5";
|
||||
}
|
||||
}
|
||||
if (prevStunde == "0") {
|
||||
prevStunde = "5";
|
||||
prevTag = std::to_string(std::stoi(tag) - 1);
|
||||
if (prevTag == "0")
|
||||
prevTag = "5";
|
||||
}
|
||||
|
||||
if (nextStunde == "6") {
|
||||
nextStunde = "1";
|
||||
nextTag = std::to_string(std::stoi(tag)+1);
|
||||
if (nextTag == "6") {
|
||||
nextTag = "1";
|
||||
}
|
||||
}
|
||||
if (nextStunde == "6") {
|
||||
nextStunde = "1";
|
||||
nextTag = std::to_string(std::stoi(tag) + 1);
|
||||
if (nextTag == "6")
|
||||
nextTag = "1";
|
||||
}
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = "
|
||||
"(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2) "
|
||||
"AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; ";
|
||||
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = "
|
||||
"(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2) "
|
||||
"AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; ";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||
|
||||
worker.commit();
|
||||
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::sucheVertretung(std::string tag, std::string stunde) {
|
||||
std::string dauer = getDauer(tag, stunde);
|
||||
vertretung(tag, stunde, dauer);
|
||||
incarbeitszeit(tag, stunde, dauer);
|
||||
|
||||
if (dauer == "4") {
|
||||
upperHour(tag, stunde);
|
||||
}
|
||||
|
||||
|
||||
worker.commit( );
|
||||
if (response.affected_rows( ) == 0) {
|
||||
std::string query2 =
|
||||
"DELETE FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $1 and uhrzeit_id = $2";
|
||||
worker.exec_params(query2, tag, stunde);
|
||||
worker.commit( );
|
||||
|
||||
if (dauer == "4") {
|
||||
std::string query3 =
|
||||
"DELETE FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $1 and uhrzeit_id = $2";
|
||||
worker.exec_params(query3, tag, nextStunde);
|
||||
worker.commit( );
|
||||
}
|
||||
} else {
|
||||
incarbeitszeit(tag, stunde, dauer);
|
||||
if (dauer == "4")
|
||||
upperHour(tag, stunde);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1;";
|
||||
|
||||
try {
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1;";
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
|
||||
sucheVertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
|
||||
}
|
||||
vertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::meldeGesund(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = FALSE WHERE ID = $1;";
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "UPDATE Veranstalter SET krank = FALSE WHERE ID = $1;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||
|
||||
//get times where id in plan
|
||||
//for each search vertretung
|
||||
//get times where id in plan
|
||||
//for each search vertretung
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
|
||||
std::string tag, stunde;
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
|
||||
for (int i = 0; i < response.affected_rows(); i++) {
|
||||
tag = response[i][0].c_str();
|
||||
stunde = response[i][1].c_str();
|
||||
sucheVertretung(tag, stunde);
|
||||
if (getDauer(tag, stunde) == "4")
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
std::string tag, stunde;
|
||||
|
||||
for (int i = 0; i < response.affected_rows( ); i++) {
|
||||
tag = response[i][0].c_str( );
|
||||
stunde = response[i][1].c_str( );
|
||||
vertretung(tag, stunde);
|
||||
if (getDauer(tag, stunde) == "4")
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstalter(std::string id) {
|
||||
deleteVeranstalterForeign(id);
|
||||
|
||||
deleteVeranstalterForeign(id);
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM Veranstalter WHERE ID = $1;";
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "DELETE FROM Veranstalter WHERE ID = $1;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
versendeEmails();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DBPlan::deleteVeranstaltung(std::string name) {
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM Veranstaltung WHERE name = $1;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, name);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "DELETE FROM Veranstaltung WHERE name = $1;";
|
||||
|
||||
worker.exec_params(query, name);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);";
|
||||
pqxx::result response = worker.exec_params(query, name, dauer, ort, raum);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);";
|
||||
worker.exec_params(query, name, dauer, ort, raum);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);";
|
||||
pqxx::result response = worker.exec_params(query, email, name, pw, admin);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);";
|
||||
worker.exec_params(query, email, name, pw, admin);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::deleteStudent(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM studenten WHERE ID = $1;";
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM studenten WHERE ID = $1;";
|
||||
worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) {
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);";
|
||||
pqxx::result response = worker.exec_params(query, email, name, pw);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);";
|
||||
worker.exec_params(query, email, name, pw);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||
|
||||
worker.commit();
|
||||
|
||||
|
||||
return response[0][0].c_str();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||
|
||||
worker.commit( );
|
||||
|
||||
return response[0][0].c_str( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 AND krank = FALSE LIMIT 1) "
|
||||
"WHERE uhrzeit_id = 1 AND tag = $1;";
|
||||
pqxx::result response = worker.exec_params(query, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 AND krank = FALSE LIMIT 1)
|
||||
WHERE uhrzeit_id = 1 AND tag = $1;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
try {
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||
"WHERE arbeitszeit <= 16 AND krank = FALSE "
|
||||
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"ORDER BY random() LIMIT 1) "
|
||||
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
WHERE arbeitszeit <= 16 AND krank = FALSE
|
||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
ORDER BY random() LIMIT 1)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addFirstOfDayFour(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 AND krank = FALSE LIMIT 1) "
|
||||
"WHERE uhrzeit_id = 1 AND tag = $1;";
|
||||
pqxx::result response = worker.exec_params(query, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 AND krank = FALSE LIMIT 1)
|
||||
WHERE uhrzeit_id = 1 AND tag = $1;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addFourHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||
"WHERE arbeitszeit <= 14 AND krank = FALSE "
|
||||
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"ORDER BY random() LIMIT 1) "
|
||||
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
WHERE arbeitszeit <= 14 AND krank = FALSE
|
||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
ORDER BY random() LIMIT 1)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
try {
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)"
|
||||
"WHERE uhrzeit_id = $3 AND tag = $2;";
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag, nextStunde);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)
|
||||
WHERE uhrzeit_id = $3 AND tag = $2;)";
|
||||
worker.exec_params(query, stunde, tag, nextStunde);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::updateStandort(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter SET standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);)";
|
||||
worker.exec_params(query, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) {
|
||||
try {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET arbeitszeit = arbeitszeit + $1 WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $2 AND tag = $3);";
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET arbeitszeit = arbeitszeit + $1 WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $2 AND tag = $3);";
|
||||
|
||||
pqxx::result response = worker.exec_params(query,amount, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
worker.exec_params(query, amount, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::insertVeranstaltungenIntoPlan(std::string cap, std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||
SELECT ID, $1, $2 FROM Veranstaltung WHERE dauer <= $3
|
||||
ORDER BY used ASC
|
||||
LIMIT 1;)";
|
||||
|
||||
worker.exec_params(query, tag, stunde, cap);
|
||||
worker.commit();
|
||||
|
||||
std::string query2 =
|
||||
R"(UPDATE Veranstaltung SET used = used+1 WHERE ID =
|
||||
worker.exec_params(query, tag, stunde, cap);
|
||||
worker.commit( );
|
||||
|
||||
std::string query2 =
|
||||
R"(UPDATE Veranstaltung SET used = used+1 WHERE ID =
|
||||
(SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $1 AND uhrzeit_id = $2); )";
|
||||
|
||||
worker.exec_params(query2, tag, stunde);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
worker.exec_params(query2, tag, stunde);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::insertAgain(std::string tag, std::string stunde) {
|
||||
try {
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
try {
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||
std::string query =
|
||||
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||
SELECT Veranstaltung_ID, $1, $2 FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $3 AND uhrzeit_id = $4;)";
|
||||
|
||||
worker.exec_params(query, tag, nextStunde, tag, stunde);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
worker.exec_params(query, tag, nextStunde, tag, stunde);
|
||||
worker.commit( );
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::insertVeranstaltungIntoPlanHandler() {
|
||||
|
||||
int timeDay;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
timeDay = 1;
|
||||
void DBPlan::insertVeranstaltungIntoPlanHandler( ) {
|
||||
|
||||
while (timeDay <= 5) {
|
||||
std::string tagStr = std::to_string(i);
|
||||
std::string stundeStr = std::to_string(timeDay);
|
||||
if (timeDay == 5) {
|
||||
insertVeranstaltungenIntoPlan("2", tagStr, stundeStr);
|
||||
}
|
||||
else {
|
||||
insertVeranstaltungenIntoPlan("4", tagStr, stundeStr);
|
||||
|
||||
if (getDauer(tagStr, stundeStr) == "4") {
|
||||
insertAgain(tagStr, stundeStr);
|
||||
timeDay++;
|
||||
}
|
||||
int timeDay;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
timeDay = 1;
|
||||
|
||||
}
|
||||
timeDay++;
|
||||
}
|
||||
}
|
||||
while (timeDay <= 5) {
|
||||
std::string tagStr = std::to_string(i);
|
||||
std::string stundeStr = std::to_string(timeDay);
|
||||
if (timeDay == 5)
|
||||
insertVeranstaltungenIntoPlan("2", tagStr, stundeStr);
|
||||
else {
|
||||
insertVeranstaltungenIntoPlan("4", tagStr, stundeStr);
|
||||
if (getDauer(tagStr, stundeStr) == "4") {
|
||||
insertAgain(tagStr, stundeStr);
|
||||
timeDay++;
|
||||
}
|
||||
}
|
||||
timeDay++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::createPlan() {
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
insertVeranstaltungIntoPlanHandler();
|
||||
for (int tag = 1; tag < 6; tag++) {
|
||||
std::string tagStr = std::to_string(tag);
|
||||
for (int stunde = 1; stunde < 6; stunde++) {
|
||||
std::string stundeStr = std::to_string(stunde);
|
||||
//get dauer of next class
|
||||
|
||||
if (std::stoi(getDauer(tagStr, stundeStr)) == 2) {
|
||||
if (stunde == 1) {
|
||||
addFirstOfDayTwo(tagStr);
|
||||
}
|
||||
else {
|
||||
addTwoHour(tagStr, stundeStr);
|
||||
}
|
||||
updateStandort(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "2");
|
||||
}
|
||||
else {
|
||||
if (stunde == 1) {
|
||||
addFirstOfDayFour(tagStr);
|
||||
|
||||
}
|
||||
else {
|
||||
addFourHour(tagStr, stundeStr);
|
||||
}
|
||||
upperHour(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "4");
|
||||
updateStandort(tagStr, stundeStr);
|
||||
stunde++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
|
||||
void DBPlan::createPlan( ) {
|
||||
try {
|
||||
insertVeranstaltungIntoPlanHandler( );
|
||||
for (int tag = 1; tag < 6; tag++) {
|
||||
std::string tagStr = std::to_string(tag);
|
||||
for (int stunde = 1; stunde < 6; stunde++) {
|
||||
std::string stundeStr = std::to_string(stunde);
|
||||
//get dauer of next class
|
||||
if (std::stoi(getDauer(tagStr, stundeStr)) == 2) {
|
||||
stunde == 1 ? addFirstOfDayTwo(tagStr) : addTwoHour(tagStr, stundeStr);
|
||||
updateStandort(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "2");
|
||||
} else {
|
||||
stunde == 1 ? addFirstOfDayFour(tagStr) : addFourHour(tagStr, stundeStr);
|
||||
upperHour(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "4");
|
||||
updateStandort(tagStr, stundeStr);
|
||||
stunde++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
std::string DBPlan::checkPlanSize() {
|
||||
try {
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"SELECT count(*) FROM Veranstalter_Veranstaltung_Uhrzeit;";
|
||||
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit();
|
||||
|
||||
return response[0][0].c_str();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
std::string DBPlan::checkPlanSize( ) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"SELECT count(*) FROM Veranstalter_Veranstaltung_Uhrzeit;";
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit( );
|
||||
return response[0][0].c_str( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> DBPlan::getPlan() {
|
||||
try {
|
||||
std::vector<std::string> DBPlan::getPlan( ) {
|
||||
std::vector<std::string> plan;
|
||||
|
||||
if (checkPlanSize() == "0")
|
||||
createPlan();
|
||||
try {
|
||||
if (checkPlanSize( ) == "0")
|
||||
createPlan( );
|
||||
|
||||
std::vector<std::string> plan;
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
||||
std::string query =
|
||||
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
||||
JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID
|
||||
JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID
|
||||
JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID
|
||||
ORDER BY tag, uhrzeit_ID;)";
|
||||
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit();
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit( );
|
||||
|
||||
for (const auto& row : response) {
|
||||
std::string rowstring;
|
||||
for (const auto& col : row) {
|
||||
rowstring.append(col.c_str());
|
||||
rowstring.append(",");
|
||||
}
|
||||
plan.push_back(rowstring);
|
||||
|
||||
}
|
||||
|
||||
return plan;
|
||||
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what());
|
||||
}
|
||||
for (const auto& row : response) {
|
||||
std::string rowstring;
|
||||
for (const auto& col : row) {
|
||||
rowstring.append(col.c_str( ));
|
||||
rowstring.append(",");
|
||||
}
|
||||
plan.push_back(rowstring);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::println(e.what( ));
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
|
||||
void DBPlan::versendeEmails() {
|
||||
//Email an alle Nutzer
|
||||
fmt::print("Der Einsatzplan wurde geupdated");
|
||||
|
||||
void DBPlan::versendeEmails( ) {
|
||||
//Email an alle Nutzer
|
||||
fmt::println("Der Einsatzplan wurde geupdated");
|
||||
}
|
||||
|
||||
@@ -15,15 +15,14 @@ private:
|
||||
void addFirstOfDayFour(std::string tag);
|
||||
void upperHour(std::string tag, std::string stunde);
|
||||
void addFourHour(std::string tag, std::string stunde);
|
||||
void sucheVertretung(std::string tag, std::string stunde);
|
||||
void vertretung(std::string tag, std::string stunde, std::string dauer);
|
||||
void vertretung(std::string tag, std::string stunde);
|
||||
void deleteVeranstalterForeign(std::string id);
|
||||
void updateStandort(std::string tag, std::string stunde);
|
||||
void incarbeitszeit(std::string tag, std::string stunde, std::string amount);
|
||||
void insertVeranstaltungenIntoPlan(std::string cap, std::string tag, std::string stunde);
|
||||
void insertVeranstaltungIntoPlanHandler();
|
||||
void insertVeranstaltungIntoPlanHandler( );
|
||||
void insertAgain(std::string tag, std::string stunde);
|
||||
std::string checkPlanSize();
|
||||
std::string checkPlanSize( );
|
||||
void versendeEmails( );
|
||||
|
||||
public:
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
inline static const std::map<std::string, std::string>& load_config(const std::string& filename) {
|
||||
inline static const std::map<std::string, std::string>& load_config( ) {
|
||||
static std::map<std::string, std::string> config;
|
||||
static bool is_loaded{ false };
|
||||
static std::string fn{ "" };
|
||||
|
||||
std::string filename = std::string(std::getenv("HOME")) + "/Dokumente/git/EinsatzplanQT/config.cfg";
|
||||
|
||||
if (!is_loaded || fn != filename) {
|
||||
std::ifstream file(filename);
|
||||
std::string line;
|
||||
@@ -19,9 +21,8 @@ inline static const std::map<std::string, std::string>& load_config(const std::s
|
||||
std::string key;
|
||||
if (std::getline(line_stream, key, '=')) {
|
||||
std::string value;
|
||||
if (std::getline(line_stream, value)) {
|
||||
if (std::getline(line_stream, value))
|
||||
config[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ CreateMemDialog::CreateMemDialog(QWidget* parent)
|
||||
color: #212121;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
background-color: #53EC87;
|
||||
background-color: #A5D6A7;
|
||||
border-radius: 10px;
|
||||
}
|
||||
)");
|
||||
@@ -106,7 +106,7 @@ CreateMemDialog::CreateMemDialog(QWidget* parent)
|
||||
color: #212121;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
background-color: #FF5555;
|
||||
background-color: #EF9A9A;
|
||||
border-radius: 10px;
|
||||
}
|
||||
)");
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "Krankmelden.hpp"
|
||||
|
||||
Krankmelden::Krankmelden(const QString& mitarbeiterName, QWidget* parent) :
|
||||
QDialog(parent),
|
||||
m_text(new QLabel(QString::fromStdString(mitarbeiterName.toStdString( ) + " krankmelden?"))) {
|
||||
setWindowTitle("Mitarbeiter Krankmelden?");
|
||||
setFixedSize(350, 150);
|
||||
setObjectName("Krankmelden");
|
||||
setStyleSheet(R"(
|
||||
#Krankmelden{
|
||||
background-color: #212121;
|
||||
border: none;
|
||||
}
|
||||
)");
|
||||
|
||||
m_accept = new QPushButton("Ja", this);
|
||||
m_accept->setFixedSize(110, 40);
|
||||
m_accept->setObjectName("acceptButton");
|
||||
m_accept->setStyleSheet(R"(
|
||||
#acceptButton{
|
||||
color: #212121;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
background-color: #A5D6A7;
|
||||
border-radius: 10px;
|
||||
}
|
||||
)");
|
||||
m_decline = new QPushButton("Nein", this);
|
||||
m_decline->setFixedSize(110, 40);
|
||||
m_decline->setObjectName("declineButton");
|
||||
m_decline->setStyleSheet(R"(
|
||||
#declineButton{
|
||||
color: #212121;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
background-color: #EF9A9A;
|
||||
border-radius: 10px;
|
||||
}
|
||||
)");
|
||||
|
||||
m_text->setObjectName("mitarbeiterName");
|
||||
m_text->setStyleSheet(R"(
|
||||
#mitarbeiterName{
|
||||
background-color: none;
|
||||
border:none;
|
||||
color: #D8D8D8;
|
||||
font-size:18px;
|
||||
}
|
||||
)");
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->addWidget(m_text, 0, Qt::AlignCenter);
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout( );
|
||||
mainLayout->addLayout(layout, 1);
|
||||
|
||||
layout->addWidget(m_accept, 1, Qt::AlignCenter);
|
||||
layout->addWidget(m_decline, 1, Qt::AlignCenter);
|
||||
|
||||
connect(m_accept, &QPushButton::clicked, this, &QDialog::accept);
|
||||
connect(m_decline, &QPushButton::clicked, this, &QDialog::reject);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
|
||||
class Krankmelden : public QDialog {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
QPushButton* m_accept;
|
||||
QPushButton* m_decline;
|
||||
QLabel* m_text;
|
||||
public:
|
||||
Krankmelden(const QString& mitarbeiterName, QWidget* parent = nullptr);
|
||||
};
|
||||
@@ -11,17 +11,10 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
}
|
||||
)");
|
||||
|
||||
m_controller = new EinsatzplanFrameController(id, admin);
|
||||
|
||||
m_profileImg = new QLabel(this);
|
||||
m_profileImg->setFixedSize(60, 60);
|
||||
m_profileImg->setPixmap(QPixmap(":account-box.png"));
|
||||
m_profileImg->setObjectName("profileImg");
|
||||
m_profileImg->setStyleSheet(R"(
|
||||
#profileImg{
|
||||
|
||||
}
|
||||
)");
|
||||
m_profileImg->show( );
|
||||
|
||||
m_id = new QLabel(id, this);
|
||||
@@ -39,6 +32,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_abmeldenButton = new QPushButton("Abmelden", this);
|
||||
m_abmeldenButton->setFixedSize(150, 50);
|
||||
m_abmeldenButton->setObjectName("abmeldenButton");
|
||||
m_abmeldenButton->setCursor(Qt::PointingHandCursor);
|
||||
m_abmeldenButton->setStyleSheet(R"(
|
||||
#abmeldenButton{
|
||||
font-size: 24px;
|
||||
@@ -72,6 +66,8 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_planGrid = new PlanGrid(this);
|
||||
m_planGrid->show( );
|
||||
|
||||
m_controller = new EinsatzplanFrameController(id, admin);
|
||||
|
||||
QVBoxLayout* totalLayout = new QVBoxLayout(this);
|
||||
totalLayout->setContentsMargins(30, 20, 30, 20);
|
||||
|
||||
@@ -94,6 +90,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_createMemberButton = new QPushButton("Mitarbeiter\nHinzufügen", this);
|
||||
m_createMemberButton->setFixedSize(200, 50);
|
||||
m_createMemberButton->setObjectName("createMember");
|
||||
m_createMemberButton->setCursor(Qt::PointingHandCursor);
|
||||
m_createMemberButton->setStyleSheet(R"(
|
||||
#createMember{
|
||||
font-size: 16px;
|
||||
@@ -114,6 +111,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_deleteMemberButton = new QPushButton("Mitarbeiter\nEntfernen", this);
|
||||
m_deleteMemberButton->setFixedSize(200, 50);
|
||||
m_deleteMemberButton->setObjectName("deleteMember");
|
||||
m_deleteMemberButton->setCursor(Qt::PointingHandCursor);
|
||||
m_deleteMemberButton->setStyleSheet(R"(
|
||||
#deleteMember{
|
||||
font-size: 16px;
|
||||
@@ -134,6 +132,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_createVeranstaltungButton = new QPushButton("Veranstaltung\nHinzufügen", this);
|
||||
m_createVeranstaltungButton->setFixedSize(200, 50);
|
||||
m_createVeranstaltungButton->setObjectName("createVeranstaltung");
|
||||
m_createVeranstaltungButton->setCursor(Qt::PointingHandCursor);
|
||||
m_createVeranstaltungButton->setStyleSheet(R"(
|
||||
#createVeranstaltung{
|
||||
font-size: 16px;
|
||||
@@ -154,6 +153,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
m_deleteVeranstaltungButton = new QPushButton("Veranstaltung\nEntfernen", this);
|
||||
m_deleteVeranstaltungButton->setFixedSize(200, 50);
|
||||
m_deleteVeranstaltungButton->setObjectName("deleteVeranstaltung");
|
||||
m_deleteVeranstaltungButton->setCursor(Qt::PointingHandCursor);
|
||||
m_deleteVeranstaltungButton->setStyleSheet(R"(
|
||||
#deleteVeranstaltung{
|
||||
font-size: 16px;
|
||||
@@ -182,7 +182,11 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
||||
}
|
||||
|
||||
void EinsatzplanFrame::abmelden( ) {
|
||||
static_cast<QApplication*>(parent( )->parent( ))->exit( );
|
||||
QString program = QApplication::applicationFilePath( );
|
||||
|
||||
QProcess::startDetached(program);
|
||||
|
||||
QApplication::quit( );
|
||||
}
|
||||
|
||||
void EinsatzplanFrame::deleteVeranstaltung( ) {
|
||||
@@ -193,6 +197,9 @@ void EinsatzplanFrame::deleteVeranstaltung( ) {
|
||||
if (ok && text.size( ) == 3) {
|
||||
m_controller->deleteVeranstaltung(text);
|
||||
QMessageBox::information(this, "Veranstaltung entfernen", "Veranstaltung wird entfernt!");
|
||||
|
||||
m_planGrid->setPlanMap(m_planGrid->planGridController->getVeranstaltungen( ));
|
||||
m_planGrid->populateGrid( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QInputDialog>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QProcess>
|
||||
|
||||
#include "../PlanGrid/PlanGrid.hpp"
|
||||
#include "../../Controller/EinsatzplanFrameController/EinsatzplanFrameController.hpp"
|
||||
@@ -38,7 +39,6 @@ public:
|
||||
EinsatzplanFrame(QWidget* parent = nullptr, QString id = "0000000", bool admin = true);
|
||||
|
||||
private slots:
|
||||
|
||||
void abmelden( );
|
||||
void deleteVeranstaltung( );
|
||||
void createVeranstaltung( );
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# include "LoginFrame.hpp"
|
||||
#include "LoginFrame.hpp"
|
||||
|
||||
LoginFrame::LoginFrame(QWidget* parent)
|
||||
:QFrame(parent) {
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
#include "../../View/EinsatzplanWindow/EinsatzplanWindow.hpp"
|
||||
|
||||
class LoginFrame : public QFrame {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
protected:
|
||||
QMainWindow* m_parent;
|
||||
QLabel* m_header;
|
||||
QLineEdit* m_id;
|
||||
QLineEdit* m_password;
|
||||
QPushButton* m_loginButton;
|
||||
QMainWindow* m_parent;
|
||||
QLabel* m_header;
|
||||
QLineEdit* m_id;
|
||||
QLineEdit* m_password;
|
||||
QPushButton* m_loginButton;
|
||||
|
||||
void loginButtonClicked( );
|
||||
void loginButtonClicked( );
|
||||
|
||||
public:
|
||||
LoginFrame(QWidget* parent = nullptr);
|
||||
~LoginFrame( );
|
||||
LoginFrame(QWidget* parent = nullptr);
|
||||
~LoginFrame( );
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "LoginWindow.hpp"
|
||||
|
||||
LoginWindow::LoginWindow(QWidget* parent)
|
||||
:QMainWindow(parent) {
|
||||
m_frame = new LoginFrame(this);
|
||||
setFixedSize(400, 550);
|
||||
m_frame->setFixedSize(size( ));
|
||||
:QMainWindow(parent) {
|
||||
m_frame = new LoginFrame(this);
|
||||
setFixedSize(400, 550);
|
||||
m_frame->setFixedSize(size( ));
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "../LoginFrame/LoginFrame.hpp"
|
||||
|
||||
class LoginWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
LoginFrame* m_frame;
|
||||
LoginFrame* m_frame;
|
||||
|
||||
public:
|
||||
LoginWindow(QWidget* parent = nullptr);
|
||||
LoginWindow(QWidget* parent = nullptr);
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@ PlanGrid::PlanGrid(QWidget* parent)
|
||||
m_times[2] = "12:00";
|
||||
m_times[3] = "14:00";
|
||||
m_times[4] = "16:00";
|
||||
m_times[5] = "18:00";
|
||||
|
||||
planMap = new QMap<QPair<QString, QString>, QWidget*>( );
|
||||
|
||||
@@ -67,7 +68,7 @@ PlanGrid::PlanGrid(QWidget* parent)
|
||||
|
||||
// Add times left to plan
|
||||
for (int i = 0; i < 5; i++) {
|
||||
QLabel* temp = new QLabel(m_times[i]);
|
||||
QLabel* temp = new QLabel(QString::fromStdString(m_times[i].toStdString( ) + " - " + m_times[i + 1].toStdString( )));
|
||||
temp->setFixedSize(130, 100);
|
||||
temp->setObjectName("temp");
|
||||
if (i == 4) {
|
||||
@@ -102,7 +103,25 @@ PlanGrid::PlanGrid(QWidget* parent)
|
||||
void PlanGrid::populateGrid( ) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
gridLayout->addWidget(planMap->value(qMakePair(m_weekdays[i], m_times[j])), j + 1, i + 1);
|
||||
auto widget = planMap->value(qMakePair(m_weekdays[i], m_times[j]));
|
||||
gridLayout->addWidget(widget, j + 1, i + 1);
|
||||
auto pb = widget->findChild<QPushButton*>("eintragung");
|
||||
if (pb != nullptr) {
|
||||
connect(pb, &QPushButton::clicked, this, [this, pb, i, j]( ) {
|
||||
auto name = pb->property("MitarbeiterName").toString( );
|
||||
Krankmelden dialog(name, this);
|
||||
if (dialog.exec( ) == QDialog::Accepted) {
|
||||
auto id = pb->property("MitarbeiterID").toInt( );
|
||||
planGridController->Krankmelden(
|
||||
id,
|
||||
i + 1,
|
||||
j + 1
|
||||
);
|
||||
}
|
||||
planMap = planGridController->getVeranstaltungen( );
|
||||
populateGrid( );
|
||||
});
|
||||
}
|
||||
if (i == 4 && j == 4) {
|
||||
(planMap->value(qMakePair(m_weekdays[i], m_times[j])))->setStyleSheet(R"(
|
||||
border-bottom-right-radius:10px;
|
||||
|
||||
@@ -6,21 +6,30 @@
|
||||
#include <QDateTime>
|
||||
|
||||
#include "../../Controller/PlanGridController/PlanGridController.hpp"
|
||||
#include "../Widgets/GridItem.hpp"
|
||||
#include "../EinsatzplanFrame/Dialogs/Krankmelden/Krankmelden.hpp"
|
||||
#include "../EinsatzplanFrame/Dialogs/CreateMember/CreateMember.hpp"
|
||||
|
||||
class PlanGrid : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString m_weekdays[5];
|
||||
QString m_times[5];
|
||||
QString m_times[6];
|
||||
|
||||
void populateGrid( );
|
||||
|
||||
protected:
|
||||
QGridLayout* gridLayout;
|
||||
QMap<QPair<QString, QString>, QWidget*>* planMap;
|
||||
PlanGridController* planGridController;
|
||||
|
||||
void KrankmeldenDialog( );
|
||||
|
||||
public:
|
||||
PlanGrid(QWidget* parent = nullptr);
|
||||
|
||||
PlanGridController* planGridController;
|
||||
|
||||
void populateGrid( );
|
||||
|
||||
inline void setPlanMap(QMap<QPair<QString, QString>, QWidget*>* planMap) {
|
||||
this->planMap = planMap;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# include "GridItem.hpp"
|
||||
|
||||
GridItem::GridItem(QString text, QWidget* parent)
|
||||
:QLabel(parent) {
|
||||
//Fix later
|
||||
//text_m = new QLabel(text,this);
|
||||
//text_m->setAlignment(Qt::AlignCenter);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
void GridItem::mousePressEvent(QMouseEvent* event) {
|
||||
if (event->button( ) == Qt::RightButton)
|
||||
emit clicked( );
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void GridItem::paintEvent(QPaintEvent* event) {
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
# pragma once
|
||||
# include <QLabel>
|
||||
# include <QMouseEvent>
|
||||
# include <QPainter>
|
||||
|
||||
class GridItem : public QLabel {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
//QLabel* text_m;
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
public:
|
||||
GridItem(QString text = "", QWidget* parent = nullptr);
|
||||
signals:
|
||||
void clicked( );
|
||||
};
|
||||
Reference in New Issue
Block a user