Advertisement
LeRoY_Go

Untitled

Feb 1st, 2022
1,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool isExit = true;
  10.             string[] fullNames = { "Гришин Аверьян Вячеславович", "Гурьев Ермак Альвианович", "Уварова Инна Оскаровна", "Комиссарова Нора Лукьяновна", "Гордеева Герда Еремеевна" };
  11.             string[] positionsEmployee = { "Специалист", "Специалист", "Старшый специалист", "Руководитель группы", "Начальник отдела" };
  12.             while (isExit == true)
  13.             {
  14.                 Console.WriteLine("1 - добавить досье\n2 - вывести все досье\n3 - удалить досье\n4 - поиск по фамилии\n5 - выход");
  15.                 Console.Write("Введите команду: ");
  16.                 string userInput = Console.ReadLine();
  17.                 switch (userInput)
  18.                 {
  19.                     case "1":
  20.                         PreparingDossier(ref fullNames, ref positionsEmployee);
  21.                         break;
  22.                     case "2":
  23.                         ShowDossier(fullNames, positionsEmployee);
  24.                         break;
  25.                     case "3":
  26.                         SelectingDossierDelete(ref fullNames, ref positionsEmployee);
  27.                         break;
  28.                     case "4":
  29.                         SearchDossier(fullNames, positionsEmployee);
  30.                         break;
  31.                     case "5":
  32.                         isExit = false;
  33.                         break;
  34.                 }
  35.                 Console.Write("Нажмите Enter чтобы вернуться в меню.");
  36.                 Console.ReadLine();
  37.  
  38.             }
  39.             Environment.Exit(50);
  40.         }
  41.  
  42.         static void PreparingDossier(ref string[] fullName, ref string[] positionEmployee)
  43.         {
  44.             Console.Write("Введите фамилию: ");
  45.             string userInputSurname = Console.ReadLine();
  46.             Console.Write("Введите имя: ");
  47.             string userInputName = Console.ReadLine();
  48.             Console.Write("Введите отчество: ");
  49.             string userInputPatronymic = Console.ReadLine();
  50.             string userInputFullName = userInputSurname + " " + userInputName + " " + userInputPatronymic;
  51.             AddDossier(ref fullName, userInputFullName);
  52.             Console.Write("Введите должность: ");
  53.             string userInputPost = Console.ReadLine();
  54.             AddDossier(ref positionEmployee, userInputPost);
  55.             Console.WriteLine("Новое досье: " + userInputFullName + " - " + userInputPost);
  56.         }
  57.  
  58.         static void AddDossier(ref string[] array, string userInput)
  59.         {
  60.             string[] tempArrey = new string[array.Length + 1];
  61.             tempArrey[tempArrey.Length - 1] = userInput;
  62.  
  63.             for (int i = 0; i < array.Length; i++)
  64.             {
  65.                 tempArrey[i] = array[i];
  66.             }
  67.             array = tempArrey;
  68.         }
  69.  
  70.         static void ShowDossier(string[] fullName, string[] post)
  71.         {
  72.             for (int i = 0; i < fullName.Length; i++)
  73.             {
  74.                 Console.WriteLine("Досье сотрудника: №" + (i + 1) + " " + fullName[i] + " - " + post[i]);
  75.             }
  76.         }
  77.  
  78.         static void SelectingDossierDelete(ref string[] fullNames, ref string[] positionsEmployee)
  79.         {
  80.             Console.Write("Введите номер досье: ");
  81.             int index = Convert.ToInt32(Console.ReadLine()) - 1;
  82.             fullNames = DeleteDossier(fullNames, index);
  83.             positionsEmployee = DeleteDossier(positionsEmployee, index);
  84.             Console.WriteLine("Досье №" + (index + 1) + " удаленно.");
  85.         }
  86.  
  87.         static string[] DeleteDossier(string[] array, int index)
  88.         {
  89.             if (index >= 0 && index <= array.Length)
  90.             {
  91.                 string[] tempArrey = new string[array.Length - 1];
  92.                 for (int i = 0; i < index; i++)
  93.                 {
  94.                     tempArrey[i] = array[i];
  95.                 }
  96.                 for (int i = index; i < tempArrey.Length; i++)
  97.                 {
  98.                     tempArrey[i] = array[i + 1];
  99.                 }
  100.                 return tempArrey;
  101.             }
  102.             else
  103.             {
  104.                 Console.WriteLine("Досье с таким номером нет.");
  105.                 return array;
  106.             }
  107.         }
  108.  
  109.         static void SearchDossier(string[] fullName, string[] post)
  110.         {
  111.             bool employeeFound = false;
  112.             Console.Write("Введите ФИО сотрудника через пробел: ");
  113.             string userInputFullName = Console.ReadLine();
  114.             for (int i = 0; i < fullName.Length; i++)
  115.             {
  116.                 if (userInputFullName.ToLower() == fullName[i].ToLower())
  117.                 {
  118.                     Console.WriteLine("Досье сотрудника: №" + (i + 1) + " " + fullName[i] + " - " + post[i]);
  119.                     employeeFound = true;
  120.                     break;
  121.                 }
  122.             }
  123.             if (employeeFound == false)
  124.             {
  125.                 Console.WriteLine("Сотрудника с такой ФИО нету.");
  126.             }
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement