コード例 #1
0
ファイル: CadastroRapido.aspx.cs プロジェクト: Mualumene/SGP
    /// <summary>
    /// Salva dados do aluno
    /// </summary>
    private void Salvar(bool novo)
    {
        try
        {
            string msgErro;
            if (lblMessage.Text == string.Empty && !UCGridContato1.SalvaConteudoGrid(out msgErro))
            {
                UCGridContato1._MensagemErro.Visible = false;
                lblMessage.Text = msgErro;
                return;
            }

            PES_Pessoa entityPessoa = new PES_Pessoa
            {
                pes_nome = txtNome.Text
                ,
                cid_idNaturalidade = string.IsNullOrEmpty(_txtCid_id.Value) ? Guid.Empty : new Guid(_txtCid_id.Value)
                ,
                pes_dataNascimento = string.IsNullOrEmpty(txtDataNasc.Text) ? new DateTime() : Convert.ToDateTime(txtDataNasc.Text)
                ,
                pes_racaCor = UCComboRacaCor1._Combo.SelectedValue == "-1" ? Convert.ToByte(null) : Convert.ToByte(UCComboRacaCor1._Combo.SelectedValue)
                ,
                pes_sexo = UCComboSexo1._Combo.SelectedValue == "-1" ? Convert.ToByte(null) : Convert.ToByte(UCComboSexo1._Combo.SelectedValue)
                ,
                pes_estadoCivil = UCComboEstadoCivil1._Combo.SelectedValue == "-1" ? Convert.ToByte(null) : Convert.ToByte(UCComboEstadoCivil1._Combo.SelectedValue)
                ,
                pes_situacao = 1
                ,
                IsNew = true
            };

            PES_PessoaDeficiencia entityPessoaDeficiencia = new PES_PessoaDeficiencia
            {
                tde_id = new Guid(UCComboTipoDeficiencia1._Combo.SelectedValue)
            };

            END_Cidade cid = new END_Cidade
            {
                cid_id = new Guid(_txtCid_idCertidao.Value)
            };
            END_CidadeBO.GetEntity(cid);

            PES_CertidaoCivil entityCertidaoCivil = new PES_CertidaoCivil
            {
                ctc_tipo = 1
                ,
                cid_idCartorio = new Guid(_txtCid_idCertidao.Value)
                ,
                unf_idCartorio = cid.unf_id
                ,
                ctc_distritoCartorio = txtDistritoCertidao.Text
                ,
                ctc_dataEmissao = string.IsNullOrEmpty(txtDataEmissao.Text) ? new DateTime() : Convert.ToDateTime(txtDataEmissao.Text)
                ,
                ctc_folha = txtFolha.Text
                ,
                ctc_livro = txtLivro.Text
                ,
                ctc_numeroTermo = txtNumeroTermo.Text
            };

            END_Endereco entityEndereco;
            string       numero;
            string       complemento;
            string       msg;

            bool cadastraEndereco = UCEnderecos1.RetornaEnderecoCadastrado(out entityEndereco, out numero, out complemento, out msg);

            if (!cadastraEndereco)
            {
                throw new ValidationException(msg);
            }

            DataTable dtEndereco = string.IsNullOrEmpty(entityEndereco.end_cep) ? new DataTable() : UCEnderecos1._VS_enderecos;

            ACA_Aluno entityAluno = new ACA_Aluno
            {
                ent_id = __SessionWEB.__UsuarioWEB.Usuario.ent_id
                ,
                alu_situacao = _ddlSituacao.SelectedValue == "-1" ? Convert.ToByte(0) : Convert.ToByte(_ddlSituacao.SelectedValue)
                ,
                IsNew = true
            };

            ACA_AlunoCurriculo entityAlunoCurriculo = new ACA_AlunoCurriculo
            {
                esc_id = UCFiltroEscolas1._ComboUnidadeEscola.SelectedValue.Split(';')[0] == "-1" ? Convert.ToInt32(null) : Convert.ToInt32(UCFiltroEscolas1._ComboUnidadeEscola.SelectedValue.Split(';')[0])
                ,
                uni_id = UCFiltroEscolas1._ComboUnidadeEscola.SelectedValue.Split(';')[1] == "-1" ? Convert.ToInt32(null) : Convert.ToInt32(UCFiltroEscolas1._ComboUnidadeEscola.SelectedValue.Split(';')[1])
                ,
                cur_id = UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[0] == "-1" ? Convert.ToInt32(null) : Convert.ToInt32(UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[0])
                ,
                crr_id = UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[1] == "-1" ? Convert.ToInt32(null) : Convert.ToInt32(UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[1])
                ,
                crp_id = UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[2] == "-1" ? Convert.ToInt32(null) : Convert.ToInt32(UCComboCurriculoPeriodo1._Combo.SelectedValue.Split(';')[2])
                ,
                alc_matriculaEstadual = txtMatriculaEstadual.Text
                ,
                alc_situacao = _ddlSituacao.SelectedValue == "-1" ? Convert.ToByte(0) : Convert.ToByte(_ddlSituacao.SelectedValue)
            };

            if (ACA_AlunoBO.Save_CadastroRapido(entityPessoa
                                                , entityPessoaDeficiencia
                                                , dtEndereco
                                                , UCGridContato1._VS_contatos
                                                , entityCertidaoCivil
                                                , txtMae.Text
                                                , txtCPFMae.Text
                                                , txtPai.Text
                                                , txtCPFPai.Text
                                                , rfvMatriculaEstadual.Enabled
                                                , entityAluno
                                                , entityAlunoCurriculo
                                                , null
                                                , null))
            {
                ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Insert, "alu_id: " + entityAluno.alu_id);
                __SessionWEB.PostMessages = UtilBO.GetErroMessage(String.Format("Aluno incluído com sucesso."), UtilBO.TipoMensagem.Sucesso);

                Response.Redirect("CadastroRapido.aspx", false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();

                string redirect = novo ?
                                  "~/Academico/Aluno/CadastroRapido.aspx" :
                                  "~/Academico/Aluno/Busca.aspx";

                Response.Redirect(redirect, false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                lblMessage.Text = UtilBO.GetErroMessage("Erro ao tentar salvar o aluno.", UtilBO.TipoMensagem.Erro);
            }
        }
        catch (ThreadAbortException)
        {
        }
        catch (ValidationException ex)
        {
            UCEnderecos1.AtualizaEnderecos();
            lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
        }
        catch (ArgumentException ex)
        {
            UCEnderecos1.AtualizaEnderecos();
            lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
        }
        catch (DuplicateNameException ex)
        {
            UCEnderecos1.AtualizaEnderecos();
            lblMessage.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
        }
        catch (Exception ex)
        {
            UCEnderecos1.AtualizaEnderecos();
            ApplicationWEB._GravaErro(ex);
            lblMessage.Text = UtilBO.GetErroMessage("Erro ao tentar salvar o aluno.", UtilBO.TipoMensagem.Erro);
        }
    }