Anonim_999

Dossiers

Oct 12th, 2022
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp7
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] fullNames = new string[0];
  10.             string[] posts = new string[0];
  11.             bool isWorking = true;
  12.  
  13.             while (isWorking)
  14.             {
  15.                 Console.Clear();
  16.                 Console.WriteLine("1.Добавить досье 2.Вывести досье 3.Удалить досье 4.Поиск по фамилии 5.Выход");
  17.                 char userInput = Console.ReadKey(true).KeyChar;
  18.  
  19.                 switch (userInput)
  20.                 {
  21.                     case '1':
  22.                         AddDossier(ref fullNames, ref posts);
  23.                         break;
  24.                     case '2':
  25.                         ShowDossiers(ref fullNames, ref posts);
  26.                         break;
  27.                     case '3':
  28.                         DeleteDossier(ref fullNames, ref posts);
  29.                         break;
  30.                     case '4':
  31.                         FindBySurname(fullNames, posts);
  32.                         break;
  33.                     case '5':
  34.                         isWorking = false;
  35.                         Console.WriteLine("Нажмите на любую кнопку...");
  36.                         break;
  37.                     default:
  38.                         Console.WriteLine("Умри");
  39.                         break;
  40.                 }
  41.                 Console.ReadKey();
  42.             }
  43.         }
  44.  
  45.         public static void FindBySurname(string[] fullNames, string[] posts)
  46.         {
  47.             Console.Write("Введите фамилию: ");
  48.             string userInput = Console.ReadLine();
  49.             string[] foundUsers = GetElements(fullNames,userInput);
  50.  
  51.             if (foundUsers.Length != 0)
  52.                 ShowArray(foundUsers, fullNames, posts);
  53.             else
  54.                 Console.WriteLine("Работник не найден");
  55.         }
  56.  
  57.         public static void ShowArray(string[] array,string[] fullNames, string[] posts)
  58.         {
  59.             for (int i = 0; i < array.Length; i++)
  60.             {
  61.                 ShowDossier(fullNames,posts,Convert.ToInt32(array[i]));
  62.             }
  63.         }
  64.  
  65.         public static void ShowDossier(string[] fullNames, string[] posts, int index)
  66.         {
  67.             Console.WriteLine($"id:{index + 1} ФИО: {fullNames[index]} Должность: {posts[index]}");
  68.         }
  69.  
  70.         public static string[] GetElements(string[] fullNames,string value)
  71.         {
  72.             string[] elements = new string[0];
  73.  
  74.             for (int i = 0; i < fullNames.Length; i++)
  75.             {
  76.                 if (fullNames[i].Contains(value))
  77.                 {
  78.                     ResizeArray(ref elements, i.ToString());
  79.                 }
  80.             }
  81.             return elements;
  82.         }
  83.  
  84.         public static void DeleteDossier(ref string[] fullNames, ref string[] posts)
  85.         {
  86.             Console.Write("Введите номер работника: ");
  87.             string userInput = Console.ReadLine();
  88.             int element;
  89.  
  90.             if (int.TryParse(userInput, out element))
  91.             {
  92.                 if (element > 0 && element <= fullNames.Length)
  93.                 {
  94.                     DeleteElementArray(ref fullNames,element);
  95.                     DeleteElementArray(ref posts,element);
  96.                     Console.WriteLine($"Досье работника под номером {element} удалено");
  97.                 }
  98.                 else
  99.                 {
  100.                     Console.WriteLine("Работника под таким номером не существует!");
  101.                 }
  102.             }
  103.             else
  104.             {
  105.                 Console.WriteLine("Ввод только числа!!!!");
  106.             }
  107.         }
  108.  
  109.         public static void DeleteElementArray(ref string[] array, int numberElement)
  110.         {
  111.             numberElement--;
  112.             string[] tempArray = new string[array.Length - 1];
  113.  
  114.             for (int i = 0; i < numberElement; i++)
  115.             {
  116.                 tempArray[i] = array[i];
  117.             }
  118.  
  119.             for (int i = numberElement + 1; i < array.Length; i++)
  120.             {
  121.                 tempArray[i - 1] = array[i];
  122.             }
  123.             array = tempArray;
  124.         }
  125.  
  126.         public static void ShowDossiers(ref string[] fullNames, ref string[] posts)
  127.         {
  128.             if (fullNames.Length > 0)
  129.                 for (int i = 0; i < fullNames.Length; i++)
  130.                     Console.Write($"\n{i + 1} - ФИО:{fullNames[i]} || Должность: {posts[i]}");
  131.             else
  132.                 Console.WriteLine("Пусто");
  133.         }
  134.  
  135.         public static void AddDossier(ref string[] fullNames, ref string[] posts)
  136.         {
  137.             Console.Write("Введите ФИО работника: ");
  138.             string fullName = Console.ReadLine();
  139.             Console.Write("Введите должность работника: ");
  140.             string post = Console.ReadLine();
  141.             ResizeArray(ref fullNames,fullName);
  142.             ResizeArray(ref posts, post);
  143.             Console.WriteLine("Досье добавлено!");
  144.         }
  145.  
  146.         public static void ResizeArray(ref string[] array, string value)
  147.         {
  148.             string[] tempArray = new string[array.Length + 1];
  149.  
  150.             for (int i = 0; i < array.Length; i++)
  151.             {
  152.                 tempArray[i] = array[i];
  153.             }
  154.             tempArray[tempArray.Length - 1] = value;
  155.             array = tempArray;
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment