diff --git a/it/unisa/info13d/Articoli/PrestazioniDopera.java b/it/unisa/info13d/Articoli/PrestazioniDopera.java index 615dd89..9dcbf94 100644 --- a/it/unisa/info13d/Articoli/PrestazioniDopera.java +++ b/it/unisa/info13d/Articoli/PrestazioniDopera.java @@ -1,5 +1,7 @@ package it.unisa.info13d.Articoli; +import java.util.GregorianCalendar; + public class PrestazioniDopera extends Utilizzabile { @@ -90,4 +92,9 @@ public class PrestazioniDopera extends Utilizzabile { private String Localita; private String Descrizione; private String Fornitore; + private GregorianCalendar scadenza = new GregorianCalendar(99999,0,1); + + public GregorianCalendar getScadenza() { + return scadenza; + } } \ No newline at end of file diff --git a/it/unisa/info13d/GestioneCatalogo/AdminSession.java b/it/unisa/info13d/GestioneCatalogo/AdminSession.java index 006803b..c99f6b9 100644 --- a/it/unisa/info13d/GestioneCatalogo/AdminSession.java +++ b/it/unisa/info13d/GestioneCatalogo/AdminSession.java @@ -55,7 +55,7 @@ public class AdminSession { //catalogo.offerteAttive(username); break; case "4": - catalogo.offerteScadute(username); + //catalogo.offerteScadute(username); break; case "5": r.reshow = false; diff --git a/it/unisa/info13d/GestioneCatalogo/Catalogo.java b/it/unisa/info13d/GestioneCatalogo/Catalogo.java index fbc6823..d91c438 100644 --- a/it/unisa/info13d/GestioneCatalogo/Catalogo.java +++ b/it/unisa/info13d/GestioneCatalogo/Catalogo.java @@ -356,27 +356,15 @@ public class Catalogo{ * @throws ClassNotFoundException * @throws IOException */ - public void offerteAttive(String user, JTextArea show_offers) throws FileNotFoundException, ClassNotFoundException, IOException + public void offerteAttive(String user, JTextArea show_offers, String in_choice) throws FileNotFoundException, ClassNotFoundException, IOException { Entry loggedUser = Access.get_user_data(user); if(!(loggedUser.getType())) { - Scanner reader = new Scanner(System.in); + //admin - System.out.println("1 --> Ordina Per Data di Scadenza"); - System.out.println("2 --> Ordina Per ID"); - - String choice; - System.out.print("Scelta operazione: "); - choice = reader.nextLine(); - for ( ; !(choice.equals("1")) && !(choice.equals("2")) ;){ - System.out.println("Scelta Errata. Riprovare"); - System.out.print("Scelta operazione: "); - choice = reader.nextLine(); - } - - if (choice.equals("1")){ + if (in_choice.equals("1")){ class CompareDataScadenza implements Comparator { @@ -401,10 +389,19 @@ public class Catalogo{ }else{ //bene vs cena + if (e2 instanceof CeneInRistoranti) { - if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) - return -1; - return 1; + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + + //bene vs prest + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } } } }else{ @@ -428,36 +425,94 @@ public class Catalogo{ }else{ //vacanza vs cena - if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) - return -1; - return 1; + if (e2 instanceof CeneInRistoranti) { + + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //vacanza vs prest + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } } } }else{ //Cene vs - if (e2 instanceof Vacanze){ - //cena vs vacanza + if (e1 instanceof CeneInRistoranti){ + if (e2 instanceof Vacanze){ + //cena vs vacanza - if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) - return -1; - return 1; + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs prest + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } }else{ - if (e2 instanceof CeneInRistoranti){ - //cena vs cena - if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) return -1; return 1; + }else{ - //cena vs bene + if (e2 instanceof CeneInRistoranti){ + //prest vs cena - if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) - return -1; - return 1; + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs prest + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } } + + + + + } } @@ -493,10 +548,17 @@ public class Catalogo{ }else{ //bene vs cena + if (e2 instanceof CeneInRistoranti){ - if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) - return -1; - return 1; + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } } } }else{ @@ -520,36 +582,89 @@ public class Catalogo{ }else{ //vacanza vs cena - if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) - return -1; - return 1; + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } } } }else{ - //Cene vs - if (e2 instanceof Vacanze){ - //cena vs vacanza + if (e1 instanceof CeneInRistoranti){ - if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) - return -1; - return 1; - }else{ - if (e2 instanceof CeneInRistoranti){ - //cena vs cena + //Cene vs + if (e2 instanceof Vacanze){ + //cena vs vacanza - if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) return -1; return 1; + }else{ - //cena vs bene + if (e2 instanceof CeneInRistoranti){ + //cena vs cena - if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) return -1; return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } } + } } @@ -567,6 +682,8 @@ public class Catalogo{ } else{ + // user + class CompareIDUser implements Comparator { @Override @@ -590,10 +707,17 @@ public class Catalogo{ }else{ //bene vs cena + if (e2 instanceof CeneInRistoranti){ - if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) - return -1; - return 1; + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } } } }else{ @@ -617,36 +741,89 @@ public class Catalogo{ }else{ //vacanza vs cena - if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) - return -1; - return 1; + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } } } }else{ + if (e1 instanceof CeneInRistoranti){ + + //Cene vs - if (e2 instanceof Vacanze){ - //cena vs vacanza + if (e2 instanceof Vacanze){ + //cena vs vacanza - if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) - return -1; - return 1; - - }else{ - if (e2 instanceof CeneInRistoranti){ - //cena vs cena - - if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) return -1; return 1; + }else{ - //cena vs bene + if (e2 instanceof CeneInRistoranti){ + //cena vs cena - if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) return -1; return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } } + } } @@ -656,11 +833,978 @@ public class Catalogo{ } - Collections.sort(catalogoOfferte,new CompareIDUser()); - print_cat_user(catalogoOfferte,loggedUser.getLocation(),show_offers); + Collections.sort(catalogoOfferte, new CompareIDUser()); + print_cat_user(catalogoOfferte, loggedUser.getLocation(), show_offers); } } + + public void offerteAttiveConScadenza(String user, JTextArea show_offers, String in_choice, GregorianCalendar datastart, GregorianCalendar data_end) throws FileNotFoundException, ClassNotFoundException, IOException + { + Entry loggedUser = Access.get_user_data(user); + ArrayList arrayData = getDataExpire(datastart,data_end); + if(!(loggedUser.getType())) + { + //admin + + + if (in_choice.equals("1")){ + + class CompareDataScadenza implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti) { + + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + + //bene vs prest + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti) { + + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //vacanza vs prest + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + + } + } + + }else{ + //Cene vs + if (e1 instanceof CeneInRistoranti){ + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs prest + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs prest + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + + + + + + } + + } + } + + } + } + + Collections.sort(arrayData,new CompareDataScadenza()); + print_cat_admin (arrayData,show_offers); + }else{ + + class CompareID implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti){ + + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + + } + } + + }else{ + if (e1 instanceof CeneInRistoranti){ + + + //Cene vs + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + + } + + } + } + + } + } + + + Collections.sort(arrayData,new CompareID()); + print_cat_admin (arrayData,show_offers); + + } + + + } else{ + + // user + + class CompareIDUser implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti){ + + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + + } + } + + }else{ + if (e1 instanceof CeneInRistoranti){ + + + //Cene vs + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + + } + + } + } + + } + } + + + Collections.sort(arrayData, new CompareIDUser()); + print_cat_user(arrayData, loggedUser.getLocation(), show_offers); + + } + } + public void offerteAttiveSenzaScadenza(String user, JTextArea show_offers, String in_choice, int votazione) throws FileNotFoundException, ClassNotFoundException, IOException + { + Entry loggedUser = Access.get_user_data(user); + ArrayList arrayData = getDealNotExpire(votazione); + if(!(loggedUser.getType())) + { + //admin + + + if (in_choice.equals("1")){ + + class CompareDataScadenza implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti) { + + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + + //bene vs prest + if (((BeniDiConsumo)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti) { + + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //vacanza vs prest + if (((Vacanze)e1).getScadenzaOfferta().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + + } + } + + }else{ + //Cene vs + if (e1 instanceof CeneInRistoranti){ + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //cena vs prest + if (((CeneInRistoranti)e1).getDataScadenzaOffertaCena().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((Vacanze)e2).getScadenzaOfferta().getTimeInMillis()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((CeneInRistoranti)e2).getDataScadenzaOffertaCena().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo) { + + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((BeniDiConsumo)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + }else{ + //prest vs prest + if (((PrestazioniDopera)e1).getScadenza().getTimeInMillis() < ((PrestazioniDopera)e2).getScadenza().getTimeInMillis()) + return -1; + return 1; + + } + } + } + + + + + + } + + } + } + + } + } + + Collections.sort(arrayData,new CompareDataScadenza()); + print_cat_admin (arrayData,show_offers); + }else{ + + class CompareID implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti){ + + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + + } + } + + }else{ + if (e1 instanceof CeneInRistoranti){ + + + //Cene vs + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + + } + + } + } + + } + } + + + Collections.sort(arrayData,new CompareID()); + print_cat_admin (arrayData,show_offers); + + } + + + } else{ + + // user + + class CompareIDUser implements Comparator { + + @Override + public int compare(Utilizzabile e1, Utilizzabile e2) { + + if (e1 instanceof BeniDiConsumo){ + //beni vs + if (e2 instanceof Vacanze){ + //beni vs vacanze + if (((BeniDiConsumo)e1).getIdBene() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof BeniDiConsumo){ + //bene vs //bene + + if (((BeniDiConsumo)e1).getIdBene() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + //bene vs cena + if (e2 instanceof CeneInRistoranti){ + + if (((BeniDiConsumo)e1).getIdBene() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((BeniDiConsumo)e1).getIdBene() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + if (e1 instanceof Vacanze){ + //vacanze vs + if (e2 instanceof BeniDiConsumo){ + //vacanze vs bene + if (((Vacanze)e1).getIdViaggio() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + + }else{ + if (e2 instanceof Vacanze){ + //vacabnza vs vacanza + + if (((Vacanze)e1).getIdViaggio() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + + }else{ + //vacanza vs cena + + if (e2 instanceof CeneInRistoranti){ + + if (((Vacanze)e1).getIdViaggio() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + + if (((Vacanze)e1).getIdViaggio() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + + } + } + + }else{ + if (e1 instanceof CeneInRistoranti){ + + + //Cene vs + if (e2 instanceof Vacanze){ + //cena vs vacanza + + if (((CeneInRistoranti)e1).getIdCena() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //cena vs cena + + if (((CeneInRistoranti)e1).getIdCena() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //cena vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((CeneInRistoranti)e1).getIdCena() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((CeneInRistoranti)e1).getIdCena() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + }else{ + + if (e2 instanceof Vacanze){ + //prest vs vacanza + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((Vacanze)e2).getIdViaggio()) + return -1; + return 1; + + }else{ + if (e2 instanceof CeneInRistoranti){ + //prest vs cena + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((CeneInRistoranti)e2).getIdCena()) + return -1; + return 1; + }else{ + //prest vs bene + + if (e2 instanceof BeniDiConsumo){ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((BeniDiConsumo)e2).getIdBene()) + return -1; + return 1; + }else{ + + if (((PrestazioniDopera)e1).getIdPrOpera() < ((PrestazioniDopera)e2).getIdPrOpera()) + return -1; + return 1; + } + } + } + + } + + } + } + + } + } + + + Collections.sort(arrayData, new CompareIDUser()); + print_cat_user(arrayData, loggedUser.getLocation(), show_offers); + + } + } /** * Questo metodo visualizza le offerte scadute del catalogo @@ -668,27 +1812,32 @@ public class Catalogo{ * @throws ClassNotFoundException * @throws FileNotFoundException */ - public void offerteScadute(String user) throws FileNotFoundException, ClassNotFoundException, IOException + public void offerteScadute(String user,JTextArea in_area) throws FileNotFoundException, ClassNotFoundException, IOException { Entry loggedUser = Access.get_user_data(user); - System.out.println("------ Offerte Scadute -----"); + //System.out.println("------ Offerte Scadute -----"); for(Utilizzabile deal: catalogoOfferte) { if(deal instanceof Vacanze) { Vacanze dealVacanza = (Vacanze)deal; - //if(!(dealVacanza.eAcquistabile())) {visualizzaVacanza(dealVacanza);continue;} + if(!(dealVacanza.eAcquistabile())) {visualizzaVacanza(dealVacanza,in_area);}continue; } if(deal instanceof BeniDiConsumo) { BeniDiConsumo dealBene = (BeniDiConsumo)deal; - //if(!(dealBene.eAcquistabile())) {visualizzaBene(dealBene);continue;} + if(!(dealBene.eAcquistabile())) {visualizzaBene(dealBene,in_area);}continue; } if(deal instanceof CeneInRistoranti) { CeneInRistoranti dealCena = (CeneInRistoranti)deal; - //if(!(dealCena.eAcquistabile())) {visualizzaCena(dealCena);continue;} + if(!(dealCena.eAcquistabile())) {visualizzaCena(dealCena,in_area);}continue; } + if(deal instanceof PrestazioniDopera) + { + PrestazioniDopera dealP = (PrestazioniDopera)deal; + if(!(dealP.eAcquistabile())) {visualizzaPrestazione(dealP,in_area);}continue; + } } } /** @@ -782,7 +1931,7 @@ public class Catalogo{ { CeneInRistoranti dealCena = (CeneInRistoranti)dealsc; - storico.add(new StoricoItem("Cena ristorante "+dealCena.getNomeRistorante()+" "+dealCena.getDescrizione_cena(), new GregorianCalendar() ,dealCena.get_prezzo_scontato())); + storico.add(new StoricoItem("Cena ristorante: "+dealCena.getNomeRistorante()+" "+dealCena.getDescrizione_cena(), new GregorianCalendar() ,dealCena.get_prezzo_scontato())); dealCena.setCeneVendute(); Access.replace_data(user, loggedUser); store_data(); @@ -792,7 +1941,7 @@ public class Catalogo{ { PrestazioniDopera deal = (PrestazioniDopera)dealsc; - storico.add(new StoricoItem("Prestazione d'opera "+deal.getDescrizione(), new GregorianCalendar() ,deal.get_prezzo_scontato())); + storico.add(new StoricoItem("Prestazione d'opera: "+deal.getDescrizione(), new GregorianCalendar() ,deal.get_prezzo_scontato())); deal.setPrestazioniVendute(); Access.replace_data(user, loggedUser); store_data(); @@ -891,24 +2040,16 @@ public class Catalogo{ * @throws ClassNotFoundException * @throws IOException */ - public void visualizzaStorico(String user) throws FileNotFoundException, ClassNotFoundException, IOException + public void visualizzaStorico(String user, String choice,JTextArea area_storico) throws FileNotFoundException, ClassNotFoundException, IOException { - Scanner reader = new Scanner(System.in); - System.out.println("1 --> Ordina Per Data di Acquisto"); - System.out.println("2 --> Ordina Per Costo Prodotto"); + //("1 --> Ordina Per Data di Acquisto"); + //("2 --> Ordina Per Costo Prodotto"); + - String choice; - System.out.print("Opzione: "); - choice = reader.nextLine(); - for ( ; !(choice.equals("1")) && !(choice.equals("2")) ;){ - System.out.println("Scelta Errata. Riprovare"); - System.out.print("Opzione: "); - choice = reader.nextLine(); - } Entry userLogged = Access.get_user_data(user); - System.out.println("---------- STORICO ----------"); + //System.out.println("---------- STORICO ----------"); ArrayList storico = userLogged.getStorico(); if (choice.equals("1")){ @@ -924,7 +2065,7 @@ public class Catalogo{ } Collections.sort(storico,new CompareDataAcquisto()); - print_storico(storico); + print_storico(storico, area_storico); } else { @@ -939,11 +2080,11 @@ public class Catalogo{ } } Collections.sort(storico,new ComparePrezzo()); - print_storico (storico); + print_storico (storico, area_storico); } } - protected void print_storico (ArrayList in){ + protected void print_storico (ArrayList in, JTextArea area_storico){ for(StoricoItem record: in) { @@ -951,7 +2092,7 @@ public class Catalogo{ int giornoP = partenza.get(Calendar.DAY_OF_MONTH); int meseP = partenza.get(Calendar.MONTH); int annoP = partenza.get(Calendar.YEAR); - System.out.println("| deal: "+record.getDescription()+"| Data Acquisto: "+giornoP+"/"+(meseP+1)+"/"+annoP+"| Prezzo: "+record.getPrezzo()); + area_storico.append("| deal: " + record.getDescription() + "| Data Acquisto: " + giornoP + "/" + (meseP + 1) + "/" + annoP + "| Prezzo: " + record.getPrezzo() + "\n"); } } diff --git a/it/unisa/info13d/GestioneCatalogo/ClientSession.java b/it/unisa/info13d/GestioneCatalogo/ClientSession.java index 43063a7..4797ab9 100644 --- a/it/unisa/info13d/GestioneCatalogo/ClientSession.java +++ b/it/unisa/info13d/GestioneCatalogo/ClientSession.java @@ -55,7 +55,7 @@ public class ClientSession { //catalogo.acquistaProdotto(username); break; case "4": - catalogo.visualizzaStorico(username); + //catalogo.visualizzaStorico(username); break; case "5": // r.reshow = false; diff --git a/it/unisa/info13d/Gui/AdminInterface.java b/it/unisa/info13d/Gui/AdminInterface.java index b22928f..c20b31e 100644 --- a/it/unisa/info13d/Gui/AdminInterface.java +++ b/it/unisa/info13d/Gui/AdminInterface.java @@ -1,12 +1,350 @@ package it.unisa.info13d.Gui; +import it.unisa.info13d.Articoli.Utilizzabile; +import it.unisa.info13d.GestioneCatalogo.Catalogo; +import it.unisa.info13d.Login.Access; +import it.unisa.info13d.Login.LoginData; + import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.GregorianCalendar; /** * Created with MONSTER. * User: xgiovio * Date: 19/01/14 - * Time: 19.05 + * Time: 19.19 */ -public class AdminInterface extends JFrame { +public class AdminInterface extends JFrame{ + + + public AdminInterface(LoginWindow in_login_window, Catalogo in_load_catalogo, LoginData in_login_data) throws FileNotFoundException,IOException,ClassNotFoundException{ + + login_window = in_login_window; + load_catalogo= in_load_catalogo; + login_data = in_login_data; + + //////////////////////////////////////////////////// begin main menu and balance + + JPanel mainWindow = new JPanel(); + mainWindow.setLayout(new BorderLayout()); + add(mainWindow); + + + JPanel north = new JPanel(); + north.setLayout(new BorderLayout() ); + + + JMenuBar mainmenu = new JMenuBar(); + north.add(mainmenu,BorderLayout.NORTH); + + JMenu filemenu = new JMenu("File"); + JMenuItem logout_menu_item = new JMenuItem("Logout"); + class logout_action implements ActionListener { + + + public logout_action (AdminInterface in_location){ + location= in_location; + } + + @Override + public void actionPerformed(ActionEvent e) { + + + location.setVisible(false); + login_window.setVisible(true); + + + } + + private AdminInterface location; + } + logout_menu_item.addActionListener(new logout_action(this)); + JMenuItem quit_menu_item = new JMenuItem("Quit"); + class exit_action implements ActionListener { + + + + + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + + } + + } + quit_menu_item.addActionListener(new exit_action()); + + JMenu searchmenu = new JMenu("Cerca"); + JMenuItem tutti_gli_articoli_attivi_id = new JMenuItem("Tutti gli articoli Attivi per ID"); + class tutti_gli_articoli_attivi_id_action implements ActionListener { + + + public tutti_gli_articoli_attivi_id_action (AdminInterface in_location, JTextArea in_offers,String in_choice){ + location= in_location; + offers = in_offers; + choice = in_choice; + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + offers.setText(""); + load_catalogo.offerteAttive(login_data.getUsername(),offers,choice); + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private AdminInterface location; + private JTextArea offers; + private String choice; + } + //action listner added at offers declaration + + JMenuItem tutti_gli_articoli_attivi_costo = new JMenuItem("Tutti gli articoli Attivi per Costo"); + class tutti_gli_articoli_attivi_costo_action implements ActionListener { + + + public tutti_gli_articoli_attivi_costo_action (AdminInterface in_location, JTextArea in_offers,String in_choice){ + location= in_location; + offers = in_offers; + choice = in_choice; + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + offers.setText(""); + load_catalogo.offerteAttive(login_data.getUsername(),offers,choice); + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private AdminInterface location; + private JTextArea offers; + private String choice; + } + //action listner added at offers declaration + + JMenuItem tutti_gli_articoli_scaduti = new JMenuItem("Tutti gli articoli Scaduti"); + class tutti_gli_articoli_scaduti_action implements ActionListener { + + + public tutti_gli_articoli_scaduti_action (AdminInterface in_location, JTextArea in_offers){ + location= in_location; + offers = in_offers; + + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + offers.setText(""); + load_catalogo.offerteScadute(login_data.getUsername(), offers); + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private AdminInterface location; + private JTextArea offers; + + } + + + + JMenu politicamenu = new JMenu("Politiche Sconto"); + JMenuItem sconto_totale_articoli = new JMenuItem("Sconto sul Totale Articoli"); + JMenuItem sconto_articoli_ultima_settimana = new JMenuItem("Sconto su Articoli Ultima Settimana"); + JMenuItem sconto_cene_50_ultima_settimana = new JMenuItem("Sconto per >50% Cene Vendute Ultima Settimana"); + + + mainmenu.add(filemenu); + mainmenu.add(searchmenu); + mainmenu.add(politicamenu); + + filemenu.add(logout_menu_item); + filemenu.add(quit_menu_item); + + searchmenu.add(tutti_gli_articoli_attivi_id); + searchmenu.add(tutti_gli_articoli_attivi_costo); + searchmenu.add(tutti_gli_articoli_scaduti); + + + + politicamenu.add(sconto_totale_articoli); + politicamenu.add(sconto_articoli_ultima_settimana); + politicamenu.add(sconto_cene_50_ultima_settimana); + + + + + JPanel AggiungiProdottiPanel = new JPanel(); + JLabel add_product_label = new JLabel("Aggiungi un nuovo Prodotto" ); + add_product_label.setPreferredSize(new Dimension(180,60)); + JButton aggiungi_bene = new JButton("Bene"); + JButton aggiungi_cena = new JButton("Cena"); + JButton aggiungi_vacanza = new JButton("Viaggio"); + JButton aggiungi_prestazione = new JButton("Prestazione"); + + + AggiungiProdottiPanel.add(add_product_label); + AggiungiProdottiPanel.add(aggiungi_bene); + AggiungiProdottiPanel.add(aggiungi_cena); + AggiungiProdottiPanel.add(aggiungi_vacanza); + AggiungiProdottiPanel.add(aggiungi_prestazione); + + + + + + + + + north.add(AggiungiProdottiPanel,BorderLayout.CENTER); + + mainWindow.add(north,BorderLayout.NORTH); + + + + + //////////////////////////////////////////////////// begin center area for all offers + + + JTextArea offers = new JTextArea(500,200); + offers.setText("Utilizza il menu Cerca per popolare questa lista"); + mainWindow.add(offers,BorderLayout.CENTER); + tutti_gli_articoli_attivi_id.addActionListener(new tutti_gli_articoli_attivi_id_action(this,offers,"0")); + tutti_gli_articoli_attivi_costo.addActionListener(new tutti_gli_articoli_attivi_costo_action(this,offers,"1")); + tutti_gli_articoli_scaduti.addActionListener(new tutti_gli_articoli_scaduti_action(this,offers)); + + + + + JPanel acquista_panel = new JPanel(); + + JLabel idlabel = new JLabel("ID"); + JTextField id = new JTextField(5); + JButton rimuovi_prodotto = new JButton("Rimuovi Prodotto"); + + + /////old class to replace with rimuovi prodotto + class aggiungi_al_carrello_action implements ActionListener { + + + public aggiungi_al_carrello_action (AdminInterface in_location, JTextField in_id, JTextArea in_offers, JLabel in_count){ + id = in_id; + location= in_location; + offers = in_offers; + count = in_count; + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + + if (offers.getText().isEmpty()){ + JOptionPane.showMessageDialog(location, + "Dovresti prima aggiornare l'elenco delle offerte attive ", + "Error", + JOptionPane.ERROR_MESSAGE); + } else{ + + if (Integer.parseInt(id.getText()) >= 0 ){ + int found = load_catalogo.search_product_id(login_data.getUsername(),id.getText()); + if (found > -1){ + Carrello.add(load_catalogo.getCatalogo().get(found)); + count.setText(" Corrello: " + Carrello.size() + " Prodotti"); + + }else{ + JOptionPane.showMessageDialog(location, + "Impossibile aggiungere il prodotto indicato ", + "Error", + JOptionPane.ERROR_MESSAGE); + } + + + }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); + + } + + + + + } + + private JTextField id; + private AdminInterface location; + private JTextArea offers; + private JLabel count; + } + rimuovi_prodotto.addActionListener(new aggiungi_al_carrello_action(this,id,offers,idlabel)); + + + + acquista_panel.add(idlabel); + acquista_panel.add(id); + acquista_panel.add(rimuovi_prodotto); + + + + mainWindow.add(acquista_panel,BorderLayout.SOUTH); + + + + + setSize(600, 400); + setLocation(login_window.getLocation()); + setTitle("Admin Logged"); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + } + + + ArrayList Carrello = new ArrayList(); + LoginWindow login_window; + Catalogo load_catalogo; + LoginData login_data; + + } diff --git a/it/unisa/info13d/Gui/LoginWindow.java b/it/unisa/info13d/Gui/LoginWindow.java index 17f7eb0..2974a48 100644 --- a/it/unisa/info13d/Gui/LoginWindow.java +++ b/it/unisa/info13d/Gui/LoginWindow.java @@ -88,7 +88,7 @@ public class LoginWindow extends JFrame { Catalogo load_catalogo = new Catalogo(); if (login.getType().equals("Admin")){ actual.setVisible(false); - //AdminInterface a = new AdminInterface(actual,load_catalogo,login); + AdminInterface a = new AdminInterface(actual,load_catalogo,login); }else{ actual.setVisible(false); UserInterface c = new UserInterface(actual,load_catalogo,login); diff --git a/it/unisa/info13d/Gui/UserInterface.java b/it/unisa/info13d/Gui/UserInterface.java index e8a1b64..2b0c78f 100644 --- a/it/unisa/info13d/Gui/UserInterface.java +++ b/it/unisa/info13d/Gui/UserInterface.java @@ -13,6 +13,7 @@ import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.GregorianCalendar; import java.util.concurrent.Callable; /** @@ -95,7 +96,7 @@ public class UserInterface extends JFrame{ public void actionPerformed(ActionEvent e) { try{ offers.setText(""); - load_catalogo.offerteAttive(login_data.getUsername(),offers); + load_catalogo.offerteAttive(login_data.getUsername(),offers,"0"); } catch (FileNotFoundException err){} @@ -107,12 +108,176 @@ public class UserInterface extends JFrame{ private UserInterface location; private JTextArea offers; } - //action listner for tutti_gli_articoli_attivi added at offers declaration + //action listner added at offers declaration JMenuItem articoli_con_scadenza_menu_item = new JMenuItem("Articoli con Scadenza"); + class tutti_gli_articoli_con_scadenza_action implements ActionListener { + + + public tutti_gli_articoli_con_scadenza_action (UserInterface in_location, JTextArea in_offers){ + location= in_location; + offers = in_offers; + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + offers.setText(""); + + + JPanel showInput = new JPanel(); + JLabel field1l = new JLabel("Data Start"); + JTextField field1 = new JTextField(10); + field1.setText("GG/MM/AAAA"); + JLabel field2l = new JLabel("Data Fine"); + JTextField field2 = new JTextField(10); + field2.setText("GG/MM/AAAA"); + showInput.add(field1l); + showInput.add(field1); + showInput.add(field2l); + showInput.add(field2); + JOptionPane.showMessageDialog(location, showInput); + + String marcatore="/"; + String data = field1.getText(); + String temp[]; + temp = data.split(marcatore); + GregorianCalendar dataPartenza = new GregorianCalendar((Integer.parseInt(temp[2])),(Integer.parseInt(temp[1]))-1,(Integer.parseInt(temp[0]))); + + String data2 = field2.getText(); + String temp2[]; + temp2 = data2.split(marcatore); + GregorianCalendar dataScad = new GregorianCalendar((Integer.parseInt(temp2[2])),(Integer.parseInt(temp2[1]))-1,(Integer.parseInt(temp2[0]))); + + + + load_catalogo.offerteAttiveConScadenza(login_data.getUsername(), offers, "0",dataPartenza,dataScad); + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private UserInterface location; + private JTextArea offers; + } + //action listner added at offers declaration + JMenuItem articoli_senza_scadenza_menu_item = new JMenuItem("Articoli senza Scadenza"); + class tutti_gli_articoli_senza_scadenza_action implements ActionListener { + + + public tutti_gli_articoli_senza_scadenza_action (UserInterface in_location, JTextArea in_offers){ + location= in_location; + offers = in_offers; + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + offers.setText(""); + + + int valutazione = Integer.parseInt( + JOptionPane.showInputDialog( + location, "Inserire valutazione fornitore","Valutazione")); + + + + load_catalogo.offerteAttiveSenzaScadenza(login_data.getUsername(), offers, "0", valutazione); + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private UserInterface location; + private JTextArea offers; + } + //action listner added at offers declaration JMenu visualizzamenu = new JMenu("Visualizza"); - JMenuItem storico_menu_item = new JMenuItem("Storico Utente"); + JMenuItem storico_data_menu_item = new JMenuItem("Storico Utente per Data"); + class storico_data_menu_item_action implements ActionListener { + + + public storico_data_menu_item_action (UserInterface in_location){ + location= in_location; + + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + + + + JPanel show_storico = new JPanel(); + JTextArea area_storico = new JTextArea(10,15); + + + show_storico.add(area_storico); + load_catalogo.visualizzaStorico(login_data.getUsername(),"1",area_storico); + + JOptionPane.showMessageDialog(location, show_storico); + + + + + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private UserInterface location; + + } + storico_data_menu_item.addActionListener(new storico_data_menu_item_action(this)); + JMenuItem storico_costo_menu_item = new JMenuItem("Storico Utente per Costo"); + class storico_costo_menu_item_action implements ActionListener { + + + public storico_costo_menu_item_action (UserInterface in_location){ + location= in_location; + + } + + @Override + public void actionPerformed(ActionEvent e) { + try{ + + + + JPanel show_storico = new JPanel(); + JTextArea area_storico = new JTextArea(10,15); + + + show_storico.add(area_storico); + load_catalogo.visualizzaStorico(login_data.getUsername(),"2",area_storico); + + JOptionPane.showMessageDialog(location, show_storico); + + + + + + } + catch (FileNotFoundException err){} + catch (IOException err){} + catch (ClassNotFoundException err){} + + } + + private UserInterface location; + + } + storico_costo_menu_item.addActionListener(new storico_costo_menu_item_action(this)); mainmenu.add(filemenu); mainmenu.add(searchmenu); @@ -126,7 +291,8 @@ public class UserInterface extends JFrame{ searchmenu.add(articoli_senza_scadenza_menu_item); - visualizzamenu.add(storico_menu_item); + visualizzamenu.add(storico_data_menu_item); + visualizzamenu.add(storico_costo_menu_item); @@ -203,6 +369,8 @@ public class UserInterface extends JFrame{ offers.setText("Utilizza il menu Cerca per popolare questa lista"); mainWindow.add(offers,BorderLayout.CENTER); tutti_gli_articoli_attivi.addActionListener(new tutti_gli_articoli_attivi_action(this,offers)); + articoli_con_scadenza_menu_item.addActionListener(new tutti_gli_articoli_con_scadenza_action(this,offers)); + articoli_senza_scadenza_menu_item.addActionListener(new tutti_gli_articoli_senza_scadenza_action(this,offers));