12Vitaly

26

Apr 19th, 2021 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace egor
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isOpen = true;
  14.             Dictionary<int, string> dossier = new Dictionary<int, string>();
  15.             int quantityDossiers = 1;
  16.             string userInput;
  17.  
  18.             while (isOpen == true)
  19.             {
  20.                 Console.WriteLine("1 - Добавить досье.\n2 - Вывести все досье.\n3 - Удалить досье.\n4 - Выход");
  21.                 Console.WriteLine("Введите номер команды.");
  22.                 userInput = Console.ReadLine();
  23.  
  24.                 switch (userInput)
  25.                 {
  26.                     case "1":
  27.                         Console.Clear();
  28.                         Console.Write("Введите ФИО и должность: ");
  29.                         userInput = Console.ReadLine();
  30.                         IncreaseArray(dossier, userInput, ref quantityDossiers);
  31.                         break;
  32.                     case "2":
  33.                         Console.Clear();
  34.                         WithdrawAllDossiers(dossier, quantityDossiers);
  35.                         break;
  36.                     case "3":
  37.                         Console.Clear();
  38.                         WithdrawAllDossiers(dossier, quantityDossiers);
  39.                         Console.WriteLine("Ввдите номер досье которое хотите удолить");
  40.                         userInput = Console.ReadLine();
  41.                         DeletionDossier(dossier, userInput);
  42.                         break;
  43.                     case "4":
  44.                         isOpen = false;
  45.                         break;
  46.                 }
  47.             }
  48.         }
  49.  
  50.         static void IncreaseArray(Dictionary<int, string> dossier, string userInput, ref int quantityDossiers)
  51.         {
  52.                 dossier.Add(quantityDossiers, userInput);
  53.                 quantityDossiers++;
  54.         }
  55.  
  56.         static void WithdrawAllDossiers(Dictionary<int, string> dossier,  int quantityDossiers)
  57.         {
  58.             foreach(var oneDossier in dossier)
  59.             {
  60.                 Console.Write(oneDossier.Key + ". " + oneDossier.Value);
  61.                 if (quantityDossiers > 2)
  62.                 {
  63.                     Console.Write("-");
  64.                 }
  65.                 Console.WriteLine();
  66.             }
  67.         }
  68.  
  69.         static void DeletionDossier(Dictionary<int, string> dossier, string userInput)
  70.         {
  71.             int dossierNumber;
  72.             bool result = int.TryParse(userInput, out dossierNumber);
  73.             if (result == true)
  74.             {
  75.                 dossier.Remove(dossierNumber);
  76.             }
  77.             else
  78.             {
  79.                 Console.WriteLine("ошибка удаления");
  80.                 Console.WriteLine("введите число");
  81.             }
  82.         }
  83.     }
  84. }
Add Comment
Please, Sign In to add comment