Advertisement
Rodunskiy

Untitled

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