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(ref positions);
- break;
- case ShowAllDossierCommand:
- ShowAllDossier(positions);
- break;
- case SearchLastnameCommand:
- SearchLastname(positions);
- break;
- case DeleteDossierCommand:
- DeleteDossier(ref positions);
- break;
- case ExitProgrammCommand:
- isRunning = false;
- break;
- }
- }
- }
- static void AddDossier(ref 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 found = 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}");
- found = true;
- }
- }
- }
- if (!found)
- {
- Console.WriteLine($"Сотрудники с фамилией '{lastName}' не найдены.");
- }
- }
- static void DeleteDossier(ref Dictionary<string, List<string>> positions)
- {
- if (positions.Count == 0)
- {
- Console.WriteLine("Нет досье для удаления.");
- return;
- }
- Console.WriteLine("Список всех сотрудников:");
- List<Tuple<string, string>> allEmployees = new List<Tuple<string, string>>();
- int index = 1;
- foreach (var position in positions)
- {
- foreach (var employee in position.Value)
- {
- Console.WriteLine($"{index}) {employee} - {position.Key}");
- allEmployees.Add(new Tuple<string, string>(employee, position.Key));
- index++;
- }
- }
- Console.WriteLine("Введите номер досье для удаления:");
- int number = ReadInt();
- if (number < 1 || number > allEmployees.Count)
- {
- Console.WriteLine("Неверный номер досье.");
- return;
- }
- var employeeToDelete = allEmployees[number - 1];
- string empName = employeeToDelete.Item1;
- string positionName = employeeToDelete.Item2;
- positions[positionName].Remove(empName);
- if (positions[positionName].Count == 0)
- {
- positions.Remove(positionName);
- }
- Console.WriteLine("Досье удалено!");
- }
- static int ReadInt()
- {
- int number = 0;
- while (int.TryParse(Console.ReadLine(), out number))
- {
- Console.WriteLine("Это не число. Пожалуйста, введите число:");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement