351 lines
11 KiB
Java
351 lines
11 KiB
Java
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.19
|
|
*/
|
|
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<Utilizzabile> Carrello = new ArrayList<Utilizzabile>();
|
|
LoginWindow login_window;
|
|
Catalogo load_catalogo;
|
|
LoginData login_data;
|
|
|
|
|
|
}
|