Mostra operazioni
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.
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,7 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -264,8 +265,12 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnListaMovimentiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListaMovimentiActionPerformed
|
||||
txtaListaMovimenti.setText(contoCorrente.getLogOperazioni());
|
||||
txtaListaMovimenti.setVisible(true);
|
||||
try {
|
||||
txtaListaMovimenti.setText(contoCorrenteAperto.getLog());
|
||||
txtaListaMovimenti.setVisible(true);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
}// GEN-LAST:event_btnListaMovimentiActionPerformed
|
||||
|
||||
private void txtNomeFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_txtNomeFocusGained
|
||||
@@ -303,6 +308,8 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
} catch (NumberFormatException _) {
|
||||
JOptionPane.showMessageDialog(null, "L'importo che si desidera versare non è valido.");
|
||||
error = true;
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
} while (error);
|
||||
}// GEN-LAST:event_btnVersamentoActionPerformed
|
||||
@@ -325,6 +332,8 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
} catch (IllegalArgumentException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
error = true;
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
} while (error);
|
||||
}// GEN-LAST:event_btnPrelievoActionPerformed
|
||||
@@ -385,21 +394,25 @@ public class GUIMyBank extends javax.swing.JFrame {
|
||||
return;
|
||||
}
|
||||
|
||||
this.contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale);
|
||||
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
||||
try {
|
||||
this.contoCorrenteAperto = MyBank.aggiungiConto(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale);
|
||||
txtNumeroContoCorrente.setText(Integer.toString(MyBank.getConti().getLast().getNumeroContoCorrente()));
|
||||
|
||||
lblNumeroContoCorrente.setVisible(true);
|
||||
txtNumeroContoCorrente.setVisible(true);
|
||||
btnVersamento.setVisible(true);
|
||||
btnPrelievo.setVisible(true);
|
||||
btnListaMovimenti.setVisible(true);
|
||||
txtNome.setEditable(false);
|
||||
txtCognome.setEditable(false);
|
||||
txtCodiceFiscale.setEditable(false);
|
||||
txtDataDiNascita.setEditable(false);
|
||||
txtSaldoIniziale.setEditable(false);
|
||||
btnAprireContoCorrente.setEnabled(false);
|
||||
btnDataDiNascita.setEnabled(false);
|
||||
lblNumeroContoCorrente.setVisible(true);
|
||||
txtNumeroContoCorrente.setVisible(true);
|
||||
btnVersamento.setVisible(true);
|
||||
btnPrelievo.setVisible(true);
|
||||
btnListaMovimenti.setVisible(true);
|
||||
txtNome.setEditable(false);
|
||||
txtCognome.setEditable(false);
|
||||
txtCodiceFiscale.setEditable(false);
|
||||
txtDataDiNascita.setEditable(false);
|
||||
txtSaldoIniziale.setEditable(false);
|
||||
btnAprireContoCorrente.setEnabled(false);
|
||||
btnDataDiNascita.setEnabled(false);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
|
||||
}// GEN-LAST:event_btnAprireContoCorrenteActionPerformed
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
*/
|
||||
package logic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -35,7 +37,7 @@ public class ContoCorrente {
|
||||
}
|
||||
|
||||
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
|
||||
int numeroContoCorrente) {
|
||||
int numeroContoCorrente) throws IOException{
|
||||
this.nome = nome;
|
||||
this.cognome = cognome;
|
||||
this.codiceFiscale = codiceFiscale;
|
||||
@@ -58,13 +60,13 @@ public class ContoCorrente {
|
||||
return numeroContoCorrente;
|
||||
}
|
||||
|
||||
public void versa(double quantita){
|
||||
public void versa(double quantita) throws IOException{
|
||||
this.saldo += quantita;
|
||||
log("Versamento di " + quantita + " effettuato con successo.");
|
||||
logSaldoCorrente();
|
||||
}
|
||||
|
||||
public void preleva(double quantita) throws IllegalArgumentException{
|
||||
public void preleva(double quantita) throws IllegalArgumentException, IOException{
|
||||
if (quantita > this.saldo) {
|
||||
log("Tentato prelievo di " + quantita + " fallito per superamento saldo.");
|
||||
logSaldoCorrente();
|
||||
@@ -77,11 +79,11 @@ public class ContoCorrente {
|
||||
}
|
||||
}
|
||||
|
||||
private void logSaldoCorrente() {
|
||||
private void logSaldoCorrente() throws IOException{
|
||||
log("Saldo corrente: " + this.saldo + "\n");
|
||||
}
|
||||
|
||||
private void log(String messaggio) {
|
||||
private void log(String messaggio) throws IOException{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.sss dd/MM/yyyy");
|
||||
try (BufferedWriter bw = new BufferedWriter(
|
||||
@@ -94,7 +96,16 @@ public class ContoCorrente {
|
||||
|
||||
bw.write(sb.toString());
|
||||
} catch (IOException _) {
|
||||
System.out.println("Errore nella scrittura del movimento.");
|
||||
throw new IOException("Errore nella scrittura del movimento.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getLog() throws IOException{
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new FileReader(MyBank.PATH_CONTI + "movimenti_" + this.numeroContoCorrente + ".txt"))) {
|
||||
return br.readAllAsString();
|
||||
} catch (IOException _) {
|
||||
throw new IOException("Errore nella lettura dei movimenti.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,23 +61,6 @@ public class MyBank {
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 3:
|
||||
if (conti.isEmpty()) {
|
||||
System.out.println(ERRORE_CONTI_VUOTO);
|
||||
} else {
|
||||
preleva(conti);
|
||||
System.out.println("Prelievo effettuato con successo.");
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 4:
|
||||
if (conti.isEmpty()) {
|
||||
System.out.println(ERRORE_CONTI_VUOTO);
|
||||
} else {
|
||||
stampaLog(conti);
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
@@ -133,7 +116,7 @@ public class MyBank {
|
||||
}
|
||||
|
||||
public static ContoCorrente aggiungiConto(String nome, String cognome, String codiceFiscale, Date dataDiNascita,
|
||||
double saldoIniziale) {
|
||||
double saldoIniziale) throws IOException{
|
||||
int numeroContoCorrente;
|
||||
ContoCorrente contoCorrente;
|
||||
boolean exit = false;
|
||||
@@ -193,13 +176,4 @@ public class MyBank {
|
||||
System.out.println("Errore: impossibile salvare il conto corrente.");
|
||||
}
|
||||
}
|
||||
|
||||
static void stampaLog(ArrayList<ContoCorrente> conti) {
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new FileReader(PATH_CONTI + "movimenti_" + selezionaConto(conti).getNumeroContoCorrente() + ".txt"))) {
|
||||
System.out.println(br.readAllAsString());
|
||||
} catch (IOException _) {
|
||||
System.out.println("Errore nella lettura dei movimenti.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user