Вы находитесь на странице: 1из 4

package VentanaPanel; import import import import import import import Conexion.ModificarIngresarVenta; java.sql.SQLException; java.util.Vector; java.util.logging.Level; java.util.logging.Logger; javax.swing.

JOptionPane; javax.swing.table.DefaultTableModel;

/** * * @author Jeremias */ public class Venta extends javax.swing.JDialog { public int n = 0, cant1 = 0, cant2 = 0, resultado = 0, cant = 0, i = 0, idtabla = 0, pos = 0, h; public double pre1 = 0.0, pre2 = 0.0, resu = 0.0; /** Creates new form Venta */ public Venta(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } public Venta(java.awt.Frame parent, boolean modal, FacturaSandalia f) { super(parent, modal); 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"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtCantidad = new javax.swing.JTextField(); btnCargar = new javax.swing.JButton(); btnCancelar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Ventana Cantidad"); setIconImage(null); getContentPane().setLayout(new java.awt.GridLayout(2, 2, 5, 5)); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Cantidad a Vender"); getContentPane().add(jLabel1); txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtCantidadKeyTyped(evt);

} }); getContentPane().add(txtCantidad); btnCargar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N btnCargar.setText("Cargar"); btnCargar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCargarActionPerformed(evt); } }); getContentPane().add(btnCargar); btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 12)); btnCancelar.setText("Cancelar"); btnCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelarActionPerformed(evt); } }); getContentPane().add(btnCancelar); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().get ScreenSize(); setBounds((screenSize.width-280)/2, (screenSize.height-104)/2, 280, 104) ; }// </editor-fold> private void btnCargarActionPerformed(java.awt.event.ActionEvent evt) { n = FacturaSandalia.tabla.getSelectedRow(); int d = FacturaSandalia.tablaFactura.getSelectedRow(); i = FacturaSandalia.tablaFactura.getRowCount(); DefaultTableModel modelo = (DefaultTableModel) FacturaSandalia.tablaFact ura.getModel(); idtabla = Integer.parseInt(FacturaSandalia.tabla.getValueAt(n, 0).toStri ng().trim()); cant1 = Integer.parseInt(FacturaSandalia.tabla.getValueAt(n, 3).toString ().trim()); cant2 = Integer.parseInt(txtCantidad.getText()); pre1 = Double.parseDouble(FacturaSandalia.tabla.getValueAt(n, 4).toStrin g()); // resultado = cant2; resu = pre1 * cant2; cant = cant1 - cant2; if (!((cant1 - cant2) <= 0)) { if (i > 0) { if (idtabla == IdTabla2()) { FacturaSandalia.tablaFactura.setValueAt(cant2 + Integer.pars eInt(FacturaSandalia.tablaFactura.getValueAt(numPosicion(), 2).toString().trim() ), numPosicion(), 2); FacturaSandalia.tablaFactura.setValueAt(resu + Double.parseD ouble(FacturaSandalia.tablaFactura.getValueAt(numPosicion(), 3).toString().trim( )), numPosicion(), 3); FacturaSandalia.tabla.setValueAt(cant, n, 3); System.out.println(1);

} else { insertarTablaFactura(); System.out.println(2); } } else { insertarTablaFactura(); System.out.println(3); } } else { JOptionPane.showMessageDialog(null, "NO HAY SUFICIENTE INVERNTARIO") ; } //this.txtCantidad.setText(""); this.dispose(); } public int numPosicion() { System.out.println("d= "+d+" i6= "+i6); for (int w = 0; w < (i); w++) { if (idtabla == Integer.parseInt(FacturaSandalia.tablaFactura.getValu eAt(w, 0).toString().trim())) { h = w; } } System.out.print("posicion= " + h); return h; } // public int IdTabla2() { int n = 0; for (int j2 = 0; j2 < (i); j2++) { if (Integer.parseInt(FacturaSandalia.tablaFactura.getValueAt(j2, 0). toString().trim()) == idtabla) { // System.out.println(" IdTabla2= " + tablaFacura.tabla2.getValue At(j, 0).toString().trim()); n = Integer.parseInt(FacturaSandalia.tablaFactura.getValueAt(j2, 0).toString().trim()); } } System.out.print("id= " + n); p = Integer.parseInt(tablaFacura.tabla1.getValueAt(6, 0).toString().tr return n; } public void insertarTablaFactura() { DefaultTableModel modelo = (DefaultTableModel) FacturaSandalia.tablaFact ura.getModel(); FacturaSandalia.tabla.setValueAt(cant, n, 3); Vector v = new Vector(); v.add(FacturaSandalia.tabla.getValueAt(n, 0)); v.add(FacturaSandalia.tabla.getValueAt(n, 1)); v.add(resultado); v.add(resu); modelo.addRow(v); FacturaSandalia.tablaFactura.setModel(modelo);

// im());

} private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) { char c = evt.getKeyChar(); if (!(Character.isDigit(c))) { evt.consume(); } } /** * @param args the command line arguments */ // Variables declaration - do not modify private javax.swing.JButton btnCancelar; private javax.swing.JButton btnCargar; private javax.swing.JLabel jLabel1; private javax.swing.JTextField txtCantidad; // End of variables declaration }

Вам также может понравиться