Advertisement
Rodunskiy

Untitled

Jun 8th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.17 KB | None | 0 0
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         const string AddDossierCommand = "1";
  6.         const string OutputEntireDossierCommand = "2";
  7.         const string DeleteDossierCommand = "3";
  8.         const string ExitCommand = "4";
  9.  
  10.         Dictionary<string, string> dossier = new Dictionary<string, string>();
  11.  
  12.         string userInput;
  13.  
  14.         bool isWorking = true;
  15.  
  16.         while (isWorking)
  17.         {
  18.             Console.Clear();
  19.             Console.ForegroundColor = ConsoleColor.Green;
  20.             Console.WriteLine("Выберите действие:");
  21.             Console.ForegroundColor = ConsoleColor.White;
  22.             Console.WriteLine($"{AddDossierCommand} <-- Добавить досье.\n{OutputEntireDossierCommand} <-- Вывод всего досье.\n{DeleteDossierCommand}" +
  23.                 $" <-- Удалить досье.\n{ExitCommand} <-- Выход.");
  24.             userInput = Console.ReadLine();
  25.             Console.Clear();
  26.  
  27.             switch (userInput)
  28.             {
  29.                 case AddDossierCommand:
  30.                     AddDossier(dossier);
  31.                     break;
  32.                    
  33.  
  34.                 case OutputEntireDossierCommand:
  35.                     OutputEntireDossier(dossier);
  36.                     break;
  37.  
  38.                 case DeleteDossierCommand:
  39.                     DeleteDossier(dossier);
  40.                     break;
  41.  
  42.                 case ExitCommand:
  43.                     isWorking = false;
  44.                     break;
  45.             }
  46.         }
  47.  
  48.         Console.ForegroundColor = ConsoleColor.Green;
  49.         Console.WriteLine("Нажмите любую клавишу что-бы выйти из программы.");
  50.         Console.ForegroundColor = ConsoleColor.White;
  51.     }
  52.  
  53.     private static void DeleteDossier(Dictionary<string, string> dossier)
  54.     {
  55.         string deleteFio = Console.ReadLine();
  56.  
  57.         if (int.TryParse(deleteFio, out int number))
  58.         {
  59.             dossier.Remove(deleteFio);
  60.         }
  61.         else
  62.         {
  63.             Console.WriteLine("Не удалось распознать ввод, попробуйте еще раз.");
  64.             Console.ReadKey();
  65.         }
  66.     }
  67.  
  68.     private static void OutputEntireDossier(Dictionary<string, string> dossier)
  69.     {
  70.         foreach (var employee in dossier)
  71.         {
  72.             Console.WriteLine($"{employee.Key} - {employee.Value}");
  73.         }
  74.         Console.ReadKey();
  75.     }
  76.  
  77.     private static void AddDossier(Dictionary<string, string> dossier)
  78.     {
  79.         Console.WriteLine("Введите ФИО сотрудника");
  80.         string fio = Console.ReadLine();
  81.         Console.WriteLine("Введите должность сотрудника");
  82.         string post = Console.ReadLine();
  83.  
  84.         if (dossier.ContainsKey(fio) == false)
  85.         {
  86.             dossier.Add(fio, post);
  87.         }
  88.         else
  89.         {
  90.             Console.ForegroundColor = ConsoleColor.Red;
  91.             Console.WriteLine("Сотрудник с такой фамилией уже есть в базе.");
  92.             Console.ReadKey();
  93.             Console.ForegroundColor = ConsoleColor.White;
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement