private void btnHomeDoSubs_Click(object sender, RoutedEventArgs e)
        {
            var inCount     = lstHomeSubs.SelectedItems.Count;
            var outCount    = lstHomeActive.SelectedItems.Count;
            var activeCount = lstHomeActive.Items.Count;
            var diff        = inCount - outCount;

            if (activeCount + diff != 5)
            {
                return;
            }

            var playersIn  = lstHomeSubs.SelectedItems.Cast <PlayerStats>().ToList();
            var playersOut = lstHomeActive.SelectedItems.Cast <PlayerStats>().ToList();

            foreach (var player in playersIn)
            {
                HomeSubs.Remove(player);
                HomeActive.Add(player);
            }
            foreach (var player in playersOut)
            {
                HomeSubs.Add(player);
                HomeActive.Remove(player);
            }
            sortPlayerLists();
        }
        private void sortPlayerLists()
        {
            AwaySubs.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));
            AwayActive.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));
            HomeSubs.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));
            HomeActive.Sort((ps1, ps2) => String.Compare(ps1.FullName, ps2.FullName, StringComparison.CurrentCultureIgnoreCase));

            PlayersComboList.Clear();
            PlayersComboList.Add(new ComboBoxItemWithIsEnabled(txbAwayTeam.Text, false));
            AwayActive.ToList().ForEach(ps => PlayersComboList.Add(new ComboBoxItemWithIsEnabled(ps.ToString(), true, ps.ID)));
            PlayersComboList.Add(new ComboBoxItemWithIsEnabled(txbHomeTeam.Text, false));
            HomeActive.ToList().ForEach(ps => PlayersComboList.Add(new ComboBoxItemWithIsEnabled(ps.ToString(), true, ps.ID)));

            populatePlayer2Combo();
        }
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (dgEvents.SelectedIndex == -1)
            {
                return;
            }
            if (btnEdit.Content.ToString() == "Edit")
            {
                var selectedPlay = dgEvents.SelectedItem as PlayByPlayEntry;
                dgEvents.IsEnabled  = false;
                btnSave.IsEnabled   = false;
                btnCancel.IsEnabled = false;
                btnAdd.IsEnabled    = false;
                btnDelete.IsEnabled = false;
                _shotClockTimer.Stop();
                _timeLeftTimer.Stop();
                _savedTimeLeft   = _timeLeft;
                _savedShotClock  = _shotClock;
                _savedAwayActive = AwayActive.ToList();
                _savedAwaySubs   = AwaySubs.ToList();
                _savedHomeActive = HomeActive.ToList();
                _savedHomeSubs   = HomeSubs.ToList();
                _savedAwayPoints = Convert.ToInt32(AwayPoints);
                _savedHomePoints = Convert.ToInt32(HomePoints);
                _savedPeriod     = CurrentPeriod;

                _timeLeft = selectedPlay.TimeLeft;
                updateTimeLeftIndication(_timeLeft);

                _shotClock = selectedPlay.ShotClockLeft;
                updateShotClockIndication(_shotClock);

                AwayActive = new ObservableCollection <PlayerStats>(selectedPlay.Team1PlayerIDs.Select(id => _pst[id]).ToList());
                AwaySubs   =
                    new ObservableCollection <PlayerStats>(
                        _bse.PBSList.Where(pbs => pbs.TeamID == _t1ID && !selectedPlay.Team1PlayerIDs.Contains(pbs.PlayerID))
                        .Select(pbs => _pst[pbs.PlayerID])
                        .ToList());
                HomeActive = new ObservableCollection <PlayerStats>(selectedPlay.Team2PlayerIDs.Select(id => _pst[id]).ToList());
                HomeSubs   =
                    new ObservableCollection <PlayerStats>(
                        _bse.PBSList.Where(pbs => pbs.TeamID == _t2ID && !selectedPlay.Team2PlayerIDs.Contains(pbs.PlayerID))
                        .Select(pbs => _pst[pbs.PlayerID])
                        .ToList());

                lstAwayActive.ItemsSource = AwayActive;
                lstAwaySubs.ItemsSource   = AwaySubs;
                lstHomeActive.ItemsSource = HomeActive;
                lstHomeSubs.ItemsSource   = HomeSubs;

                sortPlayerLists();

                cmbEventType.SelectedItem = PlayByPlayEntry.EventTypes[selectedPlay.EventType];
                txtEventDesc.Text         = selectedPlay.EventDesc;
                cmbPlayer1.SelectedItem   = PlayersComboList.Single(item => item.ID == selectedPlay.Player1ID);
                cmbPlayer2.SelectedItem   = selectedPlay.Player2ID != -1
                                              ? PlayersComboList2.Single(item => item.ID == selectedPlay.Player2ID)
                                              : null;
                cmbLocationShotDistance.SelectedItem = selectedPlay.EventType != PlayByPlayEntry.ShotAttemptEventType
                                                           ? PlayByPlayEntry.EventLocations[selectedPlay.Location]
                                                           : ShotEntry.ShotDistances[selectedPlay.ShotEntry.Distance];
                txtLocationDesc.Text       = selectedPlay.LocationDesc;
                cmbShotOrigin.SelectedItem = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType
                                                 ? ShotEntry.ShotOrigins[selectedPlay.ShotEntry.Origin]
                                                 : null;
                cmbShotType.SelectedItem = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType
                                               ? ShotEntry.ShotTypes[selectedPlay.ShotEntry.Type]
                                               : null;
                chkShotIsMade.IsChecked = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType &&
                                          selectedPlay.ShotEntry.IsMade;
                chkShotIsAssisted.IsChecked = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType &&
                                              selectedPlay.ShotEntry.IsAssisted;
                AwayPoints    = selectedPlay.T1PTS;
                HomePoints    = selectedPlay.T2PTS;
                CurrentPeriod = selectedPlay.Quarter;

                btnEdit.Content = "Save";
            }
            else
            {
                if (cmbEventType.SelectedIndex == -1 || cmbPlayer1.SelectedIndex == -1 || cmbLocationShotDistance.SelectedIndex == -1)
                {
                    return;
                }
                if (grdShotEvent.IsEnabled && (cmbShotOrigin.SelectedIndex == -1 || cmbShotType.SelectedIndex == -1))
                {
                    return;
                }
                var play = createPlayByPlayEntryFromCurrent();
                Plays.Remove(dgEvents.SelectedItem as PlayByPlayEntry);
                Plays.Add(play);
                Plays.Sort(new PlayByPlayEntryComparerAsc());

                _timeLeft = _savedTimeLeft;
                updateTimeLeftIndication(_timeLeft);
                _shotClock = _savedShotClock;
                updateShotClockIndication(_shotClock);
                AwayActive    = new ObservableCollection <PlayerStats>(_savedAwayActive);
                AwaySubs      = new ObservableCollection <PlayerStats>(_savedAwaySubs);
                HomeActive    = new ObservableCollection <PlayerStats>(_savedHomeActive);
                HomeSubs      = new ObservableCollection <PlayerStats>(_savedHomeSubs);
                AwayPoints    = _savedAwayPoints;
                HomePoints    = _savedHomePoints;
                CurrentPeriod = _savedPeriod;

                lstAwayActive.ItemsSource = AwayActive;
                lstAwaySubs.ItemsSource   = AwaySubs;
                lstHomeActive.ItemsSource = HomeActive;
                lstHomeSubs.ItemsSource   = HomeSubs;

                sortPlayerLists();

                dgEvents.IsEnabled  = true;
                btnSave.IsEnabled   = true;
                btnCancel.IsEnabled = true;
                btnAdd.IsEnabled    = true;
                btnDelete.IsEnabled = true;

                btnEdit.Content = "Edit";
            }
        }