private void btnGerar_Click(object sender, EventArgs e) { Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = contexto.Copa.Find(Convert.ToInt32(cmbCopa.SelectedValue)); bool verifCopa = true; int qtdPremios; if (int.TryParse(txtPremiacao.Text, out qtdPremios)) { if (qtdPremios >= 0) { List <Modelo.PremioCopa> lstPremioCopa = copa.premioCopa.ToList(); if (lstPremioCopa.Count > 0) { if (DialogResult.Yes == MessageBox.Show("Você realmente deseja gerar novas premiações? Premiações antigas serão removidas!", "Gerar Novas Premiações", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { for (int i = 0; i < lstPremioCopa.Count; i++) { Modelo.PremioCopa premioCopa = contexto.PremioCopa.Find(lstPremioCopa[i].id); contexto.PremioCopa.Remove(premioCopa); contexto.SaveChanges(); } } else { verifCopa = false; } } if (verifCopa) { for (int i = 0; i < qtdPremios; i++) { Modelo.PremioCopa premioCopa = new Modelo.PremioCopa(); premioCopa.ordem = i + 1; premioCopa.copaID = copa.id; premioCopa.premio = 0; contexto.PremioCopa.Add(premioCopa); } contexto.SaveChanges(); carregarCampos(); } } else { MessageBox.Show("É necessário que a quantidade seja positiva!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPremiacao.Text = copa.premioCopa.Count.ToString(); txtPremiacao.Focus(); } } else { MessageBox.Show("Valor inválido", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPremiacao.Text = copa.premioCopa.Count.ToString(); txtPremiacao.Focus(); } }
private Modelo.Copa getCopa(Modelo.Copa copa) { copa.descr = txtNomeCopa.Text; copa.campeonatoID = Convert.ToInt32(cmbCampeonato.SelectedValue); copa.dataInicio = dtpInicio.Value; copa.dataFim = dtpFim.Value; copa.premio = Convert.ToSingle(txtPremio.Text.Replace("R$", "")); if (cmbEtapaFinal.SelectedIndex > -1) { copa.copaEtapaFinalID = Convert.ToInt32(cmbEtapaFinal.SelectedValue); } else { copa.copaEtapaFinalID = null; } return(copa); }
private void setCopa(Modelo.Copa copa) { lblID.Text = copa.id.ToString(); txtNomeCopa.Text = copa.descr; cmbCampeonato.SelectedValue = copa.campeonatoID; dtpInicio.Value = copa.dataInicio; dtpFim.Value = copa.dataFim; cmbEtapaFinal.DataSource = copa.copaEtapas.OrderBy(t => t.etapaNome).ToList(); txtPremio.Text = copa.premio.ToString("R$ #,##0.00"); if (copa.copaEtapaFinalID != null) { cmbEtapaFinal.SelectedValue = copa.copaEtapaFinalID; } else { cmbEtapaFinal.SelectedIndex = -1; } }
private void btnAplicar_Click(object sender, EventArgs e) { Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = contexto.Copa.Find(Convert.ToInt32(cmbCopa.SelectedValue)); List <Modelo.CopaCompetidor> lstCopaCompetidor = copa.getCompetidores(true); //Este método já traz os competidores ordenado pela a pontuação total List <Modelo.PremioCopa> lstPremioCopa = copa.premioCopa.OrderBy(t => t.ordem).ToList(); for (int i = 0; i < lstPremioCopa.Count && i < lstCopaCompetidor.Count; i++) { Modelo.PremioCopa premioCopa = contexto.PremioCopa.Find(lstPremioCopa[i].id); premioCopa.campeonatoCompetidorID = lstCopaCompetidor[i].campeonatoCompetidorID; Modelo.CampeonatoCompetidor campeonatoCompetidor = contexto.CampeonatoCompetidor.Find(lstCopaCompetidor[i].campeonatoCompetidorID); campeonatoCompetidor.totalPremio += premioCopa.premio; contexto.Entry(premioCopa).State = System.Data.Entity.EntityState.Modified; contexto.Entry(campeonatoCompetidor).State = System.Data.Entity.EntityState.Modified; contexto.SaveChanges(); } Funcoes.Relatorios.relPremioCopa(copa.id); carregarCampos(); }
private void frmBannerTelao_Load(object sender, EventArgs e) { Bitmap img1 = new Bitmap(@".\Logos\logo1.png"); Bitmap img2 = new Bitmap(@".\Logos\logo2.png"); pictureBox1.Image = img1; pictureBox2.Image = img2; Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = contexto.Copa.Find(4); lstCopaCompetidor = copa.getCompetidores(false); //Modelo.Copa copa = contexto.Copa.Find(copaID); //Funcoes.finalizarRound.calculoBonus(this.etapaID, false); //lstCopaCompetidor = copa.getCompetidores(this.calcUltRound); difRanking(); int qtdBanners = lstCopaCompetidor.Count % 5 == 0 ? lstCopaCompetidor.Count / 5 : lstCopaCompetidor.Count / 5 + 1; for (int i = 0; i < qtdBanners - 1; i++) { cmbPosicao.Items.Add((i * 5 + 1) + "º ATÉ O " + ((i * 5 + 5) + "º")); } }
private void btnGravar_Click(object sender, EventArgs e) { if (verificarCampos()) { Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = this.op == 'I' ? getCopa(new Modelo.Copa()) : getCopa(contexto.Copa.Find(Convert.ToInt32(lblID.Text))); if (op == 'I') { contexto.Copa.Add(copa); } else { contexto.Entry(copa).State = System.Data.Entity.EntityState.Modified; } contexto.SaveChanges(); lblID.Text = copa.id.ToString(); op = 'E'; habilitarCampos(false); op = 'X'; carregarGridGeral(); } }
private void removerPremios() { Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = contexto.Copa.Find(Convert.ToInt32(cmbCopa.SelectedValue)); List <Modelo.PremioCopa> lstPremioCopa = copa.premioCopa.OrderBy(t => t.ordem).ToList(); for (int i = 0; i < lstPremioCopa.Count; i++) { if (lstPremioCopa[i].campeonatoCompetidorID != null) { Modelo.PremioCopa premioCopa = contexto.PremioCopa.Find(lstPremioCopa[i].id); Modelo.CampeonatoCompetidor campeonatoCompetidor = contexto.CampeonatoCompetidor.Find(premioCopa.campeonatoCompetidorID); premioCopa.campeonatoCompetidorID = null; campeonatoCompetidor.totalPremio -= premioCopa.premio; contexto.Entry(campeonatoCompetidor).State = System.Data.Entity.EntityState.Modified; contexto.Entry(premioCopa).State = System.Data.Entity.EntityState.Modified; contexto.Entry(premioCopa); contexto.SaveChanges(); } } carregarCampos(); MessageBox.Show("Premiação Removida dos Competidores", "Prêmios Removidos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
private void carregarCampos() { Modelo.SGCRPContexto contexto = new Modelo.SGCRPContexto(); Modelo.Copa copa = contexto.Copa.Find(Convert.ToInt32(cmbCopa.SelectedValue)); List <Modelo.PremioCopa> lstPremioCopa = copa.premioCopa.OrderBy(t => t.ordem).ToList(); txtPremiacao.Text = lstPremioCopa.Count.ToString(); if (lstPremioCopa.Count > 0) { DataTable dt = new DataTable(); dt.Columns.Add("Ordem"); dt.Columns.Add("Premio"); dt.Columns.Add("Ganhador"); for (int i = 0; i < lstPremioCopa.Count; i++) { dt.Rows.Add(lstPremioCopa[i].ordem, "R$" + lstPremioCopa[i].premio.ToString("0.00"), (lstPremioCopa[i].campeonatoCompetidorID == null ? "" : lstPremioCopa[i].campeonatoCompetidor.competidor.apelido)); } dgvPremiacao.DataSource = dt; } else { dgvPremiacao.DataSource = null; } if (lstPremioCopa.FirstOrDefault(t => t.campeonatoCompetidorID != null) != null) { btnAplicar.Enabled = false; btnRemoverPremio.Enabled = true; btnGerar.Enabled = false; } else { btnAplicar.Enabled = true; btnRemoverPremio.Enabled = false; btnGerar.Enabled = true; } }
public static void melhoresMontariaNoiteV2(int roundID, int qtd) { SGCRPContexto contexto = new SGCRPContexto(); var culture = new System.Globalization.CultureInfo("pt-BR"); Round round = contexto.Round.Find(roundID); Funcoes.finalizarRound.reodernarCompCampeonato(round.etapa.campeonatoID); round = contexto.Round.Find(roundID); List <CopaCompetidor> lstCopaCompetidor = new List <CopaCompetidor>(); if (round.etapa.copaEtapa.Count() > 0) { Modelo.Copa copa = contexto.Copa.Find(round.etapa.copaEtapa.First().copaID); lstCopaCompetidor = copa.getCompetidores(true); } string folder = Relatorios.diretorioPasta(round.etapa.campeonato.nome, round.etapa); string arq = folder + @"\CRP" + round.etapa.campeonato.modalidade.abreviacao.ToUpper() + "_MELHORES_MONT_R" + round.numRound + "_" + culture.DateTimeFormat.GetDayName(round.data.DayOfWeek).Substring(0, 3).ToUpper() + "_" + round.etapa.cidade.nome.ToUpper() + "_" + round.data.Year + ".html"; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(arq)) { sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"../../css/estilo.css\" />"); sw.WriteLine("</head>"); sw.WriteLine("<body>"); sw.WriteLine("<div class=\"divCabecalho\">"); sw.WriteLine("<th>"); sw.WriteLine("<img src=\"../../Logos/logo1.png\" class=\"imgCabecalho\"/>"); sw.WriteLine("<img src=\"../../Logos/logo2.png\" class=\"imgCabecalho\"/>"); sw.WriteLine(" <h3 style=\"margin: 10px; text-align: left;\"> "+ round.etapa.cidade.nome + " - " + round.etapa.cidade.uf + " </h3>"); sw.WriteLine(" <h3 style=\"margin: 10px; text-align: left;\">"+ round.etapa.nome + "</h3>"); sw.WriteLine(" <h3 style=\"margin: 10px; text-align: left;\">" + round.etapa.campeonato.nome + "</h3>"); sw.WriteLine(" <h3 style=\"margin: 10px; text-align: left;\">"+ round.etapa.numEtapa + "° ETAPA" + "</h3>"); sw.WriteLine("</div>"); sw.WriteLine("<br>"); CampeonatoEtapaExterno campeonatoEtapaExterno = contexto.CampeonatoEtapaExternos.FirstOrDefault(c => c.etapaID == round.etapaID); List <Montaria> lstMontaria = round.montaria.Where(t => t.touroID != null && t.pulo && t.notas.Count > 0).OrderByDescending(m => m.notaTempoMontaria).ToList(); for (int i = 0; i < qtd; i++) { CampeonatoCompetidor campeonatoCompetidor; if (campeonatoEtapaExterno != null) { campeonatoCompetidor = campeonatoEtapaExterno.campeonato.campeonatoCompetidor.FirstOrDefault(c => c.competidorID == lstMontaria[i].etapaCompetidor.competidorID); } else { campeonatoCompetidor = null; } float[] calculo = CalculoSaidaParadaTouro.calculoSaidaParada(Convert.ToInt32(lstMontaria[i].touroID)); sw.WriteLine("<center>"); sw.WriteLine("<table class=\"tbMelhoresMont\">"); sw.WriteLine("<tr> <th scope=\"col\">" + (i + 1) + "°</th> <th scope=\"col\" class=\"colComp\"> COMPETIDOR </th> <th scope=\"col\" class=\"colAnimal\"> ANIMAL </th> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> NOME </th> <td> " + lstMontaria[i].etapaCompetidor.competidor.apelido + "</td> <td> " + lstMontaria[i].touro.nome + " (" + lstMontaria[i].touro.tropeiro.sigla + ") </td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> IDADE </th> <td> " + Idade.calcIdade(lstMontaria[i].etapaCompetidor.competidor.nascimento) + "</td> <td>" + lstMontaria[i].touro.idade + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> CIDADE </th> <td> " + lstMontaria[i].cidadeCompetidor + "</td> <td> " + lstMontaria[i].touro.tropeiro.cidade.nome + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> RANKING </th> <td> " + (campeonatoCompetidor == null ? lstMontaria[i].etapaCompetidor.campeonatoCompetidor.rank : campeonatoCompetidor.rank) + "</td> <td> - </td> </tr>"); if (lstCopaCompetidor.Count > 0) { int posCopa = 0; if (campeonatoCompetidor == null) { posCopa = lstCopaCompetidor.FindIndex(c => c.campeonatoCompetidorID == lstMontaria[i].etapaCompetidor.campeonatoCompetidorID) + 1; } else { posCopa = lstCopaCompetidor.FindIndex(c => c.campeonatoCompetidor.competidorID == campeonatoCompetidor.competidorID) + 1; } sw.WriteLine("<tr> <th scope=\"linha\"> RANKING COPA </th> <td> " + posCopa + "</td> <td> - </td> </tr>"); } sw.WriteLine("<tr> <th scope=\"linha\"> TITULOS </th> <td scope=\"valor\"> " + (campeonatoCompetidor == null ? lstMontaria[i].etapaCompetidor.competidor.qtdTitulos : campeonatoCompetidor.competidor.qtdTitulos) + "</td> <td scope=\"valor\"> - </td> </tr>"); int qtdSaida = (campeonatoCompetidor == null ? lstMontaria[i].etapaCompetidor.campeonatoCompetidor.saidas : campeonatoCompetidor.saidas); int qtdParada = (campeonatoCompetidor == null ? lstMontaria[i].etapaCompetidor.campeonatoCompetidor.paradas : campeonatoCompetidor.paradas); sw.WriteLine("<tr> <th scope=\"linha\"> QUANTIDADE SAIDA </th> <td scope=\"valor\">" + qtdSaida + "</td> <td scope=\"valor\">" + calculo[0] + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> QUANTIDADE PARADA </th> <td scope=\"valor\">" + qtdParada + "<td scope=\"valor\"> " + calculo[1] + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> % DE PARADAS </th> <td scope=\"valor\">" + ((float)lstMontaria[i].etapaCompetidor.campeonatoCompetidor.paradas / (float)lstMontaria[i].etapaCompetidor.campeonatoCompetidor.saidas * 100).ToString("0.00") + "</td> <td scope=\"valor\"> " + ((float)calculo[1] / (float)calculo[0] * 100).ToString("0.00") + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> MÉDIA TEMPO </th> <td scope=\"valor\"> - </td> <td scope=\"valor\">" + (calculo[2] / (calculo[0] - calculo[1])).ToString("0.00") + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> NOTA </th> <td scope=\"valor\"> " + (lstMontaria[i].notas.Count(n => n.notaCompetidor < 8) == 0 ? lstMontaria[i].notas.Sum(n => n.notaCompetidor) : (lstMontaria[i].notas.Sum(n => n.notaCompetidor) / lstMontaria[i].notas.Count)).ToString("0.00") + "</td> <td scope=\"valor\"> " + lstMontaria[i].notas.Sum(n => n.notaTouro).ToString("0.00") + "</td> </tr>"); sw.WriteLine("<tr> <th scope=\"linha\"> TOTAL </th> <td colspan=\"2\" scope=\"total\">" + lstMontaria[i].notaMontaria.ToString("0.00") + "</td> </tr>"); sw.WriteLine("</table>"); sw.WriteLine("</center>"); sw.WriteLine("<br>"); } sw.WriteLine("</body>"); sw.WriteLine("</html>"); } System.Diagnostics.Process.Start(arq); }