NikaBang

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

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