Advertisement
TeT91

ДЗ Кадровый учет

May 18th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. const string CommandAddDossier = "1";
  10. const string CommandDeleteDossier = "2";
  11. const string CommandShowDossier = "3";
  12. const string CommandFindDossier = "4";
  13. const string CommandShowAllDossiers = "5";
  14. const string CommandExit = "exit";
  15.  
  16. string[] employeesFullNames = { "Тетерюк Антон", "Пупкин Вася", "Пупкин Петя" };
  17. string[] employeesJobs = { "Аниматор", "Программист", "Программист" };
  18.  
  19. bool isRunnig = true;
  20.  
  21. while (isRunnig)
  22. {
  23. Console.WriteLine($" {CommandAddDossier} - Добавить досье " +
  24. $"\n {CommandDeleteDossier} - Удалить досье" +
  25. $"\n {CommandShowDossier} - Найти досье по ID" +
  26. $"\n {CommandFindDossier} - Найти досье по фамилии" +
  27. $"\n {CommandShowAllDossiers} - Вывести все досье" +
  28. $"\n {CommandExit} - Выход");
  29.  
  30. string userInput = Console.ReadLine();
  31.  
  32. switch (userInput)
  33. {
  34. case CommandAddDossier:
  35. AddDossier(ref employeesFullNames, ref employeesJobs);
  36. break;
  37.  
  38. case CommandDeleteDossier:
  39. DeleteDossier(ref employeesFullNames, ref employeesJobs);
  40. break;
  41.  
  42. case CommandShowDossier:
  43. FindDossierById(employeesFullNames, employeesJobs);
  44. break;
  45.  
  46. case CommandFindDossier:
  47. FindDossierBySurname(employeesFullNames, employeesJobs);
  48. break;
  49.  
  50. case CommandShowAllDossiers:
  51. ShowAllDossiers(employeesFullNames, employeesJobs);
  52. break;
  53.  
  54. case CommandExit:
  55. isRunnig = false;
  56. break;
  57. }
  58. }
  59.  
  60. Console.ReadKey();
  61. }
  62.  
  63. private static void ShowDossier(int id, string fullName, string job)
  64. {
  65. Console.WriteLine($"{id} - {fullName} - {job}");
  66. }
  67.  
  68. private static void ShowAllDossiers(string[] employeesFullNames, string[] employeesJobs)
  69. {
  70. for (int i = 0; i < employeesFullNames.Length; i++)
  71. {
  72. ShowDossier(i, employeesFullNames[i], employeesJobs[i]);
  73. }
  74. }
  75.  
  76. private static void FindDossierBySurname(string[] employeesFullNames, string[] employeesJobs)
  77. {
  78. Console.WriteLine("Введите фамилию сотрудника:");
  79. string employeSurname = Console.ReadLine();
  80. char surnameSeparator = ' ';
  81. int surnamePosition = 0;
  82. bool isSurnaneExist = false;
  83.  
  84. for (int i = 0; i < employeesFullNames.Length; i++)
  85. {
  86. string[] tempArray = employeesFullNames[i].Split(surnameSeparator);
  87.  
  88. if (employeSurname == tempArray[surnamePosition])
  89. {
  90. isSurnaneExist = true;
  91. ShowDossier(i, employeesFullNames[i], employeesJobs[i]);
  92. }
  93. }
  94.  
  95. if (isSurnaneExist == false)
  96. {
  97. Console.WriteLine("Сотрудник с такой фамилией не найден");
  98. }
  99. }
  100.  
  101. private static void FindDossierById(string[] employeesFullNames, string[] employeesJobs)
  102. {
  103. int employeId;
  104. Console.WriteLine("Введите ID сотрудника:");
  105.  
  106. if (TryFindId(out employeId, Console.ReadLine(), employeesFullNames.Length - 1))
  107. {
  108. ShowDossier(employeId, employeesFullNames[employeId], employeesJobs[employeId]);
  109. }
  110. }
  111.  
  112. private static void DeleteDossier(ref string[] employeesFullNames, ref string[] employeesJobs)
  113. {
  114. Console.WriteLine("Введите ID");
  115.  
  116. if (TryFindId(out int employeId, Console.ReadLine(), employeesFullNames.Length - 1))
  117. {
  118. DecreaseArraySize(ref employeesFullNames, employeId);
  119. DecreaseArraySize(ref employeesJobs, employeId);
  120. }
  121. }
  122.  
  123. private static void AddDossier(ref string[] employeesFullNames, ref string[] employeesJobs)
  124. {
  125. Console.WriteLine("Введите ФИО сотрудника:");
  126.  
  127. string employeInfo = Console.ReadLine();
  128. IncreaseArraySize(ref employeesFullNames, employeInfo);
  129.  
  130. Console.WriteLine("Введите должность сотрудника:");
  131.  
  132. employeInfo = Console.ReadLine();
  133. IncreaseArraySize(ref employeesJobs, employeInfo);
  134. }
  135.  
  136. private static void IncreaseArraySize(ref string[] array, string info)
  137. {
  138. int numberToIncrease = 1;
  139. int newSize = array.Length + numberToIncrease;
  140.  
  141. string[] tempArray = new string[newSize];
  142.  
  143. for (int i = 0; i < newSize; i++)
  144. {
  145. if (i < array.Length)
  146. {
  147. tempArray[i] = array[i];
  148. }
  149. }
  150.  
  151. tempArray[tempArray.Length - 1] = info;
  152. array = tempArray;
  153. }
  154.  
  155. private static void DecreaseArraySize(ref string[] array, int startShift)
  156. {
  157. int numberToDecrease = 1;
  158. int newSize = array.Length - numberToDecrease;
  159. string[] tempArray = new string[newSize];
  160.  
  161. for (int i = startShift; i < array.Length - 1; i++)
  162. {
  163. array[i] = array[i + 1];
  164. }
  165.  
  166. for (int i = 0; i < newSize; i++)
  167. {
  168. if (i < array.Length)
  169. {
  170. tempArray[i] = array[i];
  171. }
  172. }
  173.  
  174. array = tempArray;
  175. }
  176.  
  177. private static bool TryFindId(out int employeId, string userInput, int maxIndex)
  178. {
  179. if (int.TryParse(userInput, out employeId) && employeId <= maxIndex && employeId >= 0)
  180. {
  181. return true;
  182. }
  183. Console.WriteLine("ID не найден");
  184. return false;
  185. }
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement