Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Diagnostics.CodeAnalysis;
- using System.Dynamic;
- using System.Globalization;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.IO;
- namespace CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = false;
- int menuBar = 0;
- string[] menu = { "1. Добавить досье.", "2. Вывести досье.", "3. Удалить досье.", "4. Поиск по фамилии.", "5. Выход." };
- string[] fullNames = { "Иванов Иван Иванович", "Шевцов Глеб Егорыч" };
- string[] positions = { "Директор", "Коллектор" };
- Console.CursorVisible = false;
- while (exit == false)
- {
- string selectMenuItems;
- DrawMenu(menuBar, menu);
- ChangeDirection(ref menuBar, menu, out selectMenuItems);
- Console.Clear();
- switch (selectMenuItems)
- {
- case "1. Добавить досье.":
- string newWorker, positonWorker;
- Console.Write("Ведите ФИО нового сотрудника:");
- newWorker = Console.ReadLine();
- IncreaseDossier(ref fullNames, newWorker);
- Console.Write("Ведите должность сотрудника:");
- positonWorker = Console.ReadLine();
- IncreaseDossier(ref positions, positonWorker);
- Console.Clear();
- break;
- case "2. Вывести досье.":
- DrawaAllDossier(fullNames, positions);
- break;
- case "3. Удалить досье.":
- bool verificationWasSuccessful;
- int dossierNumber = 0;
- CheckDossierNumber(fullNames, positions, ref dossierNumber, out verificationWasSuccessful);
- if (verificationWasSuccessful == true)
- {
- DecreaseDossier(ref fullNames, dossierNumber);
- DecreaseDossier(ref positions, dossierNumber);
- }
- break;
- case "4. Поиск по фамилии.":
- string command;
- Console.Write("Введите фамилию:");
- command = Console.ReadLine();
- SearchSurname(fullNames, positions, command);
- break;
- case "5. Выход.":
- exit = true;
- break;
- }
- }
- }
- static void CheckDossierNumber(string[] array, string[] array1, ref int dossierNumber, out bool verificationWasSuccessful)
- {
- verificationWasSuccessful = false;
- if (array.Length == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- DrawaAllDossier(array, array1);
- Console.SetCursorPosition(0, 0);
- Console.Write("Досье для удаления:");
- dossierNumber = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- if (dossierNumber > array.Length || dossierNumber <= 0)
- {
- DrawLabels("Нет досье с таким номером");
- }
- else
- {
- verificationWasSuccessful = true;
- }
- }
- }
- static void DrawLabels(string text)
- {
- Console.SetCursorPosition(30, 0);
- Console.Write(text);
- }
- static void SearchSurname(string[] array, string[] array1, string command)
- {
- int hitCoincidence = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i].StartsWith(command))
- {
- Console.SetCursorPosition(30, i);
- Console.WriteLine($"{i + 1}) {array[i]} - {array1[i]}");
- hitCoincidence++;
- }
- }
- if (hitCoincidence == 0)
- {
- DrawLabels("Cовпадений нет.");
- }
- }
- static void IncreaseDossier(ref string[] array, string value)
- {
- string[] temp = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temp[i] = array[i];
- }
- temp[temp.Length - 1] = value;
- array = temp;
- }
- static void DecreaseDossier(ref string[] array, int value)
- {
- string[] temp = new string[array.Length - 1];
- for (int i = 0, j = 0; i < array.Length; i++)
- {
- if (i == (value - 1))
- continue;
- temp[j] = array[i];
- j++;
- }
- array = temp;
- }
- static void DrawaAllDossier(string[] array1, string[] array2)
- {
- if (array1.Length == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- for (int i = 0; i < array1.Length; i++)
- {
- Console.SetCursorPosition(30, i);
- Console.WriteLine($"{i + 1}) {array1[i]} - {array2[i]}");
- }
- }
- }
- static void DrawMenu(int menuBar, string[] items)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < items.Length; i++)
- {
- if (i == menuBar)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(items[i]);
- }
- else
- {
- Console.WriteLine(items[i]);
- }
- Console.ResetColor();
- }
- }
- static string GetChoise(string[] items, int menuBar)
- {
- return items[menuBar];
- }
- static void ChangeDirection(ref int menuBar, string[] items, out string selectMenuItems)
- {
- selectMenuItems = "";
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- if (menuBar <= 0)
- {
- menuBar = items.Length - 1;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar--;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.DownArrow:
- if (menuBar == items.Length - 1)
- {
- menuBar = 0;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar++;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.Enter:
- {
- selectMenuItems = GetChoise(items, menuBar);
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment