-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorker.cs
395 lines (366 loc) · 18.5 KB
/
Worker.cs
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
385
386
387
388
389
390
391
392
393
394
395
using ApplicationsExceptionNamespace;
using Helper;
using StartNamespace;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace EntityNamespace
{
public class Worker : Human
{
public List<CV> CVs { get; set; } = new List<CV>();
public Worker(string name, string surname, string username, string password, string city, string phone, int age)
: base(name, surname, age, username, password, city, phone)
{
}
public Worker(Human currentUser)
: base(currentUser.Name, currentUser.Surname, currentUser.Age, currentUser.Username, currentUser.Password, currentUser.City, currentUser.Phone)
{
}
public void ApplyForJob(Worker worker)
{
List<Vacancy> vacancies = new List<Vacancy>();
foreach (var employer in GlobalData.database.Employers)
{
vacancies.AddRange(employer.Vacancies);
}
int size = vacancies.Count + 1;
ConsoleColor[] Set = new ConsoleColor[size];
int counter = 0;
while (true)
{
//Console.SetWindowPosition(0, 6 + counter + 5);
Console.Clear();
Console.CursorVisible = false;
VisualHelper.ShowVacanciesScript();
for (int i = 0; i < size; i++)
{
if (i == counter)
{
Set[i] = ConsoleColor.Yellow;
}
else
{
Set[i] = ConsoleColor.White;
}
}
for (int x = 0; x < size - 1; x++)
{
string frame = vacancies[x].Name.FrameTheWord();
Console.ForegroundColor = Set[x];
Console.WriteLine(frame);
}
Console.ForegroundColor = Set[size - 1];
string backFrame = "BACK".FrameTheWord();
Console.WriteLine(backFrame);
Console.SetCursorPosition(0, counter * 2);
Console.WriteLine("");
var key = Console.ReadKey();
if (key.Key == ConsoleKey.UpArrow && counter != 0)
{
counter--;
}
else if (key.Key == ConsoleKey.DownArrow && counter != size - 1)
{
counter++;
}
else if (key.Key == ConsoleKey.Enter)
{
if (counter == size - 1)
break;
try
{
Console.Clear();
vacancies[counter].ShowVacancy(worker);
}
catch (DetailedException ex)
{
FileHelper.WriteExceptionToFile(ex);
}
}
}
}
public void SeeMyCVs()
{
try
{
int size = CVs.Count;
if (size == 0)
{
StackFrame callStack = new StackFrame(1, true);
string currentFile = new StackTrace(true).GetFrame(0).GetFileName();
Warning.Message("YOU DON'T HAVE ANY CV. PLEASE, CREATE CV.");
throw new DetailedException($"{Name} {Surname} does not have CV.", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
else
{
size++;
ConsoleColor[] Set = new ConsoleColor[size];
int counter = 0;
while (true)
{
Console.Clear();
Console.CursorVisible = false;
VisualHelper.ShowMyCVsScript();
for (int i = 0; i < size; i++)
{
if (i == counter)
{
Set[i] = ConsoleColor.Yellow;
}
else
{
Set[i] = ConsoleColor.White;
}
}
for (int x = 0; x < size - 1; x++)
{
Console.ForegroundColor = Set[x];
string cvFrame = $"CV {x + 1}".FrameTheWord();
Console.WriteLine(cvFrame);
}
Console.ForegroundColor = Set[size - 1];
string backFrame = "BACK".FrameTheWord();
Console.WriteLine(backFrame);
Console.SetCursorPosition(0, counter * 2);
Console.WriteLine("");
var key = Console.ReadKey();
if (key.Key == ConsoleKey.UpArrow && counter != 0)
{
counter--;
}
else if (key.Key == ConsoleKey.DownArrow && counter != size - 1)
{
counter++;
}
else if (key.Key == ConsoleKey.Enter)
{
if (counter == size - 1)
break;
Console.Clear();
VisualHelper.ShowMyCVScript();
Console.WriteLine(CVs[counter]);
Warning.PressAnyKey();
}
}
}
}
catch (DetailedException ex)
{
FileHelper.WriteExceptionToFile(ex);
}
}
public void AddCV()
{
Console.ForegroundColor = ConsoleColor.White;
while (true)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.SetCursorPosition(0, 10);
Console.WriteLine(@"
╔════════════════════════════════════════════════════╗
║ ║
║ DO YOU WANT TO ADD CV ? ║
║ ║
║ YES (ENTER) | NO (ESC) ║
║ ║
╚════════════════════════════════════════════════════╝");
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Escape)
{
break;
}
else if (key.Key == ConsoleKey.Enter)
{
Console.CursorVisible = true;
Console.Clear();
VisualHelper.ShowAddingCVScript();
StackFrame callStack = new StackFrame(1, true);
string currentFile = new StackTrace(true).GetFrame(0).GetFileName();
Console.Write("\n ENTER SPECIALITY : ");
string speciality = Console.ReadLine();
if (string.IsNullOrWhiteSpace(speciality))
{
Warning.Message("SPECIALITY WAS NOT FILLED!");
throw new DetailedException("While Filling CV, Speciality Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n ENTER SCHOOL NAME : ");
string school = Console.ReadLine();
if (string.IsNullOrWhiteSpace(school))
{
Warning.Message("SCHOOL WAS NOT FILLED!");
throw new DetailedException("While Filling CV, School Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n ENTER YOUR SCORE : ");
int score;
bool converted = int.TryParse(Console.ReadLine(), out score);
if (converted)
{
if (score < 0 || score > 100)
{
Warning.Message("INCORRECT SCORE WAS ENTERED! (SCORE SHOULD BE BETWEEEN 0 AND 100)");
throw new DetailedException("While Filling CV, Incorrect Score Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
}
else
{
Warning.Message("INCORRECT SCORE WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect Score Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n ENTER YOUR NUMBER OF SKILLS: ");
int numberOfSkils;
converted = int.TryParse(Console.ReadLine(), out numberOfSkils);
List<string> skills = new List<string>();
if (converted)
{
for (int x = 0; x < numberOfSkils; x++)
{
Console.Write($" ENTER YOUR SKILL {x + 1} : ");
string skill = Console.ReadLine();
if (string.IsNullOrEmpty(skill))
{
Warning.Message("SKILL WAS NOT FILLED!");
throw new DetailedException("While Filling CV, Skill Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
skills.Add(skill);
}
}
else
{
Warning.Message("INCORRECT NUMBER OF SKILLS WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect Number Of Skills Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
int numberOfCompanies;
Console.Write("\n ENTER NUMBER OF COMPANIES YOU WORKED : ");
converted = int.TryParse(Console.ReadLine(), out numberOfCompanies);
Dictionary<string, Dictionary<string, string>> CompaniesWorked = new Dictionary<string, Dictionary<string, string>>();
if (converted)
{
for (int y = 0; y < numberOfCompanies; y++)
{
Console.Write($" ENTER NAME OF COMPANY {y + 1}: ");
string companyName = Console.ReadLine();
if (string.IsNullOrEmpty(companyName))
{
Warning.Message("COMPANY NAME WAS NOT FILLED!");
throw new DetailedException("While Filling CV, Company Name Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
DateTime startDate;
Console.Write($" ENTER START DATE OF WORK IN {companyName.ToUpper()} : ");
string startDateString = Console.ReadLine();
converted = DateTime.TryParse(startDateString, out startDate);
if (converted)
{
DateTime endDate;
Console.Write($" ENTER END DATE OF WORK IN {companyName.ToUpper()} : ");
string endDateString = Console.ReadLine();
converted = DateTime.TryParse(endDateString, out endDate);
if (converted)
{
if (startDate < endDate)
{
var dates = new Dictionary<string, string>();
dates.Add(startDate.ToLongDateString(), endDate.ToLongDateString()); ;
CompaniesWorked.Add(companyName, dates);
}
else
{
Warning.Message("INCORRECT DATES WERE ENTERED (THE END DATE COMES BEFORE THE START DATE)!");
throw new DetailedException("While Filling CV, Incorrect Dates Was Entered (The end date comes before the start date)!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
}
else
{
Warning.Message("INCORRECT END OF WORK WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect End Date Of Work Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
}
else
{
Warning.Message("INCORRECT START DATE OF WORK WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect Start Date Of Work Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.WriteLine();
}
}
else
{
Warning.Message("INCORRECT NUMBER OF COMPANIES WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect Number Of Companies Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n ENTER NUMBER OF LANGUAGES YOU KNOW : ");
int numberOfLanguages;
converted = int.TryParse(Console.ReadLine(), out numberOfLanguages);
Dictionary<string, string> languages = new Dictionary<string, string>();
if (converted)
{
for (int z = 0; z < numberOfLanguages; z++)
{
Console.Write(" ENTER LANGUAGE : ");
string language = Console.ReadLine();
if (string.IsNullOrEmpty(language))
{
Warning.Message("LANGUAGE WAS NOT FILLED!");
throw new DetailedException("While Filling CV, Language Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write(" ENTER LEVEL : ");
string languageLevel = Console.ReadLine();
if (string.IsNullOrEmpty(languageLevel))
{
Warning.Message("LANGUAGE LEVEL WAS NOT FILLED!");
throw new DetailedException("While Filling CV, Language Level Was Not Filled!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
languages.Add(language, languageLevel);
Console.WriteLine();
}
}
else
{
Warning.Message("INCORRECT NUMBER OF LANGUAGES WAS ENTERED!");
throw new DetailedException("While Filling CV, Incorrect Number Of Languages Was Entered!", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n DO YOU HAVE HONOR DIPLOMA ? (YES (1) | NO (2)): ");
string hasHonorDiplomaString = Console.ReadLine();
hasHonorDiplomaString = hasHonorDiplomaString.Trim();
bool hasHonorDiploma = false;
if (hasHonorDiplomaString == "1")
{
hasHonorDiploma = true;
}
else if (hasHonorDiplomaString == "2")
{
hasHonorDiploma = false;
}
else
{
Warning.Message("INCORRECT INPUT WAS ENTERED");
throw new DetailedException("Incorrect Input Was Entered While Answering The Question About Honor Diploma", DateTime.Now, callStack.GetFileLineNumber(), currentFile);
}
Console.Write("\n ENTER YOUR GITLINK (OPTIONAL) : ");
string gitlink = Console.ReadLine();
Console.Write("\n ENTER YOUR LINKEDIN (OPTIONAL) : ");
string linkedin = Console.ReadLine();
CV cv = new CV()
{
Speciality = speciality,
School = school,
Score = score,
Skills = skills,
CompaniesWorked = CompaniesWorked,
Languages = languages,
HasHonorsDiploma = hasHonorDiploma,
Gitlink = gitlink,
Linkedin = linkedin
};
CVs.Add(cv);
JsonSerialization.SerializeDatabase(GlobalData.database);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("\n CV Was Successfully Created And Added To Your CVs!");
Warning.PressAnyKey();
Console.CursorVisible = false;
break;
}
}
}
}
}