Advertisement
TeT91

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

May 23rd, 2024
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CSLight
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             const string CommandAddEmployee = "1";
  11.             const string CommandDeleteEmployee = "2";
  12.             const string CommandShowEmployesByJob = "3";
  13.             const string CommandExit = "Exit";
  14.  
  15.             List<string> fullNames = new List<string>();
  16.             List<string> jobs = new List<string>();
  17.  
  18.             bool isInProgress = true;
  19.  
  20.             while (isInProgress)
  21.             {
  22.                 Console.WriteLine($"Введите команду: " +
  23.                     $"\n {CommandAddEmployee} - Добавить работника " +
  24.                     $"\n {CommandDeleteEmployee} - Удлить работника " +
  25.                     $"\n {CommandShowEmployesByJob} - Показать работников одной должности " +
  26.                     $"\n {CommandExit} - выход ");
  27.  
  28.                 string userInput = Console.ReadLine();
  29.  
  30.                 switch (userInput)
  31.                 {
  32.                     case CommandAddEmployee:
  33.                         AddEmployee(jobs, fullNames);
  34.                         break;
  35.  
  36.                     case CommandDeleteEmployee:
  37.                         TryDeleteEmployee(jobs, fullNames);
  38.                         break;
  39.  
  40.                     case CommandShowEmployesByJob:
  41.                         ShowEmployesByJob(jobs, fullNames);
  42.                         break;
  43.  
  44.                     case CommandExit:
  45.                         isInProgress = false;
  46.                         break;
  47.                 }
  48.             }
  49.         }
  50.  
  51.         private static void ShowEmployesByJob(List<string> jobs, List<string> fullNames)
  52.         {
  53.             Console.WriteLine("Введите должность работника");
  54.  
  55.             string job = Console.ReadLine();
  56.  
  57.             for (int i = 0; i < jobs.Count; i++)
  58.             {
  59.                 if (jobs[i] == job)
  60.                 {
  61.                     Console.WriteLine($"{jobs[i]} - {fullNames[i]}");
  62.                 }
  63.             }
  64.         }
  65.  
  66.         private static void TryDeleteEmployee(List<string> jobs, List<string> fullNames)
  67.         {
  68.             Console.WriteLine("Введите ФИО работника");
  69.  
  70.             string fullName = Console.ReadLine();
  71.  
  72.             for (int i = 0; i < fullNames.Count; i++)
  73.             {
  74.                 if (fullName == fullNames[i])
  75.                 {
  76.                     jobs.RemoveAt(i);
  77.                     fullNames.RemoveAt(i);
  78.                 }
  79.             }
  80.         }
  81.  
  82.         private static void AddEmployee(List<string> jobs, List<string> fullNames)
  83.         {
  84.             Console.WriteLine("Введите должность");
  85.             string job = Console.ReadLine();
  86.  
  87.             Console.WriteLine("Введите ФИО");
  88.             string fullName = Console.ReadLine();
  89.  
  90.             CheckIfJobExist(jobs, job);
  91.             jobs.Add(job);
  92.             fullNames.Add(fullName);
  93.         }
  94.  
  95.         private static void CheckIfJobExist(List<string> jobs, string job)
  96.         {
  97.             if (jobs.Contains(job) == false)
  98.             {
  99.                 Console.WriteLine("В базе создана новая должность");
  100.             }
  101.             else
  102.             {
  103.                 Console.WriteLine("Такая должность уже есть в базе");
  104.             }
  105.         }
  106.  
  107.         private static void TryDeleteJob(List<string> jobs, string job)
  108.         {
  109.             if (jobs.Contains(job) == false)
  110.             {
  111.                 jobs.Remove(job);
  112.                 Console.WriteLine("Сотрудников с такой должностью больше нет. Должность удалена из базы");
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement