Skip to content

Commit 754729e

Browse files
author
BarbDev
committed
presque fini...
1 parent 465a092 commit 754729e

29 files changed

+1213
-1363
lines changed

src/main/java/bdd/Client.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static String formatFilmsForBDD(Client c) {
4141
static HashMap<Film, Date> formatFilmsForClient(String f, TableFilms tFilm) {
4242
HashMap<Film, Date> films = new HashMap<>();
4343

44+
if (f == null) return films;
4445
for (String s : f.split(";")) {
4546
String titre = s.substring(0, s.indexOf("(")); // Extraction du titre du film
4647
// Extraction de la date de fin de location

src/main/java/bdd/TableUtilisateurs.java

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package bdd;
22

3+
import org.h2.tools.Csv;
4+
35
import java.math.BigDecimal;
4-
import java.sql.PreparedStatement;
5-
import java.sql.ResultSet;
6-
import java.sql.SQLException;
6+
import java.sql.*;
77

88
public class TableUtilisateurs extends Table {
99
private static TableUtilisateurs instance = null;
@@ -121,10 +121,9 @@ public void supprimer(Utilisateur user) {
121121
/**
122122
*
123123
* @param pseudo
124-
* @param pwd
125124
* @return null si pas le bon login
126125
*/
127-
public Utilisateur getUser(String pseudo, String pwd, TableFilms tFilms) {
126+
public Utilisateur getUser(String pseudo) {
128127
Utilisateur user = null;
129128
try {
130129
PreparedStatement pst = BaseDeDonnee.getInstance().getConnection().prepareStatement("SELECT * FROM utilisateurs WHERE pseudo = ?;");
@@ -135,7 +134,7 @@ public Utilisateur getUser(String pseudo, String pwd, TableFilms tFilms) {
135134
user = new Client(set.getInt("id"),
136135
pseudo, set.getString("nom"), set.getString("prenom"),
137136
set.getString("email"), set.getString("role"),
138-
set.getBigDecimal("solde").floatValue(), Client.formatFilmsForClient(set.getString("films_loue"), tFilms));
137+
set.getBigDecimal("solde").floatValue(), Client.formatFilmsForClient(set.getString("films_loue"), TableFilms.getInstance()));
139138
} else {
140139
user = new Utilisateur(set.getInt("id"),
141140
pseudo, set.getString("nom"), set.getString("prenom"),
@@ -149,8 +148,88 @@ public Utilisateur getUser(String pseudo, String pwd, TableFilms tFilms) {
149148
return user;
150149
}
151150

151+
public String getPwd(Utilisateur user) {
152+
String pwd = null;
153+
try {
154+
PreparedStatement pst = BaseDeDonnee.getInstance().getConnection().prepareStatement("SELECT * FROM utilisateurs WHERE pseudo = ?;");
155+
pst.setString(1, user.getPseudo());
156+
ResultSet set = pst.executeQuery();
157+
if (set.next()) {
158+
pwd = set.getString("pwd");
159+
}
160+
set.close();
161+
} catch (SQLException e) {
162+
e.printStackTrace();
163+
}
164+
return pwd;
165+
}
166+
152167
@Override
153168
public void addFromCSV(String path) {
154-
// TODO
169+
try{
170+
Csv csv = new Csv();
171+
csv.setFieldSeparatorRead('|');
172+
csv.setCaseSensitiveColumnNames(true);
173+
ResultSet rs = csv.read(path, null, null);
174+
ResultSetMetaData meta = rs.getMetaData();
175+
176+
String nom = null; String prenom = null; String pseudo = null;
177+
String email = null; float solde = 0; String role = null;
178+
String pwd = null;
179+
180+
while (rs.next()) {
181+
for (int i = 0; i < meta.getColumnCount(); i++) {
182+
switch (meta.getColumnLabel(i + 1)) {
183+
case "nom":
184+
nom = rs.getString(i + 1);
185+
break;
186+
case "prenom":
187+
prenom = rs.getString(i + 1);
188+
break;
189+
case "pseudo":
190+
pseudo = rs.getString(i + 1);
191+
break;
192+
case "email":
193+
email = rs.getString(i + 1);
194+
break;
195+
case "solde":
196+
solde = Float.parseFloat(rs.getString(i + 1));
197+
break;
198+
case "pwd":
199+
pwd = rs.getString(i + 1);
200+
break;
201+
}
202+
}
203+
204+
try {
205+
PreparedStatement pst = BaseDeDonnee.getInstance().getConnection().prepareStatement("INSERT INTO utilisateurs (" +
206+
"nom," +
207+
"prenom," +
208+
"pseudo," +
209+
"email," +
210+
"solde," +
211+
"role," +
212+
"pwd" +
213+
") values (?,?,?,?,?,?,?);");
214+
pst.setString(1, nom);
215+
pst.setString(2, prenom);
216+
pst.setString(3, pseudo);
217+
pst.setString(4, email);
218+
if (role.equals("user"))
219+
pst.setBigDecimal(5, BigDecimal.valueOf(solde));
220+
else
221+
pst.setBigDecimal(5, BigDecimal.valueOf(0));
222+
pst.setString(6, role);
223+
pst.setString(7, pwd);
224+
pst.executeUpdate();
225+
pst.close();
226+
} catch (SQLException e) {
227+
e.printStackTrace();
228+
}
229+
}
230+
rs.close();
231+
} catch (SQLException e) {
232+
e.printStackTrace();
233+
}
155234
}
156235
}
Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
11
package ihm.alza.Checkout;
22

3-
import java.awt.FlowLayout;
4-
import javax.swing.JFrame;
3+
import java.awt.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
import javax.swing.*;
57

68
@SuppressWarnings("serial")
7-
public class ContinuerAchat extends JFrame{
9+
public class ContinuerAchat extends JDialog {
810

911
private PannCont panel;
1012

11-
public ContinuerAchat() {
12-
13-
panel = new PannCont(this);
13+
public ContinuerAchat(Frame parent) {
14+
super(parent, "Continuer achat ?", true);
15+
panel = new PannCont();
1416
panel.setLayout(new FlowLayout());
1517
this.setContentPane(panel);
1618
this.setVisible(true);
1719
this.setSize(400, 100);
1820
this.setTitle("Continuer achat ou payer");
1921
this.setLocationRelativeTo(null);
20-
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22+
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
23+
}
24+
25+
public class PannCont extends JPanel{
26+
27+
public PannCont() {
28+
29+
JButton bouton = new JButton("Payez");
30+
this.add(bouton);
31+
bouton.addActionListener(new ContActionListener('P'));
32+
33+
JButton bouton2 = new JButton("Continuer");
34+
this.add(bouton2);
35+
bouton2.addActionListener(new ContActionListener('C'));
36+
37+
}
38+
39+
class ContActionListener implements ActionListener {
40+
41+
private char nombouton;
42+
public ContActionListener(char nom) {
43+
nombouton = nom;
44+
}
45+
46+
@Override
47+
public void actionPerformed(ActionEvent e) {
48+
49+
if(nombouton == 'P')
50+
//Ouvrir la fenetre dans -> /Checkout/DetailPanier.java
51+
new DetailPanier(null);
52+
if(nombouton == 'C')
53+
dispose();
54+
}
55+
56+
}
2157
}
22-
23-
//
24-
// public static void main(String[] args) {
25-
// ContinuerAchat fenetre = new ContinuerAchat();
26-
// }
2758
}
Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,130 @@
11
package ihm.alza.Checkout;
22

3-
import java.awt.FlowLayout;
3+
import ihm.alza.Paiement.Paiement;
44

5-
import javax.swing.JFrame;
5+
import java.awt.*;
6+
import java.awt.event.ActionEvent;
7+
import java.awt.event.ActionListener;
8+
import java.io.IOException;
9+
10+
import javax.swing.*;
611

712
@SuppressWarnings("serial")
8-
public class DetailPanier extends JFrame{
13+
public class DetailPanier extends JDialog {
914

1015
private PannPanier centre;
1116

12-
public DetailPanier() {
13-
centre = new PannPanier(this);
17+
public DetailPanier(Frame parent) {
18+
super(parent, "Détail du panier", true);
19+
centre = new PannPanier();
1420

1521
this.setSize(900, 400);
1622
this.setTitle("Login");
1723
this.setLocationRelativeTo(null);
1824
this.setLayout(new FlowLayout());
1925

2026
this.setContentPane(centre);
21-
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27+
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
2228
this.setVisible(true);
2329
}
24-
25-
// public static void main(String[] args) {
26-
//
27-
// DetailPanier fen = new DetailPanier();
28-
//
29-
// }
30+
31+
public class PannPanier extends JPanel{
32+
33+
public PannPanier() {
34+
//Apres reflexion, je pense qu'il faut faire une JTable puisque c'est un retour de requete BDD non ?
35+
36+
this.setLayout(new GridBagLayout());
37+
38+
GridBagConstraints gbc = new GridBagConstraints();
39+
gbc.gridx = 0;
40+
gbc.gridy = 0;
41+
42+
JLabel mess = new JLabel("Detail du panier ",JLabel.CENTER);
43+
mess.setFont(new Font("Serif", Font.BOLD, 30));
44+
JLabel titre = new JLabel("Titre ", JLabel.CENTER);
45+
JLabel nbjour = new JLabel("Nombre de jours de location ", JLabel.CENTER);
46+
JLabel debut = new JLabel("Date de debut de location ", JLabel.CENTER);
47+
JLabel fin = new JLabel("Date de fin de location ", JLabel.CENTER);
48+
JLabel prix = new JLabel("Prix ", JLabel.CENTER);
49+
JLabel supp = new JLabel("Supprimer ", JLabel.CENTER);
50+
51+
JButton valider = new JButton("Valider");
52+
JButton annuler = new JButton("Annuler");
53+
54+
gbc.insets = new Insets(10, 10, 10,10);
55+
56+
gbc.gridx=2;
57+
this.add(mess,gbc);
58+
59+
gbc.gridy=3;
60+
gbc.gridx = 0;
61+
this.add(titre, gbc);
62+
gbc.gridx++;
63+
this.add(nbjour, gbc);
64+
gbc.gridx++;
65+
this.add(debut, gbc);
66+
gbc.gridx++;
67+
this.add(fin, gbc);
68+
gbc.gridx++;
69+
this.add(prix, gbc);
70+
gbc.gridx++;
71+
this.add(supp, gbc);
72+
gbc.gridx++;
73+
74+
//Pour creer l'espace, j'arrive pas a faire gbc.gridy=13;
75+
this.add(new JLabel(),gbc);
76+
gbc.gridy++;
77+
this.add(new JLabel(),gbc);
78+
gbc.gridy++;
79+
this.add(new JLabel(),gbc);
80+
gbc.gridy++;
81+
this.add(new JLabel(),gbc);
82+
gbc.gridy++;
83+
this.add(new JLabel(),gbc);
84+
gbc.gridy++;
85+
this.add(new JLabel(),gbc);
86+
gbc.gridy++;
87+
this.add(new JLabel(),gbc);
88+
gbc.gridy++;
89+
this.add(new JLabel(),gbc);
90+
gbc.gridy++;
91+
this.add(new JLabel(),gbc);
92+
gbc.gridy++;
93+
this.add(new JLabel(),gbc);
94+
95+
96+
gbc.gridx = 4;
97+
this.add(valider,gbc);
98+
valider.addActionListener(new PannAcLis('V'));
99+
gbc.gridx++;
100+
this.add(annuler,gbc);
101+
annuler.addActionListener(new PannAcLis('A'));
102+
gbc.gridy++;
103+
104+
}
105+
106+
class PannAcLis implements ActionListener {
107+
108+
private char action;
109+
public PannAcLis(char ac) {
110+
action = ac;
111+
}
112+
113+
@Override
114+
public void actionPerformed(ActionEvent e) {
115+
if(action == 'V') {
116+
try {
117+
new Paiement(null);
118+
} catch (IOException e1) {
119+
120+
e1.printStackTrace();
121+
}
122+
dispose();
123+
}if(action == 'A')
124+
dispose();
125+
}
126+
127+
}
128+
129+
}
30130
}

src/main/java/ihm/alza/Checkout/PannCont.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)