Last active
November 30, 2025 17:04
-
-
Save Attosius/469fea46e5ff19189709d6a0c1fbfc9a to your computer and use it in GitHub Desktop.
ДЗ: Кадровый учет продвинутый
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace IJuniorTasks | |
| { | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| const string CommandAddRecord = "1"; | |
| const string CommandShowAllRecords = "2"; | |
| const string CommandRemoveRecord = "3"; | |
| const string CommandFindRecords = "4"; | |
| const string CommandExit = "5"; | |
| bool isWork = true; | |
| var usersPositions = new Dictionary<string, List<string>>(); | |
| usersPositions["Прогер"] = new List<string>() | |
| { | |
| "Петров Антон Игоревич", | |
| "Смирнов Павел Андреевич", | |
| "Копылов" | |
| }; | |
| usersPositions["Юзер"] = new List<string>() | |
| { | |
| "Папин Игорь Игоревич", | |
| "Дарья Андреевич" | |
| }; | |
| while (isWork) | |
| { | |
| Console.WriteLine($"\n\nВведите команду:"); | |
| Console.WriteLine($"{CommandAddRecord}. Добавить досье"); | |
| Console.WriteLine($"{CommandShowAllRecords}. Показать все досье"); | |
| Console.WriteLine($"{CommandRemoveRecord}. Удалить досье"); | |
| Console.WriteLine($"{CommandFindRecords}. Найти досье"); | |
| Console.WriteLine($"{CommandExit}. Выход"); | |
| Console.WriteLine(); | |
| var command = Console.ReadLine(); | |
| switch (command) | |
| { | |
| case CommandAddRecord: | |
| AddRecord(usersPositions); | |
| break; | |
| case CommandShowAllRecords: | |
| ShowRecords(usersPositions); | |
| break; | |
| case CommandRemoveRecord: | |
| RemoveRecord(usersPositions); | |
| break; | |
| case CommandFindRecords: | |
| FindRecordsBySurname(usersPositions); | |
| break; | |
| case CommandExit: | |
| isWork = false; | |
| break; | |
| default: | |
| Console.WriteLine($"Некорректная команда!"); | |
| break; | |
| } | |
| } | |
| } | |
| private static void AddRecord(Dictionary<string, List<string>> usersPositions) | |
| { | |
| Console.WriteLine($"\n\nВведите Фамилию Имя и Отчество:"); | |
| var userFullName = Console.ReadLine(); | |
| Console.WriteLine($"Введите должность:"); | |
| var userPosition = Console.ReadLine(); | |
| if (!usersPositions.ContainsKey(userPosition)) | |
| { | |
| usersPositions[userPosition] = new List<string>(); | |
| } | |
| usersPositions[userPosition].Add(userFullName); | |
| Console.WriteLine($"Досье с ФИО {userFullName} и должностью {userPosition} успешно добавлено"); | |
| } | |
| private static void ShowRecords(Dictionary<string, List<string>> usersPositions) | |
| { | |
| int positionIndex = 0; | |
| int userIndex = 0; | |
| foreach (var usersPositionsKey in usersPositions.Keys) | |
| { | |
| positionIndex++; | |
| Console.WriteLine($"{positionIndex}. Должность {usersPositionsKey}."); | |
| foreach (var user in usersPositions[usersPositionsKey]) | |
| { | |
| userIndex++; | |
| Console.WriteLine($"\t{userIndex}. {user}."); | |
| } | |
| } | |
| } | |
| private static void RemoveRecord(Dictionary<string, List<string>> usersPositions) | |
| { | |
| ShowRecords(usersPositions); | |
| Console.WriteLine($"Введите должность сотрудника, которого надо удалить:"); | |
| var usersPositionsKey = Console.ReadLine(); | |
| if (!usersPositions.ContainsKey(usersPositionsKey)) | |
| { | |
| Console.WriteLine($"Должность не найдена"); | |
| return; | |
| } | |
| var users = usersPositions[usersPositionsKey]; | |
| int userIndex = 0; | |
| foreach (var user in users) | |
| { | |
| userIndex++; | |
| Console.WriteLine($"{userIndex}. {user}."); | |
| } | |
| Console.WriteLine($"Введите индекс сотрудника для удаления:"); | |
| var indexToRemoveString = Console.ReadLine(); | |
| if (int.TryParse(indexToRemoveString, out var indexToRemove) == false || users.Count + 1 < indexToRemove ) | |
| { | |
| Console.WriteLine($"Некорректный индекс для удаления!"); | |
| return; | |
| } | |
| string userNameToRemove = string.Empty; | |
| userIndex = 0; | |
| foreach (var user in users) | |
| { | |
| userIndex++; | |
| if (userIndex == indexToRemove) | |
| { | |
| userNameToRemove = user; | |
| } | |
| } | |
| if (!string.IsNullOrWhiteSpace(userNameToRemove)) | |
| { | |
| users.Remove(userNameToRemove); | |
| Console.WriteLine($"Досье с ФИО {userNameToRemove} успешно удалено"); | |
| if (users.Count == 0) | |
| { | |
| usersPositions.Remove(usersPositionsKey); | |
| } | |
| } | |
| else | |
| { | |
| Console.WriteLine($"Досье с индексом {indexToRemove} не найдено"); | |
| } | |
| } | |
| private static void FindRecordsBySurname(Dictionary<string, List<string>> usersPositions) | |
| { | |
| Console.WriteLine($"Введите фамилию для поиска:"); | |
| var surnameToFind = Console.ReadLine(); | |
| bool isFind = false; | |
| var userIndex = 0; | |
| foreach (var usersPositionsKey in usersPositions.Keys) | |
| { | |
| foreach (var user in usersPositions[usersPositionsKey]) | |
| { | |
| var surname = user.Split(' ')[0]; | |
| if (surname.Contains(surnameToFind, StringComparison.OrdinalIgnoreCase)) | |
| { | |
| Console.WriteLine($"{++userIndex}. ФИО: {user}. Должность: {usersPositionsKey}"); | |
| isFind = true; | |
| } | |
| } | |
| } | |
| if (isFind == false) | |
| { | |
| Console.WriteLine($"Досье с фамилией {surnameToFind} не найдено"); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment