Example #1
0
 private void PrecioKeyTyped(java.awt.event.KeyEvent evt) { // GEN-FIRST:event_PrecioKeyTyped
   // TODO add your handling code here:
   int cont = 0;
   char caracter = evt.getKeyChar();
   if (cont == 0) {
     if (((caracter < '0') || (caracter > '9'))
         && (caracter != KeyEvent.VK_BACK_SPACE)
         && (caracter != '.')) {
       evt.consume();
     } else if (caracter == '.') {
       String s = Precio.getText();
       if (s.length() == 0) {
         Precio.setText(0 + s);
       }
       cont++;
     }
   } else {
     if ((caracter < '0' || caracter > '9')) evt.consume();
   }
   if ((int) caracter == 8) {
     if (Precio.getText().equals("")) {
       cont = 0;
     }
   }
 } // GEN-LAST:event_PrecioKeyTyped
Example #2
0
 private void PrecioFocusLost(java.awt.event.FocusEvent evt) { // GEN-FIRST:event_PrecioFocusLost
   // TODO add your handling code here:
   try {
     if (!(Precio.getText().equals(""))) {
       double x = parseDouble(Precio.getText());
     }
   } catch (NumberFormatException e) {
     this.getToolkit().beep();
     JOptionPane.showMessageDialog(
         null,
         "Solo se pueden insertar numeros decimales",
         "Solo Numeros Decimales",
         JOptionPane.ERROR_MESSAGE,
         null);
     Precio.requestFocus();
     Precio.selectAll();
   }
 } // GEN-LAST:event_PrecioFocusLost
Example #3
0
  private void AceptarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_AceptarActionPerformed
    // TODO add your handling code here:
    if (!(Name.getText().equals("")
        && Cantidad.getText().equals("")
        && Precio.getText().equals("")
        && Marca.getText().equals("")
        && jTextArea1.getText().equals("")
        && Vias.getSelectedItem().equals("Vias de administracion")
        && Forma.getSelectedItem().equals("Forma")
        && Tipo.getSelectedItem().equals("Tipo"))) {
      if (b == false) {
        Producto p = new Producto();
        p.setName(Name.getText());
        p.setId(parseInt(jLabel2.getText()));
        p.setCantidad(parseInt(Cantidad.getText()));
        p.setPrecio(parseDouble(Precio.getText()));
        p.setDescripcion(jTextArea1.getText());
        p.setMarca(Marca.getText());
        p.setVia((String) Vias.getSelectedItem());
        p.setForma((String) Forma.getSelectedItem());
        p.setTipo((String) Tipo.getSelectedItem());
        Clear();
        new Conectar().ModificarProd(p);
        JOptionPane.showMessageDialog(null, "Su producto fue modificado exitosamente");
        dispose();
      } else {
        List<Producto> p1 = new Conectar().ConexionProd();
        for (Producto pd : p1) {
          String s, s1;
          s = new Search().SetLength("" + pd.getId());
          s1 = jLabel2.getText();
          if (s.equals(s1)) {
            double x = pd.getPrecio(), x1 = parseDouble(Precio.getText());
            double t = (x + x1) / 2;
            int y = pd.getCantidad(), y1 = parseInt(Cantidad.getText());
            int t1 = y + y1;
            Producto p = new Producto();
            p = pd;
            p.setPrecio(t);
            p.setCantidad(t1);
            Clear();
            new Conectar().ModificarProd(p);
            Calendar c = Calendar.getInstance();
            String Fecha = Integer.toString(c.get(Calendar.DATE));
            Fecha += "/";
            Fecha += Integer.toString(c.get(Calendar.MONTH) + 1);
            Fecha += "/";
            Fecha += Integer.toString(c.get(Calendar.YEAR));
            String name = null;
            try {
              name = new UseUser().GetUser();
            } catch (IOException e) {
            }
            name = name.trim();
            Producto p2 = new Producto();
            p2 = pd;
            p2.setCantidad(y1);
            p2.setPrecio(x1);
            new Conectar().InsertCompra(p2, Fecha, name);
            JOptionPane.showMessageDialog(null, "Su Compra fue realizada exitosamente");
            dispose();
          }
        }
      }
    } else if (!(Name.getText().equals("")
        && Cantidad.getText().equals("")
        && Precio.getText().equals("")
        && Marca.getText().equals("")
        && jTextArea1.getText().equals("")
        && Vias.getSelectedItem().equals("Vias de administracion")
        && Forma.getSelectedItem().equals("Forma")
        && Tipo.getSelectedItem().equals("Tipo")
        && b)) {

    } else {
      JOptionPane.showMessageDialog(
          null,
          "Debe de llenar todos los campos",
          "Informacion Incompleta",
          JOptionPane.INFORMATION_MESSAGE,
          null);
    }
  } // GEN-LAST:event_AceptarActionPerformed
Example #4
0
  /**
   * 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() {
    java.awt.GridBagConstraints gridBagConstraints;

    jPanel1 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    Name = new javax.swing.JTextField(8);
    jLabel3 = new javax.swing.JLabel();
    Marca = new javax.swing.JTextField(8);
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    Cantidad = new javax.swing.JTextField(8);
    Precio = new javax.swing.JTextField(8);
    jLabel6 = new javax.swing.JLabel();
    Vias = new javax.swing.JComboBox();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    Forma = new javax.swing.JComboBox();
    Tipo = new javax.swing.JComboBox();
    jLabel9 = new javax.swing.JLabel();
    jPanel3 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jPanel5 = new javax.swing.JPanel();
    Aceptar = new javax.swing.JButton();
    Limpiar = new javax.swing.JButton();
    Atras = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setResizable(false);

    jPanel1.setLayout(new java.awt.BorderLayout());

    java.awt.GridBagLayout jPanel2Layout = new java.awt.GridBagLayout();
    jPanel2Layout.columnWidths =
        new int[] {
          0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8, 0, 8,
          0
        };
    jPanel2Layout.rowHeights = new int[] {0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0};
    jPanel2.setLayout(jPanel2Layout);

    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel1.setText("Id:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel1, gridBagConstraints);

    jLabel2.setText("jLabel2");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel2, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Name, gridBagConstraints);

    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel3.setText("Nombre:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel3, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Marca, gridBagConstraints);

    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel4.setText("Marca:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel4, gridBagConstraints);

    jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel5.setText("Cantidad:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel5, gridBagConstraints);

    Cantidad.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            CantidadFocusLost(evt);
          }
        });
    Cantidad.addKeyListener(
        new java.awt.event.KeyAdapter() {
          public void keyTyped(java.awt.event.KeyEvent evt) {
            CantidadKeyTyped(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Cantidad, gridBagConstraints);

    Precio.addFocusListener(
        new java.awt.event.FocusAdapter() {
          public void focusLost(java.awt.event.FocusEvent evt) {
            PrecioFocusLost(evt);
          }
        });
    Precio.addKeyListener(
        new java.awt.event.KeyAdapter() {
          public void keyTyped(java.awt.event.KeyEvent evt) {
            PrecioKeyTyped(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Precio, gridBagConstraints);

    jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel6.setText("Precio:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel6, gridBagConstraints);

    Vias.removeAllItems();
    String[] v = {
      "Oral",
      "Intramuscular",
      "Intravenosa",
      "Subcutánea",
      "Inhalatoria",
      "Transdermica",
      "Nasal",
      "Oftalmica",
      "Ótica",
      "Tópica",
      "Rectal",
      "Vaginal"
    };
    Vias.addItem("Vias de administracion");
    for (String s : v) {
      Vias.addItem(s);
    }
    Vias.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ViasActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Vias, gridBagConstraints);

    jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel7.setText("Via:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel7, gridBagConstraints);

    jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel8.setText("Forma:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 12;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel8, gridBagConstraints);

    Forma.removeAllItems();
    Forma.addItem("Forma");
    Forma.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            FormaActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 12;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Forma, gridBagConstraints);

    Tipo.removeAllItems();
    Tipo.addItem("Tipo");
    Tipo.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            TipoActionPerformed(evt);
          }
        });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 14;
    gridBagConstraints.gridy = 14;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(Tipo, gridBagConstraints);

    jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabel9.setText("Tipo:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 12;
    gridBagConstraints.gridy = 14;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    jPanel2.add(jLabel9, gridBagConstraints);

    jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);
    jPanel1.add(jPanel3, java.awt.BorderLayout.PAGE_START);

    jPanel4.setLayout(new java.awt.BorderLayout());

    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder("Descripción"));
    jScrollPane1.setViewportView(jTextArea1);

    jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);

    Aceptar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    Aceptar.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            AceptarActionPerformed(evt);
          }
        });
    jPanel5.add(Aceptar);

    Limpiar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    Limpiar.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            LimpiarActionPerformed(evt);
          }
        });
    jPanel5.add(Limpiar);

    Atras.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    Atras.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            AtrasActionPerformed(evt);
          }
        });
    jPanel5.add(Atras);

    jPanel4.add(jPanel5, java.awt.BorderLayout.PAGE_END);

    jPanel1.add(jPanel4, java.awt.BorderLayout.PAGE_END);

    getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

    setSize(new java.awt.Dimension(464, 468));
    setLocationRelativeTo(null);
  } // </editor-fold>//GEN-END:initComponents