Commit a387d5d7 authored by Lefebvre michael's avatar Lefebvre michael

17/02/2020 methose emprunt

parent 9ac58f52
package dto;
import java.io.Serializable;
public class Client implements Serializable {
private int codeClient;
private String nom;
private String prenom;
private String adresse;
private long anciennete;
// -------------------------------- G E T T E R S E T T E R -------------------------------------
public int getCodeClient() {
return codeClient;
}
public void setCodeClient(int codeClient) {
this.codeClient = codeClient;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public long getAnciennete() {
return anciennete;
}
public void setAnciennete(long anciennete) {
this.anciennete = anciennete;
}
//-------------------------------------- C O N S T R U C T E U R --------------------------------
public Client(int codeClient, String nom, String prenom, String adresse, long anciennete) {
super();
this.codeClient = codeClient;
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
this.anciennete = anciennete;
}
//to string
@Override
public String toString() {
return "Client{" +
"codeClient=" + codeClient +
", nom='" + nom + '\'' +
", prenom='" + prenom + '\'' +
", adresse='" + adresse + '\'' +
", anciennete=" + anciennete +
'}';
}
}
package dto;
import java.io.Serializable;
public class EmpruntDTO implements Serializable {
private String nom;
private String prenom;
private String titre;
//GETTER SETTER
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
//CONSTRUCTEUR
public EmpruntDTO(String nom, String prenom, String titre) {
super();
this.nom = nom;
this.prenom = prenom;
this.titre = titre;
}
}
package metier;
import dto.ActeurDTO;
import dto.ConnectCinema;
import dto.FilmDTO;
import dto.GenreDTO;
import dto.*;
import javafx.collections.ArrayChangeListener;
import java.lang.reflect.Array;
......@@ -35,6 +32,66 @@ public class DAOMetier implements IDAOMetier{
" where f.nfilm = ? " +
"ORDER BY titre";
private final static String SQLfindAllFilmEmpruntables =
"SELECT nfilm , titre, realisateur as NOM_REALISATEUR, nom as NOM_ACTEUR " +
" from FILM f " +
" INNER JOIN ACTEUR " +
" ON NACTEURPRINCIPAL = NACTEUR " +
" where not nfilm in " +
" (SELECT nfilm FROM emprunt WHERE retour = 'non') " +
" ORDER BY titre";
private final static String SQLfindAllFilmEmpruntablesByClient =
"SELECT nfilm , titre, realisateur as NOM_REALISATEUR, nom as NOM_ACTEUR " +
" from FILM f " +
" INNER JOIN ACTEUR " +
" ON NACTEURPRINCIPAL = NACTEUR " +
" where not nfilm in " +
" (SELECT nfilm FROM emprunt JOIN client using(nclient) WHERE retour = 'non' AND nclient = ? ) " +
" ORDER BY titre";
private final static String SQLcreateClient =
"INSERT INTO CLIENT(nom, prenom, adresse, anciennete) VALUES ( ? , ? , ? , ? ) ";
private final static String SQLdeleteClient =
"DELETE FROM CLIENT WHERE nclient = ? ";
private final static String SQLupdateClient =
"UPDATE CLIENT "
+ " SET adresse = ? , "
+ " anciennete = ? "
+ " WHERE nclient = ? ";
private final static String SQLfindAllClients =
"SELECT nclient, nom, prenom, adresse, anciennete " +
" FROM CLIENT " +
" ORDER BY nom, prenom";
private final static String SQLfindAllClientsById =
"SELECT nclient, nom, prenom, adresse, anciennete " +
" FROM client " +
"WHERE nclient = ?";
//gestion des emprunts ---------- DEUX VERSIONS
private final static String SQLEmprunterOne =
"INSERT INTO EMPRUNT(nclient,nfilm, retour, dateEmprunt) "
+ " values ( "
+ " (SELECT nclient FROM CLIENT WHERE nom = ? and prenom = ? ), "
+ " (SELECT nfilm FROM FILM WHERE titre = ? ) , "
+ " 'non', current_date)";
private final static String SQLEmprunterTwo =
"INSERT INTO EMPRUNT(nclient, nfilm, retour , dateEmprunt) "
+ " values ( ?, ?, 'non', current_date) ";
private final static String SQLRestituer =
"UPDATE EMPRUNT "
+ "SET retour = 'oui' "
+ "WHERE "
+ " nclient = ? "
+ " and nfilm = ? ";
//---------------------------------------------------------------------------------------------
@Override
public List<GenreDTO> ensGenres() {
......@@ -123,6 +180,7 @@ public class DAOMetier implements IDAOMetier{
return f;
}
// ---------------------------------------S I N G L E T O N P R É C O C E -----------------------
private static DAOMetier INSTANCE = new DAOMetier();
private DAOMetier(){}
......@@ -148,9 +206,147 @@ public class DAOMetier implements IDAOMetier{
return null;
}
@Override
public List<FilmDTO> ensFilmEmpruntables() {
return null;
}
@Override
public void createClient(String nom, String prenom, String adresse, long anciennete) {
//controle divers
nom= (nom == null ? "GATOR" : nom.toUpperCase());
prenom = (prenom == null ? "MAGALIE" : prenom.toUpperCase());
adresse = (adresse == null ? "LILLE" : adresse.toUpperCase());
anciennete = (anciennete<0?0:anciennete);
Connection conn = ConnectCinema.getInstance();
try {
PreparedStatement ps = conn.prepareStatement(SQLcreateClient);
ps.setString(1,nom);
ps.setString(2,prenom);
ps.setString(3, adresse);
ps.setLong(4,anciennete);
conn.setAutoCommit(false);
ps.executeUpdate();
conn.commit();
}catch (SQLException e){
e.printStackTrace();
try {
conn.rollback();
}catch (SQLException ex){
ex.printStackTrace();
}
}
}
@Override
public List<Client> findAllClients() {
List<Client> liste = new ArrayList<>();
try{
Statement ps = ConnectCinema.getInstance().createStatement();
ResultSet rs = ps.executeQuery(SQLfindAllClients);
while (rs.next()){
liste.add(new Client(rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getLong(5)));
}
}catch (SQLException ex){
ex.printStackTrace();
}
return liste;
}
@Override
public void emprunter(int nclient, int nfilm) {
Connection conn = ConnectCinema.getInstance();
try {
PreparedStatement ps = conn.prepareStatement(SQLEmprunterTwo);
ps.setInt(1, nclient);
ps.setInt(2, nfilm);
conn.setAutoCommit(false);
ps.executeUpdate();
conn.commit();
}catch (SQLException e){
e.printStackTrace();
try {
conn.rollback();
}catch (SQLException ex){
ex.printStackTrace();
}
}
}
@Override
public void emprunter(String nom, String prenom, String titre) {
Connection conn = ConnectCinema.getInstance();
try {
PreparedStatement ps = conn.prepareStatement(SQLEmprunterOne);
ps.setString(1, nom);
ps.setString(2, prenom);
ps.setString(3, titre);
conn.setAutoCommit(false);
ps.executeUpdate();
conn.commit();
}catch (SQLException e){
e.printStackTrace();
try {
conn.rollback();
}catch (SQLException ex){
ex.printStackTrace();
}
}
}
@Override
public void emprunter(Client client, FilmDTO film) {
emprunter(client.getCodeClient(), film.getNfilm());
}
@Override
public void restituer(int nclient, int nfilm) {
Connection conn = ConnectCinema.getInstance();
try {
PreparedStatement ps = conn.prepareStatement(SQLRestituer);
ps.setInt(1, nclient);
ps.setInt(2, nfilm);
conn.setAutoCommit(false);
ps.executeUpdate();
conn.commit();
}catch (SQLException e){
e.printStackTrace();
try {
conn.rollback();
}catch (SQLException ex){
ex.printStackTrace();
}
}
}
@Override
public void restituer(Client client, FilmDTO film) {
restituer(client.getCodeClient(), film.getNfilm());
}
public static void main(String[] args) {
DAOMetier dao = new DAOMetier();
System.out.println("-------------------liste genre-------------------");
/* System.out.println("-------------------liste genre-------------------");
System.out.println(dao.ensGenres());
System.out.println("---------------nombre de film-------------------------");
System.out.println("Categorie 2 a : " + dao.nbreFilmDuGenre(2) + " film(s)");
......@@ -160,6 +356,21 @@ public class DAOMetier implements IDAOMetier{
FilmDTO f = dao.infoRealisateurEtActeur(3);
System.out.println(f.getTitre() +"\n"
+ f.getNomRealisateur() + "\n"
+ f.getNomActeur());
+ f.getNomActeur());*/
/*dao.createClient("biffe", "pierre", "valenciennes",2);
dao.createClient("glandu", "benjamin", "monchaux",1);
dao.createClient("glandu", "arthur", "lille",1);
dao.createClient("pif", "herclue", "valenciennes",0);
dao.createClient("leuleu", "jean-marie", "ronchin",3);*/
/*for (Client client : dao.findAllClients()){
System.out.println(client);
}*/
// dao.emprunter(2,6);
dao.restituer(2,6);
}
}
package metier;
import dto.ActeurDTO;
import dto.Client;
import dto.FilmDTO;
import dto.GenreDTO;
import javax.swing.*;
import java.util.*;
public interface IDAOMetier {
......@@ -20,5 +22,18 @@ public interface IDAOMetier {
List<FilmDTO> ensTitreDunActeur(int numActeur);
//gestion des emprunts
List<FilmDTO> ensFilmEmpruntables();
void createClient(String nom, String prenom, String adresse, long anciennete);
List<Client> findAllClients();
void emprunter(int nclient , int nfilm);
void emprunter(String nom, String prenom, String titre);
void emprunter(Client client, FilmDTO film);
void restituer(int nclient, int nfilm);
void restituer(Client client, FilmDTO film);
}
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="presentation.GestionClients">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="15993" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<tabbedpane id="745a1" binding="tabbedPane1" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="56dd7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Ajouter client"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="daf72" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Supprimer"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="68ed2" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Liste"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="643a1" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Emprunter"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="75ab1" class="javax.swing.JComboBox" binding="comboClient">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="b196" class="javax.swing.JComboBox" binding="comboFilm">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="f51b5" class="javax.swing.JButton" binding="emprunterButton" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Emprunter"/>
</properties>
</component>
</children>
</grid>
<grid id="42c7" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Restituer"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</tabbedpane>
</children>
</grid>
</children>
</grid>
</form>
package presentation;
import javax.swing.*;
public class GestionClients {
private JPanel rootPanel;
private JTabbedPane tabbedPane1;
private JComboBox comboClient;
private JComboBox comboFilm;
private JButton emprunterButton;
public static void main(String[] args) {
JFrame frame = new JFrame("GestionClients");
frame.setContentPane(new GestionClients().rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
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