Advertisement
junniorrkaa

Кадровый учет

Dec 31st, 2024 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.77 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             const string CommandAddDossier = "1";
  10.             const string CommandDeduceDossiers = "2";
  11.             const string CommandDeleteDossier = "3";
  12.             const string CommandSearchLastName = "4";
  13.             const string CommandExit = "5";
  14.  
  15.             string[] fullNames = new string[0];
  16.             string[] posts = new string[0];
  17.  
  18.             bool isWork = true;
  19.  
  20.             Console.CursorVisible = false;
  21.  
  22.             while (isWork)
  23.             {
  24.                 Console.WriteLine("Меню команд:");
  25.                 Console.SetCursorPosition(0, 2);
  26.                 Console.WriteLine(CommandAddDossier + " - Добавить досье");
  27.                 Console.WriteLine(CommandDeduceDossiers + " - Вывести все досье");
  28.                 Console.WriteLine(CommandDeleteDossier + " - Удалить досье");
  29.                 Console.WriteLine(CommandSearchLastName + " - Поиск по фамилии");
  30.                 Console.WriteLine(CommandExit + " - Выход");
  31.                 Console.SetCursorPosition(0, 8);
  32.                 Console.Write("Введите команду: ");
  33.  
  34.                 switch (Console.ReadLine())
  35.                 {
  36.                     case CommandAddDossier:
  37.                         FillDossier(ref fullNames, ref posts);
  38.                         break;
  39.  
  40.                     case CommandDeduceDossiers:
  41.                         ShowDossier(fullNames, posts);
  42.                         break;
  43.  
  44.                     case CommandDeleteDossier:
  45.                         DeleteDossier(ref fullNames, ref posts);
  46.                         break;
  47.  
  48.                     case CommandSearchLastName:
  49.                         FindLastName(fullNames, posts);
  50.                         break;
  51.  
  52.                     case CommandExit:
  53.                         isWork = false;
  54.                         break;
  55.  
  56.                     default:
  57.                         Console.WriteLine("\nОшибка. Введена неверная команда...");
  58.                         break;
  59.                 }
  60.  
  61.                 Console.ReadKey(true);
  62.                 Console.Clear();
  63.             }
  64.         }
  65.  
  66.         static void FillDossier(ref string[] fullNames, ref string[] posts)
  67.         {
  68.             Console.Write("\nВведите ФИО: ");
  69.             fullNames = AddData(fullNames);
  70.  
  71.             Console.Write("\nВведите должность: ");
  72.             posts = AddData(posts);
  73.         }
  74.  
  75.         static void ShowDossier(string[] fullNames, string[] posts)
  76.         {
  77.             int sequenceNumber = 1;
  78.  
  79.             if (fullNames.Length == 0)
  80.             {
  81.                 Console.WriteLine("\nНа данный момент у вас нет ни одного досье.");
  82.             }
  83.             else
  84.             {
  85.                 for (int i = 0; i < fullNames.Length; i++)
  86.                 {
  87.                     Console.WriteLine($"\n| {sequenceNumber++}. {fullNames[i]} - {posts[i]} |");
  88.                 }
  89.             }
  90.         }
  91.  
  92.         static void DeleteDossier(ref string[] fullNames, ref string[] posts)
  93.         {
  94.             int deletedNumber;
  95.  
  96.             Console.Write("\nВведите номер досье на удаление: ");
  97.  
  98.             deletedNumber = ReadInt() - 1;
  99.  
  100.             if (deletedNumber < 0 || fullNames.Length == 0 || deletedNumber + 1 > fullNames.Length)
  101.             {
  102.                 Console.WriteLine("\nТакого номера нет.");
  103.             }
  104.             else
  105.             {
  106.                 fullNames = DeleteElement(fullNames, deletedNumber);
  107.                 posts = DeleteElement(posts, deletedNumber);
  108.             }
  109.         }
  110.  
  111.         static void FindLastName(string[] fullNames, string[] posts)
  112.         {
  113.             string[] lastName;
  114.  
  115.             string lastNameInput;
  116.  
  117.             bool isFound = false;
  118.  
  119.             Console.Write("\nВведите фамилию: ");
  120.  
  121.             lastNameInput = Console.ReadLine();
  122.  
  123.             for (int i = 0; i < fullNames.Length; i++)
  124.             {
  125.                 lastName = fullNames[i].Split(' ');
  126.  
  127.                 if (lastName[0].ToLower() == lastNameInput.ToLower())
  128.                 {
  129.                     Console.WriteLine($"\n| {fullNames[i]} - {posts[i]} |");
  130.  
  131.                     isFound = true;
  132.                 }
  133.             }
  134.  
  135.             if (isFound == false)
  136.             {
  137.                 Console.WriteLine("\nТакой фамилии нет.");
  138.             }
  139.         }
  140.  
  141.         static string[] AddData(string[] array)
  142.         {
  143.             string[] tempArray = new string[array.Length + 1];
  144.  
  145.             for (int i = 0; i < array.Length; i++)
  146.             {
  147.                 tempArray[i] = array[i];
  148.             }
  149.  
  150.             array = tempArray;
  151.             array[array.Length - 1] = Console.ReadLine();
  152.  
  153.             return array;
  154.         }
  155.  
  156.         static string[] DeleteElement(string[] array, int index)
  157.         {
  158.             string[] tempArray = array;
  159.             array = new string[tempArray.Length - 1];
  160.  
  161.             for (int i = 0; i < array.Length; i++)
  162.             {
  163.                 if (i == index || index < i)
  164.                 {
  165.                     array[i] = tempArray[i + 1];
  166.                 }
  167.                 else
  168.                 {
  169.                     array[i] = tempArray[i];
  170.                 }
  171.             }
  172.  
  173.             return array;
  174.         }
  175.  
  176.         static int ReadInt()
  177.         {
  178.             int number = 0;
  179.  
  180.             while (int.TryParse(Console.ReadLine(), out number) == false)
  181.             {
  182.                 Console.WriteLine("\nВведите число.\n");
  183.             }
  184.  
  185.             return number;
  186.         }
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement