Skip to content

Commit c189cd6

Browse files
first commit
1 parent 71db139 commit c189cd6

14 files changed

+925
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.example.DAO;
2+
3+
import org.example.models.client;
4+
import java.sql.*;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class ClientDao {
9+
private Connection connect() throws SQLException {
10+
String url = "jdbc:postgresql://localhost:5432/cash";
11+
String user = "postgres";
12+
String password = "mario123";
13+
return DriverManager.getConnection(url, user, password);
14+
}
15+
16+
public List<client> listAllClients() throws SQLException {
17+
List<client> listClients = new ArrayList<>();
18+
try (Connection conn = connect();
19+
Statement stmt = conn.createStatement();
20+
ResultSet rs = stmt.executeQuery("SELECT * FROM CLIENT")) {
21+
while (rs.next()) {
22+
String numtel = rs.getString("numtel");
23+
String nom = rs.getString("nom");
24+
String sexe = rs.getString("sexe");
25+
String pays = rs.getString("pays");
26+
int solde = rs.getInt("solde");
27+
String mail = rs.getString("mail");
28+
listClients.add(new client(numtel, nom, sexe, pays, solde, mail));
29+
}
30+
}
31+
return listClients;
32+
}
33+
34+
public void insertClient(client client) throws SQLException {
35+
try (Connection conn = connect();
36+
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO CLIENT (numtel, nom, sexe, pays, solde, mail) VALUES (?, ?, ?, ?, ?, ?)")) {
37+
pstmt.setString(1, client.getNumtel());
38+
pstmt.setString(2, client.getNom());
39+
pstmt.setString(3, client.getSexe());
40+
pstmt.setString(4, client.getPays());
41+
pstmt.setInt(5, client.getSolde());
42+
pstmt.setString(6, client.getMail());
43+
pstmt.executeUpdate();
44+
}
45+
}
46+
47+
public client getClient(String numtel) throws SQLException {
48+
client client = null;
49+
try (Connection conn = connect();
50+
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM CLIENT WHERE numtel = ?")) {
51+
pstmt.setString(1, numtel);
52+
ResultSet rs = pstmt.executeQuery();
53+
if (rs.next()) {
54+
String nom = rs.getString("nom");
55+
String sexe = rs.getString("sexe");
56+
String pays = rs.getString("pays");
57+
int solde = rs.getInt("solde");
58+
String mail = rs.getString("mail");
59+
client = new client(numtel, nom, sexe, pays, solde, mail);
60+
}
61+
}
62+
return client;
63+
}
64+
65+
public void updateClient(client client) throws SQLException {
66+
try (Connection conn = connect();
67+
PreparedStatement pstmt = conn.prepareStatement("UPDATE CLIENT SET nom = ?, sexe = ?, pays = ?, solde = ?, mail = ? WHERE numtel = ?")) {
68+
pstmt.setString(1, client.getNom());
69+
pstmt.setString(2, client.getSexe());
70+
pstmt.setString(3, client.getPays());
71+
pstmt.setInt(4, client.getSolde());
72+
pstmt.setString(5, client.getMail());
73+
pstmt.setString(6, client.getNumtel());
74+
pstmt.executeUpdate();
75+
}
76+
}
77+
78+
public void deleteClient(String numtel) throws SQLException {
79+
try (Connection conn = connect();
80+
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM CLIENT WHERE numtel = ?")) {
81+
pstmt.setString(1, numtel);
82+
pstmt.executeUpdate();
83+
}
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.example.DAO;
2+
3+
import org.example.models.Envoyer;
4+
import java.sql.*;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class EnvoyerDao {
9+
10+
private Connection connect() throws SQLException {
11+
String url = "jdbc:postgresql://localhost:5432/cash";
12+
String user = "postgres";
13+
String password = "mario123";
14+
return DriverManager.getConnection(url, user, password);
15+
}
16+
17+
public List<Envoyer> listAllEnvois() throws SQLException {
18+
List<Envoyer> listEnvoyer = new ArrayList<>();
19+
try (Connection conn = connect();
20+
Statement stmt = conn.createStatement();
21+
ResultSet rs = stmt.executeQuery("SELECT * FROM ENVOYER")) {
22+
while (rs.next()) {
23+
int idEnv = rs.getInt("idEnv");
24+
String numEnvoyeur = rs.getString("numEnvoyeur");
25+
String numRecepteur = rs.getString("numRecepteur");
26+
int montant = rs.getInt("montant");
27+
Date date = rs.getDate("date");
28+
String raison = rs.getString("raison");
29+
listEnvoyer.add(new Envoyer(idEnv, numEnvoyeur, numRecepteur, montant, date, raison));
30+
}
31+
}
32+
return listEnvoyer;
33+
}
34+
35+
public void insertEnvoyer(Envoyer envoyer) throws SQLException {
36+
try (Connection conn = connect();
37+
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO ENVOYER (numEnvoyeur, numRecepteur, montant, date, raison) VALUES (?, ?, ?, ?, ?)")) {
38+
pstmt.setString(1, envoyer.getNumEnvoyeur());
39+
pstmt.setString(2, envoyer.getNumRecepteur());
40+
pstmt.setInt(3, envoyer.getMontant());
41+
pstmt.setTimestamp(4, new Timestamp(envoyer.getDate().getTime()));
42+
pstmt.setString(5, envoyer.getRaison());
43+
pstmt.executeUpdate();
44+
}
45+
}
46+
47+
public Envoyer getEnvoyer(int idEnv) throws SQLException {
48+
Envoyer envoyer = null;
49+
try (Connection conn = connect();
50+
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM ENVOYER WHERE idEnv = ?")) {
51+
pstmt.setInt(1, idEnv);
52+
ResultSet rs = pstmt.executeQuery();
53+
if (rs.next()) {
54+
String numEnvoyeur = rs.getString("numEnvoyeur");
55+
String numRecepteur = rs.getString("numRecepteur");
56+
int montant = rs.getInt("montant");
57+
Date date = rs.getDate("date");
58+
String raison = rs.getString("raison");
59+
envoyer = new Envoyer(idEnv, numEnvoyeur, numRecepteur, montant, date, raison);
60+
}
61+
}
62+
return envoyer;
63+
}
64+
65+
public void updateEnvoyer(Envoyer envoyer) throws SQLException {
66+
try (Connection conn = connect();
67+
PreparedStatement pstmt = conn.prepareStatement("UPDATE ENVOYER SET numEnvoyeur = ?, numRecepteur = ?, montant = ?, raison = ? WHERE idEnv = ?")) {
68+
pstmt.setString(1, envoyer.getNumEnvoyeur());
69+
pstmt.setString(2, envoyer.getNumRecepteur());
70+
pstmt.setInt(3, envoyer.getMontant());
71+
pstmt.setString(4, envoyer.getRaison());
72+
pstmt.setInt(5, envoyer.getIdEnv());
73+
pstmt.executeUpdate();
74+
}
75+
}
76+
77+
public void deleteEnvoyer(int idEnv) throws SQLException {
78+
try (Connection conn = connect();
79+
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM ENVOYER WHERE idEnv = ?")) {
80+
pstmt.setInt(1, idEnv);
81+
pstmt.executeUpdate();
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.example.DAO;
2+
3+
import org.example.models.frais;
4+
import java.sql.*;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class FraisDao {
9+
private Connection connect() throws SQLException {
10+
String url = "jdbc:postgresql://localhost:5432/cash";
11+
String user = "postgres";
12+
String password = "mario123";
13+
return DriverManager.getConnection(url, user, password);
14+
}
15+
16+
public List<frais> listAllFrais() throws SQLException {
17+
List<frais> listFrais = new ArrayList<>();
18+
try (Connection conn = connect();
19+
Statement stmt = conn.createStatement();
20+
ResultSet rs = stmt.executeQuery("SELECT * FROM FRAIS")) {
21+
while (rs.next()) {
22+
int idfrais = rs.getInt("idfrais");
23+
int montant1 = rs.getInt("montant1");
24+
int montant2 = rs.getInt("montant2");
25+
int frais = rs.getInt("frais");
26+
listFrais.add(new frais(idfrais, montant1, montant2, frais));
27+
}
28+
}
29+
return listFrais;
30+
}
31+
32+
public void insertFrais(frais frais) throws SQLException {
33+
try (Connection conn = connect();
34+
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO FRAIS (montant1, montant2, frais) VALUES (?, ?, ?)")) {
35+
pstmt.setInt(1, frais.getMontant1());
36+
pstmt.setInt(2, frais.getMontant2());
37+
pstmt.setInt(3, frais.getFrais());
38+
pstmt.executeUpdate();
39+
}
40+
}
41+
42+
public frais getFrais(int idfrais) throws SQLException {
43+
frais frais = null;
44+
try (Connection conn = connect();
45+
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM FRAIS WHERE idfrais = ?")) {
46+
pstmt.setInt(1, idfrais);
47+
ResultSet rs = pstmt.executeQuery();
48+
if (rs.next()) {
49+
int montant1 = rs.getInt("montant1");
50+
int montant2 = rs.getInt("montant2");
51+
int fraisValue = rs.getInt("frais");
52+
frais = new frais(idfrais, montant1, montant2, fraisValue);
53+
}
54+
}
55+
return frais;
56+
}
57+
58+
public void updateFrais(frais frais) throws SQLException {
59+
try (Connection conn = connect();
60+
PreparedStatement pstmt = conn.prepareStatement("UPDATE FRAIS SET montant1 = ?, montant2 = ?, frais = ? WHERE idfrais = ?")) {
61+
pstmt.setInt(1, frais.getMontant1());
62+
pstmt.setInt(2, frais.getMontant2());
63+
pstmt.setInt(3, frais.getFrais());
64+
pstmt.setInt(4, frais.getIdfrais());
65+
pstmt.executeUpdate();
66+
}
67+
}
68+
69+
public void deleteFrais(int idfrais) throws SQLException {
70+
try (Connection conn = connect();
71+
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM FRAIS WHERE idfrais = ?")) {
72+
pstmt.setInt(1, idfrais);
73+
pstmt.executeUpdate();
74+
}
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.example.DAO;
2+
3+
import org.example.models.taux;
4+
import java.sql.*;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class TauxDao {
9+
private Connection connect() throws SQLException {
10+
String url = "jdbc:postgresql://localhost:5432/cash";
11+
String user = "postgres";
12+
String password = "mario123";
13+
return DriverManager.getConnection(url, user, password);
14+
}
15+
16+
public List<taux> listAllTaux() throws SQLException {
17+
List<taux> listTaux = new ArrayList<>();
18+
try (Connection conn = connect();
19+
Statement stmt = conn.createStatement();
20+
ResultSet rs = stmt.executeQuery("SELECT * FROM TAUX")) {
21+
while (rs.next()) {
22+
int idtaux = rs.getInt("idtaux");
23+
int montant1 = rs.getInt("montant1");
24+
int montant2 = rs.getInt("montant2");
25+
listTaux.add(new taux(idtaux, montant1, montant2));
26+
}
27+
}
28+
return listTaux;
29+
}
30+
31+
public void insertTaux(taux taux) throws SQLException {
32+
try (Connection conn = connect();
33+
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO TAUX (montant1, montant2) VALUES (?, ?)")) {
34+
pstmt.setInt(1, taux.getMontant1());
35+
pstmt.setInt(2, taux.getMontant2());
36+
pstmt.executeUpdate();
37+
}
38+
}
39+
40+
public taux getTaux(int idtaux) throws SQLException {
41+
taux taux = null;
42+
try (Connection conn = connect();
43+
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM TAUX WHERE idtaux = ?")) {
44+
pstmt.setInt(1, idtaux);
45+
ResultSet rs = pstmt.executeQuery();
46+
if (rs.next()) {
47+
int montant1 = rs.getInt("montant1");
48+
int montant2 = rs.getInt("montant2");
49+
taux = new taux(idtaux, montant1, montant2);
50+
}
51+
}
52+
return taux;
53+
}
54+
55+
public void updateTaux(taux taux) throws SQLException {
56+
try (Connection conn = connect();
57+
PreparedStatement pstmt = conn.prepareStatement("UPDATE TAUX SET montant1 = ?, montant2 = ? WHERE idtaux = ?")) {
58+
pstmt.setInt(1, taux.getMontant1());
59+
pstmt.setInt(2, taux.getMontant2());
60+
pstmt.setInt(3, taux.getIdtaux());
61+
pstmt.executeUpdate();
62+
}
63+
}
64+
65+
public void deleteTaux(int idtaux) throws SQLException {
66+
try (Connection conn = connect();
67+
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM TAUX WHERE idtaux = ?")) {
68+
pstmt.setInt(1, idtaux);
69+
pstmt.executeUpdate();
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.example.models;
2+
3+
import java.util.Date;
4+
5+
public class Envoyer {
6+
7+
private String numEnvoyeur;
8+
private String numRecepteur;
9+
private int montant;
10+
private Date date;
11+
private String raison;
12+
13+
14+
public String getNumEnvoyeur() {
15+
return numEnvoyeur;
16+
}
17+
18+
public void setNumEnvoyeur(String numEnvoyeur) {
19+
this.numEnvoyeur = numEnvoyeur;
20+
}
21+
22+
public String getNumRecepteur() {
23+
return numRecepteur;
24+
}
25+
26+
public void setNumRecepteur(String numRecepteur) {
27+
this.numRecepteur = numRecepteur;
28+
}
29+
30+
public int getMontant() {
31+
return montant;
32+
}
33+
34+
public void setMontant(int montant) {
35+
this.montant = montant;
36+
}
37+
38+
public Date getDate() {
39+
return date;
40+
}
41+
42+
public void setDate(Date date) {
43+
this.date = date;
44+
}
45+
46+
public String getRaison() {
47+
return raison;
48+
}
49+
50+
public void setRaison(String raison) {
51+
this.raison = raison;
52+
}
53+
54+
public Envoyer(String numEnvoyeur, String numRecepteur, int montant, Date date, String raison) {
55+
this.numEnvoyeur = numEnvoyeur;
56+
this.numRecepteur = numRecepteur;
57+
this.montant = montant;
58+
this.date = date;
59+
this.raison = raison;
60+
}
61+
62+
}

0 commit comments

Comments
 (0)