Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homework
- {
- class Program
- {
- static void WriteMenu(string[] text, ConsoleColor ColorWord, ConsoleColor ColorBackground)
- {
- ConsoleColor defaultColorWord = Console.ForegroundColor;
- ConsoleColor defaultColorBackground = Console.BackgroundColor;
- Console.ForegroundColor = ColorWord;
- Console.BackgroundColor = ColorBackground;
- for (int i = 0;i< text.Length;i++)
- {
- Console.WriteLine(i+1+". "+text[i]);
- }
- Console.ForegroundColor = defaultColorWord;
- Console.BackgroundColor = defaultColorBackground;
- }
- static void WriteMenu(string text, ConsoleColor ColorWord = ConsoleColor.Gray, ConsoleColor ColorBackground = ConsoleColor.Black)
- {
- ConsoleColor defaultColorWord = Console.ForegroundColor;
- ConsoleColor defaultColorBackground = Console.BackgroundColor;
- Console.ForegroundColor = ColorWord;
- Console.BackgroundColor = ColorBackground;
- Console.WriteLine(" "+text+" ");
- Console.ForegroundColor = defaultColorWord;
- Console.BackgroundColor = defaultColorBackground;
- }
- static void AddNewPost(ref string[] name, ref string[] post, int minWords)
- {
- string[] copyName = new string[name.Length+1], copyPost = new string[post.Length+1];
- for (int i =0; i<name.Length; i++)
- {
- copyName[i] = name[i];
- copyPost[i] = post[i];
- }
- string strFio = "Введите ФИО: ", strPost = "Введите должность: ";
- for (int i = 0; i < strPost.Length - strFio.Length; i++)
- strFio += " ";
- WriteMenu(strFio, ConsoleColor.Black, ConsoleColor.White);
- string str = Console.ReadLine();
- char delimiterChar = ' ';
- string[] words = str.Split(delimiterChar);
- if (words.Length< minWords)
- {
- WriteMenu("В ФИО не может быть слов меньше, чем "+ minWords, ConsoleColor.Red);
- WriteMenu("Нажмите, чтобы выйти обратно в меню...");
- Console.ReadKey();
- return;
- }
- copyName[copyName.Length - 1] = str;
- WriteMenu(strPost, ConsoleColor.Black, ConsoleColor.White);
- str = Console.ReadLine();
- if (str.Length == 0)
- {
- WriteMenu("Вы ничего не ввели!",ConsoleColor.Red);
- WriteMenu("Нажмите, чтобы выйти обратно в меню...");
- Console.ReadKey();
- return;
- }
- copyPost[copyPost.Length - 1] = str;
- name = copyName;
- post = copyPost;
- }
- static void OutAllPost(string[] name, string[] post)
- {
- Console.Clear();
- WriteMenu("Все досье:", ConsoleColor.Black, ConsoleColor.White);
- if (name.Length > 0)
- for (int i = 0; i < name.Length; i++)
- {
- if (i%2==0)
- WriteMenu(i + 1 + ". " + name[i] + " - " + post[i], ConsoleColor.White, ConsoleColor.Black);
- else
- WriteMenu(i + 1 + ". " + name[i] + " - " + post[i], ConsoleColor.Gray, ConsoleColor.Black);
- }
- else WriteMenu("Ни одного досье не найдено!", ConsoleColor.Red, ConsoleColor.Black);
- }
- static void DeletePost(ref string[] name, ref string[] post)
- {
- if (name.Length > 0)
- {
- string[] copyName = new string[name.Length - 1], copyPost = new string[post.Length - 1];
- OutAllPost(name, post);
- Console.Write("Введите номер досье, которое хотите удалить: ");
- int number = Convert.ToInt32(Console.ReadLine());
- if (number <= name.Length)
- {
- for (int i =0, j=0; i< name.Length && name.Length>1; i++, j++)
- {
- if (i < name.Length-1)
- {
- if (number - 1 == i) i++;
- copyName[j] = name[i];
- copyPost[j] = post[i];
- }
- }
- name = copyName;
- post = copyPost;
- Console.WriteLine("Имеющиеся досье:");
- OutAllPost(name, post);
- }
- else WriteMenu("Введено некоректный номер досье!", ConsoleColor.Red, ConsoleColor.Black);
- }
- else WriteMenu("Ни одного досье не найдено!", ConsoleColor.Red, ConsoleColor.Black);
- WriteMenu("Нажмите, чтобы выйти обратно в меню...");
- Console.ReadKey();
- }
- static string FindName(string[] text, string[] post)
- {
- Console.Clear();
- Console.Write("Для поиска ведите фамилию: ");
- string findText = Console.ReadLine();
- int countFindText = 0;
- string findNameText="";
- for (int i=0, count=0; i<text.Length && findText.Length>0; i++)
- {
- for (int j=0; j<text[i].Length;j++)
- {
- if (Char.ToLower(text[i][j]) == Char.ToLower(findText[count])) count++;
- else count = 0;
- if (count == findText.Length)
- {
- countFindText++;
- findNameText+= "\n"+ countFindText +". "+ text[i]+" - "+post[i];
- count = 0;
- continue;
- }
- }
- }
- if (findNameText == "") findNameText = "Запрос не дал результатов";
- return findNameText;
- }
- static void Main(string[] args)
- {
- string[] name= {"Первое досье Один", "Второе досье Два", "Третье досье Три"}, post= {"Первое должность", "Вторая должность", "Третья должность"};
- string countCommand = "";
- string[] menu = {"Добавить досье.","Вывести все досье.","Удалить досье","Поиск по фамилии","Выход"};
- while (countCommand!="5")
- {
- Console.Clear();
- Console.Write("\n\t");
- WriteMenu("Кадровый учет", ConsoleColor.Black, ConsoleColor.White);
- WriteMenu(menu, ConsoleColor.White, ConsoleColor.Black);
- Console.WriteLine();
- countCommand= Console.ReadLine();
- switch (countCommand)
- {
- case "1":
- AddNewPost(ref name, ref post, 3);
- break;
- case "2":
- OutAllPost(name, post);
- WriteMenu("Нажмите, чтобы выйти обратно в меню...");
- Console.ReadKey();
- break;
- case "3":
- DeletePost(ref name, ref post);
- break;
- case "4":
- WriteMenu(FindName(name, post));
- WriteMenu("Нажмите, чтобы выйти обратно в меню...");
- Console.ReadKey();
- break;
- case "5":
- break;
- default:
- case "":
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment