Advertisement
Rodunskiy

Untitled

May 19th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.86 KB | None | 0 0
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         const string AddDossierCommand = "1";
  6.         const string OutputEntireDossierCommand = "2";
  7.         const string DeleteDossierCommand = "3";
  8.         const string SearchBySurnameCommand = "4";
  9.         const string ExitCommand = "5";
  10.  
  11.         string[] tableFullNames = new string[0];
  12.         string[] tablePosts = new string[0];
  13.  
  14.         string userInput;
  15.  
  16.         bool isWorking = true;
  17.  
  18.         while (isWorking)
  19.         {
  20.             Console.Clear();
  21.             Console.ForegroundColor = ConsoleColor.Green;
  22.             Console.WriteLine("Выберите действие:");
  23.             Console.ForegroundColor = ConsoleColor.White;
  24.             Console.WriteLine($"{AddDossierCommand} <-- Добавить досье.\n{OutputEntireDossierCommand} <-- Вывод всего досье.\n{DeleteDossierCommand}" +
  25.                 $" <-- Удалить досье\n{SearchBySurnameCommand} <-- Поиск по фамилии.\n{ExitCommand} <-- Выход.");
  26.             userInput = Console.ReadLine();
  27.             Console.Clear();
  28.  
  29.             switch (userInput)
  30.             {
  31.                 case AddDossierCommand:
  32.                     AddDossier(ref tableFullNames, ref tablePosts);
  33.                     break;
  34.  
  35.                 case OutputEntireDossierCommand:
  36.                     OutputEntireDossier(ref tableFullNames, ref tablePosts);
  37.                     break;
  38.  
  39.                 case DeleteDossierCommand:
  40.                     DeleteDossier(ref tableFullNames, ref tablePosts);
  41.  
  42.                     break;
  43.                 case SearchBySurnameCommand:
  44.                     SearchBySurname(ref tableFullNames, ref tablePosts);
  45.                     break;
  46.  
  47.                 case ExitCommand:
  48.                     isWorking = Exit(isWorking);
  49.                     break;
  50.             }
  51.         }
  52.         Console.ForegroundColor = ConsoleColor.Green;
  53.         Console.WriteLine("Нажмите любую клавишу что-бы выйти из программы.");
  54.         Console.ForegroundColor = ConsoleColor.White;
  55.     }
  56.  
  57.     static void AddDossier(ref string[] arrayFullNames, ref string[] arrayPosts)
  58.     {
  59.         arrayFullNames = ArrayExtension(arrayFullNames, "Введите ФИО сотрудника:");
  60.         arrayPosts = ArrayExtension(arrayPosts, "Введите должность сотрудника:");
  61.     }
  62.  
  63.     static string[] ArrayExtension(string[] array, string text)
  64.     {
  65.         string[] tempArray = new string[array.Length + 1];
  66.  
  67.         for (int i = 0; i < array.Length; i++)
  68.         {
  69.             tempArray[i] = array[i];
  70.         }
  71.  
  72.         Console.ForegroundColor = ConsoleColor.Green;
  73.         Console.WriteLine(text);
  74.         Console.ForegroundColor = ConsoleColor.White;
  75.         string word = Console.ReadLine();
  76.  
  77.         tempArray[tempArray.Length - 1] = word;
  78.  
  79.         return tempArray;
  80.     }
  81.  
  82.     static void OutputEntireDossier(ref string[] arrayFullNames, ref string[] arrayPosts)
  83.     {
  84.         Console.ForegroundColor = ConsoleColor.Green;
  85.         Console.WriteLine("Досье сотрудников:");
  86.         Console.ForegroundColor = ConsoleColor.White;
  87.  
  88.         for (int i = 0; i < arrayFullNames.Length; i++)
  89.         {
  90.             Console.WriteLine($"{i + 1})" + arrayFullNames[i] + "-" + arrayPosts[i]);
  91.         }
  92.  
  93.         Console.ReadKey();
  94.     }
  95.  
  96.     static void DeleteDossier(ref string[] arrayFullNames, ref string[] arrayPosts)
  97.     {
  98.         bool isExit = true;
  99.  
  100.         while (isExit)
  101.         {
  102.             Console.ForegroundColor = ConsoleColor.Green;
  103.             Console.WriteLine("Введите номер досье которые вы хотите удалить:");
  104.             Console.ForegroundColor = ConsoleColor.White;
  105.             int deleteNumber = Convert.ToInt32(Console.ReadLine());
  106.  
  107.             if (deleteNumber < 0 || deleteNumber > arrayFullNames.Length)
  108.             {
  109.                 Console.ForegroundColor = ConsoleColor.Red;
  110.                 Console.WriteLine("Досье с таким номером не существует!");
  111.                 Console.ForegroundColor = ConsoleColor.White;
  112.                 Console.ReadKey();
  113.                 Console.Clear();
  114.             }
  115.             else
  116.             {
  117.                 arrayFullNames = ArrayReducing(arrayFullNames, deleteNumber);
  118.                 arrayPosts = ArrayReducing(arrayPosts, deleteNumber);
  119.                 isExit = false;
  120.             }
  121.         }
  122.     }
  123.  
  124.     static string[] ArrayReducing(string[] array, int number)
  125.     {
  126.         for (int i = (number - 1); i < array.Length - 1; i++)
  127.         {
  128.             array[i] = array[i + 1];
  129.         }
  130.  
  131.         string[] tempArray = new string[array.Length - 1];
  132.  
  133.         for (int i = 0; i < tempArray.Length; i++)
  134.         {
  135.             tempArray[i] = array[i];
  136.         }
  137.  
  138.         return tempArray;
  139.     }
  140.  
  141.     static void SearchBySurname(ref string[] arrayFullNames,ref string[] arrayPost)
  142.     {
  143.         char symbol = ' ';
  144.         Console.ForegroundColor = ConsoleColor.Green;
  145.         Console.WriteLine("Введите фамилию сотрудника:");
  146.         Console.ForegroundColor = ConsoleColor.White;
  147.         string surname = Console.ReadLine();
  148.  
  149.         for (int i = 0; i < arrayFullNames.Length; i++)
  150.         {
  151.             string[] words = arrayFullNames[i].Split(symbol);
  152.  
  153.             if (words[i] == surname)
  154.             {
  155.                 Console.ForegroundColor = ConsoleColor.Green;
  156.                 Console.WriteLine($"Сотрудник {surname} работает на должности {arrayPost[i]}");
  157.                 Console.ForegroundColor = ConsoleColor.White;
  158.                 Console.ReadKey();
  159.                 break;
  160.             }
  161.         }
  162.     }
  163.  
  164.     static bool Exit(bool isWorking)
  165.     {
  166.         isWorking = false;
  167.  
  168.         return isWorking;
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement