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

/*
 * jFrmConsultas.java
 *
 * Created on 25-nov-2009, 18:18:19
 */

package src;

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

/**
 *
 * @author Yeiser
 */
public class jFrmConsultas extends javax.swing.JFrame {
Sucursal s;
    /** Creates new form jFrmConsultas */
    public jFrmConsultas(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() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        Jdni = new javax.swing.JTextField();
        jbuscardni = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlCuentas = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jbopciones = new javax.swing.JButton();

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

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Consultas");

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

        Jdni.setText("25361477A");
        Jdni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JdniActionPerformed(evt);
            }
        });

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

        jLabel3.setText("Cuentas del cliente:");

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

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

        jbopciones.setText("Opciones");
        jbopciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbopcionesActionPerformed(evt);
            }
        });

        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(jLabel4)
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Jdni, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                                .addComponent(jbuscardni))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(44, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(344, Short.MAX_VALUE)
                .addComponent(jbopciones)
                .addGap(33, 33, 33))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(Jdni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbuscardni))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jLabel3)))
                .addGap(33, 33, 33)
                .addComponent(jbopciones)
                .addGap(24, 24, 24))
        );

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

    private void JdniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JdniActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_JdniActionPerformed

    private void jbuscardniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbuscardniActionPerformed
       
        ArrayList<String> n=new ArrayList(); // Inicializar el arraylist
        n=s.devuelveDni(Jdni.getText());
        if (n!=null){
            DefaultListModel dlm = new DefaultListModel();
            jlCuentas.setModel(dlm);
            jlCuentas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            for(int i=0; i<n.size();i++){
                dlm.addElement(n.get(i));                
            }
            
        } else {JOptionPane.showMessageDialog(this,"El DNI no existe","Error",JOptionPane.ERROR_MESSAGE);

        }
}//GEN-LAST:event_jbuscardniActionPerformed

    private void jbopcionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbopcionesActionPerformed
        s.recogerCuenta((String) jlCuentas.getSelectedValue());
        jfrmOpciones op=new jfrmOpciones (s);
        op.setLocationRelativeTo(null);
        op.setVisible(true);
    }//GEN-LAST:event_jbopcionesActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Jdni;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbopciones;
    private javax.swing.JButton jbuscardni;
    private javax.swing.JList jlCuentas;
    // End of variables declaration//GEN-END:variables

}
