-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgendaUI.cpp
385 lines (337 loc) · 9.86 KB
/
AgendaUI.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include "AgendaUI.hpp"
#include "Storage.cpp"
#include "User.cpp"
#include "Date.cpp"
#include "Meeting.cpp"
#include "AgendaService.cpp"
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
AgendaUI::AgendaUI()
{
startAgenda();
}
void AgendaUI::OperationLoop(void)
{
string op;
do
{
cout << "-------------------------Agenda---------------------------" << endl;
cout << "action:" << endl;
cout << "l -log in Agenda by user name and password" << endl;
cout << "r -register an Agenda account" << endl;
cout << "q -quit Agenda" << endl;
cout << "----------------------------------------------------------" << endl
<< endl;
cout << "Agenda :~$";
cin >> op;
if(op == "l")
userLogIn();
if(op == "r")
userRegister();
if(op == "q")
quitAgenda();
} while (op != "q");
}
void AgendaUI::startAgenda(void)
{
m_agendaService.startAgenda();
}
std::string AgendaUI::getOperation()
{
cout << "-------------------------Agenda---------------------------" << endl;
cout << "Action:" << endl;
cout << "o -log out Agenda" << endl;
cout << "dc -delete Agenda user" << endl;
cout << "lu -list all agenda user" << endl;
cout << "cm -create a meeting" << endl;
cout << "amp -add meeting participator" << endl;
cout << "rmp -remove meeting participator" << endl;
cout << "rqm -request to quit meeting" << endl;
cout << "la -list all meeings" << endl;
cout << "las -list all sponsor meetings" << endl;
cout << "lap -list all participator meetings" << endl;
cout << "qm -query meeting by title" << endl;
cout << "qt -query meeting by time interval" << endl;
cout << "dm -delete meeting by title" << endl;
cout << "da -delete all meetings" << endl;
cout << "----------------------------------------------------------" << endl << endl;
cout << "Agenda@" << m_userName << " :~# ";
string op;
cin >> op;
return op;
}
bool AgendaUI::executeOperation(std::string t_operation)
{
if(t_operation == "o")
{
userLogOut();
return false;
}
if(t_operation == "dc")
{
deleteUser();
return false;
}
if(t_operation == "lu")
{
listAllUsers();
return true;
}
if(t_operation == "cm")
{
createMeeting();
return true;
}
if(t_operation == "amp")
{
addMeetingParticipator();
return true;
}
if(t_operation == "rmp")
{
removeMeetingParticipator();
return true;
}
if(t_operation == "rqm")
{
quitMeeting();
return true;
}
if(t_operation == "la")
{
listAllMeetings();
return true;
}
if(t_operation == "las")
{
listAllSponsorMeetings();
return true;
}
if(t_operation == "lap")
{
listAllParticipateMeetings();
return true;
}
if(t_operation == "qm")
{
queryMeetingByTitle();
return true;
}
if(t_operation == "qt")
{
queryMeetingByTimeInterval();
return true;
}
if(t_operation == "dm")
{
deleteMeetingByTitle();
return true;
}
if(t_operation == "da")
{
deleteAllMeetings();
return true;
}
return false;
}
void AgendaUI::userLogIn(void)
{
cout << endl;
cout << "[log in] [username] [password]" << endl;
cout << "[log in] " ;
string username, password;
cin >> username >> password;
if(m_agendaService.userLogIn(username, password))
{
cout << "[log in] succeed!" << endl;
m_userName = username;
m_userPassword = password;
while(executeOperation(getOperation()));
}
else
cout << "[log in] Password error or user dosen't exist" << endl;
}
void AgendaUI::userRegister(void)
{
cout << endl;
cout << "[register] [username] [password] [email] [phone]" << endl;
cout << "[register] " ;
string username, password, email, phone;
cin >> username >> password >> email >> phone;
if(m_agendaService.userRegister(username, password, email, phone))
cout << "[register] succeed" << endl;
else
cout << "[register] This user name has been registerd!" << endl;
}
void AgendaUI::userLogOut(void)
{
m_userName = "";
m_userPassword = "";
}
void AgendaUI::quitAgenda(void)
{
m_agendaService.quitAgenda();
}
void AgendaUI::deleteUser(void)
{
if(m_agendaService.deleteUser(m_userPassword, m_userPassword))
{
cout << "[delete agenda account] succeed!" << endl;
}
userLogOut();
}
void AgendaUI::listAllUsers(void)
{
list<User> user = m_agendaService.listAllUsers();
cout << endl;
cout << "[list all users]" << endl << endl;
cout << left << setw(15) << "name" << left << setw(25) << "email" << "phone" << endl;
for(auto it = user.begin(); it != user.end(); ++it)
{
cout << left << setw(15) << (*it).getName() << left << setw(25) << (*it).getEmail() << (*it).getPhone() << endl;
}
}
void AgendaUI::createMeeting(void)
{
cout << endl;
cout << "[create meeting] [the number of participators]" << endl;
int num;
cout << "[create meeting] ";
cin >> num;
vector<string> parts;
for(int i = 1; i <= num; ++i)
{
cout << "[create meeting] " << "[please enter the participator " << i << "]" << endl;
cout << "[create meeting] ";
string part;
cin >> part;
parts.push_back(part);
}
cout << "[create meeting] [title] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mmdd/hh:mm)]" << endl;
cout << "[create meeting] ";
string title, start, end;
cin >> title >> start >> end;
if(m_agendaService.createMeeting(m_userName, title, start, end, parts))
cout << "[create meeting] succeed!" << endl;
else
cout << "[create meeting] error!" << endl;
}
void AgendaUI::addMeetingParticipator(void)
{
cout << endl;
cout << "[add participator] [meeting title] [participator username]" << endl;
cout << "[add participator] ";
string title, participator;
cin >> title >> participator;
if(m_agendaService.addMeetingParticipator(m_userName, title, participator))
cout << "[add participator] succeed!" << endl;
else
cout << "[add participator] error!" << endl;
}
void AgendaUI::removeMeetingParticipator(void)
{
cout << endl;
cout << "[remove participator] [meeting title] [participator username]" << endl;
cout << "[remove participator] ";
string title, participator;
cin >> title >> participator;
if(m_agendaService.removeMeetingParticipator(m_userName, title, participator))
cout << "[remove participator] succeed!" << endl;
else
cout << "[remove participator] error!" << endl;
}
void AgendaUI::quitMeeting(void)
{
cout << endl;
cout << "[quit meeting] [meeting title]" << endl;
cout << "[quit meeting] ";
string title;
cin >> title;
if(m_agendaService.quitMeeting(m_userName, title))
cout << "[quit meeting] succeed!" << endl;
else
cout << "[quit meeting] error!" << endl;
}
void AgendaUI::listAllMeetings(void)
{
cout << endl;
cout << "[list all meetings]" << endl;
list<Meeting> meetings = m_agendaService.listAllMeetings(m_userName);
printMeetings(meetings);
}
void AgendaUI::listAllSponsorMeetings(void)
{
cout << endl;
cout << "[list all sponsor meetings]" << endl;
list<Meeting> meetings = m_agendaService.listAllSponsorMeetings(m_userName);
printMeetings(meetings);
}
void AgendaUI::listAllParticipateMeetings(void)
{
cout << endl;
cout << "[list all participator meetings]" << endl;
list<Meeting> meetings = m_agendaService.listAllParticipateMeetings(m_userName);
printMeetings(meetings);
}
void AgendaUI::queryMeetingByTitle(void)
{
cout << endl;
cout << "[query meeting] [title]" << endl;
cout << "[query meeting] ";
string title;
cin >> title;
list<Meeting> meetings = m_agendaService.meetingQuery(m_userName, title);
printMeetings(meetings);
}
void AgendaUI::queryMeetingByTimeInterval(void)
{
cout << endl;
cout << "[query meeting] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mm-dd/hh:mm)]" << endl;
cout << "[query meeting] ";
string start, end;
cin >> start >> end;
cout << "[query meeting]" << endl;
list<Meeting> meetings = m_agendaService.meetingQuery(m_userName, start, end);
printMeetings(meetings);
}
void AgendaUI::deleteMeetingByTitle(void)
{
cout << "[delete meeting] [title]" << endl;
cout << "[delete meeting] ";
string title;
if(m_agendaService.deleteMeeting(m_userName, title))
cout << "[delete meeting] succeed!" << endl;
else
cout << "[delete meeting] error!" << endl;
}
void AgendaUI::deleteAllMeetings(void)
{
if(m_agendaService.deleteAllMeetings(m_userName))
cout << "[delete all meeting] succeed!" << endl;
}
void AgendaUI::printMeetings(std::list<Meeting> t_meetings)
{
cout << endl;
cout << left << setw(15) << "title" << left << setw(12) << "sponsor"
<< left << setw(20) << "start date" << left << setw(20) << "end date" << left << setw(15) << "participators" << endl;
for(auto it = t_meetings.begin(); it != t_meetings.end(); ++it)
{
cout << left << setw(15) << (*it).getTitle() << left << setw(12) << (*it).getSponsor()
<< left << setw(20) << Date::dateToString((*it).getStartDate())
<< left << setw(20) << Date::dateToString((*it).getEndDate());
vector<string> participator = (*it).getParticipator();
for (int i = 0; i < participator.size(); ++i)
{
cout << participator[i];
if(i != participator.size() - 1)
cout << ',';
}
cout << endl;
}
}
int main(){
AgendaUI u;
u.OperationLoop();
}