Migliore gestione conto corrente esistente
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/classes/logic/ContoCorrenteWrapper.class
Normal file
BIN
build/classes/logic/ContoCorrenteWrapper.class
Normal file
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import logic.MyBank;
|
import logic.MyBank;
|
||||||
import logic.ContoCorrente;
|
import logic.ContoCorrente;
|
||||||
|
import logic.ContoCorrenteWrapper;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
@@ -59,7 +61,8 @@ public class GUIMyBank extends javax.swing.JFrame {
|
|||||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||||
|
// Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
|
|
||||||
lblNome = new javax.swing.JLabel();
|
lblNome = new javax.swing.JLabel();
|
||||||
@@ -156,29 +159,46 @@ public class GUIMyBank extends javax.swing.JFrame {
|
|||||||
.addGap(17, 17, 17)
|
.addGap(17, 17, 17)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(lblDataDiNascita)
|
.addComponent(lblDataDiNascita)
|
||||||
.addComponent(lblSaldoIniziale))
|
.addComponent(lblSaldoIniziale))
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
|
||||||
|
false)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtDataDiNascita,
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
|
||||||
.addComponent(btnDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
|
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addPreferredGap(
|
||||||
|
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||||
|
.addComponent(btnDataDiNascita,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE, 39,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||||
.addComponent(txtSaldoIniziale)))
|
.addComponent(txtSaldoIniziale)))
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(lblNome)
|
.addComponent(lblNome)
|
||||||
.addComponent(lblCognome)
|
.addComponent(lblCognome)
|
||||||
.addComponent(lblCodiceFiscale))
|
.addComponent(lblCodiceFiscale))
|
||||||
.addGap(26, 26, 26)
|
.addGap(26, 26, 26)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout
|
||||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
|
.addComponent(txtCodiceFiscale,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE, 115,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtCognome,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE, 113,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39,
|
||||||
|
Short.MAX_VALUE)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||||
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
.addComponent(btnVersamento)
|
.addComponent(btnVersamento)
|
||||||
.addComponent(btnPrelievo)
|
.addComponent(btnPrelievo)
|
||||||
.addComponent(btnListaMovimenti)
|
.addComponent(btnListaMovimenti)
|
||||||
@@ -187,36 +207,53 @@ public class GUIMyBank extends javax.swing.JFrame {
|
|||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jScrollPane1)
|
.addComponent(jScrollPane1)
|
||||||
.addContainerGap())
|
.addContainerGap()));
|
||||||
);
|
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGap(14, 14, 14)
|
.addGap(14, 14, 14)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblNome)
|
.addComponent(lblNome)
|
||||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addComponent(lblNumeroContoCorrente))
|
.addComponent(lblNumeroContoCorrente))
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblCognome)
|
.addComponent(lblCognome)
|
||||||
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtCognome, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
.addComponent(txtNumeroContoCorrente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtNumeroContoCorrente, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblCodiceFiscale)
|
.addComponent(lblCodiceFiscale)
|
||||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
.addComponent(txtCodiceFiscale,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblDataDiNascita)
|
.addComponent(lblDataDiNascita)
|
||||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(txtDataDiNascita,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addComponent(btnDataDiNascita))
|
.addComponent(btnDataDiNascita))
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout
|
||||||
|
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblSaldoIniziale)
|
.addComponent(lblSaldoIniziale)
|
||||||
.addComponent(txtSaldoIniziale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
.addComponent(txtSaldoIniziale,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||||
|
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||||
|
javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addComponent(btnVersamento)
|
.addComponent(btnVersamento)
|
||||||
.addGap(18, 18, 18)
|
.addGap(18, 18, 18)
|
||||||
@@ -227,8 +264,7 @@ public class GUIMyBank extends javax.swing.JFrame {
|
|||||||
.addComponent(btnAprireContoCorrente)
|
.addComponent(btnAprireContoCorrente)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jScrollPane1)
|
.addComponent(jScrollPane1)
|
||||||
.addGap(14, 14, 14))
|
.addGap(14, 14, 14)));
|
||||||
);
|
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
@@ -364,8 +400,23 @@ public class GUIMyBank extends javax.swing.JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale);
|
ContoCorrenteWrapper conto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita,
|
||||||
|
saldoIniziale);
|
||||||
|
contoCorrenteAperto = conto.getConto();
|
||||||
|
|
||||||
|
if (conto.isImported()) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Esiste già un conto corrente per il codice fiscale specificato.\nVerrà aperto il conto corrente esistente.");
|
||||||
|
txtNome.setText(contoCorrenteAperto.getNome());
|
||||||
|
txtCognome.setText(contoCorrenteAperto.getCognome());
|
||||||
|
txtCodiceFiscale.setText(contoCorrenteAperto.getCodiceFiscale());
|
||||||
|
txtDataDiNascita.setText(MyBank.dataDiNascita(contoCorrenteAperto.getDataDiNascita()));
|
||||||
|
txtSaldoIniziale.setText(Double.toString(contoCorrenteAperto.getSaldo()));
|
||||||
|
txtNumeroContoCorrente.setText(Integer.toString(contoCorrenteAperto.getNumeroContoCorrente()));
|
||||||
|
lblSaldoIniziale.setText("Saldo");
|
||||||
|
|
||||||
|
} else {
|
||||||
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
||||||
|
}
|
||||||
|
|
||||||
lblNumeroContoCorrente.setVisible(true);
|
lblNumeroContoCorrente.setVisible(true);
|
||||||
txtNumeroContoCorrente.setVisible(true);
|
txtNumeroContoCorrente.setVisible(true);
|
||||||
|
|||||||
19
src/logic/ContoCorrenteWrapper.java
Normal file
19
src/logic/ContoCorrenteWrapper.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class ContoCorrenteWrapper {
|
||||||
|
ContoCorrente conto;
|
||||||
|
boolean isImported;
|
||||||
|
|
||||||
|
public ContoCorrenteWrapper(ContoCorrente conto, boolean isImported) {
|
||||||
|
this.conto = conto;
|
||||||
|
this.isImported = isImported;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContoCorrente getConto() {
|
||||||
|
return conto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isImported() {
|
||||||
|
return isImported;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ public class MyBank {
|
|||||||
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
||||||
static final String ERRORE_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
|
static final String ERRORE_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
|
||||||
public static final String PATH_CONTI = "./src/logic/conti/";
|
public static final String PATH_CONTI = "./src/logic/conti/";
|
||||||
|
static final String FORMATO_DATA = "dd/MM/yyyy";
|
||||||
private static ArrayList<ContoCorrente> conti;
|
private static ArrayList<ContoCorrente> conti;
|
||||||
|
|
||||||
public static void setConti(ArrayList<ContoCorrente> conti) {
|
public static void setConti(ArrayList<ContoCorrente> conti) {
|
||||||
@@ -49,7 +50,7 @@ public class MyBank {
|
|||||||
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
||||||
File percorsoConti = new File(PATH_CONTI);
|
File percorsoConti = new File(PATH_CONTI);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy"));
|
mapper.setDateFormat(new SimpleDateFormat(FORMATO_DATA));
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
String riga;
|
String riga;
|
||||||
|
|
||||||
@@ -80,11 +81,12 @@ public class MyBank {
|
|||||||
return conti;
|
return conti;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContoCorrente aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita,
|
public static ContoCorrenteWrapper aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita,
|
||||||
double saldoIniziale) throws IOException{
|
double saldoIniziale) throws IOException{
|
||||||
int numeroContoCorrente;
|
int numeroContoCorrente;
|
||||||
ContoCorrente contoCorrente;
|
ContoCorrente contoCorrente;
|
||||||
boolean exit = false;
|
boolean exit = false;
|
||||||
|
boolean isImported;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
|
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
|
||||||
@@ -94,6 +96,7 @@ public class MyBank {
|
|||||||
exit = conti.get(i).getNumeroContoCorrente() == numeroContoCorrente;
|
exit = conti.get(i).getNumeroContoCorrente() == numeroContoCorrente;
|
||||||
}
|
}
|
||||||
contoCorrente = conti.get(i);
|
contoCorrente = conti.get(i);
|
||||||
|
isImported = true;
|
||||||
} else {
|
} else {
|
||||||
File percorsoConti = new File(PATH_CONTI);
|
File percorsoConti = new File(PATH_CONTI);
|
||||||
if (!percorsoConti.exists()) {
|
if (!percorsoConti.exists()) {
|
||||||
@@ -103,9 +106,10 @@ public class MyBank {
|
|||||||
numeroContoCorrente);
|
numeroContoCorrente);
|
||||||
conti.add(contoCorrente);
|
conti.add(contoCorrente);
|
||||||
salvaContoCorrente(contoCorrente);
|
salvaContoCorrente(contoCorrente);
|
||||||
|
isImported = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return contoCorrente;
|
return new ContoCorrenteWrapper(contoCorrente, isImported);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCodiceFiscaleValid(String codiceFiscale) {
|
public static boolean isCodiceFiscaleValid(String codiceFiscale) {
|
||||||
@@ -114,12 +118,17 @@ public class MyBank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Date dataDiNascita(String dataDiNascita) throws ParseException {
|
public static Date dataDiNascita(String dataDiNascita) throws ParseException {
|
||||||
final String FORMATO_DATA = "dd/MM/yyyy";
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
||||||
sdf.setLenient(false);
|
sdf.setLenient(false);
|
||||||
return sdf.parse(dataDiNascita);
|
return sdf.parse(dataDiNascita);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String dataDiNascita(Date dataDiNascita) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
||||||
|
sdf.setLenient(false);
|
||||||
|
return sdf.format(dataDiNascita);
|
||||||
|
}
|
||||||
|
|
||||||
public static double valoreDouble(String numeroDouble) throws NumberFormatException {
|
public static double valoreDouble(String numeroDouble) throws NumberFormatException {
|
||||||
double valoreDouble;
|
double valoreDouble;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user