Пример #1
0
        private void ButtonRemoveSingleMatch_Click(object sender, RoutedEventArgs e)
        {
            if (IsUiTeamsLocked)
            {
                return;
            }

            MatchesModel item = (sender as Button).DataContext as MatchesModel;

            if (item != null)
            {
                ConfirmationWindow _popupConfirmation = new ConfirmationWindow("Tens a certeza que pretendes remover o jogo nº "
                                                                               + item.Order.ToString());
                if (_popupConfirmation.ShowDialog() == true)
                {
                    int nRows = 0;
                    UtilsNotification.StartLoadingAnimation();

                    Thread thread = new System.Threading.Thread(() => {
                        nRows = DataGridTeams.ItemsSource.OfType <object>().Count();
                    });
                    thread.Start();
                    thread.Join();

                    new Thread(() =>
                    {
                        if (item.MatchId.HasValue)
                        {
                            if (!matchService.RemoveMatch(item.MatchId.Value))
                            {
                                NotificationHelper.notifier.ShowCustomMessage("Erro ao remover jogo nº " + item.Order.ToString() + "!");
                                UtilsNotification.StopLoadingAnimation();
                                return;
                            }
                        }

                        Application.Current.Dispatcher.BeginInvoke((Action)(() => {
                            matchItems.Remove(item);

                            for (int i = 0; i < (nRows - 1); i++)
                            {
                                matchItems[i].Order = i + 1;
                            }
                        }));

                        NotificationHelper.notifier.ShowCustomMessage("Jogo nº " + item.Order.ToString() + " removido com sucesso!");

                        UtilsNotification.StopLoadingAnimation();
                    }).Start();
                }
            }
        }
Пример #2
0
        private void ButtonAddNewGame_Click(object sender, RoutedEventArgs e)
        {
            int compId = ((CompetitionComboModel)ComboBoxCompetition.SelectedItem).CompetitionId;

            new Thread(() =>
            {
                //Get teams
                var tList = teamService.GetCompetitionTeams(compId);

                MatchesModel newMatch = new MatchesModel()
                {
                    Order      = matchItems.Count() + 1,
                    HomeTeamId = 0,
                    AwayTeamId = 0,
                    HomeGoals  = 0,
                    AwayGoals  = 0,
                    OddsHome   = (decimal)1.5,
                    OddsDraw   = (decimal)1.5,
                    OddsAway   = (decimal)1.5
                };

                if (tList != null && tList.Count() > 0)
                {
                    foreach (var item in tList)
                    {
                        newMatch.TeamsList.Add(new TeamComboModel()
                        {
                            TeamId = item.TeamId, TeamName = item.Name
                        });
                    }
                }

                Application.Current.Dispatcher.BeginInvoke((Action)(() => { matchItems.Add(newMatch); }));

                DataGridTeams.Dispatcher.BeginInvoke((Action)(() =>
                {
                    var border = VisualTreeHelper.GetChild(DataGridTeams, 0) as Decorator;
                    if (border != null)
                    {
                        var scroll = border.Child as ScrollViewer;
                        if (scroll != null)
                        {
                            scroll.ScrollToEnd();
                        }
                    }
                }));
            }).Start();
        }
Пример #3
0
        private void LoadMatchesToGrid()
        {
            //GetCompTeams
            var tList = teamService.GetCompetitionTeams(comboBoxCompetionId);

            //GetMatches
            var mList = matchService.GetMatchesByCompetitionFixture(comboBoxCompetionId, numericBoxFixtureId);

            if (tList != null && tList.Count() > 0 && mList != null && mList.Count() > 0)
            {
                int idx = 1;
                foreach (var itemMatch in mList.OrderBy(x => x.Order))
                {
                    MatchesModel match = new MatchesModel()
                    {
                        Order                  = idx,
                        MatchId                = itemMatch.MatchId,
                        CompetitionId          = itemMatch.CompetitionId,
                        FixtureId              = itemMatch.FixtureId,
                        HomeGoals              = itemMatch.HomeGoals,
                        AwayGoals              = itemMatch.AwayGoals,
                        OddsHome               = itemMatch.HomeOdd,
                        OddsDraw               = itemMatch.DrawOdd,
                        OddsAway               = itemMatch.AwayOdd,
                        ButtonRemoveVisibility = Visibility.Visible
                    };

                    //Fill Teams
                    if (tList != null && tList.Count() > 0)
                    {
                        foreach (var item in tList)
                        {
                            match.TeamsList.Add(new TeamComboModel()
                            {
                                TeamId = item.TeamId, TeamName = item.Name
                            });
                        }
                    }

                    //Select teams
                    match.HomeTeamId = match.TeamsList.IndexOf(match.TeamsList.Where(x => x.TeamId == itemMatch.HomeTeamId).FirstOrDefault());
                    match.AwayTeamId = match.TeamsList.IndexOf(match.TeamsList.Where(x => x.TeamId == itemMatch.AwayTeamId).FirstOrDefault());

                    matchItems.Add(match);
                    idx++;
                }
            }
        }
Пример #4
0
        private void LoadCompetitionDataToGrid()
        {
            //GetCompTeams
            var tList = teamService.GetCompetitionTeams(comboBoxCompetionId);

            if (tList != null && tList.Count() > 0)
            {
                for (int i = 1; i < ((tList.Count() / 2) + 1); i++)
                {
                    MatchesModel newMatch = new MatchesModel()
                    {
                        Order      = i,
                        HomeTeamId = 0,
                        AwayTeamId = 0,
                        HomeGoals  = 0,
                        AwayGoals  = 0,
                        OddsHome   = (decimal)1.5,
                        OddsDraw   = (decimal)1.5,
                        OddsAway   = (decimal)1.5
                    };

                    //Fill Teams
                    if (tList != null && tList.Count() > 0)
                    {
                        foreach (var item in tList)
                        {
                            newMatch.TeamsList.Add(new TeamComboModel()
                            {
                                TeamId = item.TeamId, TeamName = item.Name
                            });
                        }
                    }

                    matchItems.Add(newMatch);
                }
            }
        }
Пример #5
0
        private void ButtonSaveSingleMatch_Click(object sender, RoutedEventArgs e)
        {
            if (IsUiTeamsLocked)
            {
                return;
            }

            MatchesModel item = (sender as Button).DataContext as MatchesModel;

            if (item != null)
            {
                //VALIDATIONS
                if (item.HomeTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de casa");
                    return;
                }
                else if (item.AwayTeamId == 0)
                {
                    NotificationHelper.notifier.ShowCustomMessage("No jogo nº " + item.Order.ToString() +
                                                                  " falta selecionar a equipa de fora");
                    return;
                }
                else if (comboBoxCompetionId < 1)
                {
                    NotificationHelper.notifier.ShowCustomMessage("A competição está em falta!");
                    return;
                }
                else if (numericBoxFixtureId < 1)
                {
                    NotificationHelper.notifier.ShowCustomMessage("A jornada está em falta!");
                    return;
                }

                //Load necessary data
                item.CompetitionId = comboBoxCompetionId;
                item.FixtureId     = numericBoxFixtureId;
                int homeTeamIdAux = item.HomeTeamId;
                int awayTeamIdAux = item.AwayTeamId;
                item.HomeTeamId = item.TeamsList[item.HomeTeamId].TeamId;
                item.AwayTeamId = item.TeamsList[item.AwayTeamId].TeamId;

                new Thread(() =>
                {
                    UtilsNotification.StartLoadingAnimation();
                    LockAddMatchesUI();

                    //save data
                    var resultado = matchService.CreateOrUpdateMatch(item);

                    if (resultado != null)
                    {
                        //update model
                        item.MatchId = resultado.Item1;
                        item.ButtonSaveVisibility   = Visibility.Collapsed;
                        item.ButtonRemoveVisibility = Visibility.Collapsed;
                        item.ImageDoneVisibility    = Visibility.Visible;
                        item.HomeTeamId             = homeTeamIdAux;
                        item.AwayTeamId             = awayTeamIdAux;

                        string opType = resultado.Item2 == Commons.OperationTypeValues.Create ? "registado" :
                                        resultado.Item2 == Commons.OperationTypeValues.Edit ? "editado" : "inalterado (erro)";
                        NotificationHelper.notifier.ShowCustomMessage("O jogo nº " + item.Order + " foi " + opType + " com sucesso!");
                    }
                    else
                    {
                        NotificationHelper.notifier.ShowCustomMessage("Ocorreu um erro ao registar o jogo nº " + item.Order);
                    }

                    UnlockAddMatchesUI();
                    UtilsNotification.StopLoadingAnimation();
                }).Start();
            }
        }