Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace DossierProject
- {
- class Program
- {
- private static readonly string[] ConsoleOutputs = new string[]
- {
- ",",
- "Введите фамилию и время через запятую",
- "Досье успешно добавлено!",
- "Введите номер досье, которое вы хотите удалить:",
- "Нет досье!",
- "Досье успешно удалено!",
- "Нажмите любую клавишу, чтобы вернуться:",
- "Введите фамилию для поиска:",
- "Ничего не найдено!",
- "Результаты:"
- };
- private static readonly string[] MenuItems = new string[]
- {
- "Добавить новое досье",
- "Показать все досье",
- "Удалить досье",
- "Поиск по фамилии",
- "Выход",
- "Соси"
- };
- private static string[] Surnames = new string[0];
- private static string[] Positions = new string[0];
- private static int MenuPosition = 0;
- static void Main(string[] args)
- {
- PrintMenu();
- Menu();
- }
- private static void Menu()
- {
- while (true)
- {
- var key = Console.ReadKey().Key;
- switch (key)
- {
- case ConsoleKey.UpArrow:
- {
- if (MenuPosition > 0)
- {
- MenuPosition--;
- PrintMenu();
- }
- break;
- }
- case ConsoleKey.DownArrow:
- {
- if (MenuPosition < MenuItems.Length - 1)
- {
- MenuPosition++;
- PrintMenu();
- }
- break;
- }
- case ConsoleKey.Enter:
- {
- OnMenuItemSelected();
- break;
- }
- default: break;
- }
- }
- }
- private static void OnMenuItemSelected()
- {
- switch (MenuPosition)
- {
- case 0: AddDossier(); break;
- case 1: ShowAllDosiers(); break;
- case 2: DeleteDossier(); break;
- case 3: SearchDossier(); break;
- case 4: Environment.Exit(0); break;
- default: break;
- }
- }
- private static void AddDossier()
- {
- Console.Clear();
- Console.WriteLine(ConsoleOutputs[1]);
- while (true)
- {
- string line = Console.ReadLine();
- if (line.Contains(ConsoleOutputs[0]))
- {
- string[] tempSurnames = new string[Surnames.Length + 1];
- string[] tempPositions = new string[Positions.Length + 1];
- for (int i = 0; i < Surnames.Length; i++)
- {
- tempSurnames[i] = Surnames[i];
- }
- for (int i = 0; i < Positions.Length; i++)
- {
- tempPositions[i] = Positions[i];
- }
- tempSurnames[tempSurnames.Length - 1] = line.Split(',')[0];
- tempPositions[tempPositions.Length - 1] = line.Split(',')[1];
- Surnames = tempSurnames;
- Positions = tempPositions;
- Console.Clear();
- Console.WriteLine(ConsoleOutputs[2]);
- Console.ReadKey();
- break;
- }
- }
- PrintMenu();
- }
- private static void DeleteDossier()
- {
- Console.Clear();
- if (Surnames.Length == 0)
- {
- Console.WriteLine(ConsoleOutputs[4]);
- Console.ReadKey();
- }
- else
- {
- while (true)
- {
- Console.WriteLine(ConsoleOutputs[2]);
- Console.WriteLine();
- for (int i = 0; i < Surnames.Length; i++)
- {
- Console.WriteLine((i + 1) + ") " + Surnames[i] + " - " + Positions[i]);
- }
- Console.WriteLine();
- string line = Console.ReadLine();
- if (int.TryParse(line, out int number))
- {
- number -= 1;
- if (number >= 0 && number < Surnames.Length)
- {
- string[] tempSurnames = new string[Surnames.Length - 1];
- string[] tempPositions = new string[Positions.Length - 1];
- int iteratorSurnames = 0;
- int iteratorPositions = 0;
- for (int i = 0; i < tempSurnames.Length; i++)
- {
- if (i == number)
- {
- iteratorSurnames++;
- }
- tempSurnames[i] = Surnames[iteratorSurnames];
- iteratorSurnames++;
- }
- for (int i = 0; i < tempPositions.Length; i++)
- {
- if (i == number)
- {
- iteratorPositions++;
- }
- tempPositions[i] = Positions[iteratorPositions];
- iteratorPositions++;
- }
- Surnames = tempPositions;
- Positions = tempPositions;
- Console.Clear();
- Console.WriteLine(ConsoleOutputs[5]);
- Console.ReadKey();
- break;
- }
- else
- {
- Console.Clear();
- }
- }
- else
- {
- Console.Clear();
- }
- }
- }
- PrintMenu();
- }
- private static void ShowAllDosiers()
- {
- Console.Clear();
- if (Surnames.Length == 0)
- {
- Console.WriteLine(ConsoleOutputs[4]);
- }
- else
- {
- Console.WriteLine(ConsoleOutputs[6]);
- Console.WriteLine();
- for (int i = 0; i < Surnames.Length; i++)
- {
- Console.WriteLine((i + 1) + ") " + Surnames[i] + " - " + Positions[i]);
- }
- }
- Console.ReadKey();
- PrintMenu();
- }
- private static void SearchDossier()
- {
- Console.Clear();
- if (Surnames.Length == 0)
- {
- Console.WriteLine(ConsoleOutputs[4]);
- }
- else
- {
- Console.WriteLine(ConsoleOutputs[7]);
- Console.WriteLine();
- string surname = Console.ReadLine();
- int founded = 0;
- Console.Clear();
- Console.WriteLine(ConsoleOutputs[9]);
- Console.WriteLine();
- for (int i = 0; i < Surnames.Length; i++)
- {
- if (Surnames[i].Contains(surname))
- {
- Console.WriteLine(Surnames[i] + " - " + Positions[i]);
- founded++;
- }
- }
- if (founded == 0)
- {
- Console.Clear();
- Console.WriteLine();
- Console.WriteLine(ConsoleOutputs[8]);
- }
- }
- Console.ReadKey();
- PrintMenu();
- }
- private static void PrintMenu()
- {
- Console.Clear();
- for (int i = 0; i < MenuItems.Length; i++)
- {
- if (i == MenuPosition)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(MenuItems[i]);
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- else
- {
- Console.WriteLine(MenuItems[i]);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment