RatingPage.xaml.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace ModuleExam
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для RatingPage.xaml
  20. /// </summary>
  21. public partial class RatingPage : Page
  22. {
  23. public static ExamEntities DB = new ExamEntities();
  24. public List<RatingList> Rating;
  25. int id;
  26. public RatingPage(int IdUser)
  27. {
  28. InitializeComponent();
  29. Rating = RatingCalculate();
  30. UsersList.ItemsSource = Rating;
  31. id = IdUser;
  32. }
  33. /// <summary>
  34. /// Метод для составления рейтинга сотрудников исходя из общего балла
  35. /// </summary>
  36. /// <returns></returns>
  37. public static List<RatingList> RatingCalculate()
  38. {
  39. List<RatingList> list = new List<RatingList>();
  40. bool flag = false;
  41. List<usersmetrics> um = DB.usersmetrics.ToList();
  42. foreach(usersmetrics u in um)
  43. {
  44. flag = false;
  45. foreach(RatingList rate in list)
  46. {
  47. if(u.id_user == rate.UserId)
  48. {
  49. flag = true;
  50. rate.TotalScore += (double)u.coefficient;
  51. }
  52. }
  53. if(!flag)
  54. {
  55. RatingList rl = new RatingList();
  56. rl.TotalScore += (double)u.coefficient;
  57. rl.FullName = $"{u.users.surname} {u.users.firstname} {u.users.patronymic}";
  58. rl.UserId = u.id_user;
  59. list.Add(rl);
  60. }
  61. }
  62. list = list.OrderByDescending(x=>x.TotalScore).ToList();
  63. return list;
  64. }
  65. /// <summary>
  66. /// Обработчик для подсчёта места в рейтинге
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. private void PlaceInList(object sender, RoutedEventArgs e)
  71. {
  72. TextBlock tb = (TextBlock)sender;
  73. int id = Convert.ToInt32(tb.Uid);
  74. RatingList rl1 = Rating.FirstOrDefault(x => x.UserId == id);
  75. tb.Text = "Место в рейтинге: "+(Rating.IndexOf(rl1) + 1).ToString();
  76. }
  77. private void GoBack(object sender, RoutedEventArgs e)
  78. {
  79. MainFrame.MFrame.Navigate(new ActivityPage(id));
  80. }
  81. }
  82. }