SaNik74

personnel accounting

Mar 17th, 2023 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.43 KB | None | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         const string AddDossierCommand = "add";
  8.         const string OutputDossierCommand = "output all";
  9.         const string DeleteDossierCommand = "delete";
  10.         const string FindLastNameCommand = "find";
  11.         const string EndProgramCommand = "exit";
  12.  
  13.         string[] fullNames = new string[1];
  14.         string[] jobTitles = new string[1];
  15.         bool isWorking = true;
  16.  
  17.         while (isWorking)
  18.         {
  19.             Console.WriteLine($"База данных:" +
  20.             $"\nДля добавления досье введите - {AddDossierCommand}." +
  21.             $"\nДля вывода всей базы введите - {OutputDossierCommand}." +
  22.             $"\nДля удаления досье введите - {DeleteDossierCommand}." +
  23.             $"\nДля поиска по фамилии введите - {FindLastNameCommand}." +
  24.             $"\nДля выхода введите - {EndProgramCommand}.");
  25.  
  26.             string? userInput = Console.ReadLine();
  27.  
  28.             switch (userInput)
  29.             {
  30.                 case AddDossierCommand:
  31.                     AddDossier(ref fullNames, ref jobTitles);
  32.                     break;
  33.  
  34.                 case OutputDossierCommand:
  35.                     OutputAllDossier(fullNames, jobTitles);
  36.                     break;
  37.  
  38.                 case DeleteDossierCommand:
  39.                     DeleteDossier(ref fullNames, ref jobTitles);
  40.                     break;
  41.  
  42.                 case FindLastNameCommand:
  43.                     FindLastName(ref fullNames, ref jobTitles);
  44.                     break;
  45.  
  46.                 case EndProgramCommand:
  47.                     EndProgram(out isWorking);
  48.                     break;
  49.  
  50.                 default:
  51.                     UncorrectMessage();
  52.                     break;
  53.             }
  54.  
  55.             Console.Clear();
  56.         }
  57.     }
  58.  
  59.     static void AddDossier(ref string[] fullNames, ref string[] jobTitles)
  60.     {
  61.         string fullName = "ФИО";
  62.         string jobTitle = "досье";
  63.  
  64.         fullNames = FillingArray(fullNames, fullName);
  65.         jobTitles = FillingArray(jobTitles, jobTitle);
  66.     }
  67.  
  68.     static void OutputAllDossier(string[] fullNames, string[] jobTitles)
  69.     {
  70.         for (int i = 0; i < fullNames.Length - 1; i++)
  71.         {
  72.             if (i >= 0 && i < fullNames.Length - 2)
  73.             {
  74.                 Console.Write($"{i + 1} {fullNames[i]} {jobTitles[i]} - ");
  75.             }
  76.             else
  77.             {
  78.                 Console.Write($"{i + 1} {fullNames[i]} {jobTitles[i]}.");
  79.             }
  80.         }
  81.  
  82.         Console.ReadKey();
  83.     }
  84.  
  85.     static void DeleteDossier(ref string[] fullNames, ref string[] jobTitles)
  86.     {
  87.         string[] newFullNames = new string[fullNames.Length - 1];
  88.         string[] newJobTitles = new string[jobTitles.Length - 1];
  89.         Console.Write("Введите номер досье, которое хотите удалить: ");
  90.         int number = Convert.ToInt32(Console.ReadLine()) - 1;
  91.  
  92.         if (number <= 0 || number > fullNames.Length)
  93.         {
  94.             Console.WriteLine("Число вышло за пределы массива.");
  95.         }
  96.  
  97.         for (int i = 0; i < number; i++)
  98.         {
  99.             FillingArraytoIndex(ref fullNames, ref newFullNames, number, out int j);
  100.             FillingArraytoIndex(ref jobTitles, ref newJobTitles, number, out j);
  101.         }
  102.         for (int i = number + 1; i < fullNames.Length - 1; i++)
  103.         {
  104.             FillingArraytoIndex(ref fullNames, ref newFullNames, number, out int j);
  105.             FillingArraytoIndex(ref jobTitles, ref newJobTitles, number, out j);
  106.         }
  107.  
  108.         fullNames = newFullNames;
  109.         jobTitles = newJobTitles;
  110.     }
  111.  
  112.     static void FindLastName(ref string[] fullNames, ref string[] jobTitles)
  113.     {
  114.         Console.Write("Введите фамилию: ");
  115.         string? lastName = Console.ReadLine();
  116.  
  117.         for (int i = 0; i < fullNames.Length - 1; i++)
  118.         {
  119.             if (fullNames[i].Split()[0] == lastName)
  120.             {
  121.                 Console.WriteLine($"{i + 1} {fullNames[i]} {jobTitles[i]}");
  122.             }
  123.         }
  124.  
  125.         Console.ReadKey();
  126.     }
  127.  
  128.     static void EndProgram(out bool isWorking)
  129.     {
  130.         Console.WriteLine("Выход из программы. Нажмите любую клавишу...");
  131.         Console.ReadKey();
  132.         isWorking = false;
  133.     }
  134.  
  135.     static void UncorrectMessage()
  136.     {
  137.         Console.WriteLine("Введена некорректная команда. Попробуйте еще раз.");
  138.         Console.ReadKey();
  139.     }
  140.  
  141.     static string[] FillingArray(string[] array, string indexName)
  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.         Console.Write($"Введите {indexName}: ");
  151.         string? name = Console.ReadLine();
  152.         tempArray[array.Length - 1] = name;
  153.         array = tempArray;
  154.         return array;
  155.     }
  156.  
  157.     static void FillingArraytoIndex(ref string[] array, ref string[] newArray, int index, out int j)
  158.     {
  159.         j = 0;
  160.  
  161.         for (int i = 0; i < array.Length; i++)
  162.         {
  163.             if (i != index)
  164.             {
  165.                 newArray[j] = array[i];
  166.                 j++;
  167.             }
  168.         }
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment