lolblach333

Untitled

Apr 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.27 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace DossierProject
  5. {
  6. class Program
  7. {
  8. private static readonly string[] ConsoleOutputs = new string[]
  9. {
  10. ",",
  11. "Введите фамилию и время через запятую",
  12. "Досье успешно добавлено!",
  13. "Введите номер досье, которое вы хотите удалить:",
  14. "Нет досье!",
  15. "Досье успешно удалено!",
  16. "Нажмите любую клавишу, чтобы вернуться:",
  17. "Введите фамилию для поиска:",
  18. "Ничего не найдено!",
  19. "Результаты:"
  20. };
  21.  
  22. private static readonly string[] MenuItems = new string[]
  23. {
  24. "Добавить новое досье",
  25. "Показать все досье",
  26. "Удалить досье",
  27. "Поиск по фамилии",
  28. "Выход",
  29. "Соси"
  30. };
  31.  
  32. private static string[] Surnames = new string[0];
  33. private static string[] Positions = new string[0];
  34. private static int MenuPosition = 0;
  35.  
  36.  
  37. static void Main(string[] args)
  38. {
  39. PrintMenu();
  40. Menu();
  41. }
  42.  
  43. private static void Menu()
  44. {
  45. while (true)
  46. {
  47. var key = Console.ReadKey().Key;
  48.  
  49. switch (key)
  50. {
  51. case ConsoleKey.UpArrow:
  52. {
  53. if (MenuPosition > 0)
  54. {
  55. MenuPosition--;
  56. PrintMenu();
  57. }
  58.  
  59. break;
  60. }
  61. case ConsoleKey.DownArrow:
  62. {
  63. if (MenuPosition < MenuItems.Length - 1)
  64. {
  65. MenuPosition++;
  66. PrintMenu();
  67. }
  68.  
  69. break;
  70. }
  71. case ConsoleKey.Enter:
  72. {
  73. OnMenuItemSelected();
  74. break;
  75. }
  76. default: break;
  77. }
  78. }
  79. }
  80.  
  81. private static void OnMenuItemSelected()
  82. {
  83. switch (MenuPosition)
  84. {
  85. case 0: AddDossier(); break;
  86. case 1: ShowAllDosiers(); break;
  87. case 2: DeleteDossier(); break;
  88. case 3: SearchDossier(); break;
  89. case 4: Environment.Exit(0); break;
  90. default: break;
  91. }
  92. }
  93.  
  94. private static void AddDossier()
  95. {
  96. Console.Clear();
  97. Console.WriteLine(ConsoleOutputs[1]);
  98.  
  99. while (true)
  100. {
  101. string line = Console.ReadLine();
  102.  
  103. if (line.Contains(ConsoleOutputs[0]))
  104. {
  105. string[] tempSurnames = new string[Surnames.Length + 1];
  106. string[] tempPositions = new string[Positions.Length + 1];
  107.  
  108. for (int i = 0; i < Surnames.Length; i++)
  109. {
  110. tempSurnames[i] = Surnames[i];
  111. }
  112.  
  113. for (int i = 0; i < Positions.Length; i++)
  114. {
  115. tempPositions[i] = Positions[i];
  116. }
  117.  
  118. tempSurnames[tempSurnames.Length - 1] = line.Split(',')[0];
  119. tempPositions[tempPositions.Length - 1] = line.Split(',')[1];
  120.  
  121. Surnames = tempSurnames;
  122. Positions = tempPositions;
  123.  
  124. Console.Clear();
  125. Console.WriteLine(ConsoleOutputs[2]);
  126. Console.ReadKey();
  127. break;
  128. }
  129. }
  130.  
  131. PrintMenu();
  132. }
  133.  
  134. private static void DeleteDossier()
  135. {
  136. Console.Clear();
  137.  
  138. if (Surnames.Length == 0)
  139. {
  140. Console.WriteLine(ConsoleOutputs[4]);
  141. Console.ReadKey();
  142. }
  143. else
  144. {
  145. while (true)
  146. {
  147. Console.WriteLine(ConsoleOutputs[2]);
  148. Console.WriteLine();
  149.  
  150. for (int i = 0; i < Surnames.Length; i++)
  151. {
  152. Console.WriteLine((i + 1) + ") " + Surnames[i] + " - " + Positions[i]);
  153. }
  154.  
  155. Console.WriteLine();
  156.  
  157. string line = Console.ReadLine();
  158.  
  159. if (int.TryParse(line, out int number))
  160. {
  161. number -= 1;
  162.  
  163. if (number >= 0 && number < Surnames.Length)
  164. {
  165. string[] tempSurnames = new string[Surnames.Length - 1];
  166. string[] tempPositions = new string[Positions.Length - 1];
  167.  
  168. int iteratorSurnames = 0;
  169. int iteratorPositions = 0;
  170.  
  171. for (int i = 0; i < tempSurnames.Length; i++)
  172. {
  173. if (i == number)
  174. {
  175. iteratorSurnames++;
  176. }
  177.  
  178. tempSurnames[i] = Surnames[iteratorSurnames];
  179.  
  180. iteratorSurnames++;
  181. }
  182.  
  183. for (int i = 0; i < tempPositions.Length; i++)
  184. {
  185. if (i == number)
  186. {
  187. iteratorPositions++;
  188. }
  189.  
  190. tempPositions[i] = Positions[iteratorPositions];
  191.  
  192. iteratorPositions++;
  193. }
  194.  
  195. Surnames = tempPositions;
  196. Positions = tempPositions;
  197.  
  198. Console.Clear();
  199. Console.WriteLine(ConsoleOutputs[5]);
  200. Console.ReadKey();
  201. break;
  202. }
  203. else
  204. {
  205. Console.Clear();
  206. }
  207. }
  208. else
  209. {
  210. Console.Clear();
  211. }
  212. }
  213. }
  214.  
  215. PrintMenu();
  216. }
  217.  
  218. private static void ShowAllDosiers()
  219. {
  220. Console.Clear();
  221.  
  222. if (Surnames.Length == 0)
  223. {
  224. Console.WriteLine(ConsoleOutputs[4]);
  225. }
  226. else
  227. {
  228. Console.WriteLine(ConsoleOutputs[6]);
  229. Console.WriteLine();
  230.  
  231. for (int i = 0; i < Surnames.Length; i++)
  232. {
  233. Console.WriteLine((i + 1) + ") " + Surnames[i] + " - " + Positions[i]);
  234. }
  235. }
  236.  
  237. Console.ReadKey();
  238. PrintMenu();
  239. }
  240.  
  241. private static void SearchDossier()
  242. {
  243. Console.Clear();
  244.  
  245. if (Surnames.Length == 0)
  246. {
  247. Console.WriteLine(ConsoleOutputs[4]);
  248. }
  249. else
  250. {
  251. Console.WriteLine(ConsoleOutputs[7]);
  252. Console.WriteLine();
  253.  
  254. string surname = Console.ReadLine();
  255. int founded = 0;
  256.  
  257. Console.Clear();
  258. Console.WriteLine(ConsoleOutputs[9]);
  259. Console.WriteLine();
  260.  
  261. for (int i = 0; i < Surnames.Length; i++)
  262. {
  263. if (Surnames[i].Contains(surname))
  264. {
  265. Console.WriteLine(Surnames[i] + " - " + Positions[i]);
  266. founded++;
  267. }
  268. }
  269.  
  270. if (founded == 0)
  271. {
  272. Console.Clear();
  273. Console.WriteLine();
  274. Console.WriteLine(ConsoleOutputs[8]);
  275. }
  276. }
  277.  
  278. Console.ReadKey();
  279. PrintMenu();
  280. }
  281.  
  282. private static void PrintMenu()
  283. {
  284. Console.Clear();
  285.  
  286. for (int i = 0; i < MenuItems.Length; i++)
  287. {
  288. if (i == MenuPosition)
  289. {
  290. Console.ForegroundColor = ConsoleColor.Red;
  291. Console.WriteLine(MenuItems[i]);
  292. Console.ForegroundColor = ConsoleColor.Gray;
  293. }
  294. else
  295. {
  296. Console.WriteLine(MenuItems[i]);
  297. }
  298. }
  299. }
  300. }
  301. }
Add Comment
Please, Sign In to add comment