Advertisement
Rodunskiy

Untitled

Feb 28th, 2025
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.68 KB | None | 0 0
  1. namespace CSLight
  2. {
  3.     public class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             const string AddDossierCommand = "1";
  8.             const string ShowAllDossierCommand = "2";
  9.             const string SearchLastnameCommand = "3";
  10.             const string DeleteDossierCommand = "4";
  11.             const string ExitProgrammCommand = "5";
  12.  
  13.             string[] listEmployees = new string[0];
  14.             string[] positions = new string[0];
  15.             bool isRunning = true;  
  16.            
  17.             while (isRunning)
  18.             {
  19.                 Console.WriteLine(
  20.                 $"{AddDossierCommand})Добавить досье\n" +
  21.                 $"{ShowAllDossierCommand})Вывести все досье\n" +
  22.                 $"{SearchLastnameCommand})Поиск по фамилии\n" +
  23.                 $"{DeleteDossierCommand})Удалить досье\n" +
  24.                 $"{ExitProgrammCommand})Выход из программы\n");
  25.  
  26.                 switch (Console.ReadLine())
  27.                 {
  28.                     case AddDossierCommand:
  29.                         AddDossier(ref listEmployees, ref positions);
  30.                         break;
  31.  
  32.                     case ShowAllDossierCommand:
  33.                         ShowAllDossier(listEmployees, positions);
  34.                         break;
  35.  
  36.                     case SearchLastnameCommand:
  37.                         SearchLastname(listEmployees);
  38.                         break;
  39.  
  40.                     case DeleteDossierCommand:
  41.                         DeleteDossier(ref listEmployees, ref positions);
  42.                         break;
  43.  
  44.                     case ExitProgrammCommand:
  45.                         isRunning = false;
  46.                         break;
  47.                 }
  48.  
  49.             }
  50.  
  51.         }
  52.  
  53.         static void AddDossier(ref string[] listEmployees, ref string[] positions)
  54.         {
  55.             Console.WriteLine("Введите ФИО сотрудинка через пробел.");
  56.             string fullName = Console.ReadLine();
  57.             Console.WriteLine("Введите должность сотрудинка через пробел.");
  58.             string post = Console.ReadLine();
  59.  
  60.             listEmployees = ExpandArray(listEmployees, fullName);
  61.             positions = ExpandArray(positions, post);
  62.         }
  63.          
  64.         static void ShowAllDossier(string[] listEmployees, string[] positions)
  65.         {
  66.             if (listEmployees.Length == 0)
  67.             {
  68.                 Console.WriteLine("Досье отсутствуют.");
  69.                 return;
  70.             }
  71.            
  72.             for (int i = 0; i < listEmployees.Length; i++)
  73.             {
  74.                 Console.WriteLine($"{i + 1}){listEmployees[i]} - {positions[i]}");
  75.             }
  76.            
  77.             Console.ReadKey();
  78.         }
  79.  
  80.         static void SearchLastname(string[] array)
  81.         {
  82.             bool isSearch = false;
  83.  
  84.             Console.WriteLine("Введите нужную фамилию для поиска");
  85.             string lastName = Console.ReadLine();
  86.  
  87.             for (int i = 0; i < array.Length; i++)
  88.             {
  89.                 char space = ' ';
  90.                 string[] surnames = array[i].Split(space);
  91.  
  92.                 if (lastName.ToLower() == surnames[0].ToLower())
  93.                 {
  94.                     Console.WriteLine(array[i]);
  95.  
  96.                     isSearch = true;
  97.                 }
  98.             }
  99.  
  100.             if (isSearch == false)
  101.             {
  102.                 Console.WriteLine($"Сотрудники с фамилией '{lastName}' не найдены.");
  103.             }
  104.         }
  105.  
  106.         static void DeleteDossier(ref string[] listEmployees, ref string[] positions)
  107.         {
  108.             bool isRunning = true;
  109.  
  110.             ShowAllDossier(listEmployees, positions);
  111.  
  112.             Console.WriteLine("Введите номер досье которое хотите удалить.");
  113.             int number = ReadInt();
  114.  
  115.             if (number > listEmployees.Length)
  116.             {
  117.                 isRunning = false;
  118.             }
  119.  
  120.             if (isRunning == true)
  121.             {
  122.                 listEmployees = DeleteArrayElement(listEmployees, number);
  123.                 positions = DeleteArrayElement(positions, number);
  124.             }
  125.             else
  126.             {
  127.                 Console.WriteLine("Такого индекса нет.");
  128.             }
  129.         }
  130.  
  131.         static string[] ExpandArray(string[] array, string word)
  132.         {
  133.             string[] temporaryArray = new string[array.Length + 1];
  134.  
  135.             for (int i = 0; i < array.Length; i++)
  136.             {
  137.                 temporaryArray[i] = array[i];
  138.             }
  139.  
  140.             temporaryArray[temporaryArray.Length - 1] = word;
  141.  
  142.             array = temporaryArray;
  143.  
  144.             return array;
  145.         }
  146.  
  147.         static string[] DeleteArrayElement(string[] array, int number)
  148.         {
  149.             string[] temporaryArray = new string[array.Length - 1];
  150.  
  151.                 for (int i = 0; i < (number - 1); i++)
  152.                 {
  153.                     temporaryArray[i] = array[i];
  154.                 }
  155.  
  156.                 for (int i = (number - 1); i < (temporaryArray.Length); i++)
  157.                 {
  158.                     temporaryArray[i] = array[i + 1];
  159.                 }
  160.  
  161.                 array = temporaryArray;
  162.  
  163.                 return array;            
  164.         }
  165.  
  166.         static int ReadInt()
  167.         {
  168.             int number = 0;
  169.  
  170.             while (int.TryParse(Console.ReadLine(), out number) == false)
  171.             {
  172.                 Console.WriteLine("Это не число.");
  173.             }
  174.  
  175.             return number;
  176.         }
  177.     }
  178. }
  179.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement