<?php 


class DaoGrupo extends conexao {

public function Atualizar(grupo $grupo) {

try {

if ($grupo->getGrp_cd() != '') {

$sql = " UPDATE grupo SET
grp_ds = ?
WHERE grp_cd = ? ";

$stmt = self::conectar()->prepare($sql); 
$stmt->bindValue(1, $grupo->getGrp_ds());
$stmt->bindValue(2, $grupo->getGrp_cd());


} else {

$sql = " INSERT INTO grupo (grp_ds)
VALUES (?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $grupo->getGrp_ds());


}
if ($stmt->execute()){
	return true;
		} else
	return false;

} catch (Exception $e) {
print "Erro ao tentar atualizar: ".$e;
}

}

public function PesquisarGrupo($codigo){
$sql = " SELECT * FROM grupo WHERE grp_cd = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $codigo);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function ListarGrupo(){
$sql = " SELECT * FROM grupo ORDER BY grp_cd ";
$stmt = self::conectar()->prepare($sql); 
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function ProximoId(){
$sql = " SELECT COALESCE(MAX(grp_cd), 0) + 1 AS PROXIMO_REGISTRO FROM grupo ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

	
public function deletar($grp_cd){		
$sql = " DELETE FROM grupo WHERE grp_cd = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $grp_cd); 
$stmt->execute();
}

 
}
