public function alterar(Endereco $end)
 {
     parent::alterar($end);
     $where = "WHERE " . self::ID . " = '" . $end->getId() . "'";
     $e = $end->getEstado();
     if ($e->getId() <= 0) {
         $lE = new ListaEstados();
         $lE->inserir($e);
         $end->setEstado($e);
     }
     $c = $end->getCidade();
     if ($c->getId() <= 0) {
         $lC = new ListaCidades();
         $lC->inserir($c);
         $end->setCidade($c);
     } else {
         $lC = new ListaCidades();
         $lC->condicoes('', $c->getId(), ListaCidades::ID);
         if ($lC->getTotal() <= 0) {
             if ($c->getPais()->getId() <= 0) {
                 $c->setPais($end->getPais());
             }
             if ($c->getEstado()->getId() <= 0) {
                 $c->setEstado($end->getEstado());
             }
             $this->con->executar("INSERT INTO " . Sistema::$BDPrefixo . $lC->getTabela() . "(" . ListaCidades::ID . ", " . ListaCidades::PAIS . ", " . ListaCidades::ESTADO . ", " . ListaCidades::NOME . ", " . ListaCidades::DDD . ") VALUES('" . $c->getId() . "','" . $c->getPais()->getId() . "','" . $c->getEstado()->getId() . "','" . $c->nome . "','" . $c->ddd . "')");
             $id = $this->con->getId();
             $end->setCidade(new Cidade($id));
         }
     }
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::LOGRADOURO, $end->logradouro, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::NUMERO, $end->numero, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::COMPLEMENTO, $end->complemento, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::BAIRRO, $end->bairro, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::CIDADE, $end->getCidade()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::ESTADO, $end->getEstado()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::PAIS, $end->getPais()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::CEP, $end->getCep(), $where);
 }
     $p->addItem($pI);
 }
 if (!empty($_POST['CEP'])) {
     $end = $p->getEndereco();
     $end->setCep($_POST['CEP']);
     $lE = new ListaEstados();
     $lE->condicoes('', strtoupper($_POST['estado']), ListaEstados::UF);
     if ($lE->getTotal() > 0) {
         $end->setEstado($lE->listar());
     } else {
         $end->getEstado()->uf = strtoupper($_POST['estado']);
         $end->getEstado()->setPais(new Pais(1));
     }
     $lC = new ListaCidades();
     $lC->condicoes('', $_POST['cidade'], ListaCidades::NOME);
     if ($lC->getTotal() > 0) {
         $end->setCidade($lC->listar());
     } else {
         $end->getCidade()->nome = $_POST['cidade'];
         $end->getCidade()->setEstado($end->getEstado());
     }
     $end->logradouro = $_POST['Logradouro'];
     $end->numero = $_POST['Numero'];
     $end->complemento = $_POST['Complemento'];
     $end->bairro = $_POST['Bairro'];
     $end->loadCep();
     $p->setEndereco($end);
     try {
         $p->getEndereco()->setValor(0);
         $p->calcularFrete();
     } catch (Exception $e) {