12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ModuleExam
- {
- /// <summary>
- /// Логика взаимодействия для RatingPage.xaml
- /// </summary>
- public partial class RatingPage : Page
- {
- public static ExamEntities DB = new ExamEntities();
- public List<RatingList> Rating;
- int id;
- public RatingPage(int IdUser)
- {
- InitializeComponent();
- Rating = RatingCalculate();
- UsersList.ItemsSource = Rating;
- id = IdUser;
- }
- /// <summary>
- /// Метод для составления рейтинга сотрудников исходя из общего балла
- /// </summary>
- /// <returns></returns>
- public static List<RatingList> RatingCalculate()
- {
- List<RatingList> list = new List<RatingList>();
- bool flag = false;
- List<usersmetrics> um = DB.usersmetrics.ToList();
- foreach(usersmetrics u in um)
- {
- flag = false;
- foreach(RatingList rate in list)
- {
- if(u.id_user == rate.UserId)
- {
- flag = true;
- rate.TotalScore += (double)u.coefficient;
- }
- }
- if(!flag)
- {
- RatingList rl = new RatingList();
- rl.TotalScore += (double)u.coefficient;
- rl.FullName = $"{u.users.surname} {u.users.firstname} {u.users.patronymic}";
- rl.UserId = u.id_user;
- list.Add(rl);
- }
- }
- list = list.OrderByDescending(x=>x.TotalScore).ToList();
- return list;
- }
- /// <summary>
- /// Обработчик для подсчёта места в рейтинге
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PlaceInList(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int id = Convert.ToInt32(tb.Uid);
- RatingList rl1 = Rating.FirstOrDefault(x => x.UserId == id);
- tb.Text = "Место в рейтинге: "+(Rating.IndexOf(rl1) + 1).ToString();
- }
- private void GoBack(object sender, RoutedEventArgs e)
- {
- MainFrame.MFrame.Navigate(new ActivityPage(id));
- }
- }
- }
|