コード例 #1
0
        public bool AtualizarPessoaDocumento(decimal CodigoDocumento, long CodigoPessoa, int TipoPessoa)
        {
            try
            {
                AbrirConexao();

                strSQL = "update PESSOA_DO_DOCUMENTO set TP_PESSOA = @v26," +
                         "CD_PESSOA = @v27," +
                         "RAZ_SOCIAL = @v28," +
                         "INSCRICAO = @v29," +
                         "INS_ESTADUAL = @v30," +
                         "TELEFONE_1 = @v31," +
                         "EMAIL_NFE = @v32," +
                         "EMAIL = @v33," +
                         "LOGRADOURO = @v34," +
                         "NR_ENDERECO = @v35," +
                         "COMPLEMENTO = @v36," +
                         "CD_CEP = @v37," +
                         "CD_MUNICIPIO = @v38," +
                         "CD_BAIRRO = @v39," +
                         "DS_BAIRRO = @v40," +
                         "EMAIL_NFSE = @v41 where CD_DOCUMENTO = @v25 AND TP_PESSOA = @v26";
                Cmd = new SqlCommand(strSQL, Con);

                PessoaDAL pessoaDAL = new PessoaDAL();
                Pessoa    pessoa    = new Pessoa();
                pessoa = pessoaDAL.PesquisarPessoa(CodigoPessoa);

                PessoaContatoDAL pesCttDAL = new PessoaContatoDAL();
                Pessoa_Contato   pesCtt    = new Pessoa_Contato();
                pesCtt = pesCttDAL.PesquisarPessoaContato(CodigoPessoa, 1);

                PessoaEnderecoDAL pesEndDAL = new PessoaEnderecoDAL();
                Pessoa_Endereco   pesEnd    = new Pessoa_Endereco();
                pesEnd = pesEndDAL.PesquisarPessoaEndereco(CodigoPessoa, 1);

                PessoaInscricaoDAL pesInsDAL = new PessoaInscricaoDAL();
                Pessoa_Inscricao   pesIns    = new Pessoa_Inscricao();
                pesIns = pesInsDAL.PesquisarPessoaInscricao(CodigoPessoa, 1);

                Cmd.Parameters.AddWithValue("@v25", CodigoDocumento);
                Cmd.Parameters.AddWithValue("@v26", TipoPessoa);
                Cmd.Parameters.AddWithValue("@v27", CodigoPessoa);
                Cmd.Parameters.AddWithValue("@v28", pessoa.NomePessoa);
                Cmd.Parameters.AddWithValue("@v29", pesIns._NumeroInscricao);
                Cmd.Parameters.AddWithValue("@v30", pesIns._NumeroIERG);
                Cmd.Parameters.AddWithValue("@v31", pesCtt._Fone1);
                Cmd.Parameters.AddWithValue("@v32", pesCtt._MailNFE);
                Cmd.Parameters.AddWithValue("@v33", pesCtt._Mail1);
                Cmd.Parameters.AddWithValue("@v34", pesEnd._Logradouro);
                Cmd.Parameters.AddWithValue("@v35", pesEnd._NumeroLogradouro);
                Cmd.Parameters.AddWithValue("@v36", pesEnd._Complemento);
                Cmd.Parameters.AddWithValue("@v37", pesEnd._CodigoCEP);
                Cmd.Parameters.AddWithValue("@v38", pesEnd._CodigoMunicipio);
                Cmd.Parameters.AddWithValue("@v39", pesEnd._CodigoBairro);
                Cmd.Parameters.AddWithValue("@v40", pesEnd._DescricaoBairro);
                Cmd.Parameters.AddWithValue("@v41", pesCtt._MailNFSE);

                Cmd.ExecuteNonQuery();
                return(true);
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0)                 // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao Incluir PESSOA DO DOCUMENTO: " + ex.Message.ToString());
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar PESSOA DO DOCUMENTO" + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
コード例 #2
0
        public bool InserirPessoaDocumento(decimal CodigoDocumento, long CodigoPessoa, int TipoPessoa)
        {
            if (CodigoPessoa == 0)
            {
                return(true);
            }

            try
            {
                AbrirConexao();

                string strCamposPessoa  = "CD_DOCUMENTO";
                string strValoresPessoa = "@v25";

                strCamposPessoa  += ", TP_PESSOA";
                strValoresPessoa += ", @v26";

                strCamposPessoa  += ", CD_PESSOA";
                strValoresPessoa += ", @v27";

                strCamposPessoa  += ", RAZ_SOCIAL";
                strValoresPessoa += ", @v28";

                strCamposPessoa  += ", INSCRICAO";
                strValoresPessoa += ", @v29";

                strCamposPessoa  += ", INS_ESTADUAL";
                strValoresPessoa += ", @v30";

                strCamposPessoa  += ", TELEFONE_1";
                strValoresPessoa += ", @v31";

                strCamposPessoa  += ", EMAIL_NFE";
                strValoresPessoa += ", @v32";

                strCamposPessoa  += ", EMAIL";
                strValoresPessoa += ", @v33";

                strCamposPessoa  += ", LOGRADOURO";
                strValoresPessoa += ", @v34";

                strCamposPessoa  += ", NR_ENDERECO";
                strValoresPessoa += ", @v35";

                strCamposPessoa  += ", COMPLEMENTO";
                strValoresPessoa += ", @v36";

                strCamposPessoa  += ", CD_CEP";
                strValoresPessoa += ", @v37";

                strCamposPessoa  += ", CD_MUNICIPIO";
                strValoresPessoa += ", @v38";

                strCamposPessoa  += ", CD_BAIRRO";
                strValoresPessoa += ", @v39";

                strCamposPessoa  += ", DS_BAIRRO";
                strValoresPessoa += ", @v40";

                strCamposPessoa  += ", EMAIL_NFSE";
                strValoresPessoa += ", @v41";

                strSQL = "insert into PESSOA_DO_DOCUMENTO (" + strCamposPessoa + ") values (" + strValoresPessoa + "); SELECT SCOPE_IDENTITY();";

                Cmd = new SqlCommand(strSQL, Con);


                PessoaDAL pessoaDAL = new PessoaDAL();
                Pessoa    pessoa    = new Pessoa();
                pessoa = pessoaDAL.PesquisarPessoa(CodigoPessoa);

                PessoaContatoDAL pesCttDAL = new PessoaContatoDAL();
                Pessoa_Contato   pesCtt    = new Pessoa_Contato();
                pesCtt = pesCttDAL.PesquisarPessoaContato(CodigoPessoa, 1);

                PessoaEnderecoDAL pesEndDAL = new PessoaEnderecoDAL();
                Pessoa_Endereco   pesEnd    = new Pessoa_Endereco();
                pesEnd = pesEndDAL.PesquisarPessoaEndereco(CodigoPessoa, 1);

                PessoaInscricaoDAL pesInsDAL = new PessoaInscricaoDAL();
                Pessoa_Inscricao   pesIns    = new Pessoa_Inscricao();
                pesIns = pesInsDAL.PesquisarPessoaInscricao(CodigoPessoa, 1);

                Cmd.Parameters.AddWithValue("@v25", CodigoDocumento);
                Cmd.Parameters.AddWithValue("@v26", TipoPessoa);
                Cmd.Parameters.AddWithValue("@v27", CodigoPessoa);
                Cmd.Parameters.AddWithValue("@v28", pessoa.NomePessoa);
                Cmd.Parameters.AddWithValue("@v29", pesIns._NumeroInscricao);
                Cmd.Parameters.AddWithValue("@v30", pesIns._NumeroIERG);
                Cmd.Parameters.AddWithValue("@v31", pesCtt._Fone1);
                Cmd.Parameters.AddWithValue("@v32", pesCtt._MailNFE);
                Cmd.Parameters.AddWithValue("@v33", pesCtt._Mail1);
                Cmd.Parameters.AddWithValue("@v34", pesEnd._Logradouro);
                Cmd.Parameters.AddWithValue("@v35", pesEnd._NumeroLogradouro);
                Cmd.Parameters.AddWithValue("@v36", pesEnd._Complemento);
                Cmd.Parameters.AddWithValue("@v37", pesEnd._CodigoCEP);
                Cmd.Parameters.AddWithValue("@v38", pesEnd._CodigoMunicipio);
                Cmd.Parameters.AddWithValue("@v39", pesEnd._CodigoBairro);
                Cmd.Parameters.AddWithValue("@v40", pesEnd._DescricaoBairro);
                Cmd.Parameters.AddWithValue("@v41", pesCtt._MailNFSE);
                Cmd.ExecuteNonQuery();

                return(true);
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0)                 // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao Incluir pessoa do documento: " + ex.Message.ToString());
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar Pessoa do documento: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }