/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GOffertaV.java
 *
 * Created on 9-lug-2011, 19.14.48
 */

package app.gui;

import archive.exception.AlternativeFlightException;
import archive.system.OfferManager;
import java.io.FileNotFoundException;
import javax.swing.JOptionPane;
import app.Main;

public class GOffertaV extends javax.swing.JFrame {
 private OfferManager offermanager=new OfferManager(false);
    /** Creates new form GOffertaV */
    public GOffertaV() {
        Main.gui.setVisible(false);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jMenu1.setText("Gestione Offerta");

        jMenuItem1.setText("Rimozione Volo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Esporta");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void removeVolo(){
        String showInputDialog = (String) JOptionPane.showInputDialog(rootPane,"Seleziona il Volo","",JOptionPane.PLAIN_MESSAGE, null, offermanager.showList(), rootPaneCheckingEnabled);
        try {
            if(offermanager.modArchive(showInputDialog.substring(0, 4))){
                   JOptionPane.showMessageDialog(rootPane,"Volo Cancellatto");
            }
        } catch (AlternativeFlightException ex) {
            int showConfirmDialog = JOptionPane.showConfirmDialog(rootPane, "Questo volo ha delle prenotazioni vuoi cancellarne un'altro?", "", JOptionPane.YES_NO_OPTION);
             if(showConfirmDialog==0){
                  removeVolo();
             }
        }
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        removeVolo();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
      String showInputDialog = JOptionPane.showInputDialog(rootPane, "Nome File","Inserisci Nome File",JOptionPane.OK_CANCEL_OPTION);
        try {
          if(offermanager.exportPrenotation(showInputDialog)){
              JOptionPane.showMessageDialog(rootPane, "Esportazione Effettuata");
          }
        } catch (FileNotFoundException ex) {
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
Main.gui.setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    // End of variables declaration//GEN-END:variables

}
