예제 #1
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();
            }
        }
예제 #2
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();
            }
        }
예제 #3
0
        public string ObterInscricaoPessoaContato(long CodPessoa, Int32 CodItem)
        {
            try
            {
                AbrirConexao();
                string strSQL       = "Select CD_INSCRICAO from PESSOA_CONTATO Where CD_PESSOA = @v1 ";
                string strInscricao = "";

                if (CodItem == 0)
                {
                    strSQL += " and TP_Contato = 5";
                }
                else
                {
                    strSQL += " AND CD_CONTATO = @v2";
                }

                Cmd = new SqlCommand(strSQL, Con);
                Cmd.Parameters.AddWithValue("@v1", CodPessoa);

                if (CodItem != 0)
                {
                    Cmd.Parameters.AddWithValue("@v2", CodItem);
                }

                Dr = Cmd.ExecuteReader();
                Pessoa_Contato p = new Pessoa_Contato();

                if (Dr.Read())
                {
                    if (Dr["CD_INSCRICAO"] != DBNull.Value)
                    {
                        PessoaInscricaoDAL p_i = new PessoaInscricaoDAL();
                        strInscricao = p_i.ObterInscricao(CodPessoa, Convert.ToInt32(Dr["CD_INSCRICAO"]));
                    }
                }

                String strValor = strInscricao;

                strValor = strValor.Replace(".", "");
                strValor = strValor.Replace("/", "");
                strValor = strValor.Replace("-", "");

                if (strValor.Length < 14)
                {
                    if (strValor.Length < 11)
                    {
                        strInscricao = "";
                    }
                    else
                    {
                        strInscricao = strValor.Substring(0, 3) + "." + strValor.Substring(3, 3) + "." + strValor.Substring(6, 3) + "-" + strValor.Substring(9, 2);
                    }
                }
                else
                {
                    strInscricao = strValor.Substring(0, 2) + "." + strValor.Substring(2, 3) + "." + strValor.Substring(5, 3) + "/" + strValor.Substring(8, 4) + "-" + strValor.Substring(12, 2);
                }


                return(strInscricao);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao Pesquisar Contato da Pessoa: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }