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 logic.MyBank;
|
||||
import logic.ContoCorrente;
|
||||
import logic.ContoCorrenteWrapper;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
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 Code">//GEN-BEGIN:initComponents
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated
|
||||
// Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
lblNome = new javax.swing.JLabel();
|
||||
@@ -147,88 +150,121 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(99, 99, 99)
|
||||
.addComponent(btnAprireContoCorrente)
|
||||
.addContainerGap(187, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(17, 17, 17)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(lblSaldoIniziale))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, 64, 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)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(lblCodiceFiscale))
|
||||
.addGap(26, 26, 26)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.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)
|
||||
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnVersamento)
|
||||
.addComponent(btnPrelievo)
|
||||
.addComponent(btnListaMovimenti)
|
||||
.addComponent(txtNumeroContoCorrente))
|
||||
.addGap(23, 23, 23))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jScrollPane1)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(99, 99, 99)
|
||||
.addComponent(btnAprireContoCorrente)
|
||||
.addContainerGap(187, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(17, 17, 17)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(lblSaldoIniziale))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
|
||||
false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtDataDiNascita,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE, 64,
|
||||
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)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(lblCodiceFiscale))
|
||||
.addGap(26, 26, 26)
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||
113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.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)
|
||||
.addComponent(lblNumeroContoCorrente, javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btnVersamento)
|
||||
.addComponent(btnPrelievo)
|
||||
.addComponent(btnListaMovimenti)
|
||||
.addComponent(txtNumeroContoCorrente))
|
||||
.addGap(23, 23, 23))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jScrollPane1)
|
||||
.addContainerGap()));
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(14, 14, 14)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblNumeroContoCorrente))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(txtCognome, 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)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCodiceFiscale)
|
||||
.addComponent(txtCodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(txtDataDiNascita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnDataDiNascita))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblSaldoIniziale)
|
||||
.addComponent(txtSaldoIniziale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnVersamento)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnPrelievo)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnListaMovimenti)))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnAprireContoCorrente)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1)
|
||||
.addGap(14, 14, 14))
|
||||
);
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(14, 14, 14)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblNome)
|
||||
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblNumeroContoCorrente))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCognome)
|
||||
.addComponent(txtCognome, 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)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblCodiceFiscale)
|
||||
.addComponent(txtCodiceFiscale,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblDataDiNascita)
|
||||
.addComponent(txtDataDiNascita,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnDataDiNascita))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout
|
||||
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblSaldoIniziale)
|
||||
.addComponent(txtSaldoIniziale,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE,
|
||||
javax.swing.GroupLayout.DEFAULT_SIZE,
|
||||
javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnVersamento)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnPrelievo)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnListaMovimenti)))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(btnAprireContoCorrente)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1)
|
||||
.addGap(14, 14, 14)));
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
@@ -364,8 +400,23 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
}
|
||||
|
||||
try {
|
||||
contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale);
|
||||
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
||||
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()));
|
||||
}
|
||||
|
||||
lblNumeroContoCorrente.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_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
|
||||
public static final String PATH_CONTI = "./src/logic/conti/";
|
||||
static final String FORMATO_DATA = "dd/MM/yyyy";
|
||||
private static ArrayList<ContoCorrente> conti;
|
||||
|
||||
public static void setConti(ArrayList<ContoCorrente> conti) {
|
||||
@@ -49,7 +50,7 @@ public class MyBank {
|
||||
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
||||
File percorsoConti = new File(PATH_CONTI);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy"));
|
||||
mapper.setDateFormat(new SimpleDateFormat(FORMATO_DATA));
|
||||
StringBuilder sb;
|
||||
String riga;
|
||||
|
||||
@@ -80,11 +81,12 @@ public class MyBank {
|
||||
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{
|
||||
int numeroContoCorrente;
|
||||
ContoCorrente contoCorrente;
|
||||
boolean exit = false;
|
||||
boolean isImported;
|
||||
int i = 0;
|
||||
|
||||
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
|
||||
@@ -94,6 +96,7 @@ public class MyBank {
|
||||
exit = conti.get(i).getNumeroContoCorrente() == numeroContoCorrente;
|
||||
}
|
||||
contoCorrente = conti.get(i);
|
||||
isImported = true;
|
||||
} else {
|
||||
File percorsoConti = new File(PATH_CONTI);
|
||||
if (!percorsoConti.exists()) {
|
||||
@@ -103,9 +106,10 @@ public class MyBank {
|
||||
numeroContoCorrente);
|
||||
conti.add(contoCorrente);
|
||||
salvaContoCorrente(contoCorrente);
|
||||
isImported = false;
|
||||
}
|
||||
|
||||
return contoCorrente;
|
||||
return new ContoCorrenteWrapper(contoCorrente, isImported);
|
||||
}
|
||||
|
||||
public static boolean isCodiceFiscaleValid(String codiceFiscale) {
|
||||
@@ -114,12 +118,17 @@ public class MyBank {
|
||||
}
|
||||
|
||||
public static Date dataDiNascita(String dataDiNascita) throws ParseException {
|
||||
final String FORMATO_DATA = "dd/MM/yyyy";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
||||
sdf.setLenient(false);
|
||||
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 {
|
||||
double valoreDouble;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user