public List <Pessoa_Endereco> ObterPessoaEnderecos(Int64 CodPessoa) { try { AbrirConexao(); Cmd = new SqlCommand("Select * from PESSOA_ENDERECO Where CD_PESSOA = @v1 ", Con); Cmd.Parameters.AddWithValue("@v1", CodPessoa); Dr = Cmd.ExecuteReader(); List <Pessoa_Endereco> lista = new List <Pessoa_Endereco>(); while (Dr.Read()) { Pessoa_Endereco p = new Pessoa_Endereco(); p._CodigoItem = Convert.ToInt32(Dr["CD_ENDERECO"]); p._Logradouro = Dr["TX_LOGRADOURO"].ToString(); p._NumeroLogradouro = Dr["NR_ENDERECO"].ToString(); p._Complemento = Dr["TX_COMPLEMENTO"].ToString(); p._CodigoCEP = Convert.ToInt64(Dr["CD_CEP"]); p._DescricaoEstado = Dr["DS_ESTADO"].ToString(); p._DescricaoMunicipio = Dr["DS_MUNICIPIO"].ToString(); p._DescricaoBairro = Dr["DS_BAIRRO"].ToString(); p._CodigoBairro = Convert.ToInt32(Dr["CD_BAIRRO"].ToString()); p._CodigoEstado = Convert.ToInt32(Dr["CD_ESTADO"].ToString()); p._CodigoMunicipio = Convert.ToInt64(Dr["CD_MUNICIPIO"].ToString()); p._TipoEndereco = Convert.ToInt32(Dr["TP_ENDERECO"].ToString()); p._TipoEnderecoD = RnHabilTipo.DescricaoHabil_Tipo(p._TipoEndereco); if (Dr["CD_INSCRICAO"] != DBNull.Value) { p._CodigoInscricao = Convert.ToInt32(Dr["CD_INSCRICAO"]); } lista.Add(p); } return(lista); } catch (Exception ex) { throw new Exception("Erro ao Obter Endereços da Pessoa: " + ex.Message.ToString()); } finally { FecharConexao(); } }
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(); } }
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(); } }
public List <Pessoa_Endereco> ListarPessoaEnderecos(List <DBTabelaCampos> ListaFiltros, short shtTipoPessoa) { try { AbrirConexao(); string strValor = ""; string strSQL = "Select IP.*, T.DS_TIPO " + " from PESSOA_ENDERECO as IP" + " Inner Join Pessoa as P" + " on IP.CD_PESSOA = P.CD_PESSOA" + " Inner Join HABIL_TIPO as T" + " on IP.TP_ENDERECO = T.CD_TIPO" + " WHERE P.[CD_PESSOA] IN ( SELECT [VW_PESSOA].COD_PESSOA FROM [VW_PESSOA] "; strValor = MontaFiltroIntervalo(ListaFiltros); strSQL = strSQL + strValor; strSQL = strSQL + ")"; if (shtTipoPessoa == 1) { strSQL = strSQL + " and P.IN_FORNECEDOR = 1"; } else if (shtTipoPessoa == 2) { strSQL = strSQL + " and P.IN_CLIENTE = 1"; } else if (shtTipoPessoa == 3) { strSQL = strSQL + " and P.IN_TRANSPORTADOR = 1"; } Cmd = new SqlCommand(strSQL, Con); Dr = Cmd.ExecuteReader(); List <Pessoa_Endereco> lista = new List <Pessoa_Endereco>(); while (Dr.Read()) { Pessoa_Endereco p = new Pessoa_Endereco(); p._CodigoPessoa = Convert.ToInt32(Dr["CD_PESSOA"]); p._CodigoItem = Convert.ToInt32(Dr["CD_ENDERECO"]); p._Logradouro = Dr["TX_LOGRADOURO"].ToString(); p._NumeroLogradouro = Dr["NR_ENDERECO"].ToString(); p._Complemento = Dr["TX_COMPLEMENTO"].ToString(); p._CodigoCEP = Convert.ToInt64(Dr["CD_CEP"]); p._DescricaoEstado = Dr["DS_ESTADO"].ToString(); p._DescricaoMunicipio = Dr["DS_MUNICIPIO"].ToString(); p._DescricaoBairro = Dr["DS_BAIRRO"].ToString(); p._CodigoBairro = Convert.ToInt32(Dr["CD_BAIRRO"].ToString()); p._CodigoEstado = Convert.ToInt32(Dr["CD_ESTADO"].ToString()); p._CodigoMunicipio = Convert.ToInt64(Dr["CD_MUNICIPIO"].ToString()); p._TipoEndereco = Convert.ToInt32(Dr["TP_ENDERECO"].ToString()); p._TipoEnderecoD = Dr["DS_TIPO"].ToString(); if (Dr["CD_INSCRICAO"] != DBNull.Value) { p._CodigoInscricao = Convert.ToInt32(Dr["CD_INSCRICAO"]); } lista.Add(p); } Dr.Close(); return(lista); } catch (Exception ex) { throw new Exception("Erro ao Obter Endereços da Pessoa: " + ex.Message.ToString()); } finally { FecharConexao(); } }