Implementati controlli sull'input

This commit is contained in:
2014-01-21 16:38:06 +01:00
parent 1a7c89eaac
commit f551fd854e
2 changed files with 208 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.geom.Arc2D;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
@@ -185,7 +186,7 @@ public class AdminInterface extends JFrame{
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try{
JPanel showInput = new JPanel(); JPanel showInput = new JPanel();
JLabel field1l = new JLabel("Numero Articoli"); JLabel field1l = new JLabel("Numero Articoli");
@@ -207,8 +208,32 @@ public class AdminInterface extends JFrame{
String data2 = field2.getText(); String data2 = field2.getText();
double sconto = Double.parseDouble(data2); double sconto = Double.parseDouble(data2);
if (num_articoli >0 && sconto >=0 && sconto <= 1){
Global.set_sconto_min_articoli(num_articoli,sconto); Global.set_sconto_min_articoli(num_articoli,sconto);
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
@@ -260,7 +285,7 @@ public class AdminInterface extends JFrame{
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try{
JPanel showInput = new JPanel(); JPanel showInput = new JPanel();
JLabel field2l = new JLabel("Sconto Articoli Ultima Settimana 0-1"); JLabel field2l = new JLabel("Sconto Articoli Ultima Settimana 0-1");
@@ -273,9 +298,30 @@ public class AdminInterface extends JFrame{
String data2 = field2.getText(); String data2 = field2.getText();
double sconto = Double.parseDouble(data2); double sconto = Double.parseDouble(data2);
if (sconto >= 0 && sconto <= 1){
Global.setSconto_ultima_settimana(sconto); Global.setSconto_ultima_settimana(sconto);
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
@@ -326,7 +372,7 @@ public class AdminInterface extends JFrame{
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try{
JPanel showInput = new JPanel(); JPanel showInput = new JPanel();
@@ -340,9 +386,29 @@ public class AdminInterface extends JFrame{
String data2 = field2.getText(); String data2 = field2.getText();
double sconto = Double.parseDouble(data2); double sconto = Double.parseDouble(data2);
if (sconto >= 0 && sconto <= 1){
Global.setSconto_cene_sup_50(sconto); Global.setSconto_cene_sup_50(sconto);
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
@@ -446,6 +512,9 @@ public class AdminInterface extends JFrame{
showInput.add(descrizionel); showInput.add(descrizionel);
showInput.add(descrizione); showInput.add(descrizione);
showInput.add(prezzol); showInput.add(prezzol);
@@ -461,9 +530,23 @@ public class AdminInterface extends JFrame{
JOptionPane.showMessageDialog(location, showInput); JOptionPane.showMessageDialog(location, showInput);
double checkd = Double.parseDouble(prezzo.getText());
int checki = Integer.parseInt(quantita.getText());
checki = Integer.parseInt(giudizio.getText());
if (Double.parseDouble(prezzo.getText()) >= 0 && Integer.parseInt(quantita.getText()) > 0 && Integer.parseInt(giudizio.getText())>=1 && Integer.parseInt(giudizio.getText())<=5 ){
load_catalogo.nuovoProdottoBene(descrizione.getText(),prezzo.getText(),quantita.getText(),fornitore.getText(),giudizio.getText()); load_catalogo.nuovoProdottoBene(descrizione.getText(),prezzo.getText(),quantita.getText(),fornitore.getText(),giudizio.getText());
offers.setText(""); offers.setText("");
load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); load_catalogo.offerteAttive(login_data.getUsername(),offers,"0");
}
else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -471,6 +554,19 @@ public class AdminInterface extends JFrame{
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (ParseException err){} catch (ParseException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -540,16 +636,41 @@ public class AdminInterface extends JFrame{
JOptionPane.showMessageDialog(location, showInput); JOptionPane.showMessageDialog(location, showInput);
double checkd = Double.parseDouble(prezzo.getText());
int checki = Integer.parseInt(cenedavend.getText());
if ( Double.parseDouble(prezzo.getText()) >= 0 && Integer.parseInt(cenedavend.getText())>0 ) {
load_catalogo.nuovoProdottoCena(ristorante.getText(), localita.getText(), descrizione.getText(), prezzo.getText(), scadenza.getText(), cenedavend.getText()); load_catalogo.nuovoProdottoCena(ristorante.getText(), localita.getText(), descrizione.getText(), prezzo.getText(), scadenza.getText(), cenedavend.getText());
offers.setText(""); offers.setText("");
load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); load_catalogo.offerteAttive(login_data.getUsername(),offers,"0");
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
catch (FileNotFoundException err){} catch (FileNotFoundException err){}
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (ParseException err){} catch (ParseException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -606,10 +727,21 @@ public class AdminInterface extends JFrame{
JOptionPane.showMessageDialog(location, showInput); JOptionPane.showMessageDialog(location, showInput);
if (Double.parseDouble(prezzo.getText()) >= 0){
load_catalogo.nuovoProdottoVacanza(localita.getText(), datastart.getText(), dataend.getText(), prezzo.getText()); load_catalogo.nuovoProdottoVacanza(localita.getText(), datastart.getText(), dataend.getText(), prezzo.getText());
offers.setText(""); offers.setText("");
load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); load_catalogo.offerteAttive(login_data.getUsername(),offers,"0");
}
else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -617,6 +749,19 @@ public class AdminInterface extends JFrame{
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (ParseException err){} catch (ParseException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -678,10 +823,16 @@ public class AdminInterface extends JFrame{
JOptionPane.showMessageDialog(location, showInput); JOptionPane.showMessageDialog(location, showInput);
if (Integer.parseInt(giudizio.getText()) >= 1 && Integer.parseInt(giudizio.getText()) <= 5 & Double.parseDouble(prezzo.getText())>= 0 ){
load_catalogo.nuovoProdottoPrestazione(localita.getText(), descrizione.getText(), fornitore.getText(), giudizio.getText(), prezzo.getText()); load_catalogo.nuovoProdottoPrestazione(localita.getText(), descrizione.getText(), fornitore.getText(), giudizio.getText(), prezzo.getText());
offers.setText(""); offers.setText("");
load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); load_catalogo.offerteAttive(login_data.getUsername(),offers,"0");
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -689,6 +840,19 @@ public class AdminInterface extends JFrame{
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (ParseException err){} catch (ParseException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -834,7 +998,7 @@ public class AdminInterface extends JFrame{
setSize(600, 400); setSize(650, 350);
setLocation(login_window.getLocation()); setLocation(login_window.getLocation());
setTitle("Admin Logged"); setTitle("Admin Logged");
setVisible(true); setVisible(true);

View File

@@ -157,6 +157,19 @@ public class UserInterface extends JFrame{
catch (FileNotFoundException err){} catch (FileNotFoundException err){}
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -184,14 +197,32 @@ public class UserInterface extends JFrame{
JOptionPane.showInputDialog( JOptionPane.showInputDialog(
location, "Inserire valutazione fornitore","Valutazione")); location, "Inserire valutazione fornitore","Valutazione"));
if (valutazione <= 5 && valutazione >=1){
load_catalogo.offerteAttiveSenzaScadenza(login_data.getUsername(), offers, "0", valutazione); load_catalogo.offerteAttiveSenzaScadenza(login_data.getUsername(), offers, "0", valutazione);
}else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
catch (FileNotFoundException err){} catch (FileNotFoundException err){}
catch (IOException err){} catch (IOException err){}
catch (ClassNotFoundException err){} catch (ClassNotFoundException err){}
catch (NumberFormatException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NullPointerException err){
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
}
} }
@@ -324,6 +355,11 @@ public class UserInterface extends JFrame{
load_catalogo.aggiungiCredito(login_data.getUsername(), importo_da_ricaricare ); load_catalogo.aggiungiCredito(login_data.getUsername(), importo_da_ricaricare );
l.setText("Bilancio" + " " + login_data.getUsername() + " = " + (Access.get_user_data(login_data.getUsername())).getBalance()); l.setText("Bilancio" + " " + login_data.getUsername() + " = " + (Access.get_user_data(login_data.getUsername())).getBalance());
} else{
JOptionPane.showMessageDialog(location,
"Input Non valido ",
"Error",
JOptionPane.ERROR_MESSAGE);
} }
} }
catch (FileNotFoundException err){} catch (FileNotFoundException err){}
@@ -542,7 +578,7 @@ public class UserInterface extends JFrame{
setSize(600, 400); setSize(650, 350);
setLocation(login_window.getLocation()); setLocation(login_window.getLocation());
setTitle("User " + Access.get_user_data(login_data.getUsername()).getUser() + " Logged"); setTitle("User " + Access.get_user_data(login_data.getUsername()).getUser() + " Logged");
setVisible(true); setVisible(true);