
package bbuvajava;

public class jfrmUltimosMovimientos extends javax.swing.JFrame {
    Sucursal auxsuc;
    public jfrmUltimosMovimientos(Sucursal suc) {
        initComponents();
        auxsuc=suc;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        Brealizar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Tarea = new javax.swing.JTextArea();
        TBcuenta = new javax.swing.JTextField();
        TBnmov = new javax.swing.JTextField();
        LabelPrincipal = new javax.swing.JLabel();
        TBdetalle = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        Bdetalle = new javax.swing.JButton();

        jLabel2.setText("Nº CUENTA :");

        jLabel3.setText("Nº MOVIMIENTOS:");

        Brealizar.setText("REALIZAR");
        Brealizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrealizarActionPerformed(evt);
            }
        });

        Tarea.setColumns(20);
        Tarea.setEditable(false);
        Tarea.setRows(5);
        jScrollPane1.setViewportView(Tarea);

        TBcuenta.setText("20984002161000015263");

        LabelPrincipal.setFont(new java.awt.Font("Tahoma", 0, 14));
        LabelPrincipal.setForeground(new java.awt.Color(255, 0, 0));
        LabelPrincipal.setText("ULTIMOS MOVIMIENTOS");

        jLabel1.setText("Nº MOV:");

        Bdetalle.setText("VER MOVIMIENTO EN DETALLE");
        Bdetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BdetalleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(129, Short.MAX_VALUE)
                .addComponent(LabelPrincipal)
                .addGap(134, 134, 134))
            .addGroup(layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(jLabel1)
                .addGap(33, 33, 33)
                .addComponent(TBdetalle, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Bdetalle)
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Brealizar)
                            .addComponent(TBcuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TBnmov, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(44, 44, 44))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LabelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(TBcuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(TBnmov, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(Brealizar)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(Bdetalle)
                    .addComponent(TBdetalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

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

    private void BrealizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrealizarActionPerformed
        String cuenta=TBcuenta.getText();
        String nmov=TBnmov.getText();
     
        if (TBnmov.getText().isEmpty()){Tarea.setText("\n  Indica el numero de movimientos.");}
        else{
        Producto p=auxsuc.get_Producto(cuenta);
        int n = Integer.parseInt(nmov);
        if(p!=null){
            if(p.getMovimiento().size()>=n){
                String mensaje;
                mensaje=p.mostrar_nmovimientos(n);
                Tarea.setText(mensaje);
             }

            else{
                Tarea.setText("\n  No hay tantos movimientos");
            }
        }
        else{
           TBcuenta.setText("NºCuenta incorrecto");
        }

        }
}//GEN-LAST:event_BrealizarActionPerformed

    private void BdetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BdetalleActionPerformed
        String nmov=TBdetalle.getText();
        String cuenta=TBcuenta.getText();
        int n = Integer.parseInt(nmov);
        Producto p=auxsuc.get_Producto(cuenta);
        if(p!=null){
             Movimiento m=p.get_Movimiento(n);
             if(m!=null){
                  String mensaje=m.detalle();
                  String mensaje2="bien tio bien";
                 new jfrmMovDetalle(mensaje).setVisible(true);
             }
             else{
                String mensaje="NUMERO DE MOVIMIENTO INCORRECTO";
                new jfrmMovDetalle(mensaje).setVisible(true);
             }
        }
        else{
           TBcuenta.setText("NºCUENTA INCORRECTO");
        }
}//GEN-LAST:event_BdetalleActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Bdetalle;
    private javax.swing.JButton Brealizar;
    private javax.swing.JLabel LabelPrincipal;
    private javax.swing.JTextField TBcuenta;
    private javax.swing.JTextField TBdetalle;
    private javax.swing.JTextField TBnmov;
    private javax.swing.JTextArea Tarea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
