<?php 



class DaoMonitora extends conexao {

public function Atualizar(monitora $monitora) {

try {

if ($monitora->getMon_ds() != '') {

$sql = " UPDATE monitora SET
mon_usu_cd = ?,
mon_data = ?,
mon_hora = ?,
mon_emp_cd = ?
WHERE mon_ds = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $monitora->getMon_usu_cd());
$stmt->bindValue(2, $monitora->getMon_data());
$stmt->bindValue(3, $monitora->getMon_hora());
$stmt->bindValue(4, $monitora->getMon_emp_cd());
$stmt->bindValue(5, $monitora->getMon_ds());


} else {

$sql = " INSERT INTO monitora (mon_usu_cd,mon_data,mon_hora,mon_emp_cd)
VALUES (?,?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $monitora->getMon_usu_cd());
$stmt->bindValue(2, $monitora->getMon_data());
$stmt->bindValue(3, $monitora->getMon_hora());
$stmt->bindValue(4, $monitora->getMon_emp_cd());


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

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

}

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

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



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

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

 
}
