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

/*
 * jfrmDetallesMov.java
 *
 * Created on 08-dic-2009, 13:45:26
 */

package interfaz;

import daial.Movimiento;
import daial.Sucursal;
import java.util.ArrayList;

/**
 *
 * @author Alberto
 */
public class jfrmDetallesMov extends javax.swing.JFrame {

    String cadBusqueda="";
    Sucursal s;
    ArrayList<Movimiento> lista_mov;
    Movimiento mov;
    jfrmMovimientos p;

    /** Creates new form jfrmDetallesMov */
    public jfrmDetallesMov(jfrmMovimientos padre, Sucursal suc, String cadena, ArrayList<Movimiento> list) {
        initComponents();
        this.setLocationRelativeTo(null);
        cadBusqueda = cadena;
        s = suc;
        lista_mov = list;
        p = padre;

        mov = busqueda_mov(cadBusqueda);
        mostrar_mov(mov);
    }

    /** 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() {

        jLabel1 = new javax.swing.JLabel();
        jTxt_fecha = new javax.swing.JTextField();
        jTxt_concepto = new javax.swing.JTextField();
        jTxt_importe = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jBtn_atras = new javax.swing.JButton();

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

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Detalles del movimiento");

        jTxt_fecha.setBackground(new java.awt.Color(250, 250, 250));
        jTxt_fecha.setEditable(false);
        jTxt_fecha.setText("Fecha");

        jTxt_concepto.setBackground(new java.awt.Color(250, 250, 250));
        jTxt_concepto.setEditable(false);
        jTxt_concepto.setText("Concepto");

        jTxt_importe.setBackground(new java.awt.Color(250, 250, 250));
        jTxt_importe.setEditable(false);
        jTxt_importe.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTxt_importe.setText("Importe");

        jLabel2.setText("Fecha");

        jLabel3.setText("Importe");

        jLabel4.setText("Concepto");

        jBtn_atras.setText("Atrás");
        jBtn_atras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_atrasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(120, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(113, 113, 113))
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTxt_concepto, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jTxt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jTxt_importe, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGap(85, 85, 85)))))
            .addGroup(layout.createSequentialGroup()
                .addGap(188, 188, 188)
                .addComponent(jBtn_atras)
                .addContainerGap(202, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTxt_importe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxt_concepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addComponent(jBtn_atras)
                .addContainerGap(55, Short.MAX_VALUE))
        );

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

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

    private void jBtn_atrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_atrasActionPerformed
        // TODO add your handling code here:
        p.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jBtn_atrasActionPerformed

    private Movimiento busqueda_mov(String cad)
    {
        boolean encontrado = false;
        int i;

        for(i=0; i < lista_mov.size() && !encontrado; i++)
            if(cad.equals(lista_mov.get(i).getFechaOperacion().toString()))
                encontrado = true;

        return lista_mov.get(i-1);
    }

    private void mostrar_mov(Movimiento m)
    {
        jTxt_concepto.setText(m.getConcepto());
        jTxt_fecha.setText(m.getFechaOperacion().toString());
        jTxt_importe.setText(Double.toString(m.getImporte()));
    }


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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtn_atras;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTxt_concepto;
    private javax.swing.JTextField jTxt_fecha;
    private javax.swing.JTextField jTxt_importe;
    // End of variables declaration//GEN-END:variables

}
