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

/*
 * jfrmCuentasCliente.java
 *
 * Created on 30-nov-2009, 0:21:15
 */

package Vistas;

import Hito4.*;
import java.util.Iterator;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Ro
 */
public class jfrmDomiciCuentas extends javax.swing.JFrame {
    Sucursal AuxSuc;
    javax.swing.JFrame auxjf;

    /** Creates new form jfrmCuentasCliente */
    public jfrmDomiciCuentas(Sucursal suc, javax.swing.JFrame jf) {
        AuxSuc=suc;
        auxjf=jf;
        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() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jbtnCancelar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtxtNumcta = new javax.swing.JTextField();
        jbtnBuscaNumCta = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jtxtDni = new javax.swing.JTextField();
        jbtnBuscaDni = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jlstCuentas = new javax.swing.JList();
        jbtnSeleccion = new javax.swing.JButton();
        jlblSeleccion = new javax.swing.JLabel();
        jlblMensaje = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jlstDomi = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Papyrus", 1, 24));
        jLabel1.setText("Domiciliaciones de una Cuenta");

        jbtnCancelar.setText("Salir");
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Papyrus", 1, 18));
        jLabel3.setForeground(new java.awt.Color(0, 0, 102));
        jLabel3.setText("Banco ALROMA");

        jLabel4.setFont(new java.awt.Font("Papyrus", 2, 14));
        jLabel4.setText("Busqueda por Numero de Cuenta");

        jbtnBuscaNumCta.setText("Buscar");
        jbtnBuscaNumCta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnBuscaNumCtaActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Papyrus", 2, 14));
        jLabel5.setText("Busqueda por DNI Cliente");

        jbtnBuscaDni.setText("Buscar");
        jbtnBuscaDni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnBuscaDniActionPerformed(evt);
            }
        });

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

        jbtnSeleccion.setText("Selecciona");
        jbtnSeleccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSeleccionActionPerformed(evt);
            }
        });

        jlstDomi.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(jlstDomi);

        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()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlblSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(jtxtNumcta, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jbtnBuscaNumCta))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                                                .addComponent(jtxtDni, javax.swing.GroupLayout.Alignment.TRAILING))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jbtnBuscaDni)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jbtnCancelar)
                                                    .addComponent(jbtnSeleccion)))))
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(124, 124, 124)
                        .addComponent(jLabel1)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel1)
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtNumcta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnBuscaNumCta))
                        .addGap(11, 11, 11)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtxtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnBuscaDni))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(jlblSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbtnSeleccion)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jbtnCancelar)
                                .addGap(36, 36, 36))))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );

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

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        auxjf.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarActionPerformed

    private void jbtnBuscaNumCtaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBuscaNumCtaActionPerformed
        Producto p = new Producto();
        p=AuxSuc.devuelveProducto(jtxtNumcta.getText());
        if(p==null){jlblMensaje.setText("El numero de Cuenta introducido es incorrecto.");}
        else{jlblMensaje.setText("Numero de Cuenta correcto.");}
        List<Domiciliacion> D =p.getMDomiciliacion();
        
        DefaultListModel dlm = new DefaultListModel();
        jlstDomi.setModel(dlm);
        jlstDomi.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);//para que solo coja un valor
        
        Iterator iterador = D.listIterator();
        while( iterador.hasNext() ) {
            Domiciliacion d = (Domiciliacion) iterador.next();
            dlm.addElement(d.getOrdenante()+"  "+d.getConcepto()+"  "+d.getFecha()+"  "+d.getImporte());
        }
    }//GEN-LAST:event_jbtnBuscaNumCtaActionPerformed

    private void jbtnBuscaDniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBuscaDniActionPerformed
        List<Producto> P=AuxSuc.busquedaProductosCliente(jtxtDni.getText(), 1);
        
        if(P==null){jlblMensaje.setText("El numero de Cuenta introducido es incorrecto.");}
        else{jlblMensaje.setText("Numero de Cuenta correcto.");}

        DefaultListModel dlm = new DefaultListModel();
        jlstCuentas.setModel(dlm);
        jlstCuentas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);//para que solo coja un valor

        Iterator iterador = P.listIterator();
        while( iterador.hasNext() ) {
            Producto p = (Producto) iterador.next();
            dlm.addElement(p.getNumeroProducto());
        }
    }//GEN-LAST:event_jbtnBuscaDniActionPerformed

private void jbtnSeleccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSeleccionActionPerformed
        String cadena=(String) jlstCuentas.getSelectedValue();
        jlblSeleccion.setText(cadena.substring(0, 20));
        AuxSuc.almacenaNumcta(cadena.substring(0, 20));

        Producto p = new Producto();
        p=AuxSuc.devuelveProducto(jtxtNumcta.getText());
        if(p==null){jlblMensaje.setText("El numero de Cuenta introducido es incorrecto.");}
        else{jlblMensaje.setText("Numero de Cuenta correcto.");}
        List<Domiciliacion> D =p.getMDomiciliacion();

        DefaultListModel dlm = new DefaultListModel();
        jlstDomi.setModel(dlm);
        jlstDomi.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);//para que solo coja un valor

        Iterator iterador = D.listIterator();
        while( iterador.hasNext() ) {
            Domiciliacion d = (Domiciliacion) iterador.next();
            dlm.addElement(d.getOrdenante()+"  "+d.getConcepto()+"  "+d.getFecha()+"  "+d.getImporte());
        }
}//GEN-LAST:event_jbtnSeleccionActionPerformed
    
    /**
    * @param args the command line arguments
    */
/*    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfrmCuentasCliente().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbtnBuscaDni;
    private javax.swing.JButton jbtnBuscaNumCta;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JButton jbtnSeleccion;
    private javax.swing.JLabel jlblMensaje;
    private javax.swing.JLabel jlblSeleccion;
    private javax.swing.JList jlstCuentas;
    private javax.swing.JList jlstDomi;
    private javax.swing.JTextField jtxtDni;
    private javax.swing.JTextField jtxtNumcta;
    // End of variables declaration//GEN-END:variables

}
