|
|
|
|
@@ -5,7 +5,13 @@ import it.unisa.info13d.Articoli.CeneInRistoranti;
|
|
|
|
|
import it.unisa.info13d.Articoli.Global;
|
|
|
|
|
import it.unisa.info13d.Articoli.Utilizzabile;
|
|
|
|
|
import it.unisa.info13d.Articoli.Vacanze;
|
|
|
|
|
import it.unisa.info13d.Login.Access;
|
|
|
|
|
import it.unisa.info13d.Login.Entry;
|
|
|
|
|
import it.unisa.info13d.Utility.ReShow;
|
|
|
|
|
import it.unisa.info13d.Login.Access;
|
|
|
|
|
import it.unisa.info13d.Login.LoggedUser;
|
|
|
|
|
import it.unisa.info13d.Login.LoginData;
|
|
|
|
|
import it.unisa.info13d.Login.StoricoItem;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
@@ -59,12 +65,12 @@ public class Catalogo{
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
|
*/
|
|
|
|
|
public void showMenu(String userType,ReShow r) throws FileNotFoundException, ClassNotFoundException, ParseException, IOException
|
|
|
|
|
public void showMenu(String userType,String username, ReShow r) throws FileNotFoundException, ClassNotFoundException, ParseException, IOException
|
|
|
|
|
{
|
|
|
|
|
if(userType.equals("Admin"))
|
|
|
|
|
AdminSession.showAdminMenu(this,r);
|
|
|
|
|
else
|
|
|
|
|
ClientSession.showClientMenu(this,r);
|
|
|
|
|
ClientSession.showClientMenu(this,r, username);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Questo metodo permette l'inserimento di un nuovo deal all'interno del catalogo
|
|
|
|
|
@@ -98,23 +104,33 @@ public class Catalogo{
|
|
|
|
|
String localita = inputData.nextLine();
|
|
|
|
|
|
|
|
|
|
System.out.println("Data Partenza (GG/MM/AAAA): ");
|
|
|
|
|
DateFormat format = new SimpleDateFormat( "dd/MM/yyyy" );
|
|
|
|
|
String data = inputData.nextLine();
|
|
|
|
|
String temp[];
|
|
|
|
|
String marcatore="/";
|
|
|
|
|
temp = data.split(marcatore);
|
|
|
|
|
GregorianCalendar dataPartenza = new GregorianCalendar((Integer.parseInt(temp[2])),(Integer.parseInt(temp[1]))-1,(Integer.parseInt(temp[0])));
|
|
|
|
|
/*DateFormat format = new SimpleDateFormat( "dd/MM/yyyy" );
|
|
|
|
|
Date date = format.parse(inputData.nextLine());
|
|
|
|
|
GregorianCalendar dataPartenza = new GregorianCalendar();
|
|
|
|
|
dataPartenza.setTime(date);
|
|
|
|
|
dataPartenza.setTime(date);*/
|
|
|
|
|
|
|
|
|
|
System.out.println("Data Scadenza offerta (GG/MM/AAAA): ");
|
|
|
|
|
date = format.parse(inputData.nextLine());
|
|
|
|
|
String data2 = inputData.nextLine();
|
|
|
|
|
String temp2[];
|
|
|
|
|
temp2 = data2.split(marcatore);
|
|
|
|
|
GregorianCalendar dataScad = new GregorianCalendar((Integer.parseInt(temp2[2])),(Integer.parseInt(temp2[1]))-1,(Integer.parseInt(temp2[0])));
|
|
|
|
|
|
|
|
|
|
/*date = format.parse(inputData.nextLine());
|
|
|
|
|
GregorianCalendar dataScadVacanza = new GregorianCalendar();
|
|
|
|
|
dataScadVacanza.setTime(date);
|
|
|
|
|
dataScadVacanza.setTime(date);*/
|
|
|
|
|
|
|
|
|
|
System.out.println("Prezzo singola persona: ");
|
|
|
|
|
String prezzo = inputData.nextLine();
|
|
|
|
|
double prezzoPSing = Double.parseDouble(prezzo);
|
|
|
|
|
|
|
|
|
|
int idViaggio=Global.get_next_id();
|
|
|
|
|
|
|
|
|
|
catalogoOfferte.add(new Vacanze(idViaggio, localita, dataPartenza, dataScadVacanza, prezzoPSing));
|
|
|
|
|
|
|
|
|
|
catalogoOfferte.add(new Vacanze(Global.get_next_id(), localita, dataPartenza, dataScad, prezzoPSing));
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
case "2":
|
|
|
|
|
@@ -132,18 +148,22 @@ public class Catalogo{
|
|
|
|
|
double prezzoPSingCena = Double.parseDouble(prezzoCena);
|
|
|
|
|
|
|
|
|
|
System.out.println("Data Scadenza offerta (GG/MM/AAAA): ");
|
|
|
|
|
DateFormat format2 = new SimpleDateFormat( "dd/MM/yyyy" );
|
|
|
|
|
String data3 = inputData.nextLine();
|
|
|
|
|
String temp3[];
|
|
|
|
|
String marcatore2="/";
|
|
|
|
|
temp3 = data3.split(marcatore2);
|
|
|
|
|
GregorianCalendar dataScadCena = new GregorianCalendar((Integer.parseInt(temp3[2])),(Integer.parseInt(temp3[1])),(Integer.parseInt(temp3[0])));
|
|
|
|
|
/*DateFormat format2 = new SimpleDateFormat( "dd/MM/yyyy" );
|
|
|
|
|
date = format2.parse(inputData.nextLine());
|
|
|
|
|
GregorianCalendar dataScadCena = new GregorianCalendar();
|
|
|
|
|
dataScadCena.setTime(date);
|
|
|
|
|
dataScadCena.setTime(date);*/
|
|
|
|
|
|
|
|
|
|
System.out.println("Cene da Vendere: ");
|
|
|
|
|
String nCene = inputData.nextLine();
|
|
|
|
|
int ceneDaVendere = Integer.parseInt(nCene);
|
|
|
|
|
|
|
|
|
|
int idCena=Global.get_next_id();
|
|
|
|
|
|
|
|
|
|
catalogoOfferte.add(new CeneInRistoranti(idCena, ristorante, localitaCena, descrizioneCena, prezzoPSingCena, dataScadCena, ceneDaVendere));
|
|
|
|
|
catalogoOfferte.add(new CeneInRistoranti(Global.get_next_id(), ristorante, localitaCena, descrizioneCena, prezzoPSingCena, dataScadCena, ceneDaVendere));
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
case "3":
|
|
|
|
|
@@ -158,9 +178,7 @@ public class Catalogo{
|
|
|
|
|
String qntMag = inputData.nextLine();
|
|
|
|
|
int qnt_mag = Integer.parseInt(prezzoBene);
|
|
|
|
|
|
|
|
|
|
int idBene=Global.get_next_id();
|
|
|
|
|
|
|
|
|
|
catalogoOfferte.add(new BeniDiConsumo(idBene, descrizioneBene, prezzo_bene, qnt_mag));
|
|
|
|
|
catalogoOfferte.add(new BeniDiConsumo(Global.get_next_id(), descrizioneBene, prezzo_bene, qnt_mag));
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@@ -187,30 +205,39 @@ public class Catalogo{
|
|
|
|
|
CeneInRistoranti dealCena = (CeneInRistoranti)deal;
|
|
|
|
|
visualizzaCena(dealCena);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.print("Elimina prodotto [Inserisci id]: ");
|
|
|
|
|
Scanner inputData = new Scanner(System.in);
|
|
|
|
|
String id = inputData.nextLine();
|
|
|
|
|
int idDel = Integer.parseInt(id);
|
|
|
|
|
System.out.println(idDel);
|
|
|
|
|
for(Utilizzabile deal: catalogoOfferte)
|
|
|
|
|
{
|
|
|
|
|
if(deal instanceof Vacanze && ((Vacanze)deal).getIdViaggio()==idDel)
|
|
|
|
|
{
|
|
|
|
|
catalogoOfferte.remove(deal);
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(deal instanceof BeniDiConsumo && ((BeniDiConsumo) deal).getIdBene()==idDel)
|
|
|
|
|
{
|
|
|
|
|
catalogoOfferte.remove(deal);
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(deal instanceof CeneInRistoranti && ((CeneInRistoranti) deal).getIdCena()==idDel)
|
|
|
|
|
{
|
|
|
|
|
catalogoOfferte.remove(deal);
|
|
|
|
|
store_data();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Questo metodo visualizza le offerte attive del catalogo
|
|
|
|
|
*/
|
|
|
|
|
public void offerteAttive()
|
|
|
|
|
{
|
|
|
|
|
for(Utilizzabile deal: catalogoOfferte)
|
|
|
|
|
@@ -245,6 +272,9 @@ public class Catalogo{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Questo metodo visualizza le offerte scadute del catalogo
|
|
|
|
|
*/
|
|
|
|
|
public void offerteScadute()
|
|
|
|
|
{
|
|
|
|
|
System.out.println("------ Offerte Scadute -----");
|
|
|
|
|
@@ -268,9 +298,132 @@ public class Catalogo{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Questa metodo aggiunge credito al conto dell'utente
|
|
|
|
|
* @param user
|
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public void aggiungiCredito(String user) 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();
|
|
|
|
|
loggedUser.setBalance(Double.parseDouble(euro));
|
|
|
|
|
Access.replace_data(user, loggedUser);
|
|
|
|
|
System.out.println("Saldo attuale: "+loggedUser.getBalance());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Questo metodo permette all'utente di effettuare un acquisto
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public void acquistaProdotto(String user) throws FileNotFoundException, ClassNotFoundException, IOException
|
|
|
|
|
{
|
|
|
|
|
Entry loggedUser = Access.get_user_data(user);
|
|
|
|
|
System.out.println("----- Shop ----");
|
|
|
|
|
System.out.println("### Prodotti ###");
|
|
|
|
|
|
|
|
|
|
offerteAttive();
|
|
|
|
|
|
|
|
|
|
System.out.println("Offerta da acquistare[inserisci id]: ");
|
|
|
|
|
Scanner inputData = new Scanner(System.in);
|
|
|
|
|
String idProd = inputData.nextLine();
|
|
|
|
|
int idDel = Integer.parseInt(idProd);
|
|
|
|
|
|
|
|
|
|
Entry userLogged = Access.get_user_data(user);
|
|
|
|
|
boolean trovato=false;
|
|
|
|
|
ArrayList<StoricoItem> storico = userLogged.getStorico();
|
|
|
|
|
|
|
|
|
|
for(Utilizzabile dealsc: catalogoOfferte)
|
|
|
|
|
{
|
|
|
|
|
if((dealsc instanceof Vacanze) && ((Vacanze)dealsc).getIdViaggio()==idDel)
|
|
|
|
|
{
|
|
|
|
|
Vacanze dealVacanza = (Vacanze)dealsc;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Il prodotto non e' acquistabile");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((dealsc instanceof BeniDiConsumo) && ((BeniDiConsumo) dealsc).getIdBene()==idDel)
|
|
|
|
|
{
|
|
|
|
|
BeniDiConsumo dealBene = (BeniDiConsumo)dealsc;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Il prodotto non e' acquistabile");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if( (dealsc instanceof CeneInRistoranti) && ((CeneInRistoranti) dealsc).getIdCena()==idDel)
|
|
|
|
|
{
|
|
|
|
|
CeneInRistoranti dealCena = (CeneInRistoranti)dealsc;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Il prodotto non e' acquistabile");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!trovato) System.out.println("### Prodotto non presente nel catalogo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Questo metodo visualizza lo storico degli ordini effettuati dall'utente
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
|
* @throws ClassNotFoundException
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void visualizzaStorico(String user) throws FileNotFoundException, ClassNotFoundException, IOException
|
|
|
|
|
{
|
|
|
|
|
Entry userLogged = Access.get_user_data(user);
|
|
|
|
|
System.out.println("########### STORICO ###########");
|
|
|
|
|
ArrayList<StoricoItem> storico = userLogged.getStorico();
|
|
|
|
|
for(StoricoItem record: storico)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("| deal: "+record.getDescription()+"| data:"+new SimpleDateFormat("dd/MM/yyyy").format(record.getData_acquisto()+"| Prezzo: "+record.getPrezzo()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void aggiungiCredito()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
public void visualizzaVacanza(Vacanze dealVacanza)
|
|
|
|
|
{
|
|
|
|
|
@@ -283,12 +436,12 @@ public class Catalogo{
|
|
|
|
|
int meseS = scadenza.get(Calendar.MONTH);
|
|
|
|
|
int annoS = scadenza.get(Calendar.YEAR);
|
|
|
|
|
|
|
|
|
|
System.out.println("#Vacanza-"+dealVacanza.getIdViaggio()+"# Scadenza: "+giornoS+"/"+meseS+"/"+annoS+"| Localita: "+dealVacanza.getLocalitaViaggio()+"| Partenza: "+giornoP+"/"+meseP+"/"+annoP+"| Prezzo Pers. Singola: "+dealVacanza.getPrezzoPSingola());
|
|
|
|
|
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--");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void visualizzaBene(BeniDiConsumo dealBene)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("#Articolo-"+dealBene.getIdBene()+"# Descrizione: "+dealBene.getDescrizioneBene()+" Prezzo: "+dealBene.getPrezzoBene()+"| Quantita in magazzino: "+dealBene.getBeniInStock());
|
|
|
|
|
System.out.println("#Articolo-"+dealBene.getIdBene()+"# Descrizione: "+dealBene.getDescrizioneBene()+" Prezzo: "+dealBene.getPrezzoBene()+"| Quantita in magazzino: "+dealBene.getBeniInStock()+"\n--");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void visualizzaCena(CeneInRistoranti dealCena)
|
|
|
|
|
@@ -297,12 +450,19 @@ public class Catalogo{
|
|
|
|
|
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+"/"+annoSC+"| Ristorante: "+dealCena.getNomeRistorante()+"| Indirizzo: "+dealCena.getLuogo()+"| Descrizione: "+dealCena.getDescrizione_cena()+"| Costo: "+dealCena.getCostoPerPersona());
|
|
|
|
|
System.out.println("#Cena-"+dealCena.getIdCena()+"# Scadenza:"+giornoSC+"/"+(meseSC+1)+"/"+annoSC+"| Ristorante: "+dealCena.getNomeRistorante()+"| Indirizzo: "+dealCena.getLuogo()+"| Descrizione: "+dealCena.getDescrizione_cena()+"| Costo: "+dealCena.getCostoPerPersona()+"\n--");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArrayList<Utilizzabile> getCatalogo() {
|
|
|
|
|
return catalogoOfferte;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean testInputData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ArrayList<Utilizzabile> catalogoOfferte;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|