lolblach333

Untitled

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