コード例 #1
0
        public void GetPartidaCampeonato(int HomeSubscriptionId, int GuestSubscriptionId, int FieldItemId, int InscritoIdOld)
        {
            try
            {
                string sql = "";
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
                {
                    DataSource     = "SQL5028.SmarterASP.NET",
                    UserID         = "DB_9D81D5_societypro_admin",
                    Password       = "******",
                    InitialCatalog = "DB_9D81D5_societypro"
                };

                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    sql = "select * from [dbo].[PartidaCampeonato] PC INNER JOIN [dbo].[Sumula] S ON PC.IDPartidaCampeonato = S.IDPartidaCampeonato where IDInscrito1 = " + InscritoIdOld;

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        IDataReader dtreader = command.ExecuteReader();
                        DataTable   dtresult = new DataTable();
                        dtresult.Load(dtreader);
                        dtreader.Close();

                        for (int i = 0; i < dtresult.Rows.Count; i++)
                        {
                            MatchChampionship c = new MatchChampionship
                            {
                                Active              = true,
                                RegisterDate        = Convert.ToDateTime(dtresult.Rows[i]["dDataCadastro"].ToString()),
                                HomeSubscriptionId  = HomeSubscriptionId,
                                GuestSubscriptionId = GuestSubscriptionId,
                                FieldItemId         = FieldItemId,
                                HomePoints          = Convert.ToInt32(dtresult.Rows[i]["iQntGols1"].ToString()),
                                GuestPoints         = Convert.ToInt32(dtresult.Rows[i]["iQntGols2"].ToString()),
                                MatchDate           = Convert.ToDateTime(dtresult.Rows[i]["dDataPartida"].ToString()),
                                StartTime           = dtresult.Rows[i]["sHoraPartida"].ToString(),
                                Observation         = dtresult.Rows[i]["sObservacao"].ToString(),
                                Calculate           = Convert.ToBoolean(dtresult.Rows[i]["CLASSIFICACAO"].ToString()),
                                Round = Convert.ToInt32(dtresult.Rows[i]["iRodada"].ToString()),
                            };

                            Db.MatchChampionships.Add(c);
                        }

                        Db.SaveChanges();
                    }
                }
            }
            catch (SqlException e)
            {
                e.Message.ToString();
            }
        }
コード例 #2
0
        public void AutomaticMatchChampionship(int championshipId, int groupId)
        {
            Random rnd          = new Random();
            int    quantityTeam = 0;
            int    round        = 0;
            int    count        = 0;
            int    turno        = 0;
            int    fieldId      = 0;

            List <int> teamSubscription = new List <int>();

            string[] matchs;


            var championship = _championshipRepository.GetById(championshipId).Result;

            switch (championship.ChampionshipType)
            {
            case ChampionshipType.Grupos:
                if (groupId == 0)
                {
                    throw new Exception();
                }
                else
                {
                    var resultGroupChampionship = _groupChampionshipRepository.GetAll().Result;
                    var groupChampionship       = resultGroupChampionship.Where(p => p.GroupId == (Group)groupId && p.Subscription.ChampionshipId == championshipId).ToList();

                    foreach (var e in groupChampionship)
                    {
                        teamSubscription.Add(e.SubscriptionId);
                        fieldId = e.Subscription.Championship.FieldId;
                    }
                }
                break;

            case ChampionshipType.MataMata:
                break;

            case ChampionshipType.PontosCorridos:
                var result        = _subscriptionRepository.GetAll().Result;
                var subscriptions = result.Where(p => p.ChampionshipId == championshipId);

                foreach (var e in subscriptions)
                {
                    teamSubscription.Add(e.Id);
                    fieldId = e.Championship.FieldId;
                }
                break;

            default:
                break;
            }

            quantityTeam = teamSubscription.Count();

            if (quantityTeam % 2 == 0)
            {
                round = quantityTeam - 1;
            }
            else
            {
                round = quantityTeam;
            }

            if (championship.GoBack)
            {
                turno  = 2;
                matchs = new string[Divers.CalculaFatorial(quantityTeam) / Divers.CalculaFatorial(quantityTeam - 2)];
            }
            else
            {
                turno  = 1;
                matchs = new string[Divers.CalculaFatorial(quantityTeam) / Divers.CalculaFatorial(quantityTeam - 2) / 2];
            }

            count = 0;

            for (int t = 0; t < turno; t++)
            {
                for (int i = 0; i < quantityTeam; i++)
                {     //For para caminhar entre os times
                    for (int j = i; j < quantityTeam; j++)
                    { //For para caminha entre os adversários
                        if (teamSubscription[i] != teamSubscription[j])
                        {
                            MatchChampionship matchChampionship = new MatchChampionship
                            {
                                HomeSubscriptionId  = teamSubscription[i],
                                GuestSubscriptionId = teamSubscription[j],
                                HomePoints          = 0,
                                GuestPoints         = 0,
                                MatchDate           = DateTime.Now,
                                RegisterDate        = DateTime.Now,
                                StartTime           = "",
                                Round = 0
                            };

                            _matchChampionshipRepository.Add(matchChampionship);

                            //Sumula sumula = new Sumula();

                            //sumula.IDPartidaCampeonato = partidaCampeonato.IDPartidaCampeonato;
                            //sumula.sObservacao = "";
                            //sumula.dDataCadastro = DateTime.Now;
                            //db.Sumula.Add(sumula);
                            //db.SaveChanges();
                        }
                    }
                }
            }

            if (quantityTeam % 2 == 0)
            {
                OrdenaRodada(championshipId, teamSubscription);
            }
            else
            {
                List <int> timesInscritosNew = new List <int>();

                foreach (int e in teamSubscription)
                {
                    timesInscritosNew[count] = e;
                    count++;
                }

                timesInscritosNew[teamSubscription.Count()] = 10000000;

                OrdenaRodada(championshipId, timesInscritosNew);
            }
        }