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 { /// /// Логика взаимодействия для RatingPage.xaml /// public partial class RatingPage : Page { public static ExamEntities DB = new ExamEntities(); public List Rating; int id; public RatingPage(int IdUser) { InitializeComponent(); Rating = RatingCalculate(); UsersList.ItemsSource = Rating; id = IdUser; } /// /// Метод для составления рейтинга сотрудников исходя из общего балла /// /// public static List RatingCalculate() { List list = new List(); bool flag = false; List 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; } /// /// Обработчик для подсчёта места в рейтинге /// /// /// 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)); } } }