-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
192 lines (174 loc) · 5.45 KB
/
Copy pathmain.cpp
File metadata and controls
192 lines (174 loc) · 5.45 KB
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
#include "exceptions.h"
#include "mysystem.h"
#include "user.h"
class User;
System* System::instance = NULL;
int System::n = 0;
int main() {
bool exit = false;
while (!exit) {
System* client = System::get_instance();
client->file_to_vect();
string input;
cin >> input;
///////////////////////////////////////////
if (input == "login") {
if (client->get_is_login() == false) {
string username;
string password;
cin >> username >> password;
try {
client->login(username, password);
cout << "You are Login Now!" << endl;
}
catch (WrongPasswordException) { cout << "Wrong Password!" << endl; }
catch (InvalidUsernameException) { cout << "This Username is Invalid!" << endl; }
}
else
cout << "Invalid Input ! You were already loged in" << endl;
}
////////////////////////////////////////////
if (input == "logout") {
if (client->get_is_login() == true) {
client->logout();
cout << "You are Logout Now!" << endl;
}
else
cout << "You must First Login!" << endl;
}
////////////////////////////////////////////
if (input == "register") {
if (client->get_is_login() == true) {
if (client->get_login()->get_role() == "admin") {
string role;
string username;
string password;
cin >> role >> username >> password;
try {
client->register_user(role, username, password);
cout << "Register Done!" << endl;
}
catch (ReiterativeUserException) { cout << "Register Failed! Reiterative User!" << endl; }
catch (InvalidRoleInputException) { cout << "Invalid Role Input!" << endl; }
}
else
cout << "Unauthorized Access!" << endl;
}
else
cout << "You must First Login!" << endl;
}
//////////////////////////////////////////
if (input == "add") {
if (client->get_is_login() == true) {
string proj_name;
string proj_addr;
cin >> proj_name >> proj_addr;
try {
client->add_proj(proj_name, proj_addr);
cout << "Project Created !" << endl;
}
catch (ReiterativeProjectNameException) { cout << "This name is existed !" << endl; }
}
else
cout << "You must First Login!" << endl;
}
/////////////////////////////////////////
if (input == "hire") {
if (client->get_is_login() == true) {
string proj_name;
string programmer;
cin >> proj_name >> programmer;
bool is_exist = false;
vector<Project> projs = client->get_projects();
for (int i=0 ; i<projs.size() ; i++)
if (projs[i].get_proj_name() == proj_name) {
is_exist = true;
if (projs[i].get_proj_admin().get_username() == client->get_login()->get_username()) {
try {
projs[i].hire(client, programmer);
cout << "Programmer Hired!" << endl;
}
catch (InvalidUsernameHireException) { cout << "Invalid Username!" << endl; }
catch (ReiterativeProgrammerException) { cout << "Reiterative Programme!" << endl; }
}
else
cout << "Only project admins can hire!" << endl;
}
if (is_exist == false)
cout << "Invalid Project Name!" << endl;
}
else
cout << "You must First Login!" << endl;
}
/////////////////////////////////////////
if (input == "fire") {
if (client->get_is_login() == true) {
string proj_name;
string programmer;
cin >> proj_name >> programmer;
bool is_exist = false;
vector<Project> projs = client->get_projects();
for (int i=0 ; i<projs.size() ; i++)
if (projs[i].get_proj_name() == proj_name) {
is_exist = true;
if (projs[i].get_proj_admin().get_username() == client->get_login()->get_username()) {
try {
projs[i].fire(client, programmer);
cout << "Programmer Fired!" << endl;
}
catch (InvalidUsernameFireException) { cout << "Invalid Username!" << endl; }
catch (BadFireException) { cout << "The programmer that you want to add to project, is project admin!" << endl; }
}
else
cout << "Only project admins can fire!" << endl;
}
if (is_exist == false)
cout << "Invalid Project Name!" << endl;
}
else
cout << "You must First Login!" << endl;
}
//////////////////////////////////////////
if (input == "show") {
if (client->get_is_login() == true) {
string proj_name;
string unknown;
if (unknown == "-v" || unknown == "-a" || unknown == "-d") {
string par2;
string par3;
cin >> par2;
if (par2 == unknown) {
cout << "Reiterative parametr!" << endl;
break;
}
if (par2 == "-v" || par2 == "-a" || par2 == "-d") {
cin >> par3;
if (par3 == par2 || par3 == unknown) {
cout << "Reiterative parametr!" << endl;
break;
}
if (par3 == "-v" && par3 == "-a" && par3 == "-d") {
cout << "Invalid Parametr!" << endl;
break;
}
}
client->show(proj_name, unknown);
client->show(proj_name, par2);
client->show(proj_name, par3);
}
else if (client->is_file(unknown) == true)
client->show_file(proj_name, unknown);
else if (client->is_file(unknown) == false)
client->show_folder(proj_name, unknown);
}
else
cout << "You must First Login!" << endl;
}
/////////////////////////////////////////
if (input == "exit") {
client->vect_to_file();
exit = true;
}
} // while exit
return 0;
}