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

/*
 * JFCargo.java
 *
 * Created on 13-oct-2010, 19:45:30
 */

package vistas;

import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javabbuva.*;

/**
 *
 * @author Adrian
 */
public class JFCargo extends javax.swing.JFrame {

    Sucursal su;
    JFPrincipal p;

    /** Creates new form JFCargo */
    public JFCargo(Sucursal su, JFPrincipal p) {
        this.su = su;
        this.p = p;
        p.setEnabled(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() {

        jLTitulo = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTdireccion = new javax.swing.JTextField();
        jBImportar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTinformacion = new javax.swing.JTextArea();
        jBvalidar = new javax.swing.JButton();
        jBcancelar = new javax.swing.JButton();
        jLerror = new javax.swing.JLabel();
        jLSaldo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLTitulo.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLTitulo.setText("Realizando remesa cargo.");

        jLabel1.setText("Fichero a tratar:");

        jTdireccion.setText("C:\\Remesas\\remesa recibos.txt");

        jBImportar.setText("Importar");
        jBImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBImportarActionPerformed(evt);
            }
        });

        jTinformacion.setColumns(20);
        jTinformacion.setEditable(false);
        jTinformacion.setRows(5);
        jScrollPane1.setViewportView(jTinformacion);

        jBvalidar.setText("Validar");
        jBvalidar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBvalidarActionPerformed(evt);
            }
        });

        jBcancelar.setText("Cerrar");
        jBcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcancelarActionPerformed(evt);
            }
        });

        jLerror.setForeground(new java.awt.Color(204, 0, 0));

        jLSaldo.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLSaldo.setForeground(new java.awt.Color(51, 51, 51));
        jLSaldo.setText("0");
        jLSaldo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Saldo actual en caja:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLTitulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 293, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel1)
                        .addGap(32, 32, 32)
                        .addComponent(jTdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(177, 177, 177)
                        .addComponent(jBImportar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jBvalidar)
                        .addGap(32, 32, 32)
                        .addComponent(jBcancelar)
                        .addGap(18, 18, 18)
                        .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLTitulo)
                        .addGap(43, 43, 43)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jBImportar))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLSaldo)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBvalidar)
                    .addComponent(jBcancelar)
                    .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

    private void jBImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBImportarActionPerformed
        // TODO add your handling code here:
        String mensaje=su.verRemesa(jTdireccion.getText());
        jTinformacion.setText(mensaje);
    }//GEN-LAST:event_jBImportarActionPerformed

    private void jBcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBcancelarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        p.setEnabled(true);
    }//GEN-LAST:event_formWindowClosed

    private void jBvalidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBvalidarActionPerformed
        // TODO add your handling code here:
        try {
            su.incorporarRemesa(jTdireccion.getText());
        } catch (ParseException ex) {
            Logger.getLogger(JFCargo.class.getName()).log(Level.SEVERE, null, ex);
        }
        jLerror.setText(su.getMensajeError());
    }//GEN-LAST:event_jBvalidarActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        jLSaldo.setText(String.valueOf(su.getCajaActual().getSaldo()));
    }//GEN-LAST:event_formWindowActivated

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFCargo().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBImportar;
    private javax.swing.JButton jBcancelar;
    private javax.swing.JButton jBvalidar;
    private javax.swing.JLabel jLSaldo;
    private javax.swing.JLabel jLTitulo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLerror;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTdireccion;
    private javax.swing.JTextArea jTinformacion;
    // End of variables declaration//GEN-END:variables

}
