Torgach

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

Jan 13th, 2021 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.48 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.                         DisplayInfo(fullName, position);
  36.                         break;
  37.                     case 3:
  38.                         DeleteDossier(ref fullName, ref position);
  39.                         break;
  40.                     case 4:
  41.                         SearchInfo(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.         static string[] AddDossier(string[] info)
  54.         {
  55.             string userInput = Console.ReadLine();
  56.  
  57.             string[] temInfo = new string[info.Length + 1];
  58.  
  59.             for(int i = 0; i < info.Length; i++)
  60.             {
  61.                 temInfo[i] = info[i];
  62.             }
  63.  
  64.             temInfo[temInfo.Length - 1] = userInput;
  65.             info = temInfo;
  66.  
  67.             return info;
  68.         }
  69.         static void DeleteDossier(ref string[] fullName, ref string[] position)
  70.         {
  71.             Console.Write("Удаляем досье под номером: №");
  72.             int dossierNumber = Convert.ToInt32(Console.ReadLine()) - 1;
  73.  
  74.             if (dossierNumber> fullName.Length)
  75.             {
  76.                 Console.WriteLine("Номер досье не существует!");
  77.             }
  78.             else
  79.             {
  80.                 Console.WriteLine("Удаляем...");
  81.  
  82.                 string[] tempFullname = new string[fullName.Length - 1];
  83.                 string[] tempPosition = new string[position.Length - 1];
  84.  
  85.                 for (int i = 0; i < fullName.Length; i++)
  86.                 {
  87.                     if (i < dossierNumber)
  88.                     {
  89.                         tempFullname[i] = fullName[i];
  90.                         tempPosition[i] = position[i];
  91.                     }
  92.                     else if (i > dossierNumber)
  93.                     {
  94.                         tempFullname[i - 1] = fullName[i];
  95.                         tempPosition[i - 1] = position[i];
  96.                     }
  97.                 }
  98.                 fullName = tempFullname;
  99.                 position = tempPosition;
  100.             }
  101.         }
  102.         static void SearchInfo(string[] fullname, string[] position)
  103.         {
  104.             Console.WriteLine("Введите фамилию:");
  105.             string userInput = Console.ReadLine();
  106.  
  107.             for (int i = 0; i < fullname.Length; i++)
  108.             {
  109.                 if(userInput == fullname[i])
  110.                 {
  111.                     Console.WriteLine("Досье найдено: " + fullname[i] + " - " + position[i]);
  112.                     return;
  113.                 }
  114.             }
  115.             Console.WriteLine("Досье не найдено...");
  116.         }
  117.         static void DisplayInfo(string[] fullName, string[] position)
  118.         {
  119.             if (fullName.Length == 0)
  120.             {
  121.                 Console.WriteLine("Пусто!");
  122.             }
  123.             else
  124.             {
  125.                 for (int i = 0; i < fullName.Length; i++)
  126.                 {
  127.                     Console.WriteLine("№" + (i + 1) + " " + fullName[i] + "-" + position[i]);
  128.                 }
  129.             }
  130.         }
  131.     }
  132. }
Add Comment
Please, Sign In to add comment