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

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

package src;

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

/**
 *
 * @author Yeiser
 */
public class jFrmConsultaDomiciliaciones extends javax.swing.JFrame {
    Sucursal s=new Sucursal();
    Cuentas c=new Cuentas();
    
    /** Creates new form jFrmConsultaUltMov */
    public jFrmConsultaDomiciliaciones(Sucursal suc) {
        s=suc;        
        initComponents();
        jBmostrar.setEnabled(false);
    }

    /** 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();
        JDNI2 = new javax.swing.JTextField();
        botonconum1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlCuentas = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlCuentas1 = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        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);

        jLabel1.setText("DNI/CIF:");

        JDNI2.setText("25361477A");

        botonconum1.setText("ACEPTAR");
        botonconum1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonconum1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Movimientos:");

        jlCuentas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jlCuentas);

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

        jLabel3.setText("Consultas:");

        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));
        jLabel7.setText("Consulta Domicializaciones");

        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()
                        .addGap(72, 72, 72)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlblSeleccion)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(JDNI2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(botonconum1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(34, 34, 34)
                                .addComponent(jBmostrar))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 488, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addGap(98, 98, 98)
                        .addComponent(jLabel7)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(468, 468, 468)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlblSeleccion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap(69, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(JDNI2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonconum1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBmostrar)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(31, 31, 31))
        );

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

    private void botonconum1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonconum1ActionPerformed
        ArrayList<String> n=new ArrayList(); // Inicializar el arraylist
        n=s.devuelveDni(JDNI2.getText());
        if (n!=null){
            DefaultListModel dlm1 = new DefaultListModel();
            jlCuentas.setModel(dlm1);
            jlCuentas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            for(int i=0; i<n.size();i++){
                dlm1.addElement(n.get(i));
            }
        jBmostrar.setEnabled(true);
        }
        else{ JOptionPane.showMessageDialog(this,"El DNI no existe","Error",JOptionPane.ERROR_MESSAGE);
        }       
        //mMovimientos=s.devuelveUltimosMovimientos(s,JDNI2.getText());
        
        
            
                // TODO add your handling code here:
    }//GEN-LAST:event_botonconum1ActionPerformed

    private void jBmostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBmostrarActionPerformed
        // TODO add your handling code here:
        ArrayList<Domiciliaciones> mDomiciliaciones=new ArrayList();
        String cadena=(String) jlCuentas.getSelectedValue();
        //jlblSeleccion.setText(cadena.substring(1, 20));
        mDomiciliaciones=s.devuelveDomiciliaciones(s,cadena);
        DefaultListModel dlm2 = new DefaultListModel();
        jlCuentas1.setModel(dlm2);
        jlCuentas1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        dlm2.addElement("              Fecha de alta           "+"               "+"                  Empresa              "+"                "+"             Fecha ultimo importe          "+"            Importe Ulrimo recibo          ");
        dlm2.addElement("-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
        for(int i=0; i<mDomiciliaciones.size();i++){
           dlm2.addElement(mDomiciliaciones.get(i).getFechaAlta()+"         "+mDomiciliaciones.get(i).getNombre_Emoresa()+"  "+mDomiciliaciones.get(i).getFechaUltimoRecibo()+"             "+mDomiciliaciones.get(i).getImporte());
        }
}//GEN-LAST:event_jBmostrarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField JDNI2;
    private javax.swing.JButton botonconum1;
    private javax.swing.JButton jBmostrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList jlCuentas;
    private javax.swing.JList jlCuentas1;
    private javax.swing.JLabel jlblSeleccion;
    // End of variables declaration//GEN-END:variables

}
