Exemple #1
0
 // Construtor com PK
 public Endereco(int codigo, Bairro neighborhood, Tipo_Endereco type,string Street,   string number, int zipcode)
 {
     cod_end = codigo;
     Logradouro = Street;
     tipo_endereco = type.Cod_tp_endereco;
     Bairro_Endereco = neighborhood.Cod_Bairro;
     Numero = number;
     CEP = zipcode;
 }
 public bool Insert(Tipo_Endereco type_address)
 {
     try
     {
         DadosdoTipoEnd.Inserir(type_address);
         return true;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public bool Delete(Tipo_Endereco type_address)
 {
     try
     {
         DadosdoTipoEnd.Excluir(type_address);
         return true;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public bool Excluir(Tipo_Endereco type_adress)
        {
            try
            {
                int codigo = type_adress.Cod_tp_endereco;

                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.Connection = _conn.ObterConexao();
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "DELETA_TP_END";
                    cmd.Parameters.Add("D_TP_END", OracleDbType.Int32).Value = type_adress.Cod_tp_endereco;
                    cmd.ExecuteNonQuery();
                    return true;
                }
            }
            catch (OracleException ex)
            {
                throw ex;
            }
        }
        public Tipo_Endereco Buscar(string tp_end)
        {
            Tipo_Endereco type_adress = null;
            using (OracleCommand c = _conn.ObterConexao().CreateCommand())
            {
                c.CommandType = System.Data.CommandType.Text;
                c.CommandText = "select NOME FROM TP_END WHERE NOME = :nome";
                c.Parameters.Add("@nome", OracleDbType.Varchar2).Value = tp_end;

                using (OracleDataReader leitor = c.ExecuteReader())
                {
                    if (leitor.HasRows)
                    {
                        leitor.Read();
                        int bd_cod_tp_end = leitor.GetInt32(0);
                        string bd_nome_tp_end = leitor.GetString(1);

                        type_adress = new Tipo_Endereco(bd_cod_tp_end, bd_nome_tp_end);
                    }
                }
            }
            return type_adress;
        }
        public bool Inserir(Tipo_Endereco type_adress)
        {
            try
            {
                int cod_tp_adress = type_adress.Cod_tp_endereco;
                string cod_nome_tp_adress = type_adress.Nome_tp_end;

                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.Connection = _conn.ObterConexao();
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "INSERE_TP_END";
                    cmd.Parameters.Add("DESCRICAO", OracleDbType.Int32).Value = type_adress.Nome_tp_end;

                    cmd.ExecuteNonQuery();
                    return true;
                }
            }
            catch (OracleException ex)
            {
                throw ex;
            }
        }