/*
 * jFrmConsultaUltMov.java
 *
 * Created on 02-dic-2009, 18:14:18
 */

package src;

import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Yeiser
 */
public class jFrmConsultaUltMov extends javax.swing.JFrame {
    Sucursal s;

    
    /** Creates new form jFrmConsultaUltMov */
    public jFrmConsultaUltMov(Sucursal suc) {
        s=suc;        
        initComponents();
        setResizable(false); //ASI QUITAMOS QUE SE PUEDA MAXIMIZAR
    }

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

        jScrollPane2 = new javax.swing.JScrollPane();
        jlCuentas1 = new javax.swing.JList();
        jBmostrar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jlblSeleccion = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        jlCuentas1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jlCuentas1);

        jBmostrar.setText("Mostrar");
        jBmostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBmostrarActionPerformed(evt);
            }
        });

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/InterfazMINI.gif"))); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(0, 0, 255));
        jLabel7.setText("Consulta Ultimos Movimientos");

        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()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(72, 72, 72)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jlblSeleccion)
                                    .addComponent(jLabel5))))
                        .addGap(96, 96, 96)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBmostrar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel7))
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlblSeleccion, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(322, 322, 322))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(166, 166, 166)
                        .addComponent(jBmostrar)))
                .addContainerGap())
        );

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

    private void jBmostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBmostrarActionPerformed
        ArrayList<Movimientos> mMovimientos=new ArrayList();
        //Daniel
        mMovimientos=s.devuelveUltimosMovimientos(s,s.getNCuenta());
        DefaultListModel dlm2 = new DefaultListModel();
        jlCuentas1.setModel(dlm2);
        jlCuentas1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        dlm2.addElement("        Fecha operacion     "+" "+"               Importe       "+" "+"             Concepto          ");
        dlm2.addElement("-------------------------------------------------------------------------------------------------------");
        for(int i=0; i<mMovimientos.size();i++){

            Calendar calendar=Calendar.getInstance(); //Utilizamos para crear la fecha del archivo
            calendar.setTime(mMovimientos.get(i).getFecha_Operacion());
            dlm2.addElement("                  "+calendar.get(Calendar.DATE)+"/"+calendar.get(Calendar.MONTH)+1+"/"+calendar.get(Calendar.YEAR)+"                       "+mMovimientos.get(i).getImporte()+"                            "+mMovimientos.get(i).getConcepto());
        }
}//GEN-LAST:event_jBmostrarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBmostrar;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList jlCuentas1;
    private javax.swing.JLabel jlblSeleccion;
    // End of variables declaration//GEN-END:variables

}
