Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- public class Program
- {
- static void Main(string[] args)
- {
- const string AddDossierCommand = "1";
- const string ShowAllDossierCommand = "2";
- const string SearchLastnameCommand = "3";
- const string DeleteDossierCommand = "4";
- const string ExitProgrammCommand = "5";
- Dictionary<string, List<string>> positions = new Dictionary<string, List<string>>();
- bool isRunning = true;
- while (isRunning)
- {
- Console.WriteLine(
- $"{AddDossierCommand}) Добавить досье\n" +
- $"{ShowAllDossierCommand}) Вывести все досье\n" +
- $"{SearchLastnameCommand}) Поиск по фамилии\n" +
- $"{DeleteDossierCommand}) Удалить досье\n" +
- $"{ExitProgrammCommand}) Выход из программы\n");
- switch (Console.ReadLine())
- {
- case AddDossierCommand:
- AddDossier(positions);
- break;
- case ShowAllDossierCommand:
- ShowAllDossier(positions);
- break;
- case SearchLastnameCommand:
- SearchLastname(positions);
- break;
- case DeleteDossierCommand:
- DeleteDossier(positions);
- break;
- case ExitProgrammCommand:
- isRunning = false;
- break;
- }
- }
- }
- static void AddDossier(Dictionary<string, List<string>> positions)
- {
- Console.WriteLine("Введите ФИО сотрудника:");
- string fullName = Console.ReadLine();
- Console.WriteLine("Введите должность сотрудника:");
- string position = Console.ReadLine();
- if (positions.ContainsKey(position))
- {
- positions[position].Add(fullName);
- }
- else
- {
- positions[position] = new List<string> { fullName };
- }
- Console.WriteLine("Досье добавлено!");
- }
- static void ShowAllDossier(Dictionary<string, List<string>> positions)
- {
- if (positions.Count == 0)
- {
- Console.WriteLine("Досье отсутствуют.");
- return;
- }
- int index = 1;
- foreach (var position in positions)
- {
- Console.WriteLine($"Должность: {position.Key}");
- foreach (var employee in position.Value)
- {
- Console.WriteLine($"{index++}) {employee}");
- }
- Console.WriteLine();
- }
- }
- static void SearchLastname(Dictionary<string, List<string>> positions)
- {
- Console.WriteLine("Введите нужную фамилию для поиска:");
- string lastName = Console.ReadLine();
- bool isFound = false;
- foreach (var position in positions)
- {
- foreach (var employee in position.Value)
- {
- string[] names = employee.Split(' ');
- if (names[0].Equals(lastName, StringComparison.OrdinalIgnoreCase))
- {
- Console.WriteLine($"{employee} - {position.Key}");
- isFound = true;
- }
- }
- }
- if (isFound == false)
- {
- Console.WriteLine($"Сотрудники с фамилией '{lastName}' не найдены.");
- }
- }
- static void DeleteDossier(Dictionary<string, List<string>> positions)
- {
- if (positions.Count == 0)
- {
- Console.WriteLine("Нет досье для удаления.");
- return;
- }
- Console.WriteLine("Введите должность сотрудника:");
- string position = Console.ReadLine();
- if (positions.ContainsKey(position) == false)
- {
- Console.WriteLine("Должность не найдена.");
- return;
- }
- var employees = positions[position];
- Console.WriteLine("Сотрудники на должности " + position + ":");
- for (int i = 0; i < employees.Count; i++)
- {
- Console.WriteLine($"{i + 1}) {employees[i]}");
- }
- Console.WriteLine("Введите номер сотрудника для удаления:");
- int employeeNumber = ReadInt();
- if (employeeNumber < 1 || employeeNumber > employees.Count)
- {
- Console.WriteLine("Неверный номер сотрудника.");
- return;
- }
- employees.RemoveAt(employeeNumber - 1);
- Console.WriteLine("Досье удалено!");
- if (employees.Count == 0)
- {
- positions.Remove(position);
- }
- }
- static int ReadInt()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Это не число. Пожалуйста, введите число:");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement