Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Delegates
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = true;
- int set_color = 0;
- string[] name = { "Петров Петр Петрович", "Иванов Иван Иванович" };
- string[] position = { "Директор", "Заместитель директора" };
- string menu_pos = "Добавить досье.";
- string[] menu = { "Добавить досье.", "Вывести все досье.", "Поиск по фамилии.", "Удалить досье.", "Выход из программы." };
- Console.CursorVisible = false;
- while (exit)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < 5; i++)
- {
- if (i != set_color)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(menu[i]);
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- Console.WriteLine(menu[i]);
- menu_pos = menu[i];
- }
- }
- ConsoleKeyInfo charKey = Console.ReadKey(true);
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (set_color != 0)
- set_color--;
- break;
- case ConsoleKey.DownArrow:
- if (set_color != 4)
- set_color++;
- break;
- case ConsoleKey.Enter:
- menu_position(menu_pos, ref name, ref position, ref exit);
- break;
- }
- }
- }
- static void menu_position(string menu_pos, ref string[] name, ref string[] position, ref bool exit)
- {
- switch (menu_pos)
- {
- case "Добавить досье.":
- add_doc(ref name, ref position);
- break;
- case "Вывести все досье.":
- put_doc(ref name, ref position);
- break;
- case "Поиск по фамилии.":
- search_doc(ref name, ref position);
- break;
- case "Удалить досье.":
- del_doc(ref name, ref position);
- break;
- case "Выход из программы.":
- Console.Clear();
- exit = false;
- break;
- }
- }
- static void add_doc(ref string[] name, ref string[] position)
- {
- string fio;
- string pos;
- Console.SetCursorPosition(0, 6);
- Console.Write("Введите Ф.И.О. сотрудника: ");
- fio = Console.ReadLine();
- Console.Write("Введите должность сотрудника: ");
- pos = Console.ReadLine();
- string[] tempName = new string[name.Length + 1];
- for (int i = 0; i < name.Length; i++)
- tempName[i] = name[i];
- tempName[tempName.Length - 1] = fio;
- name = tempName;
- string[] tempPosition = new string[position.Length + 1];
- for (int i = 0; i < position.Length; i++)
- tempPosition[i] = position[i];
- tempPosition[tempPosition.Length - 1] = pos;
- position = tempPosition;
- Console.Clear();
- }
- static void put_doc(ref string[] name, ref string[] position)
- {
- Console.Clear();
- Console.SetCursorPosition(0, 8);
- for (int i = 0; i < name.Length; i++)
- {
- Console.Write(i + 1 + ". " + name[i] + " - " + position[i] + " ");
- }
- }
- static void search_doc(ref string[] name, ref string[] position)
- {
- string search;
- bool ser = true;
- Console.SetCursorPosition(0, 6);
- Console.Write("Введите фамилию сотрудника: ");
- search = Console.ReadLine();
- Console.Clear();
- for (int i = 0; i < name.Length; i++)
- {
- if (name[i].StartsWith(search))
- {
- Console.SetCursorPosition(0, 6);
- Console.Write(i + 1 + ". " + name[i] + " - " + position[i] + " ");
- ser = false;
- }
- }
- Console.SetCursorPosition(0, 6);
- if (ser) Console.Write("Данный сотрудник не числится в списке.");
- }
- static void del_doc(ref string[] name, ref string[] position)
- {
- string search;
- bool ser = false;
- int j = 0;
- Console.SetCursorPosition(0, 6);
- Console.Write("Введите фамилию сотрудника чье досье вы хотите удалить: ");
- search = Console.ReadLine();
- Console.Clear();
- string[] tempName = new string[name.Length - 1];
- string[] tempPosition = new string[position.Length - 1];
- for (int i = 0; i < name.Length; i++)
- {
- if (name[i].StartsWith(search))
- ser = true;
- }
- if (ser)
- {
- for (int i = 0; i < name.Length; i++)
- {
- if (!name[i].StartsWith(search))
- {
- tempName[j] = name[i];
- tempPosition[j] = position[i];
- j++;
- }
- }
- name = tempName;
- position = tempPosition;
- Console.SetCursorPosition(0, 6);
- Console.Write("Досье сотрудника " + search + " удалено.");
- }
- Console.SetCursorPosition(0, 6);
- if (!ser)
- Console.Write("Данный сотрудник не числится в списке.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement