Advertisement
CrewLab

day_04_01

May 22nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.48 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Delegates
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             bool exit = true;
  11.             int set_color = 0;
  12.             string[] name = { "Петров Петр Петрович", "Иванов Иван Иванович" };
  13.             string[] position = { "Директор", "Заместитель директора" };
  14.             string menu_pos = "Добавить досье.";
  15.             string[] menu  = { "Добавить досье.", "Вывести все досье.", "Поиск по фамилии.", "Удалить досье.", "Выход из программы." };
  16.  
  17.             Console.CursorVisible = false;
  18.             while (exit)
  19.             {
  20.                 Console.SetCursorPosition(0, 0);
  21.                 for (int i = 0; i < 5; i++)
  22.                 {
  23.                     if (i != set_color)
  24.                     {
  25.                         Console.ForegroundColor = ConsoleColor.Green;
  26.                         Console.WriteLine(menu[i]);
  27.                         Console.ForegroundColor = ConsoleColor.White;
  28.                     }
  29.                     else
  30.                     {
  31.                         Console.WriteLine(menu[i]);
  32.                         menu_pos = menu[i];
  33.                     }
  34.  
  35.                 }
  36.  
  37.                 ConsoleKeyInfo charKey = Console.ReadKey(true);
  38.                 switch (charKey.Key)
  39.                 {
  40.                     case ConsoleKey.UpArrow:
  41.                         if (set_color != 0)
  42.                             set_color--;
  43.                         break;
  44.                     case ConsoleKey.DownArrow:
  45.                         if (set_color != 4)
  46.                             set_color++;
  47.                         break;
  48.                     case ConsoleKey.Enter:
  49.                         menu_position(menu_pos, ref name, ref position, ref exit);
  50.                         break;
  51.                 }
  52.  
  53.             }
  54.  
  55.         }
  56.  
  57.         static void menu_position(string menu_pos, ref string[] name, ref string[] position, ref bool exit)
  58.         {
  59.             switch (menu_pos)
  60.             {
  61.                 case "Добавить досье.":
  62.                     add_doc(ref name, ref position);
  63.                     break;
  64.                 case "Вывести все досье.":
  65.                     put_doc(ref name, ref position);
  66.                     break;
  67.                 case "Поиск по фамилии.":
  68.                     search_doc(ref name, ref position);
  69.                     break;
  70.                 case "Удалить досье.":
  71.                     del_doc(ref name, ref position);
  72.                     break;
  73.                 case "Выход из программы.":
  74.                     Console.Clear();
  75.                     exit = false;
  76.  
  77.                     break;
  78.             }
  79.         }
  80.  
  81.         static void add_doc(ref string[] name, ref string[] position)
  82.         {
  83.             string fio;
  84.             string pos;
  85.             Console.SetCursorPosition(0, 6);
  86.             Console.Write("Введите Ф.И.О. сотрудника: ");
  87.             fio = Console.ReadLine();
  88.             Console.Write("Введите должность сотрудника: ");
  89.             pos = Console.ReadLine();
  90.  
  91.             string[] tempName = new string[name.Length + 1];
  92.             for (int i = 0; i < name.Length; i++)
  93.                 tempName[i] = name[i];
  94.             tempName[tempName.Length - 1] = fio;
  95.             name = tempName;
  96.             string[] tempPosition = new string[position.Length + 1];
  97.             for (int i = 0; i < position.Length; i++)
  98.                 tempPosition[i] = position[i];
  99.             tempPosition[tempPosition.Length - 1] = pos;
  100.             position = tempPosition;
  101.             Console.Clear();
  102.         }
  103.  
  104.         static void put_doc(ref string[] name, ref string[] position)
  105.         {
  106.             Console.Clear();
  107.             Console.SetCursorPosition(0, 8);
  108.             for (int i = 0; i < name.Length; i++)
  109.             {
  110.                 Console.Write(i + 1 + ". " + name[i] + " - " + position[i] + " ");
  111.             }
  112.         }
  113.  
  114.         static void search_doc(ref string[] name, ref string[] position)
  115.         {
  116.             string search;
  117.             bool ser = true;
  118.  
  119.             Console.SetCursorPosition(0, 6);
  120.             Console.Write("Введите фамилию сотрудника: ");
  121.             search = Console.ReadLine();
  122.             Console.Clear();
  123.             for (int i = 0; i < name.Length; i++)
  124.             {
  125.                 if (name[i].StartsWith(search))
  126.                 {
  127.                     Console.SetCursorPosition(0, 6);
  128.                     Console.Write(i + 1 + ". " + name[i] + " - " + position[i] + " ");
  129.                     ser = false;
  130.                 }
  131.             }
  132.             Console.SetCursorPosition(0, 6);
  133.             if (ser) Console.Write("Данный сотрудник не числится в списке.");
  134.  
  135.         }
  136.  
  137.         static void del_doc(ref string[] name, ref string[] position)
  138.         {
  139.             string search;
  140.             bool ser = false;
  141.             int j = 0;
  142.  
  143.             Console.SetCursorPosition(0, 6);
  144.             Console.Write("Введите фамилию сотрудника чье досье вы хотите удалить: ");
  145.             search = Console.ReadLine();
  146.             Console.Clear();
  147.             string[] tempName = new string[name.Length - 1];
  148.             string[] tempPosition = new string[position.Length - 1];
  149.             for (int i = 0; i < name.Length; i++)
  150.             {
  151.                 if (name[i].StartsWith(search))
  152.                     ser = true;
  153.             }
  154.             if (ser)
  155.             {
  156.                 for (int i = 0; i < name.Length; i++)
  157.                 {
  158.                     if (!name[i].StartsWith(search))
  159.                     {
  160.                         tempName[j] = name[i];
  161.                         tempPosition[j] = position[i];
  162.                         j++;
  163.                     }
  164.                 }
  165.                 name = tempName;
  166.                 position = tempPosition;
  167.                 Console.SetCursorPosition(0, 6);
  168.                 Console.Write("Досье сотрудника " + search + " удалено.");
  169.             }
  170.             Console.SetCursorPosition(0, 6);
  171.             if (!ser)
  172.                 Console.Write("Данный сотрудник не числится в списке.");
  173.  
  174.         }
  175.  
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement