NikaBang

ДЗ: Кадровый учет продвинутый

Nov 11th, 2025
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.87 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. internal class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         const string CommandShowDossiers = "1";
  9.         const string CommandAddDossier = "2";
  10.         const string CommandDeleteDossier = "3";
  11.         const string CommandExit = "Exit";
  12.  
  13.         string userInput;
  14.         bool isRun = true;
  15.  
  16.         Dictionary<string, List<string>> dossiers;
  17.  
  18.         dossiers = new Dictionary<string, List<string>>()
  19.             {
  20.                 {"Начальник", new List<string>{ "Сакутин Роман" } },
  21.                 {"Сеньер", new List<string>{ "Кравченко Валентин" } },
  22.                 {"Менторище", new List<string>{"Сахно Влад" } }
  23.             };
  24.  
  25.         while (isRun)
  26.         {
  27.             Console.Clear();
  28.             Console.WriteLine($"Выбери пунк меню:\n" +
  29.                 $"{CommandShowDossiers} - Показать все досье\n" +
  30.                 $"{CommandAddDossier} - Добавить досье\n" +
  31.                 $"{CommandDeleteDossier} - Удалить досье\n" +
  32.                 $"{CommandExit} - Выйти из меню");
  33.  
  34.             userInput = Console.ReadLine();
  35.  
  36.             switch (userInput)
  37.             {
  38.                 case CommandShowDossiers:
  39.                     ShowDossiers(dossiers);
  40.                     break;
  41.  
  42.                 case CommandAddDossier:
  43.                     AddDossier(dossiers);
  44.                     break;
  45.  
  46.                 case CommandDeleteDossier:
  47.                     DeleteDossier(dossiers);
  48.                     break;
  49.  
  50.                 case CommandExit:
  51.                     isRun = ExitProgram();
  52.                     break;
  53.  
  54.                 default:
  55.                     Console.WriteLine("Ошибка.");
  56.                     Console.ReadKey();
  57.                     break;
  58.             }
  59.         }
  60.     }
  61.  
  62.     static void ShowDossiers(Dictionary<string, List<string>> dossiers)
  63.     {
  64.         Console.Clear();
  65.  
  66.         foreach (var employee in dossiers)
  67.         {
  68.             string employeesSeparate = ", ";
  69.             Console.WriteLine($"{employee.Key} - {String.Join(employeesSeparate, employee.Value)}");
  70.         }
  71.  
  72.         Console.ReadKey();
  73.     }
  74.  
  75.     static void AddDossier(Dictionary<string, List<string>> dossiers)
  76.     {
  77.         Console.WriteLine("Введите должность сотрудника");
  78.         string profession = Console.ReadLine();
  79.  
  80.         Console.WriteLine("Введите ФИО сотрудника");
  81.         string name = Console.ReadLine();
  82.  
  83.         if (dossiers.ContainsKey(profession) == true)
  84.         {
  85.             dossiers[profession].Add(name);
  86.         }
  87.         else
  88.         {
  89.             dossiers.Add(profession, new List<string>() { name });
  90.         }
  91.  
  92.         Console.WriteLine("Новый сотрудник добавлен");
  93.         Console.ReadKey();
  94.     }
  95.  
  96.     static void DeleteDossier(Dictionary<string, List<string>> dossiers)
  97.     {
  98.         List<string> professionToRemove = new List<string>();
  99.         int index = 1;
  100.  
  101.         Console.WriteLine("Введите профессию сотрудника:");
  102.         string professionInput = Console.ReadLine();
  103.  
  104.         if (dossiers.ContainsKey(professionInput))
  105.         {
  106.             Console.WriteLine("Вот все сотрудники с данной профессией:");
  107.  
  108.             foreach (var employee in dossiers[professionInput])
  109.             {
  110.                 Console.WriteLine(index + " - " + employee);
  111.                 index++;
  112.             }
  113.  
  114.             Console.WriteLine("\nВведите номер сотрудника которого нужно удалить:");
  115.             int indexInput = ReadInt(Console.ReadLine());
  116.  
  117.             if (indexInput > 0 && indexInput < index)
  118.             {
  119.                 dossiers[professionInput].RemoveAt(indexInput - 1);
  120.  
  121.                 Console.WriteLine("Сотрудник был удален");
  122.             }
  123.             else
  124.             {
  125.                 Console.WriteLine("Нет такого номера!");
  126.             }
  127.  
  128.             if (dossiers[professionInput].Count == 0)
  129.             {
  130.                 professionToRemove.Add(professionInput);
  131.  
  132.                 foreach (var profession in professionToRemove)
  133.                 {
  134.                     dossiers.Remove(profession);
  135.                 }
  136.             }
  137.         }
  138.         else
  139.         {
  140.             Console.WriteLine("Нет такой профессии.");
  141.         }
  142.  
  143.         Console.ReadKey();
  144.     }
  145.  
  146.     static int ReadInt(string input)
  147.     {
  148.         int result = 0;
  149.  
  150.         int.TryParse(input, out result);
  151.         return result;
  152.     }
  153.  
  154.     static bool ExitProgram()
  155.     {
  156.         Console.WriteLine("Программа завершена.");
  157.         Console.ReadKey();
  158.  
  159.         return false;
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment