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

/*
 * jfrmNuevoTitular.java
 *
 * Created on 28-ene-2010, 19:07:27
 */

package Vistas;

import Hito4.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

    /** Creates new form jfrmNuevoTitular */
    public jfrmNuevoTitular(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() {

        jLabel3 = new javax.swing.JLabel();
        jbtnSalir = new javax.swing.JButton();
        jtxtNumCta = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jtxtNombre = new javax.swing.JTextField();
        jtxtDni = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jlblMensaje = new javax.swing.JLabel();
        jbtnValida = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

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

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

        jLabel1.setText("Numero de Cuenta");

        jLabel2.setText("Nombre");

        jLabel4.setText("DNI");

        jbtnValida.setText("Valida");
        jbtnValida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnValidaActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Papyrus", 3, 18)); // NOI18N
        jLabel5.setText("Nuevo Titular");

        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(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtxtDni)
                            .addComponent(jtxtNumCta, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(jtxtNombre))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(91, Short.MAX_VALUE)
                .addComponent(jbtnValida)
                .addGap(55, 55, 55)
                .addComponent(jbtnSalir)
                .addGap(105, 105, 105))
            .addGroup(layout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addComponent(jLabel5)
                .addContainerGap(162, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .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(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(30, 30, 30)
                .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnSalir)
                    .addComponent(jbtnValida))
                .addGap(7, 7, 7)
                .addComponent(jLabel3)
                .addGap(23, 23, 23))
        );

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

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

    private void jbtnValidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnValidaActionPerformed
        ArrayList<Producto> AP=new ArrayList<Producto>();
        ArrayList<Cliente> AC=new ArrayList<Cliente>();
        int encontrado=0;
        Producto p=new CuentaCorriente();
        List<Producto> am = auxsuc.getProducto();
        Iterator iterador = am.listIterator();
        while( iterador.hasNext() & (encontrado==0)) {
            Producto pro = (Producto) iterador.next();
            if (pro.getNumeroProducto().substring(10,19).equals(jtxtNumCta.getText())){
                Cliente c = new Cliente();
                c.setNombreCliente(jtxtNombre.getText());
                c.setDocumentacion(jtxtDni.getText());
                c.insertaProductoenCliente(p);
                p.insertaTitularenProducto(c);

                AP.add(p);
                AC.add(c);

                auxsuc.setMCliente(AC);
                encontrado=1;
            }
        }
        if (encontrado==1){jlblMensaje.setText("Titular insertado con exito.");}
        else{jlblMensaje.setText("Cuenta no encontrada, titular NO insertado.");}
    }//GEN-LAST:event_jbtnValidaActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JButton jbtnValida;
    private javax.swing.JLabel jlblMensaje;
    private javax.swing.JTextField jtxtDni;
    private javax.swing.JTextField jtxtNombre;
    private javax.swing.JTextField jtxtNumCta;
    // End of variables declaration//GEN-END:variables

}
