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

/*
 * jfrmDomiciliaciones.java
 *
 * Created on 09-dic-2009, 18:22:02
 */

package interfaz;

import daial.Caja;
import daial.Movimiento;
import daial.Producto;
import daial.Sucursal;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Alberto
 */
public class jfrmDomiciliaciones extends javax.swing.JFrame {

    private Sucursal s = new Sucursal();
    private String ctaActiva = "";
    jfrmPrincipal p;

    /** Creates new form jfrmDomiciliaciones */
    public jfrmDomiciliaciones(Sucursal suc, String cta, jfrmPrincipal principal, Caja caja_activa) {
        initComponents();
        this.setLocationRelativeTo(null);
        s = suc;
        ctaActiva = cta;
        p = new jfrmPrincipal(suc,caja_activa);
        p = principal;

        mostrar_domiciliaciones();
    }

    /** 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();
        jScrollPane1 = new javax.swing.JScrollPane();
        jL_lista = new javax.swing.JList();
        jBtn_Atras = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Domiciliaciones");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Domiciliaciones de la cuenta");

        jScrollPane1.setViewportView(jL_lista);

        jBtn_Atras.setText("Atrás");
        jBtn_Atras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_AtrasActionPerformed(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()
                        .addGap(35, 35, 35)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addComponent(jBtn_Atras)))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBtn_Atras)
                .addContainerGap(28, Short.MAX_VALUE))
        );

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

    private void jBtn_AtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_AtrasActionPerformed
        // TODO add your handling code here:
        p.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jBtn_AtrasActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        p.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

    private void mostrar_domiciliaciones(){
        Producto produc = new Producto();
        ArrayList<String> lista_dom;
        String elemento_list = "";
        int contador = 0;
        produc = s.buscarCuenta(ctaActiva);
        lista_dom = produc.getDomiciliaciones();

        DefaultListModel dlm = new DefaultListModel();
        jL_lista.setModel(dlm);
        jL_lista.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        if(!lista_dom.isEmpty())
        {
            for(int i=lista_dom.size(); i>0 ;i--)
            {
                contador++;
                elemento_list = (contador) + " // " + lista_dom.get(i-1).toString();
                dlm.addElement(elemento_list);
            }
        }
        else
        {
            JOptionPane dialogo = new JOptionPane();
            JOptionPane.showMessageDialog(rootPane, "No hay domiciliaciones en esta cuenta", "Aviso", JOptionPane.INFORMATION_MESSAGE);

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtn_Atras;
    private javax.swing.JList jL_lista;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
