From f551fd854e71d31392de15e0bde8d51471649a63 Mon Sep 17 00:00:00 2001 From: Giovanni Di Grezia Date: Tue, 21 Jan 2014 16:38:06 +0100 Subject: [PATCH] Implementati controlli sull'input --- it/unisa/info13d/Gui/AdminInterface.java | 174 ++++++++++++++++++++++- it/unisa/info13d/Gui/UserInterface.java | 42 +++++- 2 files changed, 208 insertions(+), 8 deletions(-) diff --git a/it/unisa/info13d/Gui/AdminInterface.java b/it/unisa/info13d/Gui/AdminInterface.java index 0028d3e..f39166d 100644 --- a/it/unisa/info13d/Gui/AdminInterface.java +++ b/it/unisa/info13d/Gui/AdminInterface.java @@ -10,6 +10,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.geom.Arc2D; import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; @@ -185,7 +186,7 @@ public class AdminInterface extends JFrame{ public void actionPerformed(ActionEvent e) { - + try{ JPanel showInput = new JPanel(); JLabel field1l = new JLabel("Numero Articoli"); @@ -207,8 +208,32 @@ public class AdminInterface extends JFrame{ String data2 = field2.getText(); double sconto = Double.parseDouble(data2); + if (num_articoli >0 && sconto >=0 && sconto <= 1){ + 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) { - + try{ JPanel showInput = new JPanel(); JLabel field2l = new JLabel("Sconto Articoli Ultima Settimana 0-1"); @@ -273,9 +298,30 @@ public class AdminInterface extends JFrame{ String data2 = field2.getText(); double sconto = Double.parseDouble(data2); + if (sconto >= 0 && sconto <= 1){ 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 public void actionPerformed(ActionEvent e) { - + try{ JPanel showInput = new JPanel(); @@ -340,9 +386,29 @@ public class AdminInterface extends JFrame{ String data2 = field2.getText(); double sconto = Double.parseDouble(data2); + if (sconto >= 0 && sconto <= 1){ 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(descrizione); showInput.add(prezzol); @@ -461,9 +530,23 @@ public class AdminInterface extends JFrame{ 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()); offers.setText(""); 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 (ClassNotFoundException 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); + 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()); offers.setText(""); load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); + }else{ + JOptionPane.showMessageDialog(location, + "Input Non valido ", + "Error", + JOptionPane.ERROR_MESSAGE); + + } } catch (FileNotFoundException err){} catch (IOException err){} catch (ClassNotFoundException 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); + if (Double.parseDouble(prezzo.getText()) >= 0){ + load_catalogo.nuovoProdottoVacanza(localita.getText(), datastart.getText(), dataend.getText(), prezzo.getText()); offers.setText(""); 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 (ClassNotFoundException 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); - + 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()); offers.setText(""); 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 (ClassNotFoundException 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()); setTitle("Admin Logged"); setVisible(true); diff --git a/it/unisa/info13d/Gui/UserInterface.java b/it/unisa/info13d/Gui/UserInterface.java index a04cf6d..c3abb61 100644 --- a/it/unisa/info13d/Gui/UserInterface.java +++ b/it/unisa/info13d/Gui/UserInterface.java @@ -157,6 +157,19 @@ public class UserInterface extends JFrame{ catch (FileNotFoundException err){} catch (IOException 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( location, "Inserire valutazione fornitore","Valutazione")); - - + if (valutazione <= 5 && valutazione >=1){ load_catalogo.offerteAttiveSenzaScadenza(login_data.getUsername(), offers, "0", valutazione); + }else{ + JOptionPane.showMessageDialog(location, + "Input Non valido ", + "Error", + JOptionPane.ERROR_MESSAGE); + } } catch (FileNotFoundException err){} catch (IOException 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 ); 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){} @@ -542,7 +578,7 @@ public class UserInterface extends JFrame{ - setSize(600, 400); + setSize(650, 350); setLocation(login_window.getLocation()); setTitle("User " + Access.get_user_data(login_data.getUsername()).getUser() + " Logged"); setVisible(true);