diff --git a/TrackerWPFUI/TrackerWPFUI.csproj b/TrackerWPFUI/TrackerWPFUI.csproj index 0e9dbcb..3cd3e2a 100644 --- a/TrackerWPFUI/TrackerWPFUI.csproj +++ b/TrackerWPFUI/TrackerWPFUI.csproj @@ -77,6 +77,7 @@ + CreatePersonView.xaml @@ -96,6 +97,9 @@ App.xaml Code + + TournamentViewerView.xaml + Designer MSBuild:Compile @@ -116,6 +120,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + diff --git a/TrackerWPFUI/ViewModels/ShellViewModel.cs b/TrackerWPFUI/ViewModels/ShellViewModel.cs index 20c984f..ae82ae1 100644 --- a/TrackerWPFUI/ViewModels/ShellViewModel.cs +++ b/TrackerWPFUI/ViewModels/ShellViewModel.cs @@ -29,13 +29,23 @@ namespace TrackerWPFUI.ViewModels ActivateItem(new CreateTournamentViewModel()); } + public void LoadTournament() + { + if (SelectedTournament !=null && !string.IsNullOrWhiteSpace(SelectedTournament.TournamentName)) + { + ActivateItem(new TournamentViewerViewModel(SelectedTournament)); + } + } + public void Handle(TournamentModel message) { // Open the tournamentViewer to the given tournament - throw new NotImplementedException(); + ExistingTournaments.Add(message); + SelectedTournament = message; } private BindableCollection _existingTournaments; + private TournamentModel _SelectedTournament; public BindableCollection ExistingTournaments { @@ -43,7 +53,6 @@ namespace TrackerWPFUI.ViewModels set { _existingTournaments = value; } } - private TournamentModel _SelectedTournament; public TournamentModel SelectedTournament { @@ -52,9 +61,8 @@ namespace TrackerWPFUI.ViewModels { _SelectedTournament = value; NotifyOfPropertyChange(() => SelectedTournament); + LoadTournament(); } } - - } } diff --git a/TrackerWPFUI/ViewModels/TournamentViewerViewModel.cs b/TrackerWPFUI/ViewModels/TournamentViewerViewModel.cs new file mode 100644 index 0000000..5e13848 --- /dev/null +++ b/TrackerWPFUI/ViewModels/TournamentViewerViewModel.cs @@ -0,0 +1,206 @@ +using Caliburn.Micro; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TrackerLibrary.Models; + +namespace TrackerWPFUI.ViewModels +{ + public class TournamentViewerViewModel : Screen + { + public TournamentModel Tournament { get; set; } + + private BindableCollection _rounds = new BindableCollection(); + private BindableCollection _matchups = new BindableCollection(); + private bool _unplayedOnly; + private string _teamOne; + private string _teamTwo; + private double _teamOneScore; + private double _teamTwoScore; + private MatchupModel _selectedMatchup; + private int _selectedRound = 0; + + + + + + public TournamentViewerViewModel(TournamentModel model) + { + Tournament = model; + LoadRounds(); + } + + public int SelectedRound + { + get { return _selectedRound; } + set + { + _selectedRound = value; + NotifyOfPropertyChange(() => SelectedRound); + LoadMatchups(); + } + } + + public MatchupModel SelectedMatchup + { + get { return _selectedMatchup; } + set + { + _selectedMatchup = value; + NotifyOfPropertyChange(() => SelectedMatchup); + LoadMatchup(); + } + } + + public double TeamTwoScore + { + get { return _teamTwoScore; } + set { _teamTwoScore = value; } + } + + public double TeamOneScore + { + get { return _teamOneScore; } + set { _teamOneScore = value; } + } + + public string TeamTwo + { + get { return _teamTwo; } + set + { + _teamTwo = value; + NotifyOfPropertyChange(() => TeamTwo); + } + } + + public string TeamOne + { + get { return _teamOne; } + set + { + _teamOne = value; + NotifyOfPropertyChange(() => TeamOne); + } + } + + public bool UnplayedOnly + { + get { return _unplayedOnly; } + set + { + _unplayedOnly = value; + NotifyOfPropertyChange(() => UnplayedOnly); + LoadMatchups(); + } + } + + public BindableCollection Matchups + { + get { return _matchups; } + set { _matchups = value; } + } + + + public BindableCollection Rounds + { + get { return _rounds; } + set { _rounds = value; } + } + + + + private void LoadRounds() + { + Rounds.Clear(); + + Rounds.Add(1); + int currRound = 1; + foreach (List matchups in Tournament.Rounds) + { + if (matchups.First().MatchupRound > currRound) + { + currRound = matchups.First().MatchupRound; + Rounds.Add(currRound); + } + } + + SelectedRound = 1; + } + + private void LoadMatchups() + { + foreach (List matchups in Tournament.Rounds) + { + if (matchups.First().MatchupRound == SelectedRound) + { + //loading = true; + Matchups.Clear(); + foreach (MatchupModel mm in matchups) + { + if (mm.Winner == null || !UnplayedOnly) + { + Matchups.Add(mm); + } + } + //loading = false; + } + } + + if (Matchups.Count > 0) + { + SelectedMatchup = Matchups.First(); + } + + } + + private void LoadMatchup() + { + //if (!loading) + //{ + if (SelectedMatchup == null) + { + return; + } + + for (int i = 0; i < SelectedMatchup.Entries.Count; i++) + { + if (i == 0) + { + if (SelectedMatchup.Entries[0].TeamCompeting != null) + { + TeamOne = SelectedMatchup.Entries[0].TeamCompeting.TeamName; + TeamOneScore = SelectedMatchup.Entries[0].Score; + + TeamTwo = ""; + TeamTwoScore = 0; + } + else + { + TeamOne = "Not Yet Set"; + TeamOneScore = 0; + } + } + + if (i == 1) + { + if (SelectedMatchup.Entries[1].TeamCompeting != null) + { + TeamTwo = SelectedMatchup.Entries[1].TeamCompeting.TeamName; + TeamTwoScore = SelectedMatchup.Entries[1].Score; + } + else + { + TeamTwo = "Not Yet Set"; + TeamTwoScore = 0; + } + } + } + //} + } + + + } +} diff --git a/TrackerWPFUI/Views/TournamentViewerView.xaml b/TrackerWPFUI/Views/TournamentViewerView.xaml new file mode 100644 index 0000000..09240fa --- /dev/null +++ b/TrackerWPFUI/Views/TournamentViewerView.xaml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + Round + + + + + Unplayed Only + + + + + + + Score + + + + + + - VS - + + + + + + + Score + + + + + + diff --git a/TrackerWPFUI/Views/TournamentViewerView.xaml.cs b/TrackerWPFUI/Views/TournamentViewerView.xaml.cs new file mode 100644 index 0000000..d0c519c --- /dev/null +++ b/TrackerWPFUI/Views/TournamentViewerView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +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 TrackerWPFUI.Views +{ + /// + /// Interaction logic for TournamentViewerView.xaml + /// + public partial class TournamentViewerView : UserControl + { + public TournamentViewerView() + { + InitializeComponent(); + } + } +}