Commit 55044a91 authored by Lefebvre michael's avatar Lefebvre michael

cinemafrm delete client

parent 57b8636d
......@@ -92,7 +92,78 @@ public class DAOMetier implements IDAOMetier{
+ " and nfilm = ? ";
private final static String SQLDeleteEmpruntOfClient =
"DELETE FROM EMPRUNT "
+ " WHERE nclient = ? ";
private final static String SQLNbreEmpruntEnCoursOfClient =
" SELECT COUNT(*) as nbr "
+ " FROM CLIENT "
+ " INNER JOIN EMPRUNT "
+ " USING(nclient) "
+ " WHERE retour = 'non' AND nclient = ? ";
private final static String SQLEmpruntEnCoursOfClient =
" SELECT nemprunt"
+ " FROM CLIENT "
+ " INNER JOIN EMPRUNT "
+ " USING(nclient) "
+ " WHERE retour = 'non' AND nclient = ? ";
private final static String SQLDeleteClient =
"DELETE FROM CLIENT where nclient = ? ";
//---------------------------------------------------------------------------------------------
@Override
public void deleteClient(Client client) {
deleteClient(client.getCodeClient());
}
@Override
public void deleteClient(int nclient) {
//List<Integer> liste = new ArrayList<>();
Connection conn = ConnectCinema.getInstance();
try {
conn.setAutoCommit(false);
PreparedStatement pstmt =
conn.prepareStatement(SQLEmpruntEnCoursOfClient);
ResultSet rs = null;
pstmt.setInt(1,nclient);
rs = pstmt.executeQuery();
if (rs.next()){
System.out.println("impossible"); //emprunt en cours
conn.rollback();
}else {
System.out.println("possible"); //pas d'emprunt en cours
PreparedStatement pstmt2 = conn.prepareStatement(SQLDeleteEmpruntOfClient);
pstmt2.setInt(1,nclient);
int nb2 = pstmt2.executeUpdate();
PreparedStatement pstmt3 = conn.prepareStatement(SQLDeleteClient);
pstmt3.setInt(1,nclient);
int nb3 = pstmt3.executeUpdate();
conn.commit();
}
} catch (SQLException e) {
e.printStackTrace();
try {
conn.rollback();
}catch (SQLException ex){
ex.printStackTrace();
}
}
}
@Override
public List<GenreDTO> ensGenres() {
List<GenreDTO> liste = new ArrayList<>();
......@@ -368,8 +439,12 @@ public class DAOMetier implements IDAOMetier{
System.out.println(client);
}*/
// dao.emprunter(2,6);
dao.restituer(2,6);
//dao.emprunter(3,7);
//dao.emprunter(3,5);
//dao.restituer(3,7);
//dao.deleteClient(2);
//dao.deleteClient(3);
}
......
......@@ -6,6 +6,7 @@ import dto.FilmDTO;
import dto.GenreDTO;
import javax.swing.*;
import java.sql.SQLException;
import java.util.*;
public interface IDAOMetier {
......@@ -36,4 +37,7 @@ public interface IDAOMetier {
void restituer(int nclient, int nfilm);
void restituer(Client client, FilmDTO film);
void deleteClient(Client client);
void deleteClient(int nclient) throws SQLException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment