210 lines
11 KiB
C#
210 lines
11 KiB
C#
using domain.UseCase;
|
||
using System;
|
||
using data.Repository;
|
||
using System.Globalization;
|
||
using domain.UseCase;
|
||
using ui;
|
||
|
||
namespace ui
|
||
{
|
||
public class MainMenuUI
|
||
{
|
||
private readonly UserConsoleUI _userConsoleUI;
|
||
private readonly GroupConsoleUI _groupConsoleUI;
|
||
private readonly PresenceConsoleUI _presenceConsoleUI;
|
||
|
||
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, PresenceUseCase presenceUseCase)
|
||
{
|
||
_userConsoleUI = new UserConsoleUI(userUseCase, groupUseCase);
|
||
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
|
||
_presenceConsoleUI = new PresenceConsoleUI(presenceUseCase);
|
||
}
|
||
|
||
public void DisplayMenu()
|
||
{
|
||
while (true)
|
||
{
|
||
Console.WriteLine("\n=-= Главное меню =-=\n");
|
||
|
||
Console.WriteLine("=-= Команды с Пользователями =-=");
|
||
Console.WriteLine("1. Вывести всех пользователей");
|
||
Console.WriteLine("2. Удалить пользователя по id");
|
||
Console.WriteLine("3. Обновить пользователя по id");
|
||
Console.WriteLine("4. Найти пользователя по id");
|
||
Console.WriteLine();
|
||
|
||
Console.WriteLine("=-= Команды с Группами =-=");
|
||
Console.WriteLine("5. Вывести все группы");
|
||
Console.WriteLine("6. Добавить группу");
|
||
Console.WriteLine("7. Изменить название группы");
|
||
Console.WriteLine("8. Поиск группы по ID");
|
||
Console.WriteLine();
|
||
Console.WriteLine("=-= Команды Presence =-=");
|
||
Console.WriteLine("9. Сгенерировать посещаемость на день");
|
||
Console.WriteLine("10. Сгенерировать посещаемость на неделю");
|
||
Console.WriteLine("11. Показать посещаемость");
|
||
Console.WriteLine("12. Отметить пользователя как отсутствующего");
|
||
Console.WriteLine("13. Вывести всю посещаемость группы");
|
||
Console.WriteLine("14. Вывести общую информацию об посещаемости по группе");
|
||
Console.WriteLine("15. Вывести отчётв Excel");
|
||
Console.WriteLine();
|
||
Console.WriteLine("0. Выход");
|
||
|
||
Console.Write("\nВаш выбор: ");
|
||
string comand = Console.ReadLine();
|
||
Console.WriteLine();
|
||
|
||
switch (comand)
|
||
{
|
||
case "1":
|
||
// Отображение всех пользователей
|
||
_userConsoleUI.ShowAllUsers();
|
||
break;
|
||
|
||
case "2":
|
||
// Удаление пользователя по ID
|
||
Console.Write("Введите ID пользователя для удаления: ");
|
||
_userConsoleUI.DeleteUser();
|
||
break;
|
||
|
||
case "3":
|
||
// Обновление пользователя по ID
|
||
Console.Write("Введите ID пользователя для обновления: ");
|
||
_userConsoleUI.EditUser();
|
||
break;
|
||
|
||
case "4":
|
||
// Поиск пользователя по ID
|
||
Console.Write("Введите ID пользователя для поиска: ");
|
||
string? findIdInput = Console.ReadLine();
|
||
if (int.TryParse(findIdInput, out int findUserId))
|
||
{
|
||
_userConsoleUI.FindUser();
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("Неверный формат ID");
|
||
}
|
||
break;
|
||
|
||
case "5":
|
||
// Отображение всех групп
|
||
_groupConsoleUI.ShowAllGroups();
|
||
break;
|
||
|
||
case "6":
|
||
// Добавление новой группы
|
||
Console.Write("Введите название новой группы: ");
|
||
string newGroupName = Console.ReadLine();
|
||
_groupConsoleUI.CreateNewGroup(newGroupName);
|
||
break;
|
||
|
||
case "7":
|
||
// Изменение названия группы
|
||
Console.Write("Введите ID группы для изменения: ");
|
||
if (int.TryParse(Console.ReadLine(), out int groupId))
|
||
{
|
||
Console.Write("Введите новое название группы: ");
|
||
string newName = Console.ReadLine();
|
||
_groupConsoleUI.RenameGroup(groupId, newName);
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("Неверный формат ID группы");
|
||
}
|
||
break;
|
||
|
||
case "8":
|
||
// Поиск группы
|
||
Console.Write("Введите ID группы для поиска : ");
|
||
if (int.TryParse(Console.ReadLine(), out int IdGroup))
|
||
{
|
||
_groupConsoleUI.ShowGroupDetails(IdGroup);
|
||
}
|
||
break;
|
||
|
||
case "9":
|
||
Console.Write("Введите ID группы: ");
|
||
int GroupId = int.Parse(Console.ReadLine());
|
||
Console.Write("Первое занятие: ");
|
||
int first = int.Parse(Console.ReadLine());
|
||
Console.Write("Последнее занятие: ");
|
||
int last = int.Parse(Console.ReadLine());
|
||
|
||
_presenceConsoleUI.GenerateDailyAttendance(GroupId, first, last, DateTime.Today);
|
||
break;
|
||
|
||
case "10":
|
||
// Генерация посещаемости на неделю
|
||
Console.Write("Введите номер первого занятия: ");
|
||
int firstLessonForWeek = int.Parse(Console.ReadLine());
|
||
Console.Write("Введите номер последнего занятия: ");
|
||
int lastLessonForWeek = int.Parse(Console.ReadLine());
|
||
Console.Write("Введите ID группы: ");
|
||
int groupIdForWeekPresence = int.Parse(Console.ReadLine());
|
||
|
||
_presenceConsoleUI.GenerateWeeklyAttendance(groupIdForWeekPresence, firstLessonForWeek, lastLessonForWeek, DateTime.Now);
|
||
Console.WriteLine("Посещаемость на неделю сгенерирована.");
|
||
break;
|
||
|
||
case "11":
|
||
Console.Write("Дата (дд.мм.гггг): ");
|
||
DateTime date = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
|
||
Console.Write("ID группы: ");
|
||
int group = int.Parse(Console.ReadLine());
|
||
|
||
_presenceConsoleUI.ShowAttendance(date, group);
|
||
break;
|
||
|
||
case "12":
|
||
// Отметить пользователя как отсутствующего
|
||
Console.Write("Введите ID пользователя: ");
|
||
int userId = int.Parse(Console.ReadLine());
|
||
Console.Write("Введите номер первого занятия: ");
|
||
int firstAbsLesson = int.Parse(Console.ReadLine());
|
||
Console.Write("Введите номер последнего занятия: ");
|
||
int lastAbsLesson = int.Parse(Console.ReadLine());
|
||
Console.Write("Введите ID группы: ");
|
||
int absGroupId = int.Parse(Console.ReadLine());
|
||
|
||
Console.Write("Введите дату (дд.мм.гггг): ");
|
||
string dateInput = Console.ReadLine();
|
||
DateTime absenceDate;
|
||
|
||
if (!DateTime.TryParseExact(dateInput, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out absenceDate))
|
||
{
|
||
Console.WriteLine("Ошибка: Введен некорректный формат даты. Пожалуйста, используйте формат дд.мм.гггг.");
|
||
return; // Завершает выполнение, если дата некорректна
|
||
}
|
||
_presenceConsoleUI.MarkAbsence(userId,absGroupId, absenceDate, firstAbsLesson, lastAbsLesson);
|
||
break;
|
||
case "13":
|
||
Console.Write("Введите ID группы: ");
|
||
int groupIdForAllPresence = int.Parse(Console.ReadLine());
|
||
_presenceConsoleUI.ShowFullGroupAttendance(groupIdForAllPresence);
|
||
break;
|
||
|
||
case "14":
|
||
Console.Write("Введите ID группы: ");
|
||
int searchGroupId = int.Parse(Console.ReadLine());
|
||
_presenceConsoleUI.DisplayGeneralPresence(searchGroupId);
|
||
break;
|
||
case "15":
|
||
Console.Write("ID группы: ");
|
||
int exportGroup = int.Parse(Console.ReadLine());
|
||
|
||
_presenceConsoleUI.ExportToExcel(exportGroup);
|
||
break;
|
||
case "0":
|
||
Console.WriteLine("Выход...");
|
||
return;
|
||
|
||
default:
|
||
Console.WriteLine("Неверный выбор, попробуйте снова.");
|
||
break;
|
||
}
|
||
Console.WriteLine();
|
||
}
|
||
}
|
||
}
|
||
} |