Advertisement
TwinFrame

LINQ_Hospital

Dec 19th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Clight_40_LINQ_Hospital
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> fio = new List<string> { "Иванов А.Г.", "Владимиров Б.У.", "Оксанин Г.В." , "Генацвали А.В." ,
  12. "Маринин С.А.", "Игорян Х.А.", "Евгенов С.М.", "Мариуполев С.В", "Надеждина Н.Т.", "Русланков В.А.",
  13. "Сергеев Н.Н.", "Иринина И.П.", "Маринок Ж.А.", "Игрил Х.Х.", "Оксанн П.С.", "Возбудидзе А.Ю.",
  14. "Попин М.Ю.", "Сааркян С.И." };
  15.  
  16. List<string> disease = new List<string> { "орви", "дипрессия", "аритмия", "диарея" };
  17.  
  18. Hospital hospital = new Hospital();
  19. hospital.CreatePacients(fio, disease);
  20.  
  21. while (true)
  22. {
  23. Console.Clear();
  24. Console.WriteLine("Меню больницы.\n");
  25. Console.WriteLine("F1 - Сортировка больных по фамилии.");
  26. Console.WriteLine("F2 - Сортировка больных по возрасту.");
  27. Console.WriteLine("F3 - Вывод больных по заболеванию.");
  28. Console.CursorVisible = false;
  29.  
  30. ConsoleKeyInfo key = Console.ReadKey();
  31. Console.WriteLine();
  32.  
  33. switch (key.Key)
  34. {
  35. case ConsoleKey.F1:
  36. hospital.ShowPacientByFio();
  37. Console.ReadKey();
  38. break;
  39.  
  40. case ConsoleKey.F2:
  41. hospital.ShowPacientByAge();
  42. Console.ReadKey();
  43. break;
  44.  
  45. case ConsoleKey.F3:
  46. Console.CursorVisible = true;
  47. Console.Write("Введите название заболевания (орви, дипрессия, аритмия, диарея): ");
  48. string inputUser = Console.ReadLine();
  49. Console.CursorVisible = false;
  50. Console.WriteLine();
  51.  
  52. hospital.ShowPacientByDisease(inputUser);
  53. Console.ReadKey();
  54. break;
  55.  
  56. default:
  57. Console.WriteLine("Не корректный ввод пункта меню.");
  58. break;
  59. }
  60. }
  61. }
  62. }
  63.  
  64. class Hospital
  65. {
  66. Random random = new Random();
  67.  
  68. private List<Pacient> _pacients;
  69.  
  70. public void CreatePacients(List<string> fio, List<string> diseas)
  71. {
  72. _pacients = new List<Pacient> { };
  73.  
  74. foreach (var item in fio)
  75. {
  76. int age = random.Next(18, 66);
  77. int typeOfDisease = random.Next(0, diseas.Count);
  78. Pacient tempPacient = new Pacient(item, age, diseas[typeOfDisease]);
  79. _pacients.Add(tempPacient);
  80. }
  81. }
  82.  
  83. public void ShowPacientByFio()
  84. {
  85. var sortPacients = _pacients.OrderBy(pacient => pacient.Fio);
  86.  
  87. foreach (var pacient in sortPacients)
  88. {
  89. pacient.ShowInfo();
  90. }
  91. }
  92.  
  93. public void ShowPacientByAge()
  94. {
  95. var sortPacients = _pacients.OrderBy(pacient => pacient.Age);
  96.  
  97. foreach (var pacient in sortPacients)
  98. {
  99. pacient.ShowInfo();
  100. }
  101. }
  102.  
  103. public void ShowPacientByDisease(string inputDisease)
  104. {
  105. var sortPacients = _pacients.Where( pacient => pacient.Disease == inputDisease);
  106.  
  107. if (sortPacients.Count() > 0)
  108. {
  109. foreach (var pacient in sortPacients)
  110. {
  111. pacient.ShowInfo();
  112. }
  113. }
  114. else
  115. {
  116. Console.WriteLine($"Больных с заболеванием {inputDisease} не найдено.");
  117. }
  118. }
  119. }
  120.  
  121. class Pacient
  122. {
  123. public string Fio { get; private set; }
  124. public int Age { get; private set; }
  125. public string Disease { get; private set; }
  126.  
  127. public Pacient(string fio, int age, string disease)
  128. {
  129. Fio = fio;
  130. Age = age;
  131. Disease = disease;
  132. }
  133.  
  134. public void ShowInfo()
  135. {
  136. Console.WriteLine($"Ф.И.О.: {Fio}, Возраст: {Age} лет, Заболевание: {Disease}");
  137. }
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement