kwest87

Untitled

Jan 22nd, 2024
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp28
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const string CommandAddDossier = "1";
  10.             const string CommandShowDossier = "2";
  11.             const string CommandDeleteDossier = "3";
  12.             const string CommandSearchName = "4";
  13.             const string CommandExitProgram = "5";
  14.  
  15.             string[] names = new string[0];
  16.             string[] positions = new string[0];
  17.             string userInput;
  18.             bool isWork = true;
  19.  
  20.             while (isWork)
  21.             {
  22.                 Console.WriteLine("        МЕНЮ");
  23.                 Console.WriteLine(
  24.                     $" {CommandAddDossier}) Добавить досье.\n" +
  25.                     $" {CommandShowDossier}) Показать досье.\n" +
  26.                     $" {CommandDeleteDossier}) Удалить досье.\n" +
  27.                     $" {CommandSearchName}) Поиск по фамилии.\n" +
  28.                     $" {CommandExitProgram}) Выход.");
  29.                 userInput = Console.ReadLine();
  30.                 Console.Clear();
  31.  
  32.                 switch (userInput)
  33.                 {
  34.                     case CommandAddDossier:
  35.                         AddDossier(ref names, ref positions);
  36.                         break;
  37.                     case CommandShowDossier:
  38.                         ShowDossier(names, positions);
  39.                         break;
  40.                     case CommandDeleteDossier:
  41.                         DeleteDossier(ref names, ref positions);
  42.                         break;
  43.                     case CommandSearchName:
  44.                         SearchName(names, positions);
  45.                         break;
  46.                     case CommandExitProgram:
  47.                         isWork = false;
  48.                         break;
  49.                 }
  50.             }
  51.         }
  52.  
  53.         static void AddElement(ref string[] array, string text)
  54.         {
  55.             Console.Write(text);
  56.             string userInput = Console.ReadLine();
  57.             string[] temporaryArray = new string[array.Length + 1];
  58.  
  59.             for (int i = 0; i < array.Length; i++)
  60.             {
  61.                 temporaryArray[i] = array[i];
  62.             }
  63.  
  64.             temporaryArray[temporaryArray.Length - 1] = userInput;
  65.             array = temporaryArray;
  66.         }
  67.  
  68.         static void AddDossier(ref string[] names, ref string[] positions)
  69.         {
  70.             AddElement(ref names, "Укажите ваше ФИО :");
  71.             AddElement(ref positions, "Укажите вашу должность :");
  72.         }
  73.  
  74.         static void ShowDossier(string[] names, string[] positions)
  75.         {
  76.             for (int i = 0; i < names.Length; i++)
  77.             {
  78.                 ShowElement(i, names[i], positions[i]);
  79.             }
  80.         }
  81.  
  82.         static void DeleteElement(ref string[] array, int number)
  83.         {
  84.             string[] tempArray = new string[array.Length - 1];
  85.             int index = number - 1;
  86.  
  87.             for (int i = 0; i < index; i++)
  88.             {
  89.                 tempArray[i] = array[i];
  90.             }
  91.             for (int i = index; i < tempArray.Length; i++)
  92.             {
  93.                 tempArray[i] = array[i + 1];
  94.             }
  95.  
  96.             array = tempArray;
  97.         }
  98.  
  99.         static void DeleteDossier(ref string[] names, ref string[] positions)
  100.         {
  101.             Console.Write("Укажите номер досье которое нужно удалить : ");
  102.             string userInput = Console.ReadLine();
  103.             bool isNumber = int.TryParse(userInput, out int numberValue);
  104.  
  105.             if (isNumber && numberValue <= names.Length && numberValue > 0)
  106.             {
  107.                 DeleteElement(ref names, numberValue);
  108.                 DeleteElement(ref positions, numberValue);
  109.                 Console.WriteLine($"Досье {userInput} удалено.");
  110.             }
  111.             else
  112.             {
  113.                 Console.WriteLine($"Досье {userInput} нету.");
  114.             }
  115.         }
  116.  
  117.         static void SearchName(string[] names, string[] positions)
  118.         {
  119.             Console.Write("Введите фамилию : ");
  120.             string userInput = Console.ReadLine();
  121.             string[] nameElements;
  122.             bool isFound = false;
  123.  
  124.             for (int i = 0; i < names.Length; i++)
  125.             {
  126.                 nameElements = names[i].Split(' ');
  127.  
  128.                 for (int j = 0; j < nameElements.Length; j++)
  129.                 {
  130.                     if (nameElements[j].ToLower() == userInput.ToLower())
  131.                     {
  132.                         Console.Write("Найден : ");
  133.                         ShowElement(i, names[i], positions[i]);
  134.                         isFound = true;
  135.                     }
  136.                 }
  137.             }
  138.  
  139.             if (isFound == false)
  140.             {
  141.                 Console.WriteLine("Ничего не найдено.");
  142.             }
  143.         }
  144.  
  145.         static void ShowElement(int index, string name, string position)
  146.         {
  147.             Console.WriteLine($"{index + 1}) {name} - {position}.");
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment