Renderer

  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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MTP_UManager
{
static class Renderer
{
public static void RenderNewPage()
{
Console.Clear();
Console.WriteLine("[Университет]");
Console.WriteLine();
}
public static string RenderMenu(string[] menuItems)
{
Console.WriteLine("Меню:");
for (int i = 0; i < menuItems.Length; i++)
{
Console.WriteLine($"{i + 1}. {menuItems[i]}");
}
Console.WriteLine();
Console.Write("Ввод: ");
return Console.ReadLine();
}
// Login
public static void RenderLoginPageMessage()
{
RenderNewPage();
Console.WriteLine("Введите данные для входа в приложение");
Console.WriteLine();
DataManipulator.Login();
}
// Login -> Main Menu
public static void RenderMainPageMessage(Person user)
{
RenderNewPage();
Console.WriteLine($"Добро пожаловать, {user.Username}");
Console.WriteLine($"Ваш статус: {user.Status}");
Console.WriteLine();
}
public static void RenderMainPage(Person user)
{
RenderMainPageMessage(user);
DataManipulator.CheckUserChoiceInMainPageMenu(user, RenderMenu(DataGetter.GetMainPageMenuItems()));
}
public static void RenderLoginFailedError()
{
RenderNewPage();
Console.WriteLine("Введённой вами комбинации логига и пароля не существует!");
Console.WriteLine("Нажмите любую клавишу...");
Console.ReadKey();
RenderLoginPageMessage();
}
// Login -> Main Menu -> Courses List
public static void RenderCoursesListPageMessage(Person user)
{
RenderNewPage();
Console.WriteLine($"Список курсов для {user.Username}:");
Console.WriteLine();
}
public static void RenderCoursesListPage (Student user)
{
RenderCoursesListPageMessage(user);
foreach (string courseID in user.AvailableCoursesID)
{
GetCourseInfo(user, courseID);
}
DataManipulator.CheckUserChoiceInCoursesListPageMenu(user, RenderMenu(DataGetter.GetCoursesListPageMenuItems()));
}
public static void GetCourseInfo(Student user, string courseID) /**/
{
//TODO
// Get this information from the database by the ID of course.
string name = "None",
description = "None",
teacher = "None",
status = "None";
if (user.FinishedCoursesID.Contains(courseID))
status = "Завершен";
else if (user.TakenCoursesID.Contains(courseID))
status = "Изучается";
Console.WriteLine($"[{courseID}] {name}");
Console.WriteLine($"---ОПИСАНИЕ: {description}");
Console.WriteLine($"---ПРЕПОДАВАТЕЛЬ: {teacher}");
Console.WriteLine($"---СТАТУС: {status}");
}
// Login -> Main Menu -> Courses List -> Sign Up For Course
public static void RenderSignUpForCoursePageMessage(Student user)
{
RenderNewPage();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Запись на учебный курс");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Введите ID курса или return, чтобы вернуться назад");
Console.Write("Ввод: ");
string whatCourse = Console.ReadLine();
RenderSignUpForCoursePage(user, whatCourse);
}
public static void RenderSignUpForCoursePage(Student user, string whatCourse)
{
List<string> coursesIDArray = user.AvailableCoursesID;
bool doesCourseExist = false;
// Does the user want to return or else does exist the course he choosed?
if (whatCourse == "return")
{
RenderCoursesListPage(user);
return;
}
else
foreach (string courseID in coursesIDArray)
if (whatCourse == courseID)
{
doesCourseExist = true;
break;
}
// Let's sign up for that course!
if (doesCourseExist)
{
DataManipulator.SignUpForCourse(user, whatCourse);
RenderCoursesListPageMessage(user);
}
else
{
RenderSignUpForCoursePageMessage(user);
}
}
// Login -> Main Menu -> Courses List -> Leave Course
public static void RenderLeaveCoursePageMessage(Student user)
{
RenderNewPage();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Покинуть учебный курс");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Введите ID курса или return, чтобі вернуться назад");
Console.Write("Ввод: ");
string whatCourse = Console.ReadLine();
RenderLeaveCoursePage(user, whatCourse);
}
public static void RenderLeaveCoursePage(Student user, string whatCourse)
{
List<string> signedUpCoursesIDArray = user.TakenCoursesID;
bool doesCourseExist = false;
// Does the user want to return or else does exist the course he choosed?
if (whatCourse == "return")
{
RenderCoursesListPage(user);
return;
}
else
foreach (string courseID in signedUpCoursesIDArray)
if (whatCourse == courseID)
{
doesCourseExist = true;
break;
}
// Let's leave that course!
if (doesCourseExist)
{
DataManipulator.LeaveCourse(user, whatCourse);
RenderCoursesListPage(user);
}
else
{
RenderSignUpForCoursePageMessage(user);
}
}
// Login -> Main Menu -> Courses Stats
public static void RenderStudentStatsPageMessage(Student user)
{
RenderNewPage();
Console.WriteLine($"Статистика студента {user.Username}");
Console.WriteLine();
}
public static void RenderStudentStatsPage(Student user)
{
RenderStudentStatsPageMessage(user);
Console.WriteLine($"|Курсов на изучении | {user.TakenCoursesID.Count}|");
Console.WriteLine($"|Завершенных kурсов | {user.FinishedCoursesID.Count}|");
DataManipulator.CheckUserChoiceInStudentStatsPageMenu(user, RenderMenu(DataGetter.GetStudentStatsPageMenuItems()));
}
}
}