Advertisement
IGRODELOFF

homeWorkPersonnelAccounting

Jan 5th, 2025 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.25 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace homeWorkPersonnelAccounting
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             const string CommandAddDossier = "1";
  11.             const string CommandShowDossiers = "2";
  12.             const string CommandDeleteDossier = "3";
  13.             const string CommandSearchDossierForSecondName = "4";
  14.             const string CommandExit = "5";
  15.  
  16.             string[] employeeFullName = new string[0];
  17.             string[] employeePosition = new string[0];
  18.  
  19.             bool isExit = false;
  20.  
  21.             string userInput;
  22.  
  23.             while (isExit == false)
  24.             {
  25.                 Console.Clear();
  26.  
  27.                 Console.WriteLine(
  28.                     $"Меню: \n" +
  29.                     $"{CommandAddDossier} - Добавить досье\n" +
  30.                     $"{CommandShowDossiers} - Вывести все досье\n" +
  31.                     $"{CommandDeleteDossier} - Удалить досье\n" +
  32.                     $"{CommandSearchDossierForSecondName} - Поиск по фамилии\n" +
  33.                     $"{CommandExit} - Выход\n");
  34.  
  35.                 Console.Write("Введи номер команды: ");
  36.                 userInput = Console.ReadLine();
  37.  
  38.                 switch (userInput)
  39.                 {
  40.                     case CommandAddDossier:
  41.                         AddDossier(ref employeeFullName, ref employeePosition);
  42.                         break;
  43.                     case CommandShowDossiers:
  44.                         ShowDossiers(employeeFullName, employeePosition);
  45.                         break;
  46.                     case CommandDeleteDossier:
  47.                         DeleteDossier(ref employeeFullName, ref employeePosition);
  48.                         break;
  49.                     case CommandSearchDossierForSecondName:
  50.                         SearchDossierForSecondName(employeeFullName, employeePosition);
  51.                         break;
  52.                     case CommandExit:
  53.                         isExit = true;
  54.                         break;
  55.                     default:
  56.                         Console.WriteLine("Ошибка: несуществующая команда. Нажмите любую клавишу для продолжения.");
  57.                         Console.ReadKey();
  58.                         break;
  59.                 }
  60.             }
  61.  
  62.             Console.WriteLine("Выход из программы...");
  63.         }
  64.  
  65.         static void AddDossier(ref string[] employeeFullName, ref string[] employeePosition)
  66.         {
  67.             string fullName;
  68.             string position;
  69.  
  70.             Console.Clear();
  71.  
  72.             fullName = ReadFullName();
  73.  
  74.             Console.Write("Введите должность сотрудника: ");
  75.             position = Console.ReadLine();
  76.  
  77.             employeeFullName = AddToArray(employeeFullName, fullName);
  78.             employeePosition = AddToArray(employeePosition, position);
  79.  
  80.             Console.WriteLine("Досье добавлено. Нажмите любую клавишу для продолжения.");
  81.             Console.ReadKey();
  82.         }
  83.  
  84.         static void ShowDossiers(string[] employeeFullName, string[] employeePosition)
  85.         {
  86.             Console.Clear();
  87.  
  88.             if (employeeFullName.Length > 0)
  89.             {
  90.                 for (int i = 0; i < employeeFullName.Length; i++)
  91.                 {
  92.                     Console.WriteLine($"{i + 1} - {employeePosition[i]} - {employeeFullName[i]}");
  93.                 }
  94.             }
  95.             else
  96.             {
  97.                 Console.WriteLine("В каталоге нет досье.\n");
  98.             }
  99.  
  100.             Console.WriteLine("Нажмите любую клавишу для продолжения.");
  101.             Console.ReadKey();
  102.         }
  103.  
  104.         static void DeleteDossier(ref string[] employeeFullName, ref string[] employeePosition)
  105.         {
  106.             int index;
  107.  
  108.             bool trueIndexInput;
  109.  
  110.             Console.Clear();
  111.  
  112.             if (employeeFullName.Length > 0)
  113.             {
  114.                 Console.Write("Введите индекс досье, которое хотите удалить: ");
  115.                 trueIndexInput = int.TryParse(Console.ReadLine(), out index);
  116.  
  117.                 if (trueIndexInput == true && index >= 1 && index <= employeeFullName.Length)
  118.                 {
  119.                     index--;
  120.  
  121.                     employeeFullName = RemoveFromArray(employeeFullName, index);
  122.                     employeePosition = RemoveFromArray(employeePosition, index);
  123.  
  124.                     Console.WriteLine("Досье удалено.");
  125.                 }
  126.             }
  127.             else
  128.             {
  129.                 Console.WriteLine("В каталоге нет досье.\n");
  130.             }
  131.  
  132.             Console.WriteLine("Нажмите любую клавишу для продолжения.");
  133.             Console.ReadKey();
  134.         }
  135.  
  136.         static void SearchDossierForSecondName(string[] fullNameArray, string[] position)
  137.         {
  138.             string[] fullNameParts;
  139.  
  140.             Console.Clear();
  141.  
  142.             if (fullNameArray.Length > 0)
  143.             {
  144.                 int secondNameIndex = 0;
  145.  
  146.                 string userInput;
  147.                 bool isFound = false;
  148.  
  149.                 Console.Write("Введите для поиска фамилию человека: ");
  150.                 userInput = Console.ReadLine();
  151.  
  152.                 for (int i = 0; i < fullNameArray.Length; i++)
  153.                 {
  154.                     fullNameParts = fullNameArray[i].Split(' ');
  155.  
  156.                     if (fullNameParts[secondNameIndex].Equals(userInput, StringComparison.OrdinalIgnoreCase))
  157.                     {
  158.                         Console.WriteLine($"{i + 1} - {fullNameArray[i]} + {position[i]}");
  159.                         isFound = true;
  160.                     }
  161.                 }
  162.  
  163.                 if (isFound == false)
  164.                     Console.WriteLine("Такого человека нет в базе данных. Или вы сделали ошибку в фамилии человека.");
  165.  
  166.                 Console.WriteLine("Для продолжения нажмите кнопку.");
  167.                 Console.ReadKey();
  168.             }
  169.             else
  170.             {
  171.                 Console.WriteLine("Список досье пуст.");
  172.             }
  173.         }
  174.  
  175.         static string ReadFullName()
  176.         {
  177.             string[] fullNameArray = new string[3];
  178.             string fullName = "";
  179.             string userInput;
  180.  
  181.             bool isExit = false;
  182.  
  183.             while (isExit == false)
  184.             {
  185.                 Console.Clear();
  186.                 Console.Write("Введите ФИО всё через пробел: ");
  187.                 userInput = Console.ReadLine();
  188.  
  189.                 fullNameArray = userInput.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  190.                 if (fullNameArray.Length == 3)
  191.                 {
  192.                     fullName = string.Join(" ", fullNameArray);
  193.                     isExit = true;
  194.                 }
  195.                 else
  196.                 {
  197.                     Console.WriteLine("Ошибка: введите корректное ФИО из трёх слов. Нажмите любую клавишу для повторного ввода.");
  198.                     Console.ReadKey();
  199.                 }
  200.             }
  201.  
  202.             return fullName;
  203.         }
  204.  
  205.         static string[] AddToArray (string[] array, string value)
  206.         {
  207.             string[] newArray = new string[array.Length + 1];
  208.  
  209.             for (int i = 0; i < array.Length; i++)
  210.             {
  211.                 newArray[i] = array[i];
  212.             }
  213.  
  214.             newArray[array.Length] = value;
  215.             return newArray;
  216.         }
  217.  
  218.         static string[] RemoveFromArray (string[] array, int index)
  219.         {
  220.             string[] newArray = new string[array.Length - 1];
  221.  
  222.             for (int i = 0, j = 0; i < array.Length; i++)
  223.             {
  224.                 if (i != index)
  225.                 {
  226.                     newArray[j] = array[i];
  227.                     j++;
  228.                 }
  229.             }
  230.  
  231.             return newArray;
  232.         }
  233.     }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement