Implementato il Login/Registrazione via GUI. Quasi completato la GUI lato utente. Manca la visualizzazione degli articoli con e senza scadenza con limiti (implementati ma senza actionlistner) e il visualizzo storico.
Da fixare anche il comparatore tra oggetti per la visualizzazione ordinata, bisogna aggiungere la classa prestazioni dopera.
This commit is contained in:
@@ -124,17 +124,6 @@ public class BeniDiConsumo extends Utilizzabile implements Serializable {
|
||||
@Override
|
||||
public double get_prezzo_scontato() {
|
||||
|
||||
GregorianCalendar dataOdierna = new GregorianCalendar();
|
||||
|
||||
long milliseconds1 = dataOdierna.getTimeInMillis();
|
||||
long milliseconds2 = scadenza.getTimeInMillis();
|
||||
|
||||
long diff = milliseconds2 - milliseconds1;
|
||||
long diffGiorni = diff / (24 * 60 * 60 * 1000); //differenza in giorni
|
||||
|
||||
if( diffGiorni<=7 )
|
||||
return prezzoBene - (prezzoBene*0.10) ; //Prezzo scontato
|
||||
else
|
||||
return prezzoBene; //Nessuno sconto applicabile
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,23 @@ public class Global {
|
||||
/**
|
||||
* E' il contatore statico privato
|
||||
*/
|
||||
|
||||
public static void set_sconto_min_articoli (int num, double sconto){
|
||||
min_num_articoli_per_sconto = num;
|
||||
sconto_per_min_num_articoli = sconto;
|
||||
}
|
||||
|
||||
public static int getMin_num_articoli_per_sconto() {
|
||||
return min_num_articoli_per_sconto;
|
||||
}
|
||||
|
||||
public static double getSconto_per_min_num_articoli() {
|
||||
return sconto_per_min_num_articoli;
|
||||
}
|
||||
|
||||
private static int min_num_articoli_per_sconto = 0;
|
||||
private static double sconto_per_min_num_articoli = 0;
|
||||
|
||||
private static int general_counter;
|
||||
|
||||
|
||||
|
||||
@@ -34,9 +34,6 @@ public class PrestazioniDopera extends Utilizzabile {
|
||||
return idPrOpera;
|
||||
}
|
||||
|
||||
public void setIdPrOpera(int idPrOpera) {
|
||||
this.idPrOpera = idPrOpera;
|
||||
}
|
||||
|
||||
public int getGiudizioFornitore() {
|
||||
return giudizioFornitore;
|
||||
@@ -50,8 +47,8 @@ public class PrestazioniDopera extends Utilizzabile {
|
||||
return prestazioniVendute;
|
||||
}
|
||||
|
||||
public void setPrestazioniVendute(int prestazioniVendute) {
|
||||
this.prestazioniVendute = prestazioniVendute;
|
||||
public void setPrestazioniVendute() {
|
||||
prestazioniVendute++;
|
||||
}
|
||||
|
||||
public double getPrezzoPrestazione() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package it.unisa.info13d.Articoli;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
@@ -8,7 +10,7 @@ package it.unisa.info13d.Articoli;
|
||||
*/
|
||||
|
||||
|
||||
public abstract class Utilizzabile {
|
||||
public abstract class Utilizzabile implements Serializable {
|
||||
|
||||
public abstract boolean eAcquistabile();
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AdminSession {
|
||||
catalogo.cancellaProdotto();
|
||||
break;
|
||||
case "3":
|
||||
catalogo.offerteAttive(username);
|
||||
//catalogo.offerteAttive(username);
|
||||
break;
|
||||
case "4":
|
||||
catalogo.offerteScadute(username);
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.unisa.info13d.GestioneCatalogo;
|
||||
import java.util.*;
|
||||
|
||||
import it.unisa.info13d.Articoli.*;
|
||||
import it.unisa.info13d.Gui.UserInterface;
|
||||
import it.unisa.info13d.Login.Access;
|
||||
import it.unisa.info13d.Login.Entry;
|
||||
import it.unisa.info13d.Utility.IdCounter;
|
||||
@@ -11,6 +12,7 @@ import it.unisa.info13d.Login.LoggedUser;
|
||||
import it.unisa.info13d.Login.LoginData;
|
||||
import it.unisa.info13d.Login.StoricoItem;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -173,7 +175,7 @@ public class Catalogo{
|
||||
String qntMag = inputData.nextLine();
|
||||
int qnt_mag = Integer.parseInt(prezzoBene);
|
||||
|
||||
catalogoOfferte.add(new BeniDiConsumo(Global.get_next_id(), descrizioneBene, prezzo_bene, qnt_mag));
|
||||
catalogoOfferte.add(new BeniDiConsumo(Global.get_next_id(), descrizioneBene, prezzo_bene, qnt_mag,"fornitore",5));
|
||||
store_data();
|
||||
break;
|
||||
}
|
||||
@@ -194,18 +196,18 @@ public class Catalogo{
|
||||
if(deal instanceof Vacanze)
|
||||
{
|
||||
Vacanze dealVacanza = (Vacanze)deal;
|
||||
visualizzaVacanza(dealVacanza);
|
||||
//visualizzaVacanza(dealVacanza);
|
||||
|
||||
}
|
||||
else if(deal instanceof BeniDiConsumo)
|
||||
{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)deal;
|
||||
visualizzaBene(dealBene);
|
||||
//visualizzaBene(dealBene);
|
||||
}
|
||||
else if(deal instanceof CeneInRistoranti)
|
||||
{
|
||||
CeneInRistoranti dealCena = (CeneInRistoranti)deal;
|
||||
visualizzaCena(dealCena);
|
||||
//visualizzaCena(dealCena);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +245,7 @@ public class Catalogo{
|
||||
*
|
||||
* @param a
|
||||
*/
|
||||
public void print_cat_admin (ArrayList<Utilizzabile> a){
|
||||
public void print_cat_admin (ArrayList<Utilizzabile> a,JTextArea show_offers){
|
||||
for(Utilizzabile deal: a)
|
||||
{
|
||||
if(deal instanceof Vacanze)
|
||||
@@ -251,7 +253,7 @@ public class Catalogo{
|
||||
Vacanze dealVacanza = (Vacanze)deal;
|
||||
if((dealVacanza.eAcquistabile()))
|
||||
{
|
||||
visualizzaVacanza(dealVacanza);
|
||||
visualizzaVacanza(dealVacanza, show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -260,7 +262,7 @@ public class Catalogo{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)deal;
|
||||
if((dealBene.eAcquistabile()))
|
||||
{
|
||||
visualizzaBene(dealBene);
|
||||
visualizzaBene(dealBene,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -270,7 +272,16 @@ public class Catalogo{
|
||||
|
||||
if((dealCena.eAcquistabile()))
|
||||
{
|
||||
visualizzaCena(dealCena);
|
||||
visualizzaCena(dealCena,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(deal instanceof PrestazioniDopera)
|
||||
{
|
||||
PrestazioniDopera dealP = (PrestazioniDopera)deal;
|
||||
if((deal.eAcquistabile()))
|
||||
{
|
||||
visualizzaPrestazione(dealP,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -283,7 +294,7 @@ public class Catalogo{
|
||||
* @param a
|
||||
* @param location_user_to_compare
|
||||
*/
|
||||
public void print_cat_user (ArrayList<Utilizzabile> a, String location_user_to_compare){
|
||||
public void print_cat_user (ArrayList<Utilizzabile> a, String location_user_to_compare, JTextArea show_offers){
|
||||
for(Utilizzabile deal: a)
|
||||
{
|
||||
if(deal instanceof Vacanze)
|
||||
@@ -291,7 +302,7 @@ public class Catalogo{
|
||||
Vacanze dealVacanza = (Vacanze)deal;
|
||||
if((dealVacanza.eAcquistabile()))
|
||||
{
|
||||
visualizzaVacanza(dealVacanza);
|
||||
visualizzaVacanza(dealVacanza,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -300,7 +311,7 @@ public class Catalogo{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)deal;
|
||||
if((dealBene.eAcquistabile()))
|
||||
{
|
||||
visualizzaBene(dealBene);
|
||||
visualizzaBene(dealBene,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -310,7 +321,16 @@ public class Catalogo{
|
||||
|
||||
if((dealCena.eAcquistabile() && dealCena.getLuogo().equals(location_user_to_compare )))
|
||||
{
|
||||
visualizzaCena(dealCena);
|
||||
visualizzaCena(dealCena,show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(deal instanceof PrestazioniDopera)
|
||||
{
|
||||
PrestazioniDopera dealP = (PrestazioniDopera)deal;
|
||||
if((deal.eAcquistabile()))
|
||||
{
|
||||
visualizzaPrestazione(dealP, show_offers);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -336,7 +356,7 @@ public class Catalogo{
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void offerteAttive(String user) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
public void offerteAttive(String user, JTextArea show_offers) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
{
|
||||
Entry loggedUser = Access.get_user_data(user);
|
||||
if(!(loggedUser.getType()))
|
||||
@@ -447,7 +467,7 @@ public class Catalogo{
|
||||
}
|
||||
|
||||
Collections.sort(catalogoOfferte,new CompareDataScadenza());
|
||||
print_cat_admin (catalogoOfferte);
|
||||
print_cat_admin (catalogoOfferte,show_offers);
|
||||
}else{
|
||||
|
||||
class CompareID implements Comparator<Utilizzabile> {
|
||||
@@ -540,7 +560,7 @@ public class Catalogo{
|
||||
|
||||
|
||||
Collections.sort(catalogoOfferte,new CompareID());
|
||||
print_cat_admin (catalogoOfferte);
|
||||
print_cat_admin (catalogoOfferte,show_offers);
|
||||
|
||||
}
|
||||
|
||||
@@ -637,7 +657,7 @@ public class Catalogo{
|
||||
|
||||
|
||||
Collections.sort(catalogoOfferte,new CompareIDUser());
|
||||
print_cat_user(catalogoOfferte,loggedUser.getLocation());
|
||||
print_cat_user(catalogoOfferte,loggedUser.getLocation(),show_offers);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -657,17 +677,17 @@ public class Catalogo{
|
||||
if(deal instanceof Vacanze)
|
||||
{
|
||||
Vacanze dealVacanza = (Vacanze)deal;
|
||||
if(!(dealVacanza.eAcquistabile())) {visualizzaVacanza(dealVacanza);continue;}
|
||||
//if(!(dealVacanza.eAcquistabile())) {visualizzaVacanza(dealVacanza);continue;}
|
||||
}
|
||||
if(deal instanceof BeniDiConsumo)
|
||||
{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)deal;
|
||||
if(!(dealBene.eAcquistabile())) {visualizzaBene(dealBene);continue;}
|
||||
//if(!(dealBene.eAcquistabile())) {visualizzaBene(dealBene);continue;}
|
||||
}
|
||||
if(deal instanceof CeneInRistoranti)
|
||||
{
|
||||
CeneInRistoranti dealCena = (CeneInRistoranti)deal;
|
||||
if(!(dealCena.eAcquistabile())) {visualizzaCena(dealCena);continue;}
|
||||
//if(!(dealCena.eAcquistabile())) {visualizzaCena(dealCena);continue;}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,17 +698,13 @@ public class Catalogo{
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void aggiungiCredito(String user) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
public void aggiungiCredito(String user, String in_double) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
{
|
||||
Entry loggedUser = Access.get_user_data(user);
|
||||
System.out.println("----- Acquisto Credito -----");
|
||||
System.out.println("Saldo Attuale:"+ loggedUser.getBalance());
|
||||
System.out.println("Aggiungi importo da ricaricare:");
|
||||
Scanner inputData = new Scanner(System.in);
|
||||
String euro = inputData.nextLine();
|
||||
|
||||
String euro = in_double;
|
||||
loggedUser.setBalance(Double.parseDouble(euro));
|
||||
Access.replace_data(user, loggedUser);
|
||||
System.out.println("Saldo attuale: "+loggedUser.getBalance());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -699,61 +715,140 @@ public class Catalogo{
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void acquistaProdotto(String user) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
public boolean acquistaProdotti(String user, ArrayList<Utilizzabile> Carrello) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
{
|
||||
Entry loggedUser = Access.get_user_data(user);
|
||||
System.out.println("----- Shop ----");
|
||||
System.out.println("### Prodotti ###");
|
||||
|
||||
offerteAttive(user);
|
||||
|
||||
System.out.println("Offerta da acquistare[inserisci id]: ");
|
||||
Scanner inputData = new Scanner(System.in);
|
||||
String idProd = inputData.nextLine();
|
||||
int idDel = Integer.parseInt(idProd);
|
||||
|
||||
boolean trovato=false;
|
||||
ArrayList<StoricoItem> storico = loggedUser.getStorico();
|
||||
|
||||
for(Utilizzabile dealsc: catalogoOfferte)
|
||||
double totale = 0;
|
||||
|
||||
for(Utilizzabile dealsc: Carrello)
|
||||
{
|
||||
if(dealsc instanceof Vacanze)
|
||||
{
|
||||
Vacanze dealVacanza = (Vacanze)dealsc;
|
||||
totale += dealVacanza.get_prezzo_scontato();
|
||||
}
|
||||
if(dealsc instanceof BeniDiConsumo)
|
||||
{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)dealsc;
|
||||
totale += dealBene.get_prezzo_scontato();
|
||||
|
||||
}
|
||||
if( dealsc instanceof CeneInRistoranti)
|
||||
{
|
||||
CeneInRistoranti dealCena = (CeneInRistoranti)dealsc;
|
||||
totale += dealCena.get_prezzo_scontato();
|
||||
}
|
||||
|
||||
if( dealsc instanceof PrestazioniDopera)
|
||||
{
|
||||
PrestazioniDopera deal = (PrestazioniDopera)dealsc;
|
||||
totale += deal.get_prezzo_scontato();
|
||||
}
|
||||
}
|
||||
|
||||
if (Carrello.size() >= Global.getMin_num_articoli_per_sconto()){
|
||||
totale = totale - (totale * Global.getSconto_per_min_num_articoli());
|
||||
}
|
||||
|
||||
if (totale <= loggedUser.getBalance()){
|
||||
|
||||
for(Utilizzabile dealsc: Carrello)
|
||||
{
|
||||
if(dealsc instanceof Vacanze)
|
||||
{
|
||||
Vacanze dealVacanza = (Vacanze)dealsc;
|
||||
|
||||
storico.add(new StoricoItem("Viaggio: "+dealVacanza.getLocalitaViaggio(), new GregorianCalendar() ,dealVacanza.get_prezzo_scontato()));
|
||||
dealVacanza.setViaggiVenduti();
|
||||
store_data();
|
||||
Access.replace_data(user, loggedUser);
|
||||
|
||||
}
|
||||
if(dealsc instanceof BeniDiConsumo)
|
||||
{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)dealsc;
|
||||
|
||||
storico.add(new StoricoItem("Prodotto: "+dealBene.getDescrizioneBene(), new GregorianCalendar() ,dealBene.get_prezzo_scontato()));
|
||||
dealBene.setBeniVenduti();
|
||||
Access.replace_data(user, loggedUser);
|
||||
store_data();
|
||||
|
||||
|
||||
|
||||
}
|
||||
if (dealsc instanceof CeneInRistoranti)
|
||||
{
|
||||
CeneInRistoranti dealCena = (CeneInRistoranti)dealsc;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
if (dealsc instanceof PrestazioniDopera)
|
||||
{
|
||||
PrestazioniDopera deal = (PrestazioniDopera)dealsc;
|
||||
|
||||
storico.add(new StoricoItem("Prestazione d'opera "+deal.getDescrizione(), new GregorianCalendar() ,deal.get_prezzo_scontato()));
|
||||
deal.setPrestazioniVendute();
|
||||
Access.replace_data(user, loggedUser);
|
||||
store_data();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
loggedUser.setBalance(loggedUser.getBalance() - totale);
|
||||
Access.replace_data(user, loggedUser);
|
||||
store_data();
|
||||
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int search_product_id(String user, String in_id) throws FileNotFoundException, ClassNotFoundException, IOException
|
||||
{
|
||||
Entry loggedUser = Access.get_user_data(user);
|
||||
//System.out.println("----- Shop ----");
|
||||
//System.out.println("### Prodotti ###");
|
||||
|
||||
|
||||
//System.out.println("Offerta da acquistare[inserisci id]: ");
|
||||
String idProd = in_id;
|
||||
int idDel = Integer.parseInt(idProd);
|
||||
|
||||
int trovato = -1;
|
||||
|
||||
for( int i= 0; i< catalogoOfferte.size() ;i++)
|
||||
{
|
||||
Utilizzabile dealsc = catalogoOfferte.get(i);
|
||||
if((dealsc instanceof Vacanze) && ((Vacanze)dealsc).getIdViaggio()==idDel)
|
||||
{
|
||||
Vacanze dealVacanza = (Vacanze)dealsc;
|
||||
if(dealVacanza.eAcquistabile() && loggedUser.getBalance()>=dealVacanza.getPrezzoPSingola())
|
||||
if(dealVacanza.eAcquistabile() )
|
||||
{
|
||||
trovato=true;
|
||||
storico.add(new StoricoItem("Viaggio: "+dealVacanza.getLocalitaViaggio(), new GregorianCalendar() ,dealVacanza.getPrezzoPSingola()));
|
||||
dealVacanza.setViaggiVenduti();
|
||||
loggedUser.setBalance((dealVacanza.getPrezzoPSingola() * (-1)));
|
||||
store_data();
|
||||
Access.replace_data(user, loggedUser);
|
||||
System.out.println("************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
|
||||
trovato=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
|
||||
trovato=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((dealsc instanceof BeniDiConsumo) && ((BeniDiConsumo) dealsc).getIdBene()==idDel)
|
||||
{
|
||||
BeniDiConsumo dealBene = (BeniDiConsumo)dealsc;
|
||||
if(dealBene.eAcquistabile() && loggedUser.getBalance()>=dealBene.getPrezzoBene())
|
||||
if(dealBene.eAcquistabile() )
|
||||
{
|
||||
trovato=true;
|
||||
storico.add(new StoricoItem("Prodotto: "+dealBene.getDescrizioneBene(), new GregorianCalendar() ,dealBene.getPrezzoBene()));
|
||||
dealBene.setBeniVenduti();
|
||||
loggedUser.setBalance((dealBene.getPrezzoBene() * (-1)));
|
||||
Access.replace_data(user, loggedUser);
|
||||
store_data();
|
||||
System.out.println("************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
|
||||
trovato=i;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
|
||||
trovato=true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -761,25 +856,31 @@ public class Catalogo{
|
||||
if( (dealsc instanceof CeneInRistoranti) && ((CeneInRistoranti) dealsc).getIdCena()==idDel)
|
||||
{
|
||||
CeneInRistoranti dealCena = (CeneInRistoranti)dealsc;
|
||||
if(dealCena.eAcquistabile() && loggedUser.getBalance()>=dealCena.getCostoPerPersona())
|
||||
if(dealCena.eAcquistabile() )
|
||||
{
|
||||
trovato=true;
|
||||
storico.add(new StoricoItem("Cena ristorante "+dealCena.getNomeRistorante()+" "+dealCena.getDescrizione_cena(), new GregorianCalendar() ,dealCena.getCostoPerPersona()));
|
||||
dealCena.setCeneVendute();
|
||||
loggedUser.setBalance((dealCena.getCostoPerPersona() * (-1)));
|
||||
Access.replace_data(user, loggedUser);
|
||||
store_data();
|
||||
System.out.println("*************************************\nAcquisto completato con successo! \n************************************\nSaldo Attuale:" + loggedUser.getBalance());
|
||||
trovato=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Il prodotto non e' acquistabile e/o Credito insufficiente, ricaricare");
|
||||
trovato=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( (dealsc instanceof PrestazioniDopera) && ((PrestazioniDopera) dealsc).getIdPrOpera()==idDel)
|
||||
{
|
||||
PrestazioniDopera deal = (PrestazioniDopera)dealsc;
|
||||
if(deal.eAcquistabile() )
|
||||
{
|
||||
trovato=i;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!trovato) System.out.println("### Prodotto non presente nel catalogo");
|
||||
return trovato;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -861,7 +962,7 @@ public class Catalogo{
|
||||
*
|
||||
* @param dealVacanza - oggetto di tipo Vacanze che rappresenta l'offerta della Vacanza da visualizzare
|
||||
*/
|
||||
public void visualizzaVacanza(Vacanze dealVacanza)
|
||||
public void visualizzaVacanza(Vacanze dealVacanza, JTextArea show)
|
||||
{
|
||||
GregorianCalendar partenza = dealVacanza.getDataPartenzaViaggio();
|
||||
int giornoP = partenza.get(Calendar.DAY_OF_MONTH);
|
||||
@@ -872,7 +973,7 @@ public class Catalogo{
|
||||
int meseS = scadenza.get(Calendar.MONTH);
|
||||
int annoS = scadenza.get(Calendar.YEAR);
|
||||
|
||||
System.out.println("#Vacanza-"+dealVacanza.getIdViaggio()+"# Scadenza: "+giornoS+"/"+(meseS+1)+"/"+annoS+"| Localita: "+dealVacanza.getLocalitaViaggio()+"| Partenza: "+giornoP+"/"+(meseP+1)+"/"+annoP+"| Prezzo Pers. Singola: "+dealVacanza.getPrezzoPSingola()+"\n--");
|
||||
show.append("#Vacanza-"+dealVacanza.getIdViaggio()+"# Scadenza: "+giornoS+"/"+(meseS+1)+"/"+annoS+"| Localita: "+dealVacanza.getLocalitaViaggio()+"| Partenza: "+giornoP+"/"+(meseP+1)+"/"+annoP+"| Prezzo Pers. Singola: "+dealVacanza.getPrezzoPSingola()+"\n--");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -881,9 +982,14 @@ public class Catalogo{
|
||||
* @param dealBene - oggetto di tipo beniDiConsumo che rappresenta l'offerta del bene da visualizzare
|
||||
*/
|
||||
|
||||
public void visualizzaBene(BeniDiConsumo dealBene)
|
||||
public void visualizzaBene(BeniDiConsumo dealBene, JTextArea show)
|
||||
{
|
||||
System.out.println("#Articolo-"+dealBene.getIdBene()+"# Descrizione: "+dealBene.getDescrizioneBene()+" Prezzo: "+dealBene.getPrezzoBene()+"| Quantita in magazzino: "+dealBene.getBeniInStock()+"\n--");
|
||||
show.append("#Articolo-" + dealBene.getIdBene() + "# Descrizione: " + dealBene.getDescrizioneBene() + " Prezzo: " + dealBene.getPrezzoBene() + "| Quantita in magazzino: " + dealBene.getBeniInStock() + "| Fornitore: " + dealBene.getFornitore() + "| Giudizio: +" + dealBene.getGiudizioFornitore() + "\n--");
|
||||
}
|
||||
|
||||
public void visualizzaPrestazione(PrestazioniDopera deal, JTextArea show)
|
||||
{
|
||||
show.append("#Articolo-" + deal.getIdPrOpera() + "# Descrizione: " + deal.getDescrizione() + " Prezzo: " + deal.getPrezzoPrestazione() + "| Fornitore: " + deal.getFornitore() + "| Giudizio: +" + deal.getGiudizioFornitore() + "\n--");
|
||||
}
|
||||
|
||||
|
||||
@@ -892,13 +998,13 @@ public class Catalogo{
|
||||
* Questo metodo visualizza una cena, descrivendone i suoi dati.
|
||||
* @param dealCena - oggetto di tipo CeneInRistoranti che rappresenta l'offerta della cena da visualizzare
|
||||
*/
|
||||
public void visualizzaCena(CeneInRistoranti dealCena)
|
||||
public void visualizzaCena(CeneInRistoranti dealCena, JTextArea show)
|
||||
{
|
||||
GregorianCalendar scadenzaCena = dealCena.getDataScadenzaOffertaCena();
|
||||
int giornoSC = scadenzaCena.get(Calendar.DAY_OF_MONTH);
|
||||
int meseSC = scadenzaCena.get(Calendar.MONTH);
|
||||
int annoSC = scadenzaCena.get(Calendar.YEAR);
|
||||
System.out.println("#Cena-"+dealCena.getIdCena()+"# Scadenza:"+giornoSC+"/"+(meseSC+1)+"/"+annoSC+"| Ristorante: "+dealCena.getNomeRistorante()+"| Indirizzo: "+dealCena.getLuogo()+"| Descrizione: "+dealCena.getDescrizione_cena()+"| Costo: "+dealCena.getCostoPerPersona()+"| Disponibilita:"+dealCena.getNumCenedaVendere()+"cene"+"\n--");
|
||||
show.append("#Cena-" + dealCena.getIdCena() + "# Scadenza:" + giornoSC + "/" + (meseSC + 1) + "/" + annoSC + "| Ristorante: " + dealCena.getNomeRistorante() + "| Indirizzo: " + dealCena.getLuogo() + "| Descrizione: " + dealCena.getDescrizione_cena() + "| Costo: " + dealCena.getCostoPerPersona() + "| Disponibilita:" + dealCena.getNumCenedaVendere() + "cene" + "\n--");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,19 +46,19 @@ public class ClientSession {
|
||||
switch(sceltaMenu)
|
||||
{
|
||||
case "1":
|
||||
catalogo.aggiungiCredito(username);
|
||||
//catalogo.aggiungiCredito(username);
|
||||
break;
|
||||
case "2":
|
||||
catalogo.offerteAttive(username);
|
||||
//catalogo.offerteAttive(username);
|
||||
break;
|
||||
case "3":
|
||||
catalogo.acquistaProdotto(username);
|
||||
//catalogo.acquistaProdotto(username);
|
||||
break;
|
||||
case "4":
|
||||
catalogo.visualizzaStorico(username);
|
||||
break;
|
||||
case "5":
|
||||
r.reshow = false;
|
||||
// r.reshow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
12
it/unisa/info13d/Gui/AdminInterface.java
Normal file
12
it/unisa/info13d/Gui/AdminInterface.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package it.unisa.info13d.Gui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 19/01/14
|
||||
* Time: 19.05
|
||||
*/
|
||||
public class AdminInterface extends JFrame {
|
||||
}
|
||||
160
it/unisa/info13d/Gui/LoginWindow.java
Normal file
160
it/unisa/info13d/Gui/LoginWindow.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package it.unisa.info13d.Gui;
|
||||
|
||||
import it.unisa.info13d.Login.Access;
|
||||
import it.unisa.info13d.Login.LoginData;
|
||||
import it.unisa.info13d.GestioneCatalogo.*;
|
||||
|
||||
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.text.ParseException;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 19/01/14
|
||||
* Time: 16.25
|
||||
*/
|
||||
public class LoginWindow extends JFrame {
|
||||
|
||||
public LoginWindow () {
|
||||
|
||||
JPanel mainWindow = new JPanel();
|
||||
mainWindow.setLayout(new BorderLayout());
|
||||
add(mainWindow);
|
||||
|
||||
JPanel center_panel = new JPanel();
|
||||
center_panel.setLayout(new BoxLayout(center_panel, BoxLayout.PAGE_AXIS) );
|
||||
mainWindow.add(center_panel,BorderLayout.CENTER);
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel user_panel = new JPanel();
|
||||
center_panel.add(user_panel);
|
||||
|
||||
JPanel pass_panel = new JPanel();
|
||||
center_panel.add(pass_panel);
|
||||
|
||||
|
||||
JLabel userl = new JLabel("User ");
|
||||
JTextField usert= new JTextField(10);
|
||||
|
||||
JLabel passl = new JLabel("Password");
|
||||
JPasswordField passt= new JPasswordField(10);
|
||||
|
||||
|
||||
user_panel.add(userl);
|
||||
user_panel.add(usert);
|
||||
pass_panel.add(passl);
|
||||
pass_panel.add(passt);
|
||||
|
||||
|
||||
|
||||
JPanel buttons_panel = new JPanel();
|
||||
|
||||
|
||||
JButton submit_login = new JButton("Login");
|
||||
JButton submit_register = new JButton("Go to Register Form");
|
||||
|
||||
center_panel.add(buttons_panel);
|
||||
|
||||
buttons_panel.add(submit_login);
|
||||
buttons_panel.add(submit_register);
|
||||
|
||||
|
||||
class login_action implements ActionListener {
|
||||
|
||||
|
||||
public login_action (LoginWindow in_actual,JTextField in_name, JPasswordField in_password, JTextField in_location, boolean in_action){
|
||||
name = in_name;
|
||||
password = in_password;
|
||||
location = in_location;
|
||||
action = in_action;
|
||||
actual = in_actual;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
if (Access.search_username(name.getText(),String.valueOf(password.getPassword()))){
|
||||
LoginData login = new LoginData(name.getText(),String.valueOf(password.getPassword()),location.getText(),action);
|
||||
Catalogo load_catalogo = new Catalogo();
|
||||
if (login.getType().equals("Admin")){
|
||||
actual.setVisible(false);
|
||||
//AdminInterface a = new AdminInterface(actual,load_catalogo,login);
|
||||
}else{
|
||||
actual.setVisible(false);
|
||||
UserInterface c = new UserInterface(actual,load_catalogo,login);
|
||||
}
|
||||
|
||||
|
||||
} else{
|
||||
|
||||
JOptionPane.showMessageDialog(actual,
|
||||
"User e/o Pass Inesistenti ",
|
||||
"Login Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
catch (FileNotFoundException err){}
|
||||
catch (IOException err){}
|
||||
catch (ClassNotFoundException err){}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private JTextField name;
|
||||
private JPasswordField password;
|
||||
private JTextField location;
|
||||
private boolean action;
|
||||
private LoginWindow actual;
|
||||
|
||||
|
||||
}
|
||||
class register_action implements ActionListener {
|
||||
|
||||
|
||||
public register_action (LoginWindow in_w){
|
||||
w = in_w;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
w.setVisible(false);
|
||||
RegisterWindow r = new RegisterWindow(w,w.getLocation());
|
||||
}
|
||||
|
||||
LoginWindow w;
|
||||
|
||||
|
||||
}
|
||||
submit_login.addActionListener(new login_action(this,usert,passt,usert,false));
|
||||
submit_register.addActionListener(new register_action(this));
|
||||
|
||||
|
||||
|
||||
setSize(250, 130);
|
||||
setLocation(150, 150);
|
||||
setTitle("Exam APP");
|
||||
setVisible(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
166
it/unisa/info13d/Gui/RegisterWindow.java
Normal file
166
it/unisa/info13d/Gui/RegisterWindow.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package it.unisa.info13d.Gui;
|
||||
|
||||
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.text.ParseException;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 19/01/14
|
||||
* Time: 16.25
|
||||
*/
|
||||
public class RegisterWindow extends JFrame {
|
||||
|
||||
public RegisterWindow( LoginWindow in_back, Point in_point ) {
|
||||
|
||||
setLocation(in_point);
|
||||
back = in_back;
|
||||
|
||||
JPanel mainWindow = new JPanel();
|
||||
mainWindow.setLayout(new BorderLayout());
|
||||
add(mainWindow);
|
||||
|
||||
JPanel center_panel = new JPanel();
|
||||
center_panel.setLayout(new BoxLayout(center_panel, BoxLayout.PAGE_AXIS) );
|
||||
mainWindow.add(center_panel,BorderLayout.CENTER);
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel user_panel = new JPanel();
|
||||
center_panel.add(user_panel);
|
||||
|
||||
JPanel pass_panel = new JPanel();
|
||||
center_panel.add(pass_panel);
|
||||
|
||||
JPanel location_panel = new JPanel();
|
||||
center_panel.add(location_panel);
|
||||
|
||||
|
||||
|
||||
JLabel userl = new JLabel("User ");
|
||||
JTextField usert= new JTextField(10);
|
||||
|
||||
JLabel passl = new JLabel("Password");
|
||||
JPasswordField passt= new JPasswordField(10);
|
||||
|
||||
JLabel locationl = new JLabel("Location ");
|
||||
JTextField locationt= new JTextField(10);
|
||||
|
||||
|
||||
user_panel.add(userl);
|
||||
user_panel.add(usert);
|
||||
pass_panel.add(passl);
|
||||
pass_panel.add(passt);
|
||||
location_panel.add(locationl);
|
||||
location_panel.add(locationt);
|
||||
|
||||
|
||||
|
||||
JPanel buttons_panel = new JPanel();
|
||||
|
||||
|
||||
JButton submit_register = new JButton("Register");
|
||||
JButton submit_back = new JButton("Back");
|
||||
|
||||
center_panel.add(buttons_panel);
|
||||
|
||||
buttons_panel.add(submit_register);
|
||||
buttons_panel.add(submit_back);
|
||||
|
||||
|
||||
class register_action implements ActionListener {
|
||||
|
||||
|
||||
public register_action (RegisterWindow in_actual,JTextField in_name, JPasswordField in_password, JTextField in_location, boolean in_action){
|
||||
name = in_name;
|
||||
password = in_password;
|
||||
location = in_location;
|
||||
action = in_action;
|
||||
actual = in_actual;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
if ( location.getText().isEmpty() || name.getText().isEmpty() || String.valueOf(password.getPassword()).isEmpty() ){
|
||||
JOptionPane.showMessageDialog(actual,
|
||||
"Completare tutti i campi ",
|
||||
"Register Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} else{
|
||||
|
||||
LoginData login = new LoginData(name.getText(),String.valueOf(password.getPassword()),location.getText(),action);
|
||||
JOptionPane.showMessageDialog(actual,
|
||||
"Registrazione Completata",
|
||||
"registration",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
catch (FileNotFoundException err){}
|
||||
catch (IOException err){}
|
||||
catch (ClassNotFoundException err){}
|
||||
|
||||
}
|
||||
|
||||
private JTextField name;
|
||||
private JPasswordField password;
|
||||
private JTextField location;
|
||||
private boolean action;
|
||||
private RegisterWindow actual;
|
||||
|
||||
|
||||
}
|
||||
class back_action implements ActionListener {
|
||||
|
||||
|
||||
public back_action (LoginWindow in_back, RegisterWindow in_actual){
|
||||
back = in_back;
|
||||
actual = in_actual;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
actual.setVisible(false);
|
||||
back.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
LoginWindow back;
|
||||
RegisterWindow actual;
|
||||
|
||||
|
||||
}
|
||||
submit_register.addActionListener(new register_action(this,usert,passt,locationt,true));
|
||||
submit_back.addActionListener(new back_action(back,this));
|
||||
|
||||
|
||||
|
||||
setSize(220, 180);
|
||||
setTitle("Exam APP");
|
||||
setVisible(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
LoginWindow back;
|
||||
|
||||
}
|
||||
389
it/unisa/info13d/Gui/UserInterface.java
Normal file
389
it/unisa/info13d/Gui/UserInterface.java
Normal file
@@ -0,0 +1,389 @@
|
||||
package it.unisa.info13d.Gui;
|
||||
|
||||
import com.sun.deploy.panel.JavaPanel;
|
||||
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.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 19/01/14
|
||||
* Time: 19.19
|
||||
*/
|
||||
public class UserInterface extends JFrame{
|
||||
|
||||
|
||||
public UserInterface( 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 (UserInterface in_location){
|
||||
location= in_location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
|
||||
location.setVisible(false);
|
||||
login_window.setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private UserInterface 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 = new JMenuItem("Tutti gli articoli Attivi");
|
||||
class tutti_gli_articoli_attivi_action implements ActionListener {
|
||||
|
||||
|
||||
public tutti_gli_articoli_attivi_action (UserInterface in_location, JTextArea in_offers){
|
||||
location= in_location;
|
||||
offers = in_offers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
offers.setText("");
|
||||
load_catalogo.offerteAttive(login_data.getUsername(),offers);
|
||||
|
||||
}
|
||||
catch (FileNotFoundException err){}
|
||||
catch (IOException err){}
|
||||
catch (ClassNotFoundException err){}
|
||||
|
||||
}
|
||||
|
||||
private UserInterface location;
|
||||
private JTextArea offers;
|
||||
}
|
||||
//action listner for tutti_gli_articoli_attivi added at offers declaration
|
||||
|
||||
JMenuItem articoli_con_scadenza_menu_item = new JMenuItem("Articoli con Scadenza");
|
||||
JMenuItem articoli_senza_scadenza_menu_item = new JMenuItem("Articoli senza Scadenza");
|
||||
JMenu visualizzamenu = new JMenu("Visualizza");
|
||||
JMenuItem storico_menu_item = new JMenuItem("Storico Utente");
|
||||
|
||||
mainmenu.add(filemenu);
|
||||
mainmenu.add(searchmenu);
|
||||
mainmenu.add(visualizzamenu);
|
||||
|
||||
filemenu.add(logout_menu_item);
|
||||
filemenu.add(quit_menu_item);
|
||||
|
||||
searchmenu.add(tutti_gli_articoli_attivi);
|
||||
searchmenu.add(articoli_con_scadenza_menu_item);
|
||||
searchmenu.add(articoli_senza_scadenza_menu_item);
|
||||
|
||||
|
||||
visualizzamenu.add(storico_menu_item);
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel BilancioPanel = new JPanel();
|
||||
JLabel bilancio = new JLabel("Bilancio" + " " + login_data.getUsername() + " = " + (Access.get_user_data(login_data.getUsername())).getBalance() );
|
||||
bilancio.setPreferredSize(new Dimension(150,60));
|
||||
JButton acquista_credito = new JButton("Acquista Credito");
|
||||
BilancioPanel.add(bilancio);
|
||||
BilancioPanel.add(acquista_credito);
|
||||
|
||||
class acquista_action implements ActionListener {
|
||||
|
||||
|
||||
public acquista_action (UserInterface in_location, JLabel in_l){
|
||||
l = in_l;
|
||||
location= in_location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
|
||||
String importo_da_ricaricare= JOptionPane.showInputDialog(location,"Inserire l'importo da ricaricare ");
|
||||
if (Double.parseDouble(importo_da_ricaricare) > 0){
|
||||
|
||||
load_catalogo.aggiungiCredito(login_data.getUsername(), importo_da_ricaricare );
|
||||
l.setText("Bilancio" + " " + login_data.getUsername() + " = " + (Access.get_user_data(login_data.getUsername())).getBalance());
|
||||
|
||||
}
|
||||
}
|
||||
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 JLabel l;
|
||||
private UserInterface location;
|
||||
}
|
||||
acquista_credito.addActionListener(new acquista_action(this,bilancio));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
north.add(BilancioPanel,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.addActionListener(new tutti_gli_articoli_attivi_action(this,offers));
|
||||
|
||||
|
||||
|
||||
JPanel acquista_panel = new JPanel();
|
||||
|
||||
JLabel idlabel = new JLabel("ID");
|
||||
JTextField id = new JTextField(5);
|
||||
JButton aggiungi_a_carrello = new JButton("Aggiungi al Carrello");
|
||||
JLabel prodotti_nel_carello = new JLabel(" Corrello: " + Carrello.size() + " Prodotti");
|
||||
JButton acquista = new JButton("Completa Acquisto");
|
||||
|
||||
class aggiungi_al_carrello_action implements ActionListener {
|
||||
|
||||
|
||||
public aggiungi_al_carrello_action (UserInterface 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 UserInterface location;
|
||||
private JTextArea offers;
|
||||
private JLabel count;
|
||||
}
|
||||
aggiungi_a_carrello.addActionListener(new aggiungi_al_carrello_action(this,id,offers,prodotti_nel_carello));
|
||||
|
||||
class completa_acquisto implements ActionListener {
|
||||
|
||||
|
||||
public completa_acquisto (UserInterface in_location, JLabel in_count, JLabel in_bilancio){
|
||||
count = in_count;
|
||||
location= in_location;
|
||||
bilancio = in_bilancio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try{
|
||||
|
||||
if (Carrello.size() == 0){
|
||||
JOptionPane.showMessageDialog(location,
|
||||
"Carrello Vuoto ",
|
||||
"Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} else{
|
||||
|
||||
boolean status;
|
||||
status = load_catalogo.acquistaProdotti(login_data.getUsername(),Carrello);
|
||||
|
||||
if (status){
|
||||
|
||||
|
||||
count.setText(" Corrello: 0 Prodotti");
|
||||
bilancio.setText("Bilancio" + " " + login_data.getUsername() + " = " + (Access.get_user_data(login_data.getUsername())).getBalance() );
|
||||
|
||||
JOptionPane.showMessageDialog(location,
|
||||
"Acquisto Completato",
|
||||
"Completato",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
}else{
|
||||
JOptionPane.showMessageDialog(location,
|
||||
"Impossibile completare Acquisto ",
|
||||
"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 JLabel count;
|
||||
private UserInterface location;
|
||||
private JLabel bilancio;
|
||||
}
|
||||
acquista.addActionListener(new completa_acquisto(this,prodotti_nel_carello,bilancio));
|
||||
|
||||
acquista_panel.add(idlabel);
|
||||
acquista_panel.add(id);
|
||||
acquista_panel.add(aggiungi_a_carrello);
|
||||
acquista_panel.add(prodotti_nel_carello);
|
||||
acquista_panel.add(acquista);
|
||||
|
||||
|
||||
mainWindow.add(acquista_panel,BorderLayout.SOUTH);
|
||||
|
||||
|
||||
|
||||
|
||||
setSize(600, 400);
|
||||
setLocation(login_window.getLocation());
|
||||
setTitle("User " + Access.get_user_data(login_data.getUsername()).getUser() + " Logged");
|
||||
setVisible(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ArrayList<Utilizzabile> Carrello = new ArrayList<Utilizzabile>();
|
||||
LoginWindow login_window;
|
||||
Catalogo load_catalogo;
|
||||
LoginData login_data;
|
||||
|
||||
|
||||
}
|
||||
@@ -17,29 +17,12 @@ public class Access {
|
||||
* @param set_user_logged_here dove memorizzare il nome dell'utente loggato o registrato
|
||||
* @return false se Amministratore, true se Utente
|
||||
*/
|
||||
public static boolean get_access (LoggedUser set_user_logged_here) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
public static boolean get_access (LoggedUser set_user_logged_here, String in_name,String in_password,String in_location,boolean in_action) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
|
||||
System.out.println("---------- Benvenuto ----------");
|
||||
Scanner reader = new Scanner(System.in);
|
||||
|
||||
|
||||
System.out.println("1 --> Login");
|
||||
System.out.println("2 --> Registrazione");
|
||||
|
||||
String choice;
|
||||
System.out.print("\nScelta operazione: ");
|
||||
choice = reader.nextLine();
|
||||
for ( ; !(choice.equals("1")) && !(choice.equals("2")) ;){
|
||||
System.out.println("Scelta Errata. Riprovare");
|
||||
System.out.print("\nScelta operazione: ");
|
||||
choice = reader.nextLine();
|
||||
if (in_action == false){
|
||||
return login(set_user_logged_here,in_name,in_password);
|
||||
}
|
||||
|
||||
if (choice.equals("1")){
|
||||
System.out.println("---------- Login ----------");
|
||||
return login(set_user_logged_here);
|
||||
}
|
||||
return register(set_user_logged_here);
|
||||
return register(set_user_logged_here,in_name,in_password,in_location);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,40 +33,16 @@ public class Access {
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
protected static boolean login(LoggedUser set_user_logged_here) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
protected static boolean login(LoggedUser set_user_logged_here, String in_name,String in_password) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
|
||||
Scanner reader = new Scanner(System.in);
|
||||
String name;
|
||||
String password;
|
||||
|
||||
System.out.print("Username: ");
|
||||
name = reader.nextLine();
|
||||
System.out.print("Password: ");
|
||||
password = reader.nextLine();
|
||||
|
||||
for (; !(search_username (name,password)) ;){
|
||||
System.out.println("Username e/o password non trovati. Vuoi Registrarti ?: Y/N");
|
||||
|
||||
String choice;
|
||||
choice = reader.nextLine();
|
||||
for ( ; !(choice.equals("Y")) && !(choice.equals("N")) ;){
|
||||
System.out.println("Scelta Errata. Riprovare");
|
||||
choice = reader.nextLine();
|
||||
}
|
||||
|
||||
if (choice.equals("Y")){
|
||||
return register(set_user_logged_here);
|
||||
}
|
||||
System.out.println("Reinserisci i dati di Login ");
|
||||
|
||||
System.out.print("Username: ");
|
||||
name = reader.nextLine();
|
||||
System.out.print("Password: ");
|
||||
password = reader.nextLine();
|
||||
}
|
||||
|
||||
name = in_name;
|
||||
password = in_password;
|
||||
set_user_logged_here.logged_user = name;
|
||||
System.out.println("Logged");
|
||||
return getAccountType(name);
|
||||
|
||||
}
|
||||
@@ -96,24 +55,14 @@ public class Access {
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
protected static boolean register ( LoggedUser set_user_logged_here ) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
protected static boolean register ( LoggedUser set_user_logged_here, String in_name,String in_password,String in_location ) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
|
||||
Scanner reader = new Scanner(System.in);
|
||||
String name;
|
||||
String password;
|
||||
String location;
|
||||
System.out.println("---------- Registrazione ----------");
|
||||
System.out.println("Inserisci i dati di Registrazione");
|
||||
System.out.print("Username: ");
|
||||
name = reader.nextLine();
|
||||
System.out.print("Password: ");
|
||||
password = reader.nextLine();
|
||||
System.out.print("Location: ");
|
||||
location = reader.nextLine();
|
||||
|
||||
String name = in_name;
|
||||
String password = in_password;
|
||||
String location = in_location;
|
||||
|
||||
store_data(name,password,location);
|
||||
System.out.println("Registrato e login effettuato");
|
||||
|
||||
set_user_logged_here.logged_user = name;
|
||||
return true;
|
||||
@@ -127,7 +76,7 @@ public class Access {
|
||||
* @param in_password - password dell'utente
|
||||
* @return true se la ricerca ha avuto esito, false altrimenti
|
||||
*/
|
||||
protected static boolean search_username (String in_name, String in_password) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
public static boolean search_username (String in_name, String in_password) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
|
||||
File f_data = new File("user_db");
|
||||
if ( (f_data.exists())){
|
||||
|
||||
@@ -22,11 +22,11 @@ public class LoginData {
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public LoginData () throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
public LoginData (String in_name, String in_password, String in_location, boolean in_action) throws FileNotFoundException,IOException,ClassNotFoundException{
|
||||
|
||||
LoggedUser logged_user = new LoggedUser();
|
||||
boolean AccountType = true;
|
||||
AccountType = Access.get_access(logged_user); //chiama al form di login e/o registrazione
|
||||
AccountType = Access.get_access(logged_user,in_name,in_password,in_location,in_action); //chiama al form di login e/o registrazione
|
||||
|
||||
type = convert_type (AccountType);
|
||||
username = logged_user.logged_user;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.unisa.info13d;
|
||||
|
||||
import it.unisa.info13d.GestioneCatalogo.Catalogo;
|
||||
import it.unisa.info13d.Gui.LoginWindow;
|
||||
import it.unisa.info13d.Login.Access;
|
||||
import it.unisa.info13d.Login.LoggedUser;
|
||||
import it.unisa.info13d.Login.LoginData;
|
||||
@@ -21,6 +22,8 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException,IOException,ClassNotFoundException, ParseException {
|
||||
|
||||
|
||||
/*
|
||||
LoginData login = new LoginData();
|
||||
login.getUserDataInfo();
|
||||
|
||||
@@ -30,5 +33,17 @@ public class Main {
|
||||
ReShow r = new ReShow();
|
||||
for (;r.reshow;)
|
||||
load_catalogo.showMenu(login.getType(),login.getUsername(),r);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
LoginWindow l = new LoginWindow();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user