コード例 #1
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);
            }
        }