Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandShowDossiers = "1";
- const string CommandAddDossier = "2";
- const string CommandDeleteDossier = "3";
- const string CommandExit = "Exit";
- string userInput;
- bool isRun = true;
- Dictionary<string, List<string>> dossiers;
- dossiers = new Dictionary<string, List<string>>()
- {
- {"Начальник", new List<string>{ "Сакутин Роман" } },
- {"Сеньер", new List<string>{ "Кравченко Валентин" } },
- {"Менторище", new List<string>{"Сахно Влад" } }
- };
- while (isRun)
- {
- Console.Clear();
- Console.WriteLine($"Выбери пунк меню:\n" +
- $"{CommandShowDossiers} - Показать все досье\n" +
- $"{CommandAddDossier} - Добавить досье\n" +
- $"{CommandDeleteDossier} - Удалить досье\n" +
- $"{CommandExit} - Выйти из меню");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandShowDossiers:
- ShowDossiers(dossiers);
- break;
- case CommandAddDossier:
- AddDossier(dossiers);
- break;
- case CommandDeleteDossier:
- DeleteDossier(dossiers);
- break;
- case CommandExit:
- isRun = ExitProgram();
- break;
- default:
- Console.WriteLine("Ошибка.");
- Console.ReadKey();
- break;
- }
- }
- }
- static void ShowDossiers(Dictionary<string, List<string>> dossiers)
- {
- Console.Clear();
- foreach (var employee in dossiers)
- {
- string employeesSeparate = ", ";
- Console.WriteLine($"{employee.Key} - {String.Join(employeesSeparate, employee.Value)}");
- }
- Console.ReadKey();
- }
- static void AddDossier(Dictionary<string, List<string>> dossiers)
- {
- Console.WriteLine("Введите должность сотрудника");
- string profession = Console.ReadLine();
- Console.WriteLine("Введите ФИО сотрудника");
- string name = Console.ReadLine();
- if (dossiers.ContainsKey(profession) == false)
- {
- dossiers.Add(profession, new List<string>());
- }
- dossiers[profession].Add(name);
- Console.WriteLine("Новый сотрудник добавлен");
- Console.ReadKey();
- }
- static void DeleteDossier(Dictionary<string, List<string>> dossiers)
- {
- Console.WriteLine("Введите должность сотрудника:");
- string positionInput = Console.ReadLine();
- if (dossiers.ContainsKey(positionInput) == true)
- {
- List<string> employees = dossiers[positionInput];
- Console.WriteLine("Cотрудники на данной должностью:");
- for (int i = 0; i < employees.Count; i++)
- {
- Console.WriteLine($"{i + 1} - {employees[i]}");
- }
- Console.Write("Введите номер сотрудника для удаления: ");
- dossiers[positionInput].RemoveAt(ReadInt(employees.Count) - 1);
- Console.WriteLine("Сотрудник удален.");
- if (dossiers[positionInput].Count == 0)
- {
- dossiers.Remove(positionInput);
- }
- }
- else
- {
- Console.WriteLine("Нет такой должности.");
- }
- Console.ReadKey();
- }
- static int ReadInt(int countEmployees)
- {
- int index;
- while (true)
- {
- string input = Console.ReadLine();
- if (int.TryParse(input, out index) && index >= 1 && index <= countEmployees)
- break;
- Console.Write("\nОшибка ввода. Попробуйте снова: ");
- }
- return index;
- }
- static bool ExitProgram()
- {
- Console.WriteLine("Программа завершена.");
- Console.ReadKey();
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment