-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeekly_Bulletin.cpp
116 lines (104 loc) · 3.9 KB
/
Weekly_Bulletin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "pch.h" // Include precompiled headers
#include "Weekly_Bulletin.h"
#include <fstream>
CString WeeklyBulletin::formatDate(std::time_t date) const {
char buffer[80];
struct tm timeinfo;
localtime_s(&timeinfo, &date); // Use localtime_s for safety
strftime(buffer, 80, "%B %d, %Y", &timeinfo);
return CString(buffer);
}
void WeeklyBulletin::setDates(std::time_t start, std::time_t end) {
startDate = start;
endDate = end;
}
void WeeklyBulletin::addBranch(const CString& name, Load load, const CString& customIndicator) {
Branch branch;
branch.name = name;
branch.predictedLoad = load;
branch.customIndicator = customIndicator;
branches.push_back(branch);
}
void WeeklyBulletin::addWarningToBranch(const CString& branchName, const CString& warning) {
for (auto& branch : branches) {
if (branch.name == branchName) {
branch.warnings.push_back(warning);
break;
}
}
}
void WeeklyBulletin::addTaskToBranch(const CString& branchName, const CString& category, Task& task) {
task.taskId = nextTaskId++; // Assign the next available task ID as an int
for (auto& branch : branches) {
if (branch.name == branchName) {
branch.categories[category].push_back(task);
return;
}
}
// Optionally handle the case where the branch isn't found.
}
void WeeklyBulletin::addSubTaskToTask(const CString& branchName, const CString& category, int taskId, const SubTask& subTask) {
for (auto& branch : branches) {
if (branch.name == branchName) {
auto& tasks = branch.categories[category];
for (auto& task : tasks) {
if (task.taskId == taskId) {
task.subTasks.push_back(subTask);
return;
}
}
}
}
// Optionally handle the case where the branch, category, or task isn't found.
}
CString WeeklyBulletin::printBulletin() const {
CString result_Display;
CString line;
line.Format(_T("Weekly Bulletin (%s to %s):\r\n"), formatDate(startDate), formatDate(endDate));
result_Display += line;
for (const auto& branch : branches) {
line.Format(_T(" %s ("), branch.name);
result_Display += line;
switch (branch.predictedLoad) {
case NoLoad:
line = _T("No load has been established");
break;
case LessLoad:
line = _T("Less load has been established");
break;
case NormalLoad:
line = _T("Normal load has been established");
break;
case HighLoad:
line = _T("High load has been established");
break;
}
if (!branch.customIndicator.IsEmpty()) {
line.AppendFormat(_T(", %s"), branch.customIndicator);
}
line += _T("):\r\n");
result_Display += line;
for (const auto& warning : branch.warnings) {
line.Format(_T(" Warning: %s\r\n"), warning);
result_Display += line;
}
for (const auto& category : branch.categories) {
line.Format(_T(" %s:\r\n"), category.first);
result_Display += line;
for (const auto& task : category.second) {
// Including task ID in the printout
line.Format(_T(" #%d - %s (Due %s)\r\n"), task.taskId, task.description, formatDate(task.dueDate));
result_Display += line;
for (const auto& subtask : task.subTasks) {
line.Format(_T(" * %s (Due %s)\r\n"), subtask.description, formatDate(subtask.dueDate));
result_Display += line;
}
for (const auto& warning : task.warnings) {
line.Format(_T(" Warning: %s\r\n"), warning);
result_Display += line;
}
}
}
}
return result_Display;
}