package labsis.financeiro.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import labsis.DataBase;
import labsis.financeiro.model.Cheques;
import labsis.financeiro.model.Fornecedor;
import labsis.financeiro.servlets.Controller;
public class DaoCheques {
private Connection conn;
public DaoCheques() throws SQLException {
DataBase db = DataBase.getDb();
conn = db.getConnection();
}
public void cadastrarCheque(Cheques c) {
try{
CallableStatement cstmt = Controller.conectar().prepareCall("exec inserirCheque ?, ?, ?, ?, ?, ?");
String clienteCpf = c.getClientecpf();
Date dataParaDesconto = c.getDataParaDesconto();
float valor = c.getValor();
String banco = c.getBanco();
String agencia = c.getAgencia();
int numeroDaConta = c.getNumConta();
cstmt.setString(1, clienteCpf);
cstmt.setDate(2, (java.sql.Date) dataParaDesconto);
cstmt.setFloat(3, valor);
cstmt.setString(4, banco);
cstmt.setString(5, agencia);
cstmt.setInt(6, numeroDaConta);
cstmt.executeUpdate();
cstmt.close();
}
catch(Exception e){
e.printStackTrace();
}
}
public ArrayList<Cheques> listarCheques(String s) {
CallableStatement cstmt = null;
ArrayList<Cheques> lista = new ArrayList<Cheques>();
try {
cstmt = conn.prepareCall("exec listarCheques ?");
cstmt.setString(1, s);
ResultSet rs = cstmt.executeQuery();
while(rs.next()){
Cheques c = new Cheques();
c.setCodigo(rs.getInt(1));
c.setClientecpf(rs.getString(2));
c.setDataParaDesconto(rs.getDate(3));
c.setValor(rs.getFloat(4));
c.setBanco(rs.getString(5));
c.setAgencia(rs.getString(6));
c.setNumConta(rs.getInt(7));
lista.add(c);
}
cstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
cstmt.close();
}
catch(Exception e) {
e.printStackTrace();
}
return lista;
}
}
public boolean excluirCheques(int c){
int x = 0;
try {
CallableStatement cstmt = Controller.conectar().prepareCall("exec excluirCheques ?");
cstmt.setInt(1, c);
x = cstmt.executeUpdate();
cstmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
if(x > 0) return true;
else return false;
}
}