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
- {
- delegate void method();
- static void Main(string[] args)
- {
- string[] it = { "Авторизация", "Регистрация" };
- method[] method = new method[] { avt1, avt2 };
- ConsoleMenu menu2 = new ConsoleMenu(it);
- int Result;
- do
- {
- Result = menu2.PrintMenu();
- method[Result]();
- } while (Result != it.Length - 1);
- void avt2()
- {
- g1:
- try
- {
- bool avtor = false;
- do
- {
- Console.Write("Введите Логин:");
- string log = Console.ReadLine();
- Console.Write("Введите Пароль:");
- string pass = Console.ReadLine();
- Console.Write("Введите пароль повторно:");
- string pass2 = Console.ReadLine();
- if (File.Exists($@"C:\Menu\{log}.txt"))
- {
- Console.WriteLine("Данный пользователь уже создан, создайте нового!");
- }
- else
- {
- if (pass == pass2)
- {
- Console.WriteLine("Вы зарегистрировали новый аккаунт");
- File.AppendAllText($@"C:\Menu\{log}.txt", $"{pass}");
- avtor = true;
- }
- else
- {
- Console.WriteLine("Ошибка,пароли не совпадают!");
- avtor = false;
- }
- }
- }
- while (avtor == false);
- }
- catch (SystemException)
- {
- Console.WriteLine("Что то пошло не так, повторите попытку");
- goto g1;
- }
- }
- void avt1()
- {
- g2:
- try
- {
- bool avtor = false;
- do
- {
- Console.Write("Введите Логин:");
- string log = Console.ReadLine();
- if (File.Exists($@"C:\Menu\{log}.txt"))
- {
- Console.Write("Введите Пароль:");
- string pass = Console.ReadLine();
- FileStream fs1;
- fs1 = new FileStream($@"C:\Menu\{log}.txt", FileMode.Open);
- if (fs1.Length == pass.Length)
- {
- avtor = true;
- Menu();
- }
- }
- else
- {
- Console.WriteLine("Ошибка");
- avtor = false;
- }
- }
- while (avtor == false);
- }
- catch (SystemException)
- {
- Console.WriteLine("Что то пошло не так, повторите попытку");
- goto g2;
- }
- }
- }
- static void Menu()
- {
- string[] items = { "Создание файла", "Чтение из файла", "Сохранение в файл", "Сохранение в новый файл", "Переименование файла", "Удаление файла", "Выход" };
- method[] methods = new method[] { 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 Method1()
- {
- Console.WriteLine("Выбрано действие 'Создание файла' ");
- Console.WriteLine("Укажите путь к папке где хотите создать файл");
- try
- {
- string path = Console.ReadLine();
- File.Create(path);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Method2()
- {
- Console.WriteLine("Выбрано действие 'Чтение из файла' ");
- 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("Выбрано действие 'Сохранение в файл' ");
- 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("Выбрано действие 'Сохранение в новый файл' ");
- Console.WriteLine("Введите текст который хотите перезаписать");
- string text = Console.ReadLine();
- Console.WriteLine("Укажите путь к файлу котрый хотите перезаписать ");
- try
- {
- string path = Console.ReadLine();
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Method5()
- {
- Console.WriteLine("Выбрано действие 'Переименование файла' ");
- }
- static void Method6()
- {
- Console.WriteLine("Выбрано действие 'Удаление файла' ");
- Console.WriteLine("Укажите путь к файлу котрый хотите удалить ");
- try
- {
- string path = Console.ReadLine();
- File.Delete(path);
- }
- catch (Exception)
- {
- Console.WriteLine("Ошибка!");
- }
- }
- static void Exit()
- {
- Console.WriteLine("Приложение заканчивает работу!");
- }
- }
- 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