Advertisement
Rodunskiy

Untitled

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