Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text;
- using System;
- using System.IO;
- namespace Menu
- {
- class Program
- {
- public static string login = "";
- public static bool activ = false;
- public delegate void method();
- static void Frst()
- {
- string[] first = { "Вход", "Регистрация", "Выход" };
- method[] methods = new method[] { Vhod, Reg, Exit };
- ConsoleMenu menu = new ConsoleMenu(first);
- zikl(menu, methods, first);
- }
- static void Two()
- {
- string[] first = { "Отчислиться", "Вернуться" };
- method[] methods = new method[] { Otchislen, Exit };
- ConsoleMenu menu = new ConsoleMenu(first);
- int menuResult;
- do
- {
- menuResult = menu.PrintMenu();
- methods[menuResult]();
- Console.WriteLine("Для продолжения нажмите любую клавишу");
- Console.ReadKey();
- } while (menuResult != 1);
- }
- static void zikl(ConsoleMenu menu, method[] methods, string[] items)
- {
- int menuResult;
- do
- {
- menuResult = menu.PrintMenu();
- methods[menuResult]();
- Console.WriteLine("Для продолжения нажмите любую клавишу");
- //Console.ReadKey();
- } while (activ == false);
- }
- static void Main(string[] args)
- {
- F:
- if (activ == false)
- {
- Frst();
- goto F;
- }
- else
- {
- string[] items = { $"Логин: {login}", "Создать файл", "Прочитать текст из файла", "Сохранить в файл", "Сохранить в новый файл", "Переименовать файла", "Удалить файл", "Выход" };
- method[] methods = new method[] { Account, Method1, Method2, Method3, Method4, Method5, Method6, Exit };
- ConsoleMenu menu = new ConsoleMenu(items);
- int menuResult;
- do
- {
- menuResult = menu.PrintMenu();
- methods[menuResult]();
- Console.WriteLine("Для продолжения нажмите любую клавишу");
- //Console.ReadKey();
- } while (menuResult != items.Length - 1);
- }
- }
- static void Account()
- {
- Console.Write("Это ваш аккаунт. Выберите действие.");
- Two();
- }
- static void Vhod()
- {
- bool dop;
- dop = Vhod1();
- if (dop)
- {
- Console.WriteLine("вход выполнен");
- activ = true;
- }
- }
- static bool Vhod1()
- {
- int kol_vo = 3;
- Console.WriteLine("Введите логин");
- string login_2 = Console.ReadLine();
- try
- {
- FileStream file1 = new FileStream($"D://_py//{login_2}.txt", FileMode.Open);
- StreamReader dop = new StreamReader(file1);
- Console.WriteLine("Введите пароль");
- M:
- if (Console.ReadLine() == dop.ReadLine())
- {
- dop.Close();
- login = login_2;
- return true;
- }
- else
- {
- kol_vo--;
- if (kol_vo == 0)
- {
- return false;
- }
- Console.WriteLine($"Пароль введен неверно. Попроуйте еще раз. Кол-во попыток : {kol_vo}");
- goto M;
- }
- }
- catch
- {
- Console.WriteLine("Логин введен не првильно");
- }
- return false;
- }
- static void Reg()
- {
- Console.WriteLine("введите логин");
- string text = Console.ReadLine();
- login = text;
- Console.WriteLine("Введите пароль");
- string pass = Console.ReadLine();
- File.WriteAllText($"D://_py//{text}.txt", pass);
- activ = true;
- }
- static void Method1()
- {
- Console.WriteLine("Укажите путь к папке где хотите создать файл");
- try
- {
- string path = Console.ReadLine();
- File.Create($"D://_py//{login}_2.txt");
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка");
- }
- }
- static void Method2()
- {
- Console.WriteLine("Укажите путь к файлу");
- try
- {
- string path = Console.ReadLine();
- FileStream file1 = new FileStream(path, FileMode.Open);
- StreamReader reader = new StreamReader(file1);
- Console.WriteLine($"Текст из файла: {reader.ReadToEnd()}");
- reader.Close();
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка");
- }
- }
- static void Method3()
- {
- Console.WriteLine("Введите текст");
- string text = Console.ReadLine();
- Console.WriteLine("Укажите путь к файлу который хотите дозаписать ");
- try
- {
- string path = Console.ReadLine();
- File.AppendAllText(path, text);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Method4()
- {
- Console.WriteLine("Введите текст");
- string text = Console.ReadLine();
- Console.WriteLine("Укажите путь к файлу");
- try
- {
- string path = Console.ReadLine();
- File.WriteAllText(path, text);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Method5()
- {
- Console.WriteLine("Укажите путь к файлу котрый хотите перетменовать ");
- try
- {
- string path = Console.ReadLine();
- Console.WriteLine("Укажите путь к файлу и новое имя");
- string ath = Console.ReadLine();
- File.Move(path, ath);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Method6()
- {
- Console.WriteLine("Укажите путь к файлу котрый хотите удалить ");
- try
- {
- string path = Console.ReadLine();
- File.Delete(path);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Exit()
- {
- Console.WriteLine("Отчислен");
- }
- static void Otchislen()
- {
- Environment.Exit(0);
- }
- }
- class ConsoleMenu
- {
- string[] menuItems;
- int counter = 0;
- public ConsoleMenu(string[] menuItems)
- {
- this.menuItems = menuItems;
- }
- public int PrintMenu()
- {
- ConsoleKeyInfo key;
- do
- {
- Console.Clear();
- for (int i = 0; i < menuItems.Length; i++)
- {
- if (counter == i)
- {
- Console.BackgroundColor = ConsoleColor.Cyan;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(menuItems[i]);
- Console.BackgroundColor = ConsoleColor.Black;
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- Console.WriteLine(menuItems[i]);
- }
- key = Console.ReadKey();
- if (key.Key == ConsoleKey.UpArrow)
- {
- counter--;
- if (counter == -1) counter = menuItems.Length - 1;
- }
- if (key.Key == ConsoleKey.DownArrow)
- {
- counter++;
- if (counter == menuItems.Length) counter = 0;
- }
- }
- while (key.Key != ConsoleKey.Enter);
- return counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement