// SALVA UMA NOVA INSCRIÇÃO
 public void salvar(inscricaoEvento inscricao)
 {
     if (listaInscricoes().Count(x => x.Codigo == inscricao.Codigo) > 0)
     {
         atualizaInscricao(inscricao);
     }
     else
     {
         insereInscricao(inscricao);
     }
 }
Example #2
0
        private void salvarBtn_Click(object sender, EventArgs e)
        {
            try
            {
                validaControles = new isEmpty();
                foreach (Control child in this.Controls)
                {
                    string tag = validaControles.empty(child);
                    if (tag != "")
                    {
                        throw new Exception("O campo '" + tag + "' está vazio");
                    }
                    else
                    {
                        appInsc = new inscricaoEventoAplicacao();
                        appPart = new participanteAplicacao();
                        inscricao = new inscricaoEvento();
                        appInscSem = new inscricaoSeminfoAplicacao();
                        appEvento = new eventoAplicacao();
                        evento = new Evento();

                        if (!appInscSem.jaCadastrado(cpfMsk.Text))
                        {
                            throw new Exception("CPF ainda não cadastrado!!!");
                        }

                        if (appInsc.cadastradoEvento(appEvento.retornaCodEv(eventoCB.Text), cpfMsk.Text))
                        {
                            throw new Exception("CPF já cadastrado neste evento!!!");
                        }
                        evento = appEvento.selectEventoWhere(eventoCB.Text);
                        int codSeminfo = appInsc.retornoCodSeminfo(cpfMsk.Text);
                        if (appEvento.evSameTime(codSeminfo, evento.Data, evento.Hora))
                        {
                            throw new Exception("CPF já cadastrado em outro evento no mesmo horário");
                        }
                        else
                        {
                            inscricao.Evento = evento.Codigo;
                            inscricao.Data = evento.Data;
                            inscricao.codigoSeminfo = codSeminfo;
                            appInsc.salvar(inscricao);
                            MessageBox.Show("Espectador cadastrado com sucesso!");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 // ATUALIZA UMA INSCRIÇÃO NA TABELA DE INSCRIÇÃO DE EVENTOS
 private void atualizaInscricao(inscricaoEvento inscricao)
 {
     var strUpdate = "";
     strUpdate += @"UPDATE tblInscEvento SET ";
     strUpdate += string.Format(@"nCodEv = {0},
     nCodSi = {1})", inscricao.Evento, inscricao.codigoSeminfo);
     using (contexto = new Contexto())
     {
         contexto.executaComando(strUpdate);
     }
 }
 // INSERE UMA NOVA INSCRIÇÃO NA TABELA DE INSCRIÇÃO DE EVENTOS
 private void insereInscricao(inscricaoEvento inscricao)
 {
     var strInsert = "";
     strInsert += @"INSERT INTO tblInscEvento (nCodEv, nCodSi)";
     strInsert += string.Format(@" VALUES ({0}, {1})",
     inscricao.Evento, inscricao.codigoSeminfo);
     using (contexto = new Contexto())
     {
         contexto.executaComando(strInsert);
     }
 }
 //CONVERTE O DATAREADER DO MÉTODO ACIMA
 private List<inscricaoEvento> inscricaoReaderToObjectList(SqlDataReader reader)
 {
     //EM UMA LISTA DE INSCRIÇÃO DE EVENTOS
     var inscricoes = new List<inscricaoEvento>();
     while (reader.Read())
     {
         var temp = new inscricaoEvento()
         {
             Codigo = int.Parse(reader["nCodInsc"].ToString()),
             Evento = int.Parse(reader["nCodEv"].ToString()),
             codigoSeminfo = int.Parse(reader["nCodSi"].ToString())
         };
         inscricoes.Add(temp);
     }
     reader.Close();
     return inscricoes;
 }