Torgach

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

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