Advertisement
Rodunskiy

Untitled

Jun 8th, 2023
65
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.                 case OutputEntireDossierCommand:
  34.                     OutputEntireDossier(dossier);
  35.                     break;
  36.  
  37.                 case DeleteDossierCommand:
  38.                     DeleteDossier(dossier);
  39.                     break;
  40.  
  41.                 case ExitCommand:
  42.                     isWorking = false;
  43.                     break;
  44.             }
  45.         }
  46.  
  47.         Console.ForegroundColor = ConsoleColor.Green;
  48.         Console.WriteLine("Нажмите любую клавишу что-бы выйти из программы.");
  49.         Console.ForegroundColor = ConsoleColor.White;
  50.     }
  51.  
  52.     private static void DeleteDossier(Dictionary<string, string> dossier)
  53.     {
  54.         string deleteFio = Console.ReadLine();
  55.  
  56.         if (int.TryParse(deleteFio, out int number))
  57.         {
  58.             dossier.Remove(deleteFio);
  59.         }
  60.         else
  61.         {
  62.             Console.WriteLine("Не удалось распознать ввод, попробуйте еще раз.");
  63.             Console.ReadKey();
  64.         }
  65.     }
  66.  
  67.     private static void OutputEntireDossier(Dictionary<string, string> dossier)
  68.     {
  69.         foreach (var employee in dossier)
  70.         {
  71.             Console.WriteLine($"{employee.Key} - {employee.Value}");
  72.         }
  73.         Console.ReadKey();
  74.     }
  75.  
  76.     private static void AddDossier(Dictionary<string, string> dossier)
  77.     {
  78.         Console.WriteLine("Введите ФИО сотрудника");
  79.         string fio = Console.ReadLine();
  80.         Console.WriteLine("Введите должность сотрудника");
  81.         string post = Console.ReadLine();
  82.  
  83.         if (dossier.ContainsKey(fio) == false)
  84.         {
  85.             dossier.Add(fio, post);
  86.         }
  87.         else
  88.         {
  89.             Console.ForegroundColor = ConsoleColor.Red;
  90.             Console.WriteLine("Сотрудник с такой фамилией уже есть в базе.");
  91.             Console.ReadKey();
  92.             Console.ForegroundColor = ConsoleColor.White;
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement