Advertisement
Torgach

tempPersonnelRecords

Mar 13th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 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.                         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.         static void AddFile(Dictionary<string, string> files)
  39.         {
  40.             Console.Write("Введите ФИО: ");
  41.             string fullName = Console.ReadLine();
  42.  
  43.             if(files.ContainsKey(fullName))
  44.             {
  45.                 Console.WriteLine("Ошибка! Сотрудник существует.");
  46.                 return;
  47.             }
  48.  
  49.             Console.Write("Введите должность: ");
  50.             string position = Console.ReadLine();
  51.  
  52.  
  53.  
  54.             files.Add(fullName, position);
  55.         }
  56.  
  57.         static void PrintFiles(Dictionary<string, string> files)
  58.         {
  59.             if (files.Count == 0)
  60.             {
  61.                 Console.WriteLine("Пусто!");
  62.                 return;
  63.             }
  64.  
  65.             foreach (var file in files)
  66.             {
  67.                 Console.WriteLine($"{file.Key} - {file.Value}");
  68.             }
  69.         }
  70.         static void DeleteFile(Dictionary<string, string> files)
  71.         {
  72.             string userInput;
  73.  
  74.             if (files.Count == 0)
  75.             {
  76.                 Console.WriteLine("Пусто!");
  77.                 return;
  78.             }
  79.  
  80.             Console.Write("Введите ФИО: ");
  81.             userInput = Console.ReadLine();
  82.  
  83.             if (files.ContainsKey(userInput) == true)
  84.             {
  85.                 Console.WriteLine("Удаляем...");
  86.                 files.Remove(userInput);
  87.             }
  88.             else
  89.             {
  90.                 Console.WriteLine("Такого досье нет!");
  91.                 return;
  92.             }
  93.  
  94.         }
  95.  
  96.  
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement