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

/*
 * jfrmIngreso.java
 *
 * Created on 21-nov-2009, 12:49:42
 */

package interfaz;

import com.sun.java.swing.plaf.windows.resources.windows;
import daial.Caja;
import daial.Sucursal;
import java.awt.Dialog;
import java.awt.Dialog.ModalityType;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

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

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

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

    /** 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();
        jLabel2 = new javax.swing.JLabel();
        jBtn_ingresar = new javax.swing.JButton();
        jBtn_atras = new javax.swing.JButton();
        jTxt_cantidad = new javax.swing.JTextField();

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

        jLabel1.setText("INGRESO");

        jLabel2.setText("Cantidad a ingresar: ");

        jBtn_ingresar.setText("Aceptar");
        jBtn_ingresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_ingresarActionPerformed(evt);
            }
        });

        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(164, 164, 164)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jBtn_ingresar)
                            .addComponent(jLabel2))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(46, 46, 46)
                                .addComponent(jBtn_atras))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jTxt_cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(73, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(jLabel1)
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTxt_cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtn_ingresar)
                    .addComponent(jBtn_atras))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleDescription("Ingresar dinero");

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

    private void jBtn_ingresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_ingresarActionPerformed
        // TODO add your handling code here:
        if(jTxt_cantidad.getText().compareTo("") != 0)
        {
            double ingreso = Double.parseDouble(jTxt_cantidad.getText());
            s.buscarCuenta(ctaActiva).ingresar_enCta(ingreso, caja_activa);
            p.actualizar_info();
            JOptionPane dialogo = new JOptionPane();
            JOptionPane.showMessageDialog(rootPane, "Ingreso realizado con éxito", "Aviso", JOptionPane.INFORMATION_MESSAGE);            
            p.setEnabled(true);
            this.dispose();           
        }


}//GEN-LAST:event_jBtn_ingresarActionPerformed

    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
/**/
    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new jfrmIngreso().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtn_atras;
    private javax.swing.JButton jBtn_ingresar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTxt_cantidad;
    // End of variables declaration//GEN-END:variables

}
