public TableStat(ChampionatConfig conf) { InitializeComponent(); if (conf == null) { return; } var uchs = new SortedDictionary <int?, UchastChamp>(); foreach (var uch in conf.UchastChamps) { uchs.Add(uch.OrderNum, uch); } var luch = new List <UchastChamp>(); foreach (var u in uchs) { luch.Add(u.Value); } for (int i = 0, j = 1; i < 6; i += 3) { if (i > luch.Count - 1) { break; } var tb = new TbGroup() { conf = conf, OrderGroup = j++ }; tb.uch1 = luch[i]; if (luch.Count > i + 1) { tb.uch2 = luch[i + 1]; } if (luch.Count > i + 2) { tb.uch3 = luch[i + 2]; } gr.Children.Add(new TableGroup(tb)); } if (luch.Count > 3) { gr.Children.Add(new TableGroupWin(luch, conf)); } }
public TableGroup(TbGroup tb) { DataContext = tb; InitializeComponent(); if (tb.uch1 != null && tb.uch2 != null || tb.uch3 != null) { if (tb.uch2 != null) { Win12.Content = GetCountWinGroup(tb.uch1) != 0 ? tb.uch1.Uchastnick.Name : tb.uch2.Uchastnick.Name; Win21.Content = Win12.Content; } if (tb.uch3 != null) { Win13.Content = GetCountWinGroup(tb.uch1) != 0 ? tb.uch1.Uchastnick.Name : tb.uch3.Uchastnick.Name; Win31.Content = Win13.Content; } if (tb.uch2 != null && tb.uch3 != null) { Win23.Content = GetCountWinGroup(tb.uch2) != 0 ? tb.uch2.Uchastnick.Name : tb.uch3.Uchastnick.Name; Win32.Content = Win23.Content; } int GetCountWinGroup(UchastChamp uc) => uc.Sorevnovanies.Where(u => u.Winner == 0 && u.Red == uc.ID || u.Winner == 1 && u.White == uc.ID).Count(); } }