RedFlys

Home work - personnel registration

Oct 4th, 2021 (edited)
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home_Work
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] fullNames = new string[0];
  14.             string[] positions = new string[0];
  15.             bool isWorking = true;
  16.  
  17.             while (isWorking)
  18.             {
  19.                 ShowCommand();
  20.  
  21.                 switch (Console.ReadLine())
  22.                 {
  23.                     case "1":
  24.                         AddDossier(ref fullNames, ref positions);
  25.                         break;
  26.  
  27.                     case "2":
  28.                         ShowDossiers(fullNames, positions);
  29.                         break;
  30.  
  31.                     case "3":
  32.                         DeleteDossier(ref fullNames, ref positions);
  33.                         break;
  34.  
  35.                     case "4":
  36.                         FindDossierBySurname(fullNames, positions);
  37.                         break;
  38.  
  39.                     case "5":
  40.                         isWorking = false;
  41.                         break;
  42.  
  43.                     default:
  44.                         Console.WriteLine("Команды с таким номером не существует.");
  45.                         break;
  46.                 }
  47.  
  48.                 GetPush();
  49.             }
  50.         }
  51.  
  52.         static void ShowCommand()
  53.         {
  54.             Console.WriteLine("Доступны следующие команды:\n" +
  55.                 "1 - добавить досье\n" +
  56.                 "2 - вывести все досье\n" +
  57.                 "3 - удалить досье\n" +
  58.                 "4 - найти досье по фамилии\n" +
  59.                 "5 - закрыть программу ");
  60.         }
  61.  
  62.         static void GetPush()
  63.         {
  64.             Console.WriteLine("Нажмите любую клавишу, что бы продолжить...");
  65.             Console.ReadKey();
  66.             Console.Clear();
  67.         }
  68.  
  69.         static void AddDossier(ref string[] fullNames, ref string[] positions)
  70.         {
  71.             string fullName;
  72.             string position;
  73.  
  74.             Console.Write("Введите ФИО: ");
  75.             fullName = Console.ReadLine();
  76.  
  77.             Console.Write("Введите должность: ");
  78.             position = Console.ReadLine();
  79.  
  80.             fullNames = ExpandArray(fullNames, fullName);
  81.             positions = ExpandArray(positions, position);
  82.         }
  83.  
  84.         static string[] ExpandArray(string[] arrayForExpansion, string value)
  85.         {
  86.             string[] tempArray = new string[arrayForExpansion.Length + 1];
  87.  
  88.             for (int i = 0; i < arrayForExpansion.Length; i++)
  89.             {
  90.                 tempArray[i] = arrayForExpansion[i];
  91.             }
  92.  
  93.             tempArray[tempArray.Length - 1] = value;
  94.  
  95.             return tempArray;
  96.         }
  97.  
  98.         static bool CheckForMissingData(string[] fullNames)
  99.         {
  100.             if (fullNames.Length > 0)
  101.             {
  102.                 return false;
  103.             }
  104.             else
  105.             {
  106.                 Console.WriteLine("Данные отсутвуют.");
  107.  
  108.                 return true;
  109.             }
  110.         }
  111.  
  112.         static void ShowDossiers(string[] fullNames, string[] positions)
  113.         {
  114.             if (CheckForMissingData(fullNames) == false)
  115.             {
  116.                 for (int i = 0; i < fullNames.Length; i++)
  117.                 {
  118.                     Console.WriteLine((i + 1) + ". " + fullNames[i] + " - " + positions[i]);
  119.                 }
  120.             }
  121.         }
  122.  
  123.         static void DeleteDossier(ref string[] fullNames, ref string[] positions)
  124.         {
  125.             if (CheckForMissingData(fullNames) == false)
  126.             {
  127.                 int index;
  128.  
  129.                 Console.WriteLine("Введите порядковый номер досье: ");
  130.                 index = GetIndex(fullNames.Length);
  131.  
  132.                 fullNames = ReduceArray(index, fullNames);
  133.                 positions = ReduceArray(index, positions);
  134.             }
  135.         }
  136.  
  137.         static int GetIndex(int maxIndex)
  138.         {
  139.             bool isExistsIndex = false;
  140.             int number = 0;
  141.             string userInput;
  142.  
  143.             while (isExistsIndex == false)
  144.             {
  145.                 Console.Write("Введите число: ");
  146.                 userInput = Console.ReadLine();
  147.  
  148.                 if (Int32.TryParse(userInput, out number))
  149.                 {
  150.                     if (number > 0 && number <= maxIndex)
  151.                     {
  152.                         isExistsIndex = true;
  153.                     }
  154.                     else
  155.                     {
  156.                         Console.WriteLine("Досье с таким номером не существует.");
  157.                     }
  158.                 }
  159.                 else
  160.                 {
  161.                     Console.WriteLine("Это не число.");
  162.                 }
  163.             }
  164.  
  165.             return number - 1;
  166.         }
  167.  
  168.         static string[] ReduceArray(int index, string[] arrayForReduce)
  169.         {
  170.             string[] tempArray = new string[arrayForReduce.Length - 1];
  171.  
  172.             for (int i = 0; i < index; i++)
  173.             {
  174.                 tempArray[i] = arrayForReduce[i];
  175.             }
  176.  
  177.             for (int i = index; i < tempArray.Length; i++)
  178.             {
  179.                 tempArray[i] = arrayForReduce[i + 1];
  180.             }
  181.  
  182.             return tempArray;
  183.         }
  184.  
  185.         static void FindDossierBySurname(string[] fullNames, string[] positions)
  186.         {
  187.             if (CheckForMissingData(fullNames) == false)
  188.             {
  189.                 string userInput;
  190.  
  191.                 Console.WriteLine("Введите фамилию: ");
  192.                 userInput = Console.ReadLine();
  193.  
  194.                 for (int i = 0; i < fullNames.Length; i++)
  195.                 {
  196.                     if(userInput == fullNames[i].Split(' ')[0])
  197.                     {
  198.                         Console.WriteLine((i + 1) + ". " + fullNames[i] + " - " + positions[i]);
  199.                     }
  200.                 }
  201.             }
  202.         }
  203.     }
  204. }
Add Comment
Please, Sign In to add comment