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

/*
 * jfrmAperturaPrestamo.java
 *
 * Created on 28-ene-2010, 20:28:04
 */

package Vistas;
import Hito4.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;
/**
 *
 * @author Ro
 */
public class jfrmRemesaTrans extends javax.swing.JFrame {
    Sucursal sucursal;
    javax.swing.JFrame auxjf;

    /** Creates new form jfrmAperturaPrestamo */
    public jfrmRemesaTrans(Sucursal s, javax.swing.JFrame jf) {
        sucursal=s;
        auxjf=jf;
        initComponents();

        List<OP_Transferencia> OPT =sucursal.getMOP_Transferencia();

        DefaultListModel dlm = new DefaultListModel();
        jlstRemTrans.setModel(dlm);
        dlm.addElement("Concepto             Fecha     Importe       Cuenta Origen        Cuenta Destino");
        Iterator iterador = OPT.listIterator();
        while( iterador.hasNext()) {
            OP_Transferencia opt = (OP_Transferencia) iterador.next();
            Date fechaActual = new Date();
            fechaActual=opt.getFechaOperacion();
            SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
            String cadenaFecha = formato.format(fechaActual);

            dlm.addElement("\n"+opt.getConcepto()+"         "+cadenaFecha+"     "+opt.getImporte()+"       "+opt.getOrigen()+"       "+opt.getDestino());
        }
    }

    /** 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();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jlstRemTrans = new javax.swing.JList();
        jbtnSalir = new javax.swing.JButton();
        jlblMensaje = new javax.swing.JLabel();
        jbtnGenera = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

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

        jLabel1.setFont(new java.awt.Font("Papyrus", 1, 18)); // NOI18N
        jLabel1.setText("Remesa Transferencias");

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

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

        jbtnGenera.setText("Generar Fichero");
        jbtnGenera.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnGeneraActionPerformed(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(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jbtnGenera)
                        .addGap(42, 42, 42)
                        .addComponent(jbtnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(195, 195, 195))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 215, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addGap(78, 78, 78)))
                .addGap(60, 60, 60))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(326, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(204, 204, 204))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnSalir)
                    .addComponent(jbtnGenera))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11))
        );

        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 jbtnGeneraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnGeneraActionPerformed
        String sFichero = "RemesaTransferencia.txt";
        File fichero = new File(sFichero);
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(sFichero));
        } catch (IOException ex) {
            Logger.getLogger(jfrmRemesaTrans.class.getName()).log(Level.SEVERE, null, ex);
        }

        List<OP_Transferencia> OPT =sucursal.getMOP_Transferencia();
        try {
            bw.write("Concepto             Fecha     Importe       Cuenta Origen        Cuenta Destino");
        } catch (IOException ex) {
            Logger.getLogger(jfrmRemesaTrans.class.getName()).log(Level.SEVERE, null, ex);
        }
        Iterator iterador = OPT.listIterator();
        while( iterador.hasNext()) {
            OP_Transferencia opt = (OP_Transferencia) iterador.next();
            Date fechaActual = new Date();
            fechaActual=opt.getFechaOperacion();
            SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
            String cadenaFecha = formato.format(fechaActual);
            try {
                bw.write("\n" + opt.getConcepto() + "         " + cadenaFecha + "     " + opt.getImporte() + "       " + opt.getOrigen() + "       " + opt.getDestino());
            } catch (IOException ex) {
                Logger.getLogger(jfrmRemesaTrans.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        try {
            bw.close();
        } catch (IOException ex) {
            Logger.getLogger(jfrmRemesaTrans.class.getName()).log(Level.SEVERE, null, ex);
        }
        jlblMensaje.setText("Fichero Generado Correctamente.");
}//GEN-LAST:event_jbtnGeneraActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnGenera;
    private javax.swing.JButton jbtnSalir;
    private javax.swing.JLabel jlblMensaje;
    private javax.swing.JList jlstRemTrans;
    // End of variables declaration//GEN-END:variables

}
