131 lines
3.9 KiB
C#
131 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TrackerLibrary.Models;
|
|
|
|
namespace TrackerUI
|
|
{
|
|
public partial class TournamentViewerForm : Form
|
|
{
|
|
private readonly TournamentModel tournament;
|
|
BindingList<int> rounds = new BindingList<int>();
|
|
BindingList<MatchupModel> selectedMatchups = new BindingList<MatchupModel>();
|
|
bool loading = false;
|
|
|
|
|
|
public TournamentViewerForm(TournamentModel tournamentModel)
|
|
{
|
|
InitializeComponent();
|
|
tournament = tournamentModel;
|
|
WireUpLists();
|
|
LoadFormData();
|
|
LoadRounds();
|
|
}
|
|
|
|
private void LoadFormData()
|
|
{
|
|
tournamentName.Text = tournament.TournamentName;
|
|
}
|
|
|
|
private void WireUpLists()
|
|
{
|
|
roundDropDown.DataSource = rounds;
|
|
MatchUpListBox.DataSource = selectedMatchups;
|
|
MatchUpListBox.DisplayMember = "DisplayName";
|
|
}
|
|
|
|
private void LoadRounds()
|
|
{
|
|
rounds.Clear();
|
|
|
|
rounds.Add(1);
|
|
int currRound = 1;
|
|
foreach (List<MatchupModel> matchups in tournament.Rounds)
|
|
{
|
|
if (matchups.First().MatchupRound > currRound)
|
|
{
|
|
currRound = matchups.First().MatchupRound;
|
|
rounds.Add(currRound);
|
|
}
|
|
}
|
|
LoadMatchups(1);
|
|
}
|
|
|
|
private void roundDropDown_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
LoadMatchups( (int)roundDropDown.SelectedItem);
|
|
}
|
|
|
|
|
|
private void LoadMatchups(int round)
|
|
{
|
|
foreach (List<MatchupModel> matchups in tournament.Rounds)
|
|
{
|
|
if (matchups.First().MatchupRound == round)
|
|
{
|
|
loading = true;
|
|
selectedMatchups.Clear();
|
|
foreach (MatchupModel mm in matchups)
|
|
{
|
|
selectedMatchups.Add(mm);
|
|
}
|
|
loading = false;
|
|
}
|
|
}
|
|
|
|
LoadMatchup(selectedMatchups.First());
|
|
}
|
|
|
|
private void LoadMatchup(MatchupModel m)
|
|
{
|
|
if (!loading)
|
|
{
|
|
for (int i = 0; i < m.Entries.Count; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
if (m.Entries[0].TeamCompeting != null)
|
|
{
|
|
teamOneName.Text = m.Entries[0].TeamCompeting.TeamName;
|
|
teamOneScoeValue.Text = m.Entries[0].Score.ToString();
|
|
|
|
teamTwoName.Text = "<bye>";
|
|
teamTwoScoeValue.Text = "0";
|
|
}
|
|
else
|
|
{
|
|
teamOneName.Text = "Not Yet Set";
|
|
teamOneScoeValue.Text = "";
|
|
}
|
|
}
|
|
|
|
if (i == 1)
|
|
{
|
|
if (m.Entries[1].TeamCompeting != null)
|
|
{
|
|
teamTwoName.Text = m.Entries[1].TeamCompeting.TeamName;
|
|
teamTwoScoeValue.Text = m.Entries[1].Score.ToString();
|
|
}
|
|
else
|
|
{
|
|
teamTwoName.Text = "Not Yet Set";
|
|
teamTwoScoeValue.Text = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MatchUpListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
LoadMatchup((MatchupModel)MatchUpListBox.SelectedItem);
|
|
}
|
|
}
|
|
}
|