Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | None | 0 0
  1. using System.Text;
  2. using System;
  3. using System.IO;
  4.  
  5. namespace Menu
  6. {
  7.  
  8. class Program
  9. {
  10. public static string login = "";
  11. public static bool activ = false;
  12.  
  13. public delegate void method();
  14. static void Frst()
  15. {
  16. string[] first = { "Вход", "Регистрация", "Выход" };
  17. method[] methods = new method[] { Vhod, Reg, Exit };
  18. ConsoleMenu menu = new ConsoleMenu(first);
  19. zikl(menu, methods, first);
  20.  
  21. }
  22. static void Two()
  23. {
  24. string[] first = { "Отчислиться", "Вернуться" };
  25. method[] methods = new method[] { Otchislen, Exit };
  26. ConsoleMenu menu = new ConsoleMenu(first);
  27. int menuResult;
  28. do
  29. {
  30. menuResult = menu.PrintMenu();
  31.  
  32. methods[menuResult]();
  33. Console.WriteLine("Для продолжения нажмите любую клавишу");
  34. Console.ReadKey();
  35. } while (menuResult != 1);
  36.  
  37. }
  38. static void zikl(ConsoleMenu menu, method[] methods, string[] items)
  39. {
  40. int menuResult;
  41. do
  42. {
  43. menuResult = menu.PrintMenu();
  44. methods[menuResult]();
  45. Console.WriteLine("Для продолжения нажмите любую клавишу");
  46. //Console.ReadKey();
  47. } while (activ == false);
  48.  
  49. }
  50. static void Main(string[] args)
  51. {
  52. F:
  53. if (activ == false)
  54. {
  55. Frst();
  56. goto F;
  57.  
  58. }
  59. else
  60. {
  61. string[] items = { $"Логин: {login}", "Создать файл", "Прочитать текст из файла", "Сохранить в файл", "Сохранить в новый файл", "Переименовать файла", "Удалить файл", "Выход" };
  62. method[] methods = new method[] { Account, Method1, Method2, Method3, Method4, Method5, Method6, Exit };
  63. ConsoleMenu menu = new ConsoleMenu(items);
  64. int menuResult;
  65. do
  66. {
  67. menuResult = menu.PrintMenu();
  68. methods[menuResult]();
  69. Console.WriteLine("Для продолжения нажмите любую клавишу");
  70. //Console.ReadKey();
  71. } while (menuResult != items.Length - 1);
  72.  
  73. }
  74.  
  75.  
  76. }
  77. static void Account()
  78. {
  79. Console.Write("Это ваш аккаунт. Выберите действие.");
  80. Two();
  81.  
  82.  
  83. }
  84. static void Vhod()
  85. {
  86. bool dop;
  87. dop = Vhod1();
  88. if (dop)
  89. {
  90. Console.WriteLine("вход выполнен");
  91. activ = true;
  92. }
  93.  
  94.  
  95.  
  96. }
  97. static bool Vhod1()
  98. {
  99. int kol_vo = 3;
  100.  
  101. Console.WriteLine("Введите логин");
  102.  
  103. string login_2 = Console.ReadLine();
  104. try
  105. {
  106. FileStream file1 = new FileStream($"D://_py//{login_2}.txt", FileMode.Open);
  107. StreamReader dop = new StreamReader(file1);
  108. Console.WriteLine("Введите пароль");
  109. M:
  110.  
  111. if (Console.ReadLine() == dop.ReadLine())
  112. {
  113. dop.Close();
  114. login = login_2;
  115. return true;
  116. }
  117. else
  118. {
  119. kol_vo--;
  120. if (kol_vo == 0)
  121. {
  122. return false;
  123. }
  124. Console.WriteLine($"Пароль введен неверно. Попроуйте еще раз. Кол-во попыток : {kol_vo}");
  125.  
  126. goto M;
  127. }
  128.  
  129.  
  130. }
  131. catch
  132. {
  133. Console.WriteLine("Логин введен не првильно");
  134. }
  135. return false;
  136. }
  137.  
  138. static void Reg()
  139. {
  140. Console.WriteLine("введите логин");
  141. string text = Console.ReadLine();
  142. login = text;
  143. Console.WriteLine("Введите пароль");
  144.  
  145. string pass = Console.ReadLine();
  146. File.WriteAllText($"D://_py//{text}.txt", pass);
  147. activ = true;
  148.  
  149. }
  150. static void Method1()
  151. {
  152.  
  153.  
  154. Console.WriteLine("Укажите путь к папке где хотите создать файл");
  155. try
  156. {
  157. string path = Console.ReadLine();
  158. File.Create($"D://_py//{login}_2.txt");
  159. }
  160. catch (Exception)
  161. {
  162. Console.WriteLine("Ошибка");
  163. }
  164.  
  165. }
  166. static void Method2()
  167. {
  168.  
  169. Console.WriteLine("Укажите путь к файлу");
  170. try
  171. {
  172. string path = Console.ReadLine();
  173. FileStream file1 = new FileStream(path, FileMode.Open);
  174. StreamReader reader = new StreamReader(file1);
  175. Console.WriteLine($"Текст из файла: {reader.ReadToEnd()}");
  176. reader.Close();
  177. }
  178. catch (Exception)
  179. {
  180. Console.WriteLine("Ошибка");
  181. }
  182.  
  183. }
  184. static void Method3()
  185. {
  186.  
  187.  
  188. Console.WriteLine("Введите текст");
  189. string text = Console.ReadLine();
  190. Console.WriteLine("Укажите путь к файлу который хотите дозаписать ");
  191. try
  192. {
  193. string path = Console.ReadLine();
  194. File.AppendAllText(path, text);
  195. }
  196. catch (Exception)
  197. {
  198. Console.WriteLine("Ошибка!");
  199. }
  200. }
  201. static void Method4()
  202. {
  203.  
  204. Console.WriteLine("Введите текст");
  205. string text = Console.ReadLine();
  206. Console.WriteLine("Укажите путь к файлу");
  207. try
  208. {
  209. string path = Console.ReadLine();
  210. File.WriteAllText(path, text);
  211. }
  212. catch (Exception)
  213. {
  214. Console.WriteLine("Ошибка!");
  215. }
  216. }
  217. static void Method5()
  218. {
  219.  
  220. Console.WriteLine("Укажите путь к файлу котрый хотите перетменовать ");
  221. try
  222. {
  223. string path = Console.ReadLine();
  224. Console.WriteLine("Укажите путь к файлу и новое имя");
  225. string ath = Console.ReadLine();
  226. File.Move(path, ath);
  227. }
  228. catch (Exception)
  229. {
  230. Console.WriteLine("Ошибка!");
  231. }
  232. }
  233. static void Method6()
  234. {
  235.  
  236. Console.WriteLine("Укажите путь к файлу котрый хотите удалить ");
  237. try
  238. {
  239. string path = Console.ReadLine();
  240. File.Delete(path);
  241. }
  242. catch (Exception)
  243. {
  244. Console.WriteLine("Ошибка!");
  245. }
  246.  
  247. }
  248. static void Exit()
  249. {
  250. Console.WriteLine("Отчислен");
  251. }
  252. static void Otchislen()
  253. {
  254. Environment.Exit(0);
  255.  
  256. }
  257. }
  258.  
  259.  
  260. class ConsoleMenu
  261. {
  262. string[] menuItems;
  263. int counter = 0;
  264. public ConsoleMenu(string[] menuItems)
  265. {
  266. this.menuItems = menuItems;
  267. }
  268.  
  269. public int PrintMenu()
  270. {
  271. ConsoleKeyInfo key;
  272. do
  273. {
  274. Console.Clear();
  275. for (int i = 0; i < menuItems.Length; i++)
  276. {
  277. if (counter == i)
  278. {
  279. Console.BackgroundColor = ConsoleColor.Cyan;
  280. Console.ForegroundColor = ConsoleColor.Black;
  281. Console.WriteLine(menuItems[i]);
  282. Console.BackgroundColor = ConsoleColor.Black;
  283. Console.ForegroundColor = ConsoleColor.White;
  284. }
  285. else
  286. Console.WriteLine(menuItems[i]);
  287.  
  288. }
  289. key = Console.ReadKey();
  290. if (key.Key == ConsoleKey.UpArrow)
  291. {
  292. counter--;
  293. if (counter == -1) counter = menuItems.Length - 1;
  294. }
  295. if (key.Key == ConsoleKey.DownArrow)
  296. {
  297. counter++;
  298. if (counter == menuItems.Length) counter = 0;
  299. }
  300. }
  301. while (key.Key != ConsoleKey.Enter);
  302. return counter;
  303. }
  304.  
  305. }
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement