Compare commits
28 Commits
loginwindo
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b30500eaa6 | ||
|
|
a73b37e9c5 | ||
|
|
1b168dbc2e | ||
|
|
38dfc2d75c | ||
|
|
d448705f1c | ||
|
|
8a8901c30a | ||
|
|
dc67766671 | ||
|
|
80bae45a15 | ||
|
|
4a475458d0 | ||
|
|
68b18e12e0 | ||
|
|
b8512190b7 | ||
|
|
c42edb9b6c | ||
|
|
701a8c3a98 | ||
|
|
5bce421326 | ||
|
|
ba4ab0a580 | ||
|
|
2df47779c3 | ||
|
|
5bf75861fd | ||
|
|
66cd03b957 | ||
|
|
babbf65e07 | ||
|
|
35cd5f7d57 | ||
|
|
06f04f9afa | ||
|
|
a3aa086929 | ||
|
|
99c56e5ffc | ||
|
|
4735d9a918 | ||
|
|
66edcbcc3e | ||
|
|
261031c443 | ||
|
|
0321effc40 | ||
|
|
5c907eea99 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -55,4 +55,5 @@ compile_commands.json
|
|||||||
|
|
||||||
build
|
build
|
||||||
debug
|
debug
|
||||||
config.cfg
|
config.cfg
|
||||||
|
*config.hpp
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
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 NAMES Qt6 REQUIRED COMPONENTS Widgets Svg Core Sql)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} 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
|
pqxx
|
||||||
stdc++fs
|
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)
|
||||||
|
|||||||
444
script.sql
444
script.sql
@@ -1,25 +1,5 @@
|
|||||||
|
|
||||||
DROP VIEW studenten_veranstalter;
|
CREATE SEQUENCE global_id_seq START WITH 1000000 INCREMENT BY 1;
|
||||||
DROP TABLE Veranstalter_Veranstaltung_Uhrzeit;
|
|
||||||
DROP TABLE Studenten;
|
|
||||||
DROP TABLE Veranstalter;
|
|
||||||
DROP TABLE Uhrzeit;
|
|
||||||
DROP TABLE veranstaltung;
|
|
||||||
DROP SEQUENCE global_id_seq;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE SEQUENCE global_id_seq;
|
|
||||||
|
|
||||||
CREATE TABLE Studenten (
|
|
||||||
matrikelnummer INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
|
||||||
name VARCHAR(30) NOT NULL,
|
|
||||||
email VARCHAR(30) NOT NULL,
|
|
||||||
passwort VARCHAR(30) NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION random_between_two()
|
CREATE OR REPLACE FUNCTION random_between_two()
|
||||||
RETURNS VARCHAR AS $$
|
RETURNS VARCHAR AS $$
|
||||||
@@ -32,120 +12,324 @@ BEGIN
|
|||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION random_between_days()
|
||||||
|
RETURNS INTEGER AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN floor(random() * 5 + 1)::INTEGER;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE TABLE Veranstalter (
|
CREATE TABLE IF NOT EXISTS Uhrzeit (
|
||||||
ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
ID SERIAL PRIMARY KEY,
|
||||||
name VARCHAR(30),
|
anfangszeit TIME NOT NULL,
|
||||||
email VARCHAR(30),
|
endzeit TIME NOT NULL
|
||||||
passwort VARCHAR(30),
|
|
||||||
arbeitszeit INTEGER DEFAULT 0,
|
|
||||||
standort VARCHAR(30) DEFAULT random_between_two(),
|
|
||||||
krank BOOLEAN DEFAULT FALSE,
|
|
||||||
admin BOOLEAN NOT NULL DEFAULT FALSE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS Veranstaltung(
|
||||||
|
name VARCHAR(3) PRIMARY KEY,
|
||||||
|
ort VARCHAR(1) DEFAULT random_between_two(),
|
||||||
|
raum INTEGER NOT NULL,
|
||||||
|
dauer INTEGER NOT NULL,
|
||||||
|
used_in_plan INTEGER DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS Veranstalter(
|
||||||
|
ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
||||||
|
name VARCHAR(30),
|
||||||
|
email VARCHAR(30),
|
||||||
|
passwort VARCHAR(30),
|
||||||
|
arbeitszeit INTEGER DEFAULT 0,
|
||||||
|
admin BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS StundeImPlan (
|
||||||
|
uhrzeit INTEGER REFERENCES Uhrzeit(ID),
|
||||||
|
tag INTEGER NOT NULL,
|
||||||
|
veranstaltung VARCHAR(3) REFERENCES Veranstaltung(name) ON DELETE CASCADE,
|
||||||
|
veranstalter INTEGER REFERENCES Veranstalter(ID) ON DELETE SET NULL,
|
||||||
|
PRIMARY KEY(uhrzeit, tag)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS Krank(
|
||||||
|
ID SERIAL PRIMARY KEY,
|
||||||
|
stundeImPlan_uhrzeit INTEGER,
|
||||||
|
stundeImPlan_tag INTEGER,
|
||||||
|
veranstalter INTEGER REFERENCES Veranstalter(ID) ON DELETE SET NULL,
|
||||||
|
krank BOOLEAN DEFAULT FALSE,
|
||||||
|
FOREIGN KEY (stundeImPlan_uhrzeit, stundeImPlan_tag) REFERENCES StundeImPlan(uhrzeit, tag) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION delete_stundeimplan_for_veranstaltung()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM StundeImPlan WHERE veranstaltung = OLD.name;
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER trg_delete_stundeimplan_for_veranstaltung
|
||||||
|
AFTER DELETE ON Veranstaltung
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION delete_stundeimplan_for_veranstaltung();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION update_stundeimplan_for_veranstalter()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
new_veranstalter_id INTEGER;
|
||||||
|
BEGIN
|
||||||
|
SELECT ID INTO new_veranstalter_id
|
||||||
|
FROM Veranstalter
|
||||||
|
WHERE arbeitszeit < 18
|
||||||
|
ORDER BY arbeitszeit ASC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF new_veranstalter_id IS NOT NULL THEN
|
||||||
|
UPDATE StundeImPlan
|
||||||
|
SET veranstalter = new_veranstalter_id
|
||||||
|
WHERE veranstalter = OLD.ID;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER trg_update_stundeimplan_for_veranstalter
|
||||||
|
AFTER DELETE ON Veranstalter
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_stundeimplan_for_veranstalter();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION update_arbeitszeit_for_veranstalter()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
UPDATE Veranstalter
|
||||||
|
SET arbeitszeit = arbeitszeit + (SELECT dauer FROM Veranstaltung WHERE name = NEW.veranstaltung)
|
||||||
|
WHERE ID = NEW.veranstalter;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER trg_update_arbeitszeit_for_veranstalter
|
||||||
|
AFTER INSERT ON StundeImPlan
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_arbeitszeit_for_veranstalter();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION generate_plan()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
v_row RECORD;
|
||||||
|
u_row RECORD;
|
||||||
|
available_veranstalter RECORD;
|
||||||
|
random_day INTEGER;
|
||||||
|
BEGIN
|
||||||
|
FOR u_row IN SELECT * FROM Uhrzeit LOOP
|
||||||
|
FOR v_row IN SELECT * FROM Veranstaltung WHERE used_in_plan = 0 LOOP
|
||||||
|
SELECT * INTO available_veranstalter
|
||||||
|
FROM Veranstalter v
|
||||||
|
WHERE v.arbeitszeit + v_row.dauer <= 18
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM StundeImPlan sp
|
||||||
|
JOIN Veranstaltung va ON sp.veranstaltung = va.name
|
||||||
|
WHERE sp.uhrzeit = u_row.ID
|
||||||
|
AND sp.tag = random_day
|
||||||
|
AND sp.veranstalter = v.ID
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM StundeImPlan prev_sp
|
||||||
|
JOIN Veranstaltung prev_va ON prev_sp.veranstaltung = prev_va.name
|
||||||
|
WHERE prev_sp.uhrzeit = u_row.ID - 1
|
||||||
|
AND prev_sp.tag = random_day
|
||||||
|
AND prev_sp.veranstalter = v.ID
|
||||||
|
AND prev_va.ort <> v_row.ort
|
||||||
|
)
|
||||||
|
ORDER BY v.arbeitszeit ASC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF FOUND THEN
|
||||||
|
random_day = random_between_days();
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM StundeImPlan
|
||||||
|
WHERE uhrzeit = u_row.ID AND tag = random_day
|
||||||
|
) THEN
|
||||||
|
INSERT INTO StundeImPlan (uhrzeit, tag, veranstaltung, veranstalter)
|
||||||
|
VALUES (u_row.ID, random_day, v_row.name, available_veranstalter.ID);
|
||||||
|
|
||||||
|
UPDATE Veranstaltung SET used_in_plan = used_in_plan + 1 WHERE name = v_row.name;
|
||||||
|
UPDATE Veranstalter SET arbeitszeit = arbeitszeit + v_row.dauer WHERE ID = available_veranstalter.ID;
|
||||||
|
|
||||||
|
IF v_row.dauer = 4 THEN
|
||||||
|
IF EXISTS (SELECT 1 FROM Uhrzeit WHERE ID = u_row.ID + 1) THEN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM StundeImPlan
|
||||||
|
WHERE uhrzeit = u_row.ID + 1 AND tag = random_day
|
||||||
|
) THEN
|
||||||
|
INSERT INTO StundeImPlan (uhrzeit, tag, veranstaltung, veranstalter)
|
||||||
|
VALUES (u_row.ID + 1, random_day, v_row.name, available_veranstalter.ID);
|
||||||
|
|
||||||
|
UPDATE Veranstaltung SET used_in_plan = used_in_plan + 1 WHERE name = v_row.name;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END LOOP;
|
||||||
|
END LOOP;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
CREATE TRIGGER trg_generate_plan
|
||||||
|
AFTER INSERT ON Veranstaltung
|
||||||
|
FOR EACH STATEMENT
|
||||||
|
EXECUTE FUNCTION generate_plan();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION handle_krank_insert()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
new_veranstalter_id INTEGER;
|
||||||
|
v_name VARCHAR(3);
|
||||||
|
BEGIN
|
||||||
|
SELECT veranstaltung.name INTO v_name
|
||||||
|
FROM Veranstaltung
|
||||||
|
WHERE name = (SELECT veranstaltung FROM StundeImPlan WHERE uhrzeit = NEW.stundeImPlan_uhrzeit AND tag = NEW.stundeImPlan_tag);
|
||||||
|
|
||||||
|
WITH PreviousHour AS (
|
||||||
|
SELECT sp.veranstalter, v.ort
|
||||||
|
FROM StundeImPlan sp
|
||||||
|
JOIN Veranstaltung v ON sp.veranstaltung = v.name
|
||||||
|
WHERE sp.uhrzeit = NEW.stundeImPlan_uhrzeit - 1
|
||||||
|
AND sp.tag = NEW.stundeImPlan_tag
|
||||||
|
)
|
||||||
|
SELECT v.ID INTO new_veranstalter_id
|
||||||
|
FROM Veranstalter v
|
||||||
|
JOIN StundeImPlan sp ON v.ID = sp.veranstalter
|
||||||
|
JOIN Veranstaltung va ON sp.veranstaltung = va.name
|
||||||
|
LEFT JOIN PreviousHour ph ON v.ID = ph.veranstalter
|
||||||
|
WHERE v.arbeitszeit + (SELECT dauer FROM Veranstaltung WHERE name = v_name) <= 18
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM Krank k
|
||||||
|
WHERE k.veranstalter = v.ID
|
||||||
|
AND k.stundeImPlan_uhrzeit = NEW.stundeImPlan_uhrzeit
|
||||||
|
AND k.stundeImPlan_tag = NEW.stundeImPlan_tag
|
||||||
|
)
|
||||||
|
AND (ph.veranstalter IS NULL OR ph.veranstalter <> (
|
||||||
|
SELECT v.ID
|
||||||
|
FROM Veranstalter v
|
||||||
|
JOIN StundeImPlan sp ON v.ID = sp.veranstalter
|
||||||
|
JOIN Veranstaltung vaa ON sp.veranstaltung = vaa.name
|
||||||
|
WHERE sp.uhrzeit = NEW.stundeImPlan_uhrzeit
|
||||||
|
AND sp.tag = NEW.stundeImPlan_tag
|
||||||
|
AND vaa.ort = va.ort
|
||||||
|
))
|
||||||
|
ORDER BY v.arbeitszeit ASC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF new_veranstalter_id IS NOT NULL THEN
|
||||||
|
UPDATE Veranstalter
|
||||||
|
SET arbeitszeit = arbeitszeit + (SELECT dauer FROM Veranstaltung WHERE name = v_name)
|
||||||
|
WHERE ID = new_veranstalter_id;
|
||||||
|
|
||||||
|
UPDATE StundeImPlan
|
||||||
|
SET veranstalter = new_veranstalter_id
|
||||||
|
WHERE uhrzeit = NEW.stundeImPlan_uhrzeit AND tag = NEW.stundeImPlan_tag;
|
||||||
|
ELSE
|
||||||
|
UPDATE StundeImPlan
|
||||||
|
SET veranstalter = NULL
|
||||||
|
WHERE uhrzeit = NEW.stundeImPlan_uhrzeit AND tag = NEW.stundeImPlan_tag;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER trg_handle_krank_insert
|
||||||
|
AFTER INSERT ON Krank
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION handle_krank_insert();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION handle_veranstalter_deletion() RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
new_veranstalter RECORD;
|
||||||
|
affected_row RECORD;
|
||||||
|
BEGIN
|
||||||
|
FOR affected_row IN
|
||||||
|
SELECT * FROM StundeImPlan WHERE veranstalter = OLD.id
|
||||||
|
LOOP
|
||||||
|
SELECT * INTO new_veranstalter
|
||||||
|
FROM Veranstalter v
|
||||||
|
WHERE v.arbeitszeit + (SELECT dauer FROM Veranstaltung va WHERE va.name = affected_row.veranstaltung) <= 18
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM Krank k
|
||||||
|
WHERE k.veranstalter = v.ID
|
||||||
|
AND k.stundeImPlan_uhrzeit = affected_row.uhrzeit
|
||||||
|
AND k.stundeImPlan_tag = affected_row.tag
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM StundeImPlan sp
|
||||||
|
JOIN Veranstaltung va ON sp.veranstaltung = va.name
|
||||||
|
WHERE sp.uhrzeit = affected_row.uhrzeit - 1
|
||||||
|
AND sp.tag = affected_row.tag
|
||||||
|
AND sp.veranstalter = v.ID
|
||||||
|
AND va.ort <> (SELECT ort FROM Veranstaltung WHERE name = affected_row.veranstaltung)
|
||||||
|
)
|
||||||
|
AND v.ID <> affected_row.veranstalter
|
||||||
|
ORDER BY v.arbeitszeit ASC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
UPDATE StundeImPlan
|
||||||
|
SET veranstalter = new_veranstalter.ID
|
||||||
|
WHERE uhrzeit = affected_row.uhrzeit AND tag = affected_row.tag AND veranstalter = OLD.id;
|
||||||
|
|
||||||
|
UPDATE Veranstalter
|
||||||
|
SET arbeitszeit = arbeitszeit + (SELECT dauer FROM Veranstaltung WHERE name = affected_row.veranstaltung)
|
||||||
|
WHERE ID = new_veranstalter.ID;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TRIGGER before_veranstalter_delete
|
||||||
|
BEFORE DELETE ON Veranstalter
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION handle_veranstalter_deletion();
|
||||||
|
|
||||||
|
INSERT INTO Uhrzeit (anfangszeit, endzeit) VALUES
|
||||||
CREATE VIEW studenten_veranstalter AS
|
('08:00:00', '10:00:00'),
|
||||||
SELECT matrikelnummer AS id, passwort, NULL AS admin FROM Studenten
|
('10:00:00', '12:00:00'),
|
||||||
UNION ALL
|
('12:00:00', '14:00:00'),
|
||||||
SELECT ID, passwort, admin FROM Veranstalter;
|
('14:00:00', '16:00:00'),
|
||||||
|
('16:00:00', '18:00:00');
|
||||||
|
|
||||||
|
INSERT INTO Veranstalter (name, email, passwort, admin) VALUES
|
||||||
|
('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
|
||||||
CREATE TABLE Veranstaltung (
|
('A', '101', 'GDI', 2),
|
||||||
ID SERIAL PRIMARY KEY,
|
('B', '202', 'ALD', 4),
|
||||||
ort VARCHAR(30) NOT NULL,
|
('A', '103', 'ITS', 2),
|
||||||
raum INTEGER NOT NULL,
|
('B', '204', 'BSY', 4),
|
||||||
name VARCHAR(90) NOT NULL,
|
('A', '105', 'PE1', 2),
|
||||||
dauer INTEGER NOT NULL
|
('B', '206', 'THI', 4),
|
||||||
);
|
('A', '107', 'DBS', 2),
|
||||||
|
('B', '208', 'WEB', 2),
|
||||||
|
('A', '109', 'BVA', 2),
|
||||||
|
('B', '210', 'MA1', 2);
|
||||||
|
|
||||||
CREATE TABLE Uhrzeit (
|
|
||||||
ID SERIAL PRIMARY KEY,
|
|
||||||
anfangszeit TIME NOT NULL,
|
|
||||||
endzeit TIME NOT NULL );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO Uhrzeit (anfangszeit, endzeit) VALUES
|
|
||||||
('08:00:00', '10:00:00'),
|
|
||||||
('10:00:00', '12:00:00'),
|
|
||||||
('12:00:00', '14:00:00'),
|
|
||||||
('14:00:00', '16:00:00'),
|
|
||||||
('16:00:00', '18:00:00');
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE Veranstalter_Veranstaltung_Uhrzeit (
|
|
||||||
uhrzeit_ID INTEGER REFERENCES Uhrzeit(ID),
|
|
||||||
tag INTEGER NOT NULL,
|
|
||||||
veranstalter_ID INTEGER REFERENCES Veranstalter(ID),
|
|
||||||
veranstaltung_ID INTEGER REFERENCES Veranstaltung(ID),
|
|
||||||
PRIMARY KEY(uhrzeit_ID, tag)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES
|
|
||||||
('A', '101', 'Grundlagen der Programmierung', 2),
|
|
||||||
('B', '202', 'Algorithmen und Datenstrukturen', 4),
|
|
||||||
('A', '103', 'Netzwerkgrundlagen', 2),
|
|
||||||
('B', '204', 'Betriebssystemkonzepte', 4),
|
|
||||||
('A', '105', 'Softwareentwicklung', 2),
|
|
||||||
('B', '206', 'Intelligente Systeme', 4),
|
|
||||||
('A', '107', 'Datenbanksysteme', 2),
|
|
||||||
('B', '208', 'Webtechnologien', 2),
|
|
||||||
('A', '109', 'Computergrafikgrundlagen', 2),
|
|
||||||
('B', '210', 'Maschinelles Lernen', 2);
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (uhrzeit_ID, tag, veranstaltung_ID) VALUES
|
|
||||||
(1, 1, 1),
|
|
||||||
(2, 1, 7),
|
|
||||||
(3, 1, 8),
|
|
||||||
(4, 1, 3),
|
|
||||||
(5, 1, 10),
|
|
||||||
|
|
||||||
(1, 2, 4),
|
|
||||||
(2, 2, 4),
|
|
||||||
(3, 2, 5),
|
|
||||||
(4, 2, 6),
|
|
||||||
(5, 2, 6),
|
|
||||||
|
|
||||||
(1, 3, 7),
|
|
||||||
(2, 3, 8),
|
|
||||||
(3, 3, 9),
|
|
||||||
(4, 3, 10),
|
|
||||||
(5, 3, 1),
|
|
||||||
|
|
||||||
(1, 4, 2),
|
|
||||||
(2, 4, 2),
|
|
||||||
(3, 4, 3),
|
|
||||||
(4, 4, 4),
|
|
||||||
(5, 4, 4),
|
|
||||||
|
|
||||||
(1, 5, 5),
|
|
||||||
(2, 5, 6),
|
|
||||||
(3, 5, 6),
|
|
||||||
(4, 5, 7),
|
|
||||||
(5, 5, 8);
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,34 +3,30 @@
|
|||||||
EinsatzplanFrameController::EinsatzplanFrameController(QString id, bool admin)
|
EinsatzplanFrameController::EinsatzplanFrameController(QString id, bool admin)
|
||||||
:m_id(id),
|
:m_id(id),
|
||||||
m_admin(admin) {
|
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(
|
m_dbHandler = std::make_unique<DBHandler>(fmt::format(
|
||||||
"host={} port={} dbname={} user={} password={}",
|
"host={} port={} dbname={} user={} password={}",
|
||||||
config.at("DB_HOST"),
|
config.at("DB_HOST"),
|
||||||
config.at("DB_PORT"),
|
config.at("DB_PORT"),
|
||||||
config.at("DB_NAME"),
|
config.at("DB_NAME"),
|
||||||
config.at("DB_USER"),
|
config.at("DB_USER"),
|
||||||
config.at("DB_PASSWORD")
|
config.at("DB_PASSWORD")
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrameController::deleteMember(QString id) {
|
void EinsatzplanFrameController::deleteMember(QString id) {
|
||||||
DBPlan* db = new DBPlan(m_connectionString);
|
m_dbHandler->deleteVeranstalter(id.toStdString( ));
|
||||||
db->deleteVeranstalter(id.toStdString( ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrameController::deleteVeranstaltung(QString veranstaltungsname) {
|
void EinsatzplanFrameController::deleteVeranstaltung(QString veranstaltungsname) {
|
||||||
DBPlan* db = new DBPlan(m_connectionString);
|
m_dbHandler->deleteVeranstaltung(veranstaltungsname.toStdString( ));
|
||||||
db->deleteVeranstaltung(veranstaltungsname.toStdString( ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrameController::createMember(QString name, QString email, QString passwort, bool admin) {
|
void EinsatzplanFrameController::createMember(QString name, QString email, QString passwort, bool admin) {
|
||||||
DBPlan* db = new DBPlan(m_connectionString);
|
m_dbHandler->createVeranstalter(name.toStdString( ), email.toStdString( ), passwort.toStdString( ), admin);
|
||||||
db->hinzufuegenVeranstalter(email.toStdString( ), name.toStdString( ), passwort.toStdString( ), admin ? "TRUE" : "FALSE");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrameController::createVeranstaltung(QString name, QString raum, QString campus, QString time) {
|
void EinsatzplanFrameController::createVeranstaltung(QString name, QString raum, QString campus, QString time) {
|
||||||
DBPlan* db = new DBPlan(m_connectionString);
|
m_dbHandler->createVeranstaltung(name.toStdString( ), campus.toStdString( ), raum.toStdString( ), std::to_string((char)time.toStdString( ).at(0) - 48));
|
||||||
db->hinzufuegenVeranstaltung(name.toStdString( ), time.toStdString( ), campus.toStdString( ), raum.toStdString( ));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "../../Core/DBHandler/DBPlan/DBPlan.hpp"
|
#include "../../Core/DBHandler/DBHandler.hpp"
|
||||||
#include "../../Core/config/config.hpp"
|
#include "../../Core/config/config.hpp"
|
||||||
|
|
||||||
class EinsatzplanFrameController {
|
class EinsatzplanFrameController {
|
||||||
private:
|
private:
|
||||||
std::string m_connectionString;
|
std::unique_ptr<DBHandler> m_dbHandler;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
@@ -20,4 +20,5 @@ public:
|
|||||||
void deleteVeranstaltung(QString veranstaltungsname);
|
void deleteVeranstaltung(QString veranstaltungsname);
|
||||||
void createMember(QString name, QString email, QString passwort, bool admin);
|
void createMember(QString name, QString email, QString passwort, bool admin);
|
||||||
void createVeranstaltung(QString name, QString raum, QString campus, QString time);
|
void createVeranstaltung(QString name, QString raum, QString campus, QString time);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
#include "LoginFrameController.hpp"
|
#include "LoginFrameController.hpp"
|
||||||
|
|
||||||
LoginFrameController::LoginFrameController()
|
LoginFrameController::LoginFrameController( ) {
|
||||||
{
|
auto config = load_config( );
|
||||||
|
|
||||||
|
m_dbHandler = std::make_unique<DBHandler>(fmt::format(
|
||||||
|
"host={} port={} dbname={} user={} password={}",
|
||||||
|
config.at("DB_HOST"),
|
||||||
|
config.at("DB_PORT"),
|
||||||
|
config.at("DB_NAME"),
|
||||||
|
config.at("DB_USER"),
|
||||||
|
config.at("DB_PASSWORD")
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoginFrameController::tryLogin(QString id, QString password){
|
int LoginFrameController::tryLogin(QString id, QString password) {
|
||||||
//DatabaseHandler dbHandler = new Databasehandler();
|
return m_dbHandler->tryAuthenticate(id.toStdString( ), password.toStdString( ));
|
||||||
//dbHandler.CheckValidLogin();
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
class LoginFrameController{
|
#include "../../Core/DBHandler/DBHandler.hpp"
|
||||||
|
#include "../../Core/config/config.hpp"
|
||||||
|
|
||||||
|
class LoginFrameController {
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<DBHandler> m_dbHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LoginFrameController();
|
LoginFrameController( );
|
||||||
bool tryLogin(QString id, QString password);
|
|
||||||
};
|
int tryLogin(QString id, QString password);
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,64 +7,125 @@ PlanGridController::PlanGridController( ) {
|
|||||||
weekdays[3] = "Donnerstag";
|
weekdays[3] = "Donnerstag";
|
||||||
weekdays[4] = "Freitag";
|
weekdays[4] = "Freitag";
|
||||||
|
|
||||||
times[0] = "8:00 - 10:00";
|
times[0] = "08:00";
|
||||||
times[1] = "10:00 - 12:00";
|
times[1] = "10:00";
|
||||||
times[2] = "12:00 - 14:00";
|
times[2] = "12:00";
|
||||||
times[3] = "14:00 - 16:00";
|
times[3] = "14:00";
|
||||||
times[4] = "16:00 - 18:00";
|
times[4] = "16:00";
|
||||||
|
|
||||||
planMap = new QMap<QPair<QString, QString>, QLabel*>( );
|
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(
|
m_dbHandler = std::make_unique<DBHandler>(fmt::format(
|
||||||
"host={} port={} dbname={} user={} password={}",
|
"host={} port={} dbname={} user={} password={}",
|
||||||
config.at("DB_HOST"),
|
config.at("DB_HOST"),
|
||||||
config.at("DB_PORT"),
|
config.at("DB_PORT"),
|
||||||
config.at("DB_NAME"),
|
config.at("DB_NAME"),
|
||||||
config.at("DB_USER"),
|
config.at("DB_USER"),
|
||||||
config.at("DB_PASSWORD")
|
config.at("DB_PASSWORD")
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QPair<QString, QString>, QLabel*>* PlanGridController::getVeranstaltungen( ) {
|
QMap<QPair<QString, QString>, QWidget*>* PlanGridController::getVeranstaltungen( ) {
|
||||||
DBPlan* db = new DBPlan(m_connectionString);
|
std::vector<std::string> planData = m_dbHandler->getPlan( );
|
||||||
|
|
||||||
// stringFormat = tag , anfangszeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID
|
for (int i = 0; i < 5; ++i)
|
||||||
std::vector<std::string> planData = db->getPlan( );
|
for (int j = 0; j < 5; ++j) {
|
||||||
|
QLabel* temp = new QLabel( );
|
||||||
|
temp->setObjectName("temp");
|
||||||
|
temp->setStyleSheet(R"(
|
||||||
|
#temp{
|
||||||
|
background-color: #313131;
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
temp->setFixedSize(240, 100);
|
||||||
|
planMap->insert(qMakePair(weekdays[i], times[j]), temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string color;
|
||||||
|
|
||||||
QString tag;
|
|
||||||
QString anfang;
|
|
||||||
QString ort;
|
|
||||||
QString name;
|
|
||||||
QString mitarbeiter;
|
|
||||||
QString mitarbeiterId;
|
|
||||||
std::string temp;
|
|
||||||
for (const auto& veranstaltung : planData) {
|
for (const auto& veranstaltung : planData) {
|
||||||
std::istringstream f(veranstaltung);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
tag.fromStdString(temp);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
anfang.fromStdString(temp);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
ort.fromStdString(temp);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
name.fromStdString(temp);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
mitarbeiter.fromStdString(temp);
|
|
||||||
std::getline(f, temp, ',');
|
|
||||||
mitarbeiterId.fromStdString(temp);
|
|
||||||
|
|
||||||
QLabel* temp = new QLabel(name + "\n" + mitarbeiter + "\n" + ort);
|
std::vector<std::string> infoVector;
|
||||||
temp->setObjectName("temp");
|
std::stringstream ss(veranstaltung);
|
||||||
temp->setStyleSheet(R"(
|
std::string str;
|
||||||
#temp{
|
|
||||||
|
while (std::getline(ss, str, ','))
|
||||||
|
infoVector.push_back(str);
|
||||||
|
|
||||||
|
//Wochentag, Uhrzeit,Uhrzeitende, Campus, Veranstaltung, ProfName,raum, prof id
|
||||||
|
QFrame* container = new QFrame( );
|
||||||
|
|
||||||
|
container->setObjectName("container");
|
||||||
|
container->setStyleSheet(R"(
|
||||||
|
#container{
|
||||||
|
background-color: #313131;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
temp->setFixedSize(240, 100);
|
auto layout = new QVBoxLayout(container);
|
||||||
planMap->insert(qMakePair(tag, anfang), temp);
|
container->setLayout(layout);
|
||||||
|
|
||||||
|
QPushButton* widget = new QPushButton(QString::fromStdString(infoVector.at(4) + " - " + infoVector.at(5) + "\n" + infoVector.at(3) + infoVector.at(6)));
|
||||||
|
layout->addWidget(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);
|
||||||
|
|
||||||
|
if (infoVector.at(4) == "THI") {
|
||||||
|
color = "#9FA8DA";
|
||||||
|
} else if (infoVector.at(4) == "DBS") {
|
||||||
|
color = "#EF9A9A";
|
||||||
|
} else if (infoVector.at(4) == "WIN") {
|
||||||
|
color = "#FFCC80";
|
||||||
|
} else if (infoVector.at(4) == "ALD") {
|
||||||
|
color = "#E6EE9C";
|
||||||
|
} else if (infoVector.at(4) == "GDI") {
|
||||||
|
color = "#90CAF9";
|
||||||
|
} else if (infoVector.at(4) == "BSY") {
|
||||||
|
color = "#FFF59D";
|
||||||
|
} else if (infoVector.at(4) == "ITS") {
|
||||||
|
color = "#9FA8DA";
|
||||||
|
} else if (infoVector.at(4) == "WEB") {
|
||||||
|
color = "#A5D6A7";
|
||||||
|
} else if (infoVector.at(4) == "BVA") {
|
||||||
|
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 = "#D8D8D8";
|
||||||
|
}
|
||||||
|
|
||||||
|
widget->setStyleSheet(QString::fromStdString(R"(
|
||||||
|
#eintragung{
|
||||||
|
border: 0px solid #313131;
|
||||||
|
background-color: )" + color + R"(;
|
||||||
|
color: #212121;
|
||||||
|
font-weight: 900;
|
||||||
|
font-size: 18px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
)"));
|
||||||
|
|
||||||
|
container->setFixedSize(240, 100);
|
||||||
|
|
||||||
|
planMap->insert(qMakePair(
|
||||||
|
weekdays[std::stoi(infoVector.at(0)) - 1],
|
||||||
|
QString::fromStdString(infoVector.at(1).erase(5, 8))),
|
||||||
|
container);
|
||||||
}
|
}
|
||||||
|
|
||||||
return planMap;
|
return planMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlanGridController::Krankmelden(const int id, const int tag, const std::string& uhrzeit) {
|
||||||
|
m_dbHandler->krankmelden(std::to_string(id), uhrzeit, tag);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,21 +3,25 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "../../Core/config/config.hpp"
|
#include "../../Core/config/config.hpp"
|
||||||
#include "../../Core/DBHandler/DBPlan/DBPlan.hpp"
|
#include "../../Core/DBHandler/DBHandler.hpp"
|
||||||
|
|
||||||
class PlanGridController {
|
class PlanGridController : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::string m_connectionString;
|
std::unique_ptr<DBHandler> m_dbHandler;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString weekdays[5];
|
QString weekdays[5];
|
||||||
QString times[5];
|
QString times[5];
|
||||||
QMap<QPair<QString, QString>, QLabel*>* planMap;
|
QMap<QPair<QString, QString>, QWidget*>* planMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlanGridController( );
|
PlanGridController( );
|
||||||
|
|
||||||
QMap<QPair<QString, QString>, QLabel*>* getVeranstaltungen( );
|
QMap<QPair<QString, QString>, QWidget*>* getVeranstaltungen( );
|
||||||
|
void Krankmelden(const int id, const int tag, const std::string& uhrzeit);
|
||||||
};
|
};
|
||||||
|
|||||||
168
src/Core/DBHandler/DBHandler.cpp
Normal file
168
src/Core/DBHandler/DBHandler.cpp
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
#include "DBHandler.hpp"
|
||||||
|
|
||||||
|
DBHandler::DBHandler(const std::string& connStr) :
|
||||||
|
m_dbConnection(std::make_unique<pqxx::connection>(connStr.c_str( ))) {
|
||||||
|
try {
|
||||||
|
m_dbConnection->is_open( ) ?
|
||||||
|
fmt::print("Databased connected") :
|
||||||
|
fmt::print("Failed to connect to Databased");
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int DBHandler::tryAuthenticate(std::string id, std::string pw) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
|
||||||
|
std::string query =
|
||||||
|
"SELECT admin FROM veranstalter WHERE id = $1 AND passwort = $2";
|
||||||
|
|
||||||
|
pqxx::result response = W.exec_params(query, id, pw);
|
||||||
|
|
||||||
|
return response.affected_rows( ) > 0 ? response[0][0].as<bool>( ) : -1;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::createVeranstalter(const std::string& name, const std::string& email, const std::string& password, bool admin) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string admin_value = admin ? "TRUE" : "FALSE";
|
||||||
|
std::string query = fmt::format(
|
||||||
|
"INSERT INTO Veranstalter (name, email, passwort, admin) VALUES ({}, {}, {}, {})",
|
||||||
|
W.quote(name), W.quote(email), W.quote(password), admin_value
|
||||||
|
);
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::deleteVeranstalter(int id) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string query = fmt::format(
|
||||||
|
"DELETE FROM Veranstalter WHERE ID = {}", W.quote(id)
|
||||||
|
);
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::deleteVeranstalter(const std::string& name) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string query = fmt::format(
|
||||||
|
"DELETE FROM Veranstalter WHERE id = {}", W.quote(name)
|
||||||
|
);
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::createVeranstaltung(const std::string& name, const std::string& campus, const std::string& raum, const std::string& dauer) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string cmp(1, campus.back( ));
|
||||||
|
std::string query = fmt::format(
|
||||||
|
"INSERT INTO Veranstaltung (name, ort, raum, dauer) VALUES ({}, {}, {}, {})",
|
||||||
|
W.quote(name), W.quote(cmp), W.quote(raum), W.quote(dauer)
|
||||||
|
);
|
||||||
|
fmt::print(query);
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::deleteVeranstaltung(const std::string& name) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string query = fmt::format(
|
||||||
|
"DELETE FROM Veranstaltung WHERE name = {}", W.quote(name)
|
||||||
|
);
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DBHandler::krankmelden(const std::string& veranstalter, const std::string& uhrzeit, int tag) {
|
||||||
|
try {
|
||||||
|
pqxx::work W(*m_dbConnection.get( ));
|
||||||
|
std::string query =
|
||||||
|
"INSERT INTO Krank (stundeImPlan_uhrzeit, stundeImPlan_tag, veranstalter, krank) "
|
||||||
|
"SELECT SIP.uhrzeit, SIP.tag, V.ID, TRUE "
|
||||||
|
"FROM StundeImPlan SIP "
|
||||||
|
"JOIN Veranstalter V ON SIP.veranstalter = V.ID "
|
||||||
|
"JOIN Uhrzeit U ON SIP.uhrzeit = U.ID "
|
||||||
|
"JOIN Veranstaltung VA ON SIP.veranstaltung = VA.name "
|
||||||
|
"WHERE V.id = " + W.quote(veranstalter) +
|
||||||
|
" AND U.anfangszeit = " + W.quote(std::string(uhrzeit + ":00")) +
|
||||||
|
" AND SIP.tag = " + W.quote(tag) + ";";
|
||||||
|
|
||||||
|
W.exec(query);
|
||||||
|
W.commit( );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> DBHandler::getPlan( ) {
|
||||||
|
std::vector<std::string> plan;
|
||||||
|
try {
|
||||||
|
pqxx::nontransaction N(*m_dbConnection.get( ));
|
||||||
|
std::string query =
|
||||||
|
R"(SELECT SIP.tag, U.anfangszeit, U.endzeit, VA.ort, VA.name AS veranstaltungsname, V.name AS veranstaltername, VA.raum, SIP.veranstalter, VA.dauer
|
||||||
|
FROM StundeImPlan SIP
|
||||||
|
JOIN Uhrzeit U ON SIP.uhrzeit = U.ID
|
||||||
|
JOIN Veranstaltung VA ON SIP.veranstaltung = VA.name
|
||||||
|
LEFT JOIN Veranstalter V ON SIP.veranstalter = V.ID
|
||||||
|
ORDER BY U.anfangszeit)";
|
||||||
|
pqxx::result R(N.exec(query));
|
||||||
|
|
||||||
|
for (auto row : R) {
|
||||||
|
std::string entry = fmt::format(
|
||||||
|
"{},{},{},{},{},{},{},{},{}",
|
||||||
|
row["tag"].c_str( ), row["anfangszeit"].c_str( ), row["endzeit"].c_str( ), row["ort"].c_str( ),
|
||||||
|
row["veranstaltungsname"].c_str( ), row["veranstaltername"].is_null( ) ? "frei" : row["veranstaltername"].c_str( ), row["raum"].c_str( ), row["veranstalter"].c_str( ), row["dauer"].c_str( )
|
||||||
|
);
|
||||||
|
plan.push_back(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
fmt::print(e.what( ));
|
||||||
|
}
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
34
src/Core/DBHandler/DBHandler.hpp
Normal file
34
src/Core/DBHandler/DBHandler.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pqxx/pqxx>
|
||||||
|
#include <string>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <random>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
class DBHandler {
|
||||||
|
private:
|
||||||
|
std::unique_ptr<pqxx::connection> m_dbConnection;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DBHandler(const std::string& connStr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to login the user
|
||||||
|
* @param id user id
|
||||||
|
* @param pw user password
|
||||||
|
* @return returns 1 if admin and 0 if not
|
||||||
|
*/
|
||||||
|
int tryAuthenticate(std::string id, std::string pw);
|
||||||
|
|
||||||
|
bool createVeranstalter(const std::string& name, const std::string& email, const std::string& password, bool admin);
|
||||||
|
bool deleteVeranstalter(int id);
|
||||||
|
bool deleteVeranstalter(const std::string& name);
|
||||||
|
|
||||||
|
bool createVeranstaltung(const std::string& name, const std::string& campus, const std::string& time, const std::string& veranstalter);
|
||||||
|
bool deleteVeranstaltung(const std::string& name);
|
||||||
|
|
||||||
|
bool krankmelden(const std::string& veranstalter, const std::string& uhrzeit, int tag);
|
||||||
|
|
||||||
|
std::vector<std::string> getPlan( );
|
||||||
|
};
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include "DBHandler.hpp"
|
|
||||||
|
|
||||||
DBHandler::DBHandler(std::string connStr) :
|
|
||||||
connectionObject(connStr.c_str( )) {
|
|
||||||
try {
|
|
||||||
if (connectionObject.is_open( ))
|
|
||||||
fmt::print("Databased connected");
|
|
||||||
else
|
|
||||||
fmt::print("Failed to connect to Databased");
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma onc
|
|
||||||
|
|
||||||
#include <pqxx/pqxx>
|
|
||||||
#include <string>
|
|
||||||
#include <fmt/core.h>
|
|
||||||
|
|
||||||
class DBHandler {
|
|
||||||
protected:
|
|
||||||
pqxx::connection connectionObject;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DBHandler(std::string connStr);
|
|
||||||
};
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#include "DBLogin.hpp"
|
|
||||||
|
|
||||||
DBLogin::DBLogin(std::string connStr) : DBHandler(connStr) { };
|
|
||||||
|
|
||||||
int DBLogin::checkValidLogin(std::string id, std::string pw) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
std::string query =
|
|
||||||
"SELECT admin FROM studenten_veranstalter WHERE id = $1 AND passwort = $2";
|
|
||||||
|
|
||||||
pqxx::result response = worker.exec_params(query, id, pw);
|
|
||||||
|
|
||||||
if (response.affected_rows( ) > 0) {
|
|
||||||
if (response[0][0].is_null( ))
|
|
||||||
return 0;
|
|
||||||
return response[0][0].as<bool>( );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::printf("ERROR: %s", e.what( ));
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <fmt/printf.h>
|
|
||||||
|
|
||||||
#include "../DBHandler/DBHandler.hpp"
|
|
||||||
|
|
||||||
class DBLogin : public DBHandler {
|
|
||||||
public:
|
|
||||||
DBLogin(std::string connStr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Tries to login the user
|
|
||||||
* @param id user id
|
|
||||||
* @param pw user password
|
|
||||||
* @return returns 1 if admin and 0 if not
|
|
||||||
*/
|
|
||||||
int checkValidLogin(std::string id, std::string pw);
|
|
||||||
};
|
|
||||||
@@ -1,376 +0,0 @@
|
|||||||
#include "DBPlan.hpp"
|
|
||||||
|
|
||||||
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);
|
|
||||||
fmt::print(nextStunde);
|
|
||||||
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
std::string query = R"(
|
|
||||||
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; )";
|
|
||||||
|
|
||||||
worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter SET krank = TRUE WHERE ID = $1", id);
|
|
||||||
worker.commit( );
|
|
||||||
|
|
||||||
sucheVertretung(tag, stunde);
|
|
||||||
meldeGesund(id);
|
|
||||||
versendeEmails( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::meldeGesund(std::string id) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter SET krank = FALSE WHERE ID = $1", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
versendeEmails( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::deleteVeranstalter(std::string id) {
|
|
||||||
deleteVeranstalterForeign(id);
|
|
||||||
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM Veranstalter WHERE ID = $1", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::deleteVeranstaltungForeign(std::string id) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstaltung_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
versendeEmails( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::deleteVeranstaltung(std::string id) {
|
|
||||||
deleteVeranstaltungForeign(id);
|
|
||||||
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM Veranstaltung WHERE ID = $1", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
worker.exec_params("INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);", name, dauer, ort, raum);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("INSERT INTO Veranstalter (email, name, passwort, admin) VALUES ($1, $2, $3, $4);", email, name, pw, admin);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::deleteStudent(std::string id) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM studenten WHERE ID = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);", email, name, pw);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
pqxx::result response = worker.exec_params(
|
|
||||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);",
|
|
||||||
stunde,
|
|
||||||
tag
|
|
||||||
);
|
|
||||||
|
|
||||||
worker.commit( );
|
|
||||||
return response[0][0].c_str( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
|
||||||
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::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
|
||||||
try {
|
|
||||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
|
||||||
|
|
||||||
fmt::printf("PrevStunde: %s\n Tag: %s\n Stunde: %s \n", prevStunde, tag, stunde);
|
|
||||||
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::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::addFirstOfDayFour(std::string tag) {
|
|
||||||
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::print(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 =
|
|
||||||
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::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
|
||||||
try {
|
|
||||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
|
||||||
|
|
||||||
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::print(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);";
|
|
||||||
worker.exec_params(query, stunde, tag);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) {
|
|
||||||
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);";
|
|
||||||
|
|
||||||
worker.exec_params(query, amount, stunde, tag);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::createPlan( ) {
|
|
||||||
try {
|
|
||||||
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::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> DBPlan::getPlan( ) {
|
|
||||||
try {
|
|
||||||
std::vector<std::string> plan;
|
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
std::string query =
|
|
||||||
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit LEFT JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID
|
|
||||||
LEFT JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID
|
|
||||||
LEFT JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID
|
|
||||||
ORDER BY tag, uhrzeit_ID;)";
|
|
||||||
|
|
||||||
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( ));
|
|
||||||
}
|
|
||||||
return std::vector<std::string>{ "" };
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::versendeEmails( ) {
|
|
||||||
fmt::print("Der Einsatzplan wurde geändert");
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <fmt/core.h>
|
|
||||||
#include <fmt/printf.h>
|
|
||||||
|
|
||||||
#include "../DBHandler/DBHandler.hpp"
|
|
||||||
|
|
||||||
class DBPlan : public DBHandler {
|
|
||||||
private:
|
|
||||||
//Functions needed for creation and updating of the plan
|
|
||||||
std::string getDauer(std::string tag, std::string stunde);
|
|
||||||
void addFirstOfDayTwo(std::string tag);
|
|
||||||
void addTwoHour(std::string tag, std::string stunde);
|
|
||||||
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 deleteVeranstalterForeign(std::string id);
|
|
||||||
void deleteVeranstaltungForeign(std::string id);
|
|
||||||
void updateStandort(std::string tag, std::string stunde);
|
|
||||||
void incarbeitszeit(std::string tag, std::string stunde, std::string amount);
|
|
||||||
void versendeEmails( );
|
|
||||||
|
|
||||||
public:
|
|
||||||
DBPlan(std::string connStr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deletes prof from plan and searches new one
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @param tag
|
|
||||||
* @param stunde
|
|
||||||
*/
|
|
||||||
void meldeKrank(std::string id, std::string tag, std::string stunde);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Currently directly used after meldeKrank, so Mitarbeiter is only sick for specific hour
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
void meldeGesund(std::string id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deletes Veranstaltung from relation Veranstaltung and from Einsatzplan
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
void deleteVeranstaltung(std::string id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds Veranstaltung to relation Veranstaltung
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param dauer
|
|
||||||
* @param ort
|
|
||||||
* @param raum
|
|
||||||
*/
|
|
||||||
void hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deletes Veranstlater from relattion Veranstalter and from Einsatzplan
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
void deleteVeranstalter(std::string id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add Veranstalter to relation Veranstalter
|
|
||||||
*
|
|
||||||
* @param email
|
|
||||||
* @param name
|
|
||||||
* @param pw
|
|
||||||
* @param admin
|
|
||||||
*/
|
|
||||||
void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deletes a student from the database
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
void deleteStudent(std::string id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds a new student
|
|
||||||
*
|
|
||||||
* @param email
|
|
||||||
* @param name
|
|
||||||
* @param pw
|
|
||||||
*/
|
|
||||||
void hinzufuegenStudent(std::string email, std::string name, std::string pw);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create a Plan object
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void createPlan( );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Each string in form of (tag , anfangszeit , endzeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID , )
|
|
||||||
*
|
|
||||||
* @return std::vector<std::string>
|
|
||||||
*/
|
|
||||||
std::vector<std::string> getPlan( );
|
|
||||||
};
|
|
||||||
@@ -5,11 +5,17 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
#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 std::map<std::string, std::string> config;
|
||||||
static bool is_loaded{ false };
|
static bool is_loaded{ false };
|
||||||
static std::string fn{ "" };
|
static std::string fn{ "" };
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
std::string filename = std::string(std::getenv("USER")) + "\\config.cfg";
|
||||||
|
#elif defined(__unix__) || defined(__APPLE__)
|
||||||
|
std::string filename = std::string(std::getenv("HOME")) + "/Dokumente/Studium/Studium Dokumente/4. Semester/SWE/EinsatzplanQT/config.cfg";
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!is_loaded || fn != filename) {
|
if (!is_loaded || fn != filename) {
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -19,9 +25,8 @@ inline static const std::map<std::string, std::string>& load_config(const std::s
|
|||||||
std::string key;
|
std::string key;
|
||||||
if (std::getline(line_stream, key, '=')) {
|
if (std::getline(line_stream, key, '=')) {
|
||||||
std::string value;
|
std::string value;
|
||||||
if (std::getline(line_stream, value)) {
|
if (std::getline(line_stream, value))
|
||||||
config[key] = value;
|
config[key] = value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ CreateMemDialog::CreateMemDialog(QWidget* parent)
|
|||||||
color: #212121;
|
color: #212121;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
background-color: #53EC87;
|
background-color: #A5D6A7;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
@@ -106,7 +106,7 @@ CreateMemDialog::CreateMemDialog(QWidget* parent)
|
|||||||
color: #212121;
|
color: #212121;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
background-color: #FF5555;
|
background-color: #EF9A9A;
|
||||||
border-radius: 10px;
|
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 = new QLabel(this);
|
||||||
m_profileImg->setFixedSize(60, 60);
|
m_profileImg->setFixedSize(60, 60);
|
||||||
m_profileImg->setPixmap(QPixmap(":account-box.png"));
|
m_profileImg->setPixmap(QPixmap(":account-box.png"));
|
||||||
m_profileImg->setObjectName("profileImg");
|
m_profileImg->setObjectName("profileImg");
|
||||||
m_profileImg->setStyleSheet(R"(
|
|
||||||
#profileImg{
|
|
||||||
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
m_profileImg->show( );
|
m_profileImg->show( );
|
||||||
|
|
||||||
m_id = new QLabel(id, this);
|
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 = new QPushButton("Abmelden", this);
|
||||||
m_abmeldenButton->setFixedSize(150, 50);
|
m_abmeldenButton->setFixedSize(150, 50);
|
||||||
m_abmeldenButton->setObjectName("abmeldenButton");
|
m_abmeldenButton->setObjectName("abmeldenButton");
|
||||||
|
m_abmeldenButton->setCursor(Qt::PointingHandCursor);
|
||||||
m_abmeldenButton->setStyleSheet(R"(
|
m_abmeldenButton->setStyleSheet(R"(
|
||||||
#abmeldenButton{
|
#abmeldenButton{
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
@@ -72,6 +66,8 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
|||||||
m_planGrid = new PlanGrid(this);
|
m_planGrid = new PlanGrid(this);
|
||||||
m_planGrid->show( );
|
m_planGrid->show( );
|
||||||
|
|
||||||
|
m_controller = new EinsatzplanFrameController(id, admin);
|
||||||
|
|
||||||
QVBoxLayout* totalLayout = new QVBoxLayout(this);
|
QVBoxLayout* totalLayout = new QVBoxLayout(this);
|
||||||
totalLayout->setContentsMargins(30, 20, 30, 20);
|
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 = new QPushButton("Mitarbeiter\nHinzufügen", this);
|
||||||
m_createMemberButton->setFixedSize(200, 50);
|
m_createMemberButton->setFixedSize(200, 50);
|
||||||
m_createMemberButton->setObjectName("createMember");
|
m_createMemberButton->setObjectName("createMember");
|
||||||
|
m_createMemberButton->setCursor(Qt::PointingHandCursor);
|
||||||
m_createMemberButton->setStyleSheet(R"(
|
m_createMemberButton->setStyleSheet(R"(
|
||||||
#createMember{
|
#createMember{
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
@@ -114,6 +111,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
|||||||
m_deleteMemberButton = new QPushButton("Mitarbeiter\nEntfernen", this);
|
m_deleteMemberButton = new QPushButton("Mitarbeiter\nEntfernen", this);
|
||||||
m_deleteMemberButton->setFixedSize(200, 50);
|
m_deleteMemberButton->setFixedSize(200, 50);
|
||||||
m_deleteMemberButton->setObjectName("deleteMember");
|
m_deleteMemberButton->setObjectName("deleteMember");
|
||||||
|
m_deleteMemberButton->setCursor(Qt::PointingHandCursor);
|
||||||
m_deleteMemberButton->setStyleSheet(R"(
|
m_deleteMemberButton->setStyleSheet(R"(
|
||||||
#deleteMember{
|
#deleteMember{
|
||||||
font-size: 16px;
|
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 = new QPushButton("Veranstaltung\nHinzufügen", this);
|
||||||
m_createVeranstaltungButton->setFixedSize(200, 50);
|
m_createVeranstaltungButton->setFixedSize(200, 50);
|
||||||
m_createVeranstaltungButton->setObjectName("createVeranstaltung");
|
m_createVeranstaltungButton->setObjectName("createVeranstaltung");
|
||||||
|
m_createVeranstaltungButton->setCursor(Qt::PointingHandCursor);
|
||||||
m_createVeranstaltungButton->setStyleSheet(R"(
|
m_createVeranstaltungButton->setStyleSheet(R"(
|
||||||
#createVeranstaltung{
|
#createVeranstaltung{
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
@@ -154,6 +153,7 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
|||||||
m_deleteVeranstaltungButton = new QPushButton("Veranstaltung\nEntfernen", this);
|
m_deleteVeranstaltungButton = new QPushButton("Veranstaltung\nEntfernen", this);
|
||||||
m_deleteVeranstaltungButton->setFixedSize(200, 50);
|
m_deleteVeranstaltungButton->setFixedSize(200, 50);
|
||||||
m_deleteVeranstaltungButton->setObjectName("deleteVeranstaltung");
|
m_deleteVeranstaltungButton->setObjectName("deleteVeranstaltung");
|
||||||
|
m_deleteVeranstaltungButton->setCursor(Qt::PointingHandCursor);
|
||||||
m_deleteVeranstaltungButton->setStyleSheet(R"(
|
m_deleteVeranstaltungButton->setStyleSheet(R"(
|
||||||
#deleteVeranstaltung{
|
#deleteVeranstaltung{
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
@@ -182,7 +182,11 @@ EinsatzplanFrame::EinsatzplanFrame(QWidget* parent, QString id, bool admin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrame::abmelden( ) {
|
void EinsatzplanFrame::abmelden( ) {
|
||||||
static_cast<QApplication*>(parent( )->parent( ))->exit( );
|
QString program = QApplication::applicationFilePath( );
|
||||||
|
|
||||||
|
QProcess::startDetached(program);
|
||||||
|
|
||||||
|
QApplication::quit( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrame::deleteVeranstaltung( ) {
|
void EinsatzplanFrame::deleteVeranstaltung( ) {
|
||||||
@@ -190,19 +194,24 @@ void EinsatzplanFrame::deleteVeranstaltung( ) {
|
|||||||
QString text = QInputDialog::getText(this, tr("Veranstaltung Entfernen"),
|
QString text = QInputDialog::getText(this, tr("Veranstaltung Entfernen"),
|
||||||
tr("Bitte geben sie den Veranstaltungskürzel ein:"), QLineEdit::Normal,
|
tr("Bitte geben sie den Veranstaltungskürzel ein:"), QLineEdit::Normal,
|
||||||
"", &ok);
|
"", &ok);
|
||||||
(ok && text.size( ) == 3) ?
|
if (ok && text.size( ) == 3) {
|
||||||
QMessageBox::information(this, "Veranstaltung Entfernen", "Veranstaltungskürzel besteht aus 3 Zeichen!") :
|
m_controller->deleteVeranstaltung(text);
|
||||||
QMessageBox::information(this, "Veranstaltung entfernen", "Veranstaltung wird entfernt!");
|
|
||||||
|
m_planGrid->setPlanMap(m_planGrid->planGridController->getVeranstaltungen( ));
|
||||||
|
m_planGrid->populateGrid( );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrame::createVeranstaltung( ) {
|
void EinsatzplanFrame::createVeranstaltung( ) {
|
||||||
CreateVerDialog dialog(this);
|
CreateVerDialog dialog(this);
|
||||||
if (dialog.exec( ) == QDialog::Accepted) {
|
if (dialog.exec( ) == QDialog::Accepted && dialog.getName().size() == 3) {
|
||||||
QString name = dialog.getName( );
|
QString name = dialog.getName( );
|
||||||
QString raum = dialog.getRaum( );
|
QString raum = dialog.getRaum( );
|
||||||
QString campus = dialog.getCampus( );
|
QString campus = dialog.getCampus( );
|
||||||
QString time = dialog.getTime( );
|
QString time = dialog.getTime( );
|
||||||
m_controller->createVeranstaltung(name, raum, campus, time);
|
m_controller->createVeranstaltung(name, raum, campus, time);
|
||||||
|
m_planGrid->setPlanMap(m_planGrid->planGridController->getVeranstaltungen( ));
|
||||||
|
m_planGrid->populateGrid( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,9 +221,11 @@ void EinsatzplanFrame::deleteMember( ) {
|
|||||||
tr("Bitte geben sie die Mitarbeiter ID ein:"), QLineEdit::Normal,
|
tr("Bitte geben sie die Mitarbeiter ID ein:"), QLineEdit::Normal,
|
||||||
"", &ok);
|
"", &ok);
|
||||||
|
|
||||||
(ok && text.size( ) == 7) ?
|
if (ok && text.size( ) == 7) {
|
||||||
QMessageBox::information(this, "Mitarbeiter entfernen", "Mitarbeiter wird entfernt!") :
|
m_controller->deleteMember(text);
|
||||||
QMessageBox::information(this, "Mitarbeiter Entfernen", "Mitarbeiter ID besteht aus 7 Zahlen!");
|
m_planGrid->setPlanMap(m_planGrid->planGridController->getVeranstaltungen( ));
|
||||||
|
m_planGrid->populateGrid( );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EinsatzplanFrame::createMember( ) {
|
void EinsatzplanFrame::createMember( ) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
#include "../PlanGrid/PlanGrid.hpp"
|
#include "../PlanGrid/PlanGrid.hpp"
|
||||||
#include "../../Controller/EinsatzplanFrameController/EinsatzplanFrameController.hpp"
|
#include "../../Controller/EinsatzplanFrameController/EinsatzplanFrameController.hpp"
|
||||||
@@ -38,7 +39,6 @@ public:
|
|||||||
EinsatzplanFrame(QWidget* parent = nullptr, QString id = "0000000", bool admin = true);
|
EinsatzplanFrame(QWidget* parent = nullptr, QString id = "0000000", bool admin = true);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void abmelden( );
|
void abmelden( );
|
||||||
void deleteVeranstaltung( );
|
void deleteVeranstaltung( );
|
||||||
void createVeranstaltung( );
|
void createVeranstaltung( );
|
||||||
|
|||||||
@@ -1,123 +1,123 @@
|
|||||||
# include "LoginFrame.hpp"
|
#include "LoginFrame.hpp"
|
||||||
|
|
||||||
LoginFrame::LoginFrame(QWidget* parent)
|
LoginFrame::LoginFrame(QWidget* parent)
|
||||||
:QFrame(parent) {
|
:QFrame(parent) {
|
||||||
//configure LoginFrame
|
//configure LoginFrame
|
||||||
setObjectName("LoginFrame");
|
setObjectName("LoginFrame");
|
||||||
setStyleSheet(R"(
|
setStyleSheet(R"(
|
||||||
#LoginFrame{
|
#LoginFrame{
|
||||||
background-color: #212121;
|
background-color: #212121;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
setFrameStyle(QFrame::Box);
|
setFrameStyle(QFrame::Box);
|
||||||
|
|
||||||
|
//create QWidgets and add LoginFrame as parent
|
||||||
//create QWidgets and add LoginFrame as parent
|
m_header = new QLabel("Einsatzplan", this);
|
||||||
header_m = new QLabel("Einsatzplan", this);
|
m_header->setFrameStyle(QFrame::Box);
|
||||||
header_m->setFrameStyle(QFrame::Box);
|
m_header->setObjectName("Header");
|
||||||
header_m->setObjectName("Header");
|
m_header->setStyleSheet(R"(
|
||||||
header_m->setStyleSheet(R"(
|
|
||||||
#Header{
|
#Header{
|
||||||
color: #93F8FF;
|
color: #93F8FF;
|
||||||
font-size: 36px;
|
font-size: 36px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
header_m->show( );
|
m_header->show( );
|
||||||
|
|
||||||
|
m_id = new QLineEdit(this);
|
||||||
id_m = new QLineEdit(this);
|
m_id->setPlaceholderText("ID...");
|
||||||
id_m->setPlaceholderText("ID...");
|
m_id->setObjectName("ID");
|
||||||
id_m->setObjectName("ID");
|
m_id->setFixedSize(300, 40);
|
||||||
id_m->setFixedSize(300, 40);
|
m_id->setStyleSheet(R"(
|
||||||
id_m->setStyleSheet(R"(
|
|
||||||
#ID{
|
#ID{
|
||||||
color: #DADADA;
|
color: #DADADA;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
background-color: #313131;
|
background-color: #313131;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 2px solid #414141;
|
border: 2px solid #414141;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
id_m->show( );
|
m_id->show( );
|
||||||
|
|
||||||
|
m_password = new QLineEdit(this);
|
||||||
password_m = new QLineEdit(this);
|
m_password->setPlaceholderText("Passwort...");
|
||||||
password_m->setPlaceholderText("Passwort...");
|
m_password->setObjectName("Password");
|
||||||
password_m->setObjectName("Password");
|
m_password->setEchoMode(QLineEdit::Password);
|
||||||
password_m->setEchoMode(QLineEdit::Password);
|
m_password->setFixedSize(300, 40);
|
||||||
password_m->setFixedSize(300, 40);
|
m_password->setStyleSheet(R"(
|
||||||
password_m->setStyleSheet(R"(
|
|
||||||
#Password{
|
#Password{
|
||||||
color: #DADADA;
|
color: #DADADA;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
background-color: #313131;
|
background-color: #313131;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 2px solid #414141;
|
border: 2px solid #414141;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
password_m->show( );
|
m_password->show( );
|
||||||
|
|
||||||
loginButton_m = new QPushButton("Login", this);
|
m_loginButton = new QPushButton("Login", this);
|
||||||
loginButton_m->setObjectName("loginButton");
|
m_loginButton->setObjectName("loginButton");
|
||||||
loginButton_m->setFixedSize(QSize(150, 50));
|
m_loginButton->setFixedSize(QSize(150, 50));
|
||||||
loginButton_m->setStyleSheet(R"(
|
m_loginButton->setStyleSheet(R"(
|
||||||
#loginButton{
|
#loginButton{
|
||||||
color: #212121;
|
color: #212121;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
background-color: #53EC87;
|
background-color: #53EC87;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
#loginButton:pressed {
|
#loginButton:pressed {
|
||||||
background-color: #43DC77;
|
background-color: #43DC77;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
loginButton_m->show( );
|
m_loginButton->show( );
|
||||||
|
|
||||||
//create layout
|
//create layout
|
||||||
QVBoxLayout* layout = new QVBoxLayout( );
|
QVBoxLayout* layout = new QVBoxLayout( );
|
||||||
|
|
||||||
//layout->setContentsMargins(50, 20, 50, 20);
|
//layout->setContentsMargins(50, 20, 50, 20);
|
||||||
layout->addWidget(header_m, 3, Qt::AlignCenter);
|
layout->addWidget(m_header, 3, Qt::AlignCenter);
|
||||||
layout->addWidget(id_m, 1, Qt::AlignCenter);
|
layout->addWidget(m_id, 1, Qt::AlignCenter);
|
||||||
layout->addWidget(password_m, 1, Qt::AlignCenter);
|
layout->addWidget(m_password, 1, Qt::AlignCenter);
|
||||||
layout->addWidget(loginButton_m, 3, Qt::AlignCenter);
|
layout->addWidget(m_loginButton, 3, Qt::AlignCenter);
|
||||||
|
|
||||||
//add Layout to LoginFrame
|
//add Layout to LoginFrame
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
//connect loginButton with function
|
//connect loginButton with function
|
||||||
connect(loginButton_m, &QPushButton::clicked, this, &LoginFrame::loginButtonClicked);
|
connect(m_loginButton, &QPushButton::clicked, this, &LoginFrame::loginButtonClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
//try Login if Button clicked
|
//try Login if Button clicked
|
||||||
void LoginFrame::loginButtonClicked( ) {
|
void LoginFrame::loginButtonClicked( ) {
|
||||||
QString id = id_m->text( );
|
QString id = m_id->text( );
|
||||||
QString password = password_m->text( );
|
QString password = m_password->text( );
|
||||||
|
|
||||||
//check if Contents Valid
|
//check if Contents Valid
|
||||||
if (id.isEmpty( ) || password.isEmpty( )) {
|
if (id.isEmpty( ) || password.isEmpty( )) {
|
||||||
QMessageBox::warning(this, "Error", "Bitte füllen Sie sowohl die ID als auch das Passwort aus.");
|
QMessageBox::warning(this, "Error", "Bitte füllen Sie sowohl die ID als auch das Passwort aus.");
|
||||||
} else {
|
} else {
|
||||||
LoginFrameController* controller = new LoginFrameController( );
|
LoginFrameController* controller = new LoginFrameController( );
|
||||||
if (!controller->tryLogin(id, password)) {
|
int res = controller->tryLogin(id, password);
|
||||||
QMessageBox::warning(this, "Error", "ID und Passwort stimmen nicht überein!");
|
if (res == -1) {
|
||||||
} else {
|
QMessageBox::warning(this, "Error", "ID und Passwort stimmen nicht überein!");
|
||||||
((QWidget*)(this->parent( )))->hide( );
|
} else {
|
||||||
//TODO: Create new window
|
((QWidget*)(this->parent( )))->hide( );
|
||||||
}
|
EinsatzplanWindow* win = new EinsatzplanWindow(nullptr, id, res);
|
||||||
}
|
win->show( );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginFrame::~LoginFrame( ) {
|
LoginFrame::~LoginFrame( ) {
|
||||||
header_m->~QLabel( );
|
m_header->~QLabel( );
|
||||||
id_m->~QLineEdit( );
|
m_id->~QLineEdit( );
|
||||||
password_m->~QLineEdit( );
|
m_password->~QLineEdit( );
|
||||||
loginButton_m->~QPushButton( );
|
m_loginButton->~QPushButton( );
|
||||||
parent_m->~QMainWindow( );
|
m_parent->~QMainWindow( );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
# pragma once
|
#pragma once
|
||||||
# include <QFrame>
|
|
||||||
# include <QWidget>
|
|
||||||
# include <QPushButton>
|
|
||||||
# include <QInputDialog>
|
|
||||||
# include <QLabel>
|
|
||||||
# include <QVBoxLayout>
|
|
||||||
# include <QMessageBox>
|
|
||||||
# include <QMainWindow>
|
|
||||||
# include "../../Controller/LoginFrameController/LoginFrameController.hpp"
|
|
||||||
|
|
||||||
class LoginFrame : public QFrame{
|
#include <QFrame>
|
||||||
Q_OBJECT
|
#include <QWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
#include "../../Controller/LoginFrameController/LoginFrameController.hpp"
|
||||||
|
#include "../../View/EinsatzplanWindow/EinsatzplanWindow.hpp"
|
||||||
|
|
||||||
|
class LoginFrame : public QFrame {
|
||||||
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
QMainWindow* parent_m;
|
QMainWindow* m_parent;
|
||||||
QLabel* header_m;
|
QLabel* m_header;
|
||||||
QLineEdit* id_m;
|
QLineEdit* m_id;
|
||||||
QLineEdit* password_m;
|
QLineEdit* m_password;
|
||||||
QPushButton* loginButton_m;
|
QPushButton* m_loginButton;
|
||||||
|
|
||||||
void loginButtonClicked();
|
void loginButtonClicked( );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LoginFrame(QWidget* parent = nullptr);
|
LoginFrame(QWidget* parent = nullptr);
|
||||||
~LoginFrame();
|
~LoginFrame( );
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "LoginWindow.hpp"
|
#include "LoginWindow.hpp"
|
||||||
|
|
||||||
LoginWindow::LoginWindow(QWidget* parent)
|
LoginWindow::LoginWindow(QWidget* parent)
|
||||||
:QMainWindow(parent)
|
:QMainWindow(parent) {
|
||||||
{
|
m_frame = new LoginFrame(this);
|
||||||
frame_m = new LoginFrame(this);
|
setFixedSize(400, 550);
|
||||||
setFixedSize(400,550);
|
m_frame->setFixedSize(size( ));
|
||||||
frame_m->setFixedSize(size());
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
# pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include "../LoginFrame/LoginFrame.hpp"
|
#include "../LoginFrame/LoginFrame.hpp"
|
||||||
|
|
||||||
class LoginWindow : public QMainWindow{
|
class LoginWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
LoginFrame* frame_m;
|
LoginFrame* m_frame;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LoginWindow(QWidget* parent = nullptr);
|
LoginWindow(QWidget* parent = nullptr);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include "PlanGrid.hpp"
|
#include "PlanGrid.hpp"
|
||||||
|
|
||||||
PlanGrid::PlanGrid(QWidget* parent)
|
PlanGrid::PlanGrid(QWidget* parent)
|
||||||
:QWidget(parent) {
|
:QWidget(parent),
|
||||||
|
planGridController(new PlanGridController( )) {
|
||||||
setObjectName("PlanGrid");
|
setObjectName("PlanGrid");
|
||||||
setStyleSheet(R"(
|
setStyleSheet(R"(
|
||||||
QWidget{
|
QWidget{
|
||||||
@@ -16,31 +17,18 @@ PlanGrid::PlanGrid(QWidget* parent)
|
|||||||
m_weekdays[3] = "Donnerstag";
|
m_weekdays[3] = "Donnerstag";
|
||||||
m_weekdays[4] = "Freitag";
|
m_weekdays[4] = "Freitag";
|
||||||
|
|
||||||
m_times[0] = "8:00 - 10:00";
|
m_times[0] = "08:00";
|
||||||
m_times[1] = "10:00 - 12:00";
|
m_times[1] = "10:00";
|
||||||
m_times[2] = "12:00 - 14:00";
|
m_times[2] = "12:00";
|
||||||
m_times[3] = "14:00 - 16:00";
|
m_times[3] = "14:00";
|
||||||
m_times[4] = "16:00 - 18:00";
|
m_times[4] = "16:00";
|
||||||
|
m_times[5] = "18:00";
|
||||||
|
|
||||||
planMap = new QMap<QPair<QString, QString>, QLabel*>( );
|
planMap = new QMap<QPair<QString, QString>, QWidget*>( );
|
||||||
|
|
||||||
gridLayout = new QGridLayout(this);
|
gridLayout = new QGridLayout(this);
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i)
|
// Empty top left corner
|
||||||
for (int j = 0; j < 5; ++j) {
|
|
||||||
QLabel* temp = new QLabel( );
|
|
||||||
temp->setObjectName("temp");
|
|
||||||
temp->setStyleSheet(R"(
|
|
||||||
#temp{
|
|
||||||
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
temp->setFixedSize(240, 100);
|
|
||||||
planMap->insert(qMakePair(m_weekdays[i], m_times[j]), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
populateGrid( );
|
|
||||||
|
|
||||||
QLabel* temp = new QLabel( );
|
QLabel* temp = new QLabel( );
|
||||||
temp->setObjectName("temp");
|
temp->setObjectName("temp");
|
||||||
temp->setStyleSheet(R"(
|
temp->setStyleSheet(R"(
|
||||||
@@ -51,6 +39,7 @@ PlanGrid::PlanGrid(QWidget* parent)
|
|||||||
temp->setFixedSize(130, 80);
|
temp->setFixedSize(130, 80);
|
||||||
gridLayout->addWidget(temp, 0, 0);
|
gridLayout->addWidget(temp, 0, 0);
|
||||||
|
|
||||||
|
// Add Weekdays ontop of plan
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
QLabel* temp = new QLabel(m_weekdays[i]);
|
QLabel* temp = new QLabel(m_weekdays[i]);
|
||||||
temp->setFixedSize(240, 80);
|
temp->setFixedSize(240, 80);
|
||||||
@@ -77,8 +66,9 @@ PlanGrid::PlanGrid(QWidget* parent)
|
|||||||
gridLayout->addWidget(temp, 0, i + 1);
|
gridLayout->addWidget(temp, 0, i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add times left to plan
|
||||||
for (int i = 0; i < 5; i++) {
|
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->setFixedSize(130, 100);
|
||||||
temp->setObjectName("temp");
|
temp->setObjectName("temp");
|
||||||
if (i == 4) {
|
if (i == 4) {
|
||||||
@@ -103,6 +93,9 @@ PlanGrid::PlanGrid(QWidget* parent)
|
|||||||
gridLayout->addWidget(temp, i + 1, 0);
|
gridLayout->addWidget(temp, i + 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
planMap = planGridController->getVeranstaltungen( );
|
||||||
|
populateGrid( );
|
||||||
|
|
||||||
gridLayout->setSpacing(0);
|
gridLayout->setSpacing(0);
|
||||||
setLayout(gridLayout);
|
setLayout(gridLayout);
|
||||||
}
|
}
|
||||||
@@ -110,7 +103,25 @@ PlanGrid::PlanGrid(QWidget* parent)
|
|||||||
void PlanGrid::populateGrid( ) {
|
void PlanGrid::populateGrid( ) {
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int j = 0; j < 5; ++j) {
|
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,
|
||||||
|
m_times[j].toStdString( )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
planMap = planGridController->getVeranstaltungen( );
|
||||||
|
populateGrid( );
|
||||||
|
});
|
||||||
|
}
|
||||||
if (i == 4 && j == 4) {
|
if (i == 4 && j == 4) {
|
||||||
(planMap->value(qMakePair(m_weekdays[i], m_times[j])))->setStyleSheet(R"(
|
(planMap->value(qMakePair(m_weekdays[i], m_times[j])))->setStyleSheet(R"(
|
||||||
border-bottom-right-radius:10px;
|
border-bottom-right-radius:10px;
|
||||||
|
|||||||
@@ -6,20 +6,29 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "../../Controller/PlanGridController/PlanGridController.hpp"
|
#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 {
|
class PlanGrid : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString m_weekdays[5];
|
QString m_weekdays[5];
|
||||||
QString m_times[5];
|
QString m_times[6];
|
||||||
|
|
||||||
void populateGrid( );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QGridLayout* gridLayout;
|
QGridLayout* gridLayout;
|
||||||
QMap<QPair<QString, QString>, QLabel*>* planMap;
|
QMap<QPair<QString, QString>, QWidget*>* planMap;
|
||||||
|
|
||||||
|
void KrankmeldenDialog( );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlanGrid(QWidget* parent = nullptr);
|
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( );
|
|
||||||
};
|
|
||||||
14
src/main.cpp
14
src/main.cpp
@@ -1,10 +1,10 @@
|
|||||||
# include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
# include "View/LoginWindow/LoginWindow.hpp"
|
#include "View/LoginWindow/LoginWindow.hpp"
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
int main(int argc, char* argv[]) {
|
||||||
QApplication app(argc,argv);
|
QApplication app(argc, argv);
|
||||||
LoginWindow* loginWindow = new LoginWindow();
|
LoginWindow* loginWindow = new LoginWindow( );
|
||||||
loginWindow->show();
|
loginWindow->show( );
|
||||||
return app.exec();
|
return app.exec( );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user