Torgach

Кадровый_Учет

Jan 23rd, 2021 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Кадровый_Учет
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool isWorking = true;
  10.  
  11.             string[] fullName = new string[0];
  12.             string[] position = new string[0];
  13.  
  14.             while (isWorking)
  15.             {
  16.                 Console.WriteLine("\nМеню:\n" +
  17.                 "1) добавить досье;\n" +
  18.                 "2) вывести все досье\n" +
  19.                 "3) удалить досье\n" +
  20.                 "4) поиск по фамилии\n" +
  21.                 "5) выход");
  22.  
  23.                 Console.Write("\nВвод: ");
  24.  
  25.                 switch (Convert.ToInt32(Console.ReadLine()))
  26.                 {
  27.                     case 1:
  28.                         Console.Write("Введите ФИО: ");
  29.                         fullName = AddDossier(fullName);
  30.  
  31.                         Console.Write("Введите должность: ");
  32.                         position = AddDossier(position);
  33.                         break;
  34.                     case 2:
  35.                         PrintInfo(fullName, position);
  36.                         break;
  37.                     case 3:
  38.                         DeleteDossier(ref fullName, ref position);
  39.                         break;
  40.                     case 4:
  41.                         FindDossierByFullname(fullName, position);
  42.                         break;
  43.                     case 5:
  44.                         Console.WriteLine("Выход...");
  45.                         isWorking = false;
  46.                         break;
  47.                     default:
  48.                         Console.WriteLine("Ошибка, повторно введите команду");
  49.                         break;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         static string[] AddDossier(string[] array)
  55.         {
  56.             string userInput = Console.ReadLine();
  57.  
  58.             string[] tempArray = new string[array.Length + 1];
  59.  
  60.             for (int i = 0; i < array.Length; i++)
  61.             {
  62.                 tempArray[i] = array[i];
  63.             }
  64.  
  65.             tempArray[tempArray.Length - 1] = userInput;
  66.             array = tempArray;
  67.  
  68.             return array;
  69.         }
  70.  
  71.         static void ChangeDossier(ref string[] array, int dossierNumber)
  72.         {
  73.             string[] tempArray = new string[array.Length - 1];
  74.  
  75.             for (int i = 0; i < array.Length; i++)
  76.             {
  77.                 if (i < dossierNumber)
  78.                 {
  79.                     tempArray[i] = array[i];
  80.                 }
  81.                 else if (i > dossierNumber)
  82.                 {
  83.                     tempArray[i - 1] = array[i];
  84.                 }
  85.             }
  86.             array = tempArray;
  87.         }
  88.  
  89.         static void DeleteDossier(ref string[] fullName, ref string[] position)
  90.         {
  91.             Console.Write("Удаляем досье под номером: №");
  92.             int dossierNumber = Convert.ToInt32(Console.ReadLine()) - 1;
  93.  
  94.             if (dossierNumber >= fullName.Length || dossierNumber < 0)
  95.             {
  96.                 Console.WriteLine("Номер досье не существует!");
  97.             }
  98.             else
  99.             {
  100.                 Console.WriteLine("Удаляем...");
  101.  
  102.                 ChangeDossier(ref fullName, dossierNumber);
  103.                 ChangeDossier(ref position, dossierNumber);
  104.             }
  105.         }
  106.  
  107.         static void FindDossierByFullname(string[] fullname, string[] position)
  108.         {
  109.             Console.WriteLine("Введите фамилию:");
  110.             string userInput = Console.ReadLine();
  111.  
  112.             for (int i = 0; i < fullname.Length; i++)
  113.             {
  114.                 if (userInput == fullname[i])
  115.                 {
  116.                     Console.WriteLine("Досье найдено: " + fullname[i] + " - " + position[i]);
  117.                     return;
  118.                 }
  119.             }
  120.             Console.WriteLine("Досье не найдено...");
  121.         }
  122.  
  123.         static void PrintInfo(string[] fullName, string[] position)
  124.         {
  125.             if (fullName.Length == 0)
  126.             {
  127.                 Console.WriteLine("Пусто!");
  128.             }
  129.             else
  130.             {
  131.                 for (int i = 0; i < fullName.Length; i++)
  132.                 {
  133.                     Console.WriteLine("№" + (i + 1) + " " + fullName[i] + " - " + position[i]);
  134.                 }
  135.             }
  136.         }
  137.  
  138.     }
  139. }
Add Comment
Please, Sign In to add comment