dxoraxs

Untitled

Apr 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.18 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homework
  4. {
  5.     class Program
  6.     {
  7.         static void WriteMenu(string[] text, ConsoleColor ColorWord, ConsoleColor ColorBackground)
  8.         {
  9.             ConsoleColor defaultColorWord = Console.ForegroundColor;
  10.             ConsoleColor defaultColorBackground = Console.BackgroundColor;
  11.  
  12.             Console.ForegroundColor = ColorWord;
  13.             Console.BackgroundColor = ColorBackground;
  14.             for (int i = 0;i< text.Length;i++)
  15.             {
  16.                 Console.WriteLine(i+1+". "+text[i]);
  17.             }
  18.             Console.ForegroundColor = defaultColorWord;
  19.             Console.BackgroundColor = defaultColorBackground;
  20.         }
  21.  
  22.         static void WriteMenu(string text, ConsoleColor ColorWord = ConsoleColor.Gray, ConsoleColor ColorBackground = ConsoleColor.Black)
  23.         {
  24.             ConsoleColor defaultColorWord = Console.ForegroundColor;
  25.             ConsoleColor defaultColorBackground = Console.BackgroundColor;
  26.  
  27.             Console.ForegroundColor = ColorWord;
  28.             Console.BackgroundColor = ColorBackground;
  29.  
  30.             Console.WriteLine(" "+text+" ");
  31.  
  32.             Console.ForegroundColor = defaultColorWord;
  33.             Console.BackgroundColor = defaultColorBackground;
  34.         }
  35.  
  36.         static void AddNewPost(ref string[] name, ref string[] post, int minWords)
  37.         {
  38.             string[] copyName = new string[name.Length+1], copyPost = new string[post.Length+1];
  39.             for (int i =0; i<name.Length; i++)
  40.             {
  41.                 copyName[i] = name[i];
  42.                 copyPost[i] = post[i];
  43.             }
  44.             string strFio = "Введите ФИО: ", strPost = "Введите должность: ";
  45.             for (int i = 0; i < strPost.Length - strFio.Length; i++)
  46.                 strFio += " ";
  47.             WriteMenu(strFio, ConsoleColor.Black, ConsoleColor.White);
  48.  
  49.             string str = Console.ReadLine();
  50.             char delimiterChar = ' ';
  51.             string[] words = str.Split(delimiterChar);
  52.             if (words.Length< minWords)
  53.             {
  54.                 WriteMenu("В ФИО не может быть слов меньше, чем "+ minWords, ConsoleColor.Red);
  55.                 WriteMenu("Нажмите, чтобы выйти обратно в меню...");
  56.                 Console.ReadKey();
  57.                 return;
  58.             }
  59.             copyName[copyName.Length - 1] = str;
  60.  
  61.             WriteMenu(strPost, ConsoleColor.Black, ConsoleColor.White);
  62.             str = Console.ReadLine();
  63.             if (str.Length == 0)
  64.             {
  65.                 WriteMenu("Вы ничего не ввели!",ConsoleColor.Red);
  66.                 WriteMenu("Нажмите, чтобы выйти обратно в меню...");
  67.                 Console.ReadKey();
  68.                 return;
  69.             }
  70.             copyPost[copyPost.Length - 1] = str;
  71.  
  72.             name = copyName;
  73.             post = copyPost;
  74.         }
  75.  
  76.         static void OutAllPost(string[] name, string[] post)
  77.         {
  78.             Console.Clear();
  79.             WriteMenu("Все досье:", ConsoleColor.Black, ConsoleColor.White);
  80.             if (name.Length > 0)
  81.                 for (int i = 0; i < name.Length; i++)
  82.                 {
  83.                     if (i%2==0)
  84.                     WriteMenu(i + 1 + ". " + name[i] + " - " + post[i], ConsoleColor.White, ConsoleColor.Black);
  85.                     else
  86.                         WriteMenu(i + 1 + ". " + name[i] + " - " + post[i], ConsoleColor.Gray, ConsoleColor.Black);
  87.                 }
  88.             else WriteMenu("Ни одного досье не найдено!", ConsoleColor.Red, ConsoleColor.Black);
  89.         }
  90.  
  91.         static void DeletePost(ref string[] name, ref string[] post)
  92.         {
  93.             if (name.Length > 0)
  94.             {
  95.                 string[] copyName = new string[name.Length - 1], copyPost = new string[post.Length - 1];
  96.                 OutAllPost(name, post);
  97.                 Console.Write("Введите номер досье, которое хотите удалить: ");
  98.                 int number = Convert.ToInt32(Console.ReadLine());
  99.                 if (number <= name.Length)
  100.                 {
  101.                     for (int i =0, j=0; i< name.Length && name.Length>1; i++, j++)
  102.                     {
  103.                         if (i < name.Length-1)
  104.                         {
  105.                             if (number - 1 == i) i++;
  106.                             copyName[j] = name[i];
  107.                             copyPost[j] = post[i];
  108.                         }
  109.                        
  110.                     }
  111.                     name = copyName;
  112.                     post = copyPost;
  113.                     Console.WriteLine("Имеющиеся досье:");
  114.                     OutAllPost(name, post);
  115.                 }
  116.                 else WriteMenu("Введено некоректный номер досье!", ConsoleColor.Red, ConsoleColor.Black);
  117.             }
  118.             else WriteMenu("Ни одного досье не найдено!", ConsoleColor.Red, ConsoleColor.Black);
  119.             WriteMenu("Нажмите, чтобы выйти обратно в меню...");
  120.             Console.ReadKey();
  121.         }
  122.  
  123.         static string FindName(string[] text, string[] post)
  124.         {
  125.             Console.Clear();
  126.             Console.Write("Для поиска ведите фамилию: ");
  127.             string findText = Console.ReadLine();
  128.             int countFindText = 0;
  129.             string findNameText="";
  130.             for (int i=0, count=0; i<text.Length && findText.Length>0; i++)
  131.             {
  132.                 for (int j=0; j<text[i].Length;j++)  
  133.                 {
  134.                     if (Char.ToLower(text[i][j]) == Char.ToLower(findText[count])) count++;
  135.                     else count = 0;
  136.                     if (count == findText.Length)
  137.                     {
  138.                         countFindText++;
  139.                         findNameText+= "\n"+ countFindText +". "+ text[i]+" - "+post[i];
  140.                         count = 0;
  141.                         continue;
  142.                     }
  143.                 }
  144.             }
  145.             if (findNameText == "") findNameText = "Запрос не дал результатов";
  146.             return findNameText;
  147.         }
  148.  
  149.         static void Main(string[] args)
  150.         {
  151.             string[] name= {"Первое досье Один", "Второе досье Два", "Третье досье Три"}, post= {"Первое должность", "Вторая должность", "Третья должность"};
  152.             string countCommand = "";
  153.             string[] menu = {"Добавить досье.","Вывести все досье.","Удалить досье","Поиск по фамилии","Выход"};
  154.             while (countCommand!="5")
  155.             {
  156.                 Console.Clear();
  157.                 Console.Write("\n\t");
  158.                 WriteMenu("Кадровый учет", ConsoleColor.Black, ConsoleColor.White);
  159.                 WriteMenu(menu, ConsoleColor.White, ConsoleColor.Black);
  160.                 Console.WriteLine();
  161.                 countCommand= Console.ReadLine();
  162.                 switch (countCommand)
  163.                 {
  164.                     case "1":
  165.                         AddNewPost(ref name, ref post, 3);
  166.                         break;
  167.                     case "2":
  168.                         OutAllPost(name, post);
  169.                         WriteMenu("Нажмите, чтобы выйти обратно в меню...");
  170.                         Console.ReadKey();
  171.                         break;
  172.                     case "3":
  173.                         DeletePost(ref name, ref post);
  174.                         break;
  175.                     case "4":
  176.                         WriteMenu(FindName(name, post));
  177.                         WriteMenu("Нажмите, чтобы выйти обратно в меню...");
  178.                         Console.ReadKey();
  179.                         break;
  180.                     case "5":
  181.                         break;
  182.                     default:
  183.                     case "":
  184.                        
  185.                         break;
  186.                 }
  187.             }
  188.         }
  189.     }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment