Garloon

4.1

Sep 2nd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3._3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] name = new string[0];
  14.             string[] work = new string[0];
  15.  
  16.             int index = 0;
  17.  
  18.             bool mainMenu = true;
  19.  
  20.             while(mainMenu == true)
  21.             {
  22.                 Console.WriteLine("ПАНЕЛЬ УПРАВЛЕНИЯ ДОСЬЕ");
  23.                 Console.WriteLine("\nМЕНЮ\n" +
  24.                     "\n1. Добавить досье" +
  25.                     "\n2. Вывести все досье" +
  26.                     "\n3. Удалить досье" +
  27.                     "\n4. Выход");
  28.                 Console.Write("\nВаше действие: ");
  29.  
  30.                 switch (Convert.ToInt32(Console.ReadLine()))
  31.                 {
  32.                     case 1:
  33.                         Console.Clear();
  34.                         Console.WriteLine("ПАНЕЛЬ ДОБАВЛЕНИЯ РАБОТНИКА В ДОСЬЕ");
  35.                         Console.Write("\nВведите Ф.И.О полностью: ");
  36.                         name = NameListExtension(name);
  37.                         Console.Write("\nВведите должность: ");
  38.                         work = WorkListExtension(work);
  39.                         ConsoleMessage("Вы успешно добавили работника!");
  40.                         break;
  41.                     case 2:
  42.                         Console.Clear();
  43.                         Console.WriteLine("СПИСОК РАБОТНИКОВ\n");
  44.                         ShowList(ref index, ref name, ref work);
  45.                         Search(ref name);
  46.                         Console.ReadKey();
  47.                         Console.Clear();
  48.                         break;
  49.                     case 3:
  50.                         Console.Clear();
  51.                         Console.WriteLine("ПАНЕЛЬ УДАЛЕНИЯ РАБОТНИКОВ ИЗ СПИСКА\n");
  52.                         ShowList(ref index, ref name, ref work);
  53.                         Console.Write("\nВведите порядковый номер работника, которого выхотите удалить: ");
  54.  
  55.                         int userInput = Convert.ToInt32(Console.ReadLine());
  56.                         userInput--;
  57.  
  58.                         name = Remove(name, userInput);
  59.                         work = Remove(work, userInput);
  60.  
  61.                         ConsoleMessage("Работник успешно удален!");
  62.                         Console.Clear();
  63.                         break;
  64.                     case 4:
  65.                         mainMenu = false;
  66.                         break;
  67.                     default:
  68.                         ConsoleMessage("\nНеизвестная команда!");
  69.                         break;
  70.                 }
  71.             }
  72.         }
  73.  
  74.         static void ConsoleMessage(string message)
  75.         {
  76.             Console.ForegroundColor = ConsoleColor.Red;
  77.             Console.WriteLine(message);
  78.             Console.ResetColor();
  79.             Console.ReadKey();
  80.             Console.Clear();
  81.         }
  82.  
  83.         static void Search(ref string[] name)
  84.         {
  85.             Console.Write("\nВведите фамилию работника, которого хотите найти: ");
  86.             string searchInput = Console.ReadLine().ToUpper();
  87.             for(int i = 0; i < name.Length; i++)
  88.             {
  89.                 string[]surname = name[i].Split(' ');
  90.                 if(searchInput == surname[0])
  91.                 {
  92.                     Console.WriteLine((i+1) + ". " + name[i]);
  93.                 }
  94.             }
  95.         }
  96.  
  97.         static void ShowList(ref int index, ref string[] name, ref string[] work)
  98.         {
  99.             for (int i = 0; i < name.Length; i++)
  100.             {
  101.                 index = i;
  102.                 Console.WriteLine((index + 1) + ". " + name[index] + " - " + work[index] + ";");
  103.             }
  104.         }
  105.  
  106.         static string[] NameListExtension(string [] name)
  107.         {
  108.             string userInput = Console.ReadLine().ToUpper();
  109.             string[] tempName = new string[name.Length + 1];
  110.             for(int i = 0; i < name.GetLength(0); i++)
  111.             {
  112.                 tempName[i] = name[i];
  113.             }
  114.  
  115.             tempName[tempName.Length - 1] = userInput;
  116.             name = tempName;
  117.             return tempName;
  118.         }
  119.  
  120.         static string[] WorkListExtension(string[] work)
  121.         {
  122.             string userInput = Console.ReadLine();
  123.             string[] tempWork = new string[work.Length + 1];
  124.             for (int i = 0; i < work.GetLength(0); i++)
  125.             {
  126.                 tempWork[i] = work[i];
  127.             }
  128.  
  129.             tempWork[tempWork.Length - 1] = userInput;
  130.             work = tempWork;
  131.             return tempWork;
  132.         }
  133.  
  134.         static string[] Remove(string[] name, int input)
  135.         {
  136.             int index = -1;
  137.  
  138.             for (int i = 0; i < name.Length; ++i)
  139.             {
  140.                 if (i == input)
  141.                 {
  142.                     index = i;
  143.                     break;
  144.                 }
  145.             }
  146.  
  147.             string[] tempName = new string[name.Length - 1];
  148.  
  149.             for (int i = 0, j = 0; i < tempName.Length; ++i, ++j)
  150.             {
  151.                 if (j == index)
  152.                     ++j;
  153.  
  154.                 tempName[i] = name[j];
  155.             }
  156.             name = tempName;
  157.  
  158.             return tempName;
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment