Advertisement
Torgach

personnelRecords

Mar 12th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 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 personnelRecords
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isRun = true;
  14.             Dictionary<string, string> files = new Dictionary<string, string>(0);
  15.  
  16.             while (isRun)
  17.             {
  18.                 Console.WriteLine("[1] - добавить досье\n[2] - вывести все досье\n[3] - удалить досье\n[4] - выход");
  19.                 Console.Write("Ввод: ");
  20.                 switch (Console.ReadLine())
  21.                 {
  22.                     case "1":
  23.                         files = AddFile(files);
  24.                         break;
  25.                     case "2":
  26.                         PrintFiles(files);
  27.                         break;
  28.                     case "3":
  29.                         DeleteFile(files);
  30.                         break;
  31.                     case "4":
  32.                         isRun = false;
  33.                         break;
  34.                 }
  35.  
  36.             }
  37.         }
  38.  
  39.         static Dictionary<string, string> AddFile(Dictionary<string, string> files)
  40.         {
  41.             Console.Write("Введите ФИО: ");
  42.             string fullName = Console.ReadLine();
  43.  
  44.             Console.Write("Введите должность: ");
  45.             string position = Console.ReadLine();
  46.  
  47.             files.Add(fullName, position);
  48.             return files;
  49.         }
  50.  
  51.         static void PrintFiles(Dictionary<string, string> files)
  52.         {
  53.             if(files.Count == 0)
  54.             {
  55.                 Console.WriteLine("Пусто!");
  56.             }
  57.  
  58.             foreach (var file in files)
  59.             {
  60.                 Console.WriteLine($"{file.Key} - {file.Value}");
  61.             }
  62.         }
  63.         static Dictionary<string, string> DeleteFile(Dictionary<string, string> files)
  64.         {
  65.             bool isFileEntered = false;
  66.             string userInput;
  67.  
  68.             while (isFileEntered == false)
  69.             {
  70.                 Console.Write("Введите ФИО или должность: ");
  71.                 userInput = Console.ReadLine();
  72.  
  73.                 if ((files.ContainsKey(userInput) || files.ContainsValue(userInput)) == true)
  74.                 {
  75.                     Console.WriteLine("Удаляем...");
  76.                     files.Remove(userInput);
  77.                     isFileEntered = true;
  78.                 }
  79.                 else
  80.                 {
  81.                     Console.WriteLine("Такого досье нет! Повторите ввод.");
  82.                 }
  83.             }
  84.  
  85.             return files;
  86.         }
  87.  
  88.  
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement