Пример #1
0
 private void agregarFila(Producto c) {
   String row[] = new String[3];
   row[0] = c.getString("numero_producto");
   row[1] = c.getString("nombre");
   row[2] = c.getString("marca");
   tablaProductos.addRow(row);
 }
Пример #2
0
 private void actualizarLista() {
   if (!Base.hasConnection()) {
     Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/sexshop", "root", "root");
   }
   tablaProductos.setRowCount(0);
   Iterator<Producto> it = pl.iterator();
   while (it.hasNext()) {
     Producto a = it.next();
     String row[] = new String[3];
     row[0] = a.getString("numero_producto");
     row[1] = a.getString("nombre");
     row[2] = a.getString("marca");
     tablaProductos.addRow(row);
   }
   if (Base.hasConnection()) Base.close();
 }
Пример #3
0
 public void actualizarListaProd() {
   abrirBase();
   tablaProd.setRowCount(0);
   prodlista =
       busqueda.filtroProducto(textcodprod.getText(), textnom.getText(), textmarca.getText());
   Iterator<Producto> it = prodlista.iterator();
   while (it.hasNext()) {
     Producto a = it.next();
     String row[] = new String[3];
     row[0] = a.getString("numero_producto");
     row[1] = a.getString("nombre");
     row[2] = a.getString("marca");
     tablaProd.addRow(row);
   }
   if (Base.hasConnection()) {
     Base.close();
   }
 }
Пример #4
0
  private void cargarDatosProd(Producto c, boolean id) {
    try {
      String nombre = TratamientoString.eliminarTildes(prodGui.getNombre().getText()).toUpperCase();
      c.set("nombre", nombre);
    } catch (ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en el nombre", "Error!", JOptionPane.ERROR_MESSAGE);
    }
    try {
      String marca = TratamientoString.eliminarTildes(prodGui.getMarca().getText()).toUpperCase();
      c.set("marca", marca);
    } catch (ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en la marca", "Error!", JOptionPane.ERROR_MESSAGE);
    }
    try {
      String tipo = TratamientoString.eliminarTildes(prodGui.getTipo().getText()).toUpperCase();
      c.set("tipo", tipo);
    } catch (ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en el tipo", "Error!", JOptionPane.ERROR_MESSAGE);
    }
    try {
      Double precioCompra =
          Double.valueOf(
              TratamientoString.eliminarTildes(prodGui.getPrecioCompra().getText()).toUpperCase());
      c.set("precio_compra", BigDecimal.valueOf(precioCompra).setScale(2, RoundingMode.CEILING));
    } catch (NumberFormatException | ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en precio de compra", "Error!", JOptionPane.ERROR_MESSAGE);
    }
    try {
      Double precioVenta =
          Double.valueOf(
              TratamientoString.eliminarTildes(prodGui.getPrecioVenta().getText()).toUpperCase());
      c.set("precio_venta", BigDecimal.valueOf(precioVenta).setScale(2, RoundingMode.CEILING));
    } catch (NumberFormatException | ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en precio de venta", "Error!", JOptionPane.ERROR_MESSAGE);
    }

    c.set("stock", prodGui.getStock().getValue());

    try {
      Integer numeroProducto = Integer.valueOf(prodGui.getIdArticulo().getText());
      c.set("numero_producto", numeroProducto);
    } catch (NumberFormatException | ClassCastException e) {
      JOptionPane.showMessageDialog(
          prodGui, "Error en el numero de producto", "Error!", JOptionPane.ERROR_MESSAGE);
    }

    // if(id)
    // c.setId(TratamientoString.eliminarTildes(prodGui.getIdArticulo().getText()).toUpperCase());
  }
Пример #5
0
 public void tablaMouseClicked(java.awt.event.MouseEvent evt) {
   prodGui.getProveedores().removeAllItems();
   abrirBase();
   prodGui.habilitarCampos(false);
   prodGui.getModificar().setEnabled(true);
   prodGui.getBorrar().setEnabled(true);
   prodGui.getGuardar().setEnabled(false);
   nuevoPulsado = false;
   modificarPulsado = false;
   System.out.println("tabla pulsada");
   int r = tabla.getSelectedRow();
   Producto p = Producto.first("numero_producto = ?", tabla.getValueAt(r, 0));
   if (p != null) {
     prodGui.CargarCampos(p);
     Proveedor prov = Proveedor.findById(p.getInteger("proveedor_id"));
     if (prov != null) {
       String nom = prov.getString("nombre");
       String cuil = prov.getString("cuil");
       String pr = nom + ";" + cuil;
       prodGui.getProveedores().addItem(pr);
     }
   }
   if (Base.hasConnection()) Base.close();
 }
Пример #6
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == ventaGui.getClienteALaFactura()) { // Boton cliente a la factura
      int row = ventaGui.getTablaClientes().getSelectedRow();
      if (row > -1) {
        String id = (String) tablaClientes.getValueAt(row, 0);
        String nom = (String) tablaClientes.getValueAt(row, 1);
        String ap = (String) tablaClientes.getValueAt(row, 2);
        ventaGui.getClienteFactura().setText(id + " " + nom + " " + ap);
      }
    }

    if (e.getSource() == ventaGui.getArticulosALaFactura()) { // Boton articulos a la factura
      int[] rows = ventaGui.getTablaArticulos().getSelectedRows();
      if (rows.length > 0) {
        for (int i = 0; i < rows.length; i++) {
          abrirBase();
          if (!existeProdFacc(Integer.valueOf((String) tablap.getValueAt(rows[i], 0)))) {
            Producto p = Producto.findFirst("numero_producto = ?", (tablap.getValueAt(rows[i], 0)));
            Object cols[] = new Object[5];
            cols[0] = p.get("numero_producto");
            cols[1] = 1;
            cols[2] = p.get("nombre") + " " + p.get("marca");
            cols[3] =
                BigDecimal.valueOf(p.getFloat("precio_venta")).setScale(2, RoundingMode.CEILING);
            cols[4] =
                BigDecimal.valueOf(p.getFloat("precio_venta")).setScale(2, RoundingMode.CEILING);
            if (Base.hasConnection()) {
              Base.close();
            }
            ventaGui.getTablaFacturaDefault().addRow(cols);
            setCellEditor();
            actualizarPrecio();
          }
        }
      }
    }

    if (e.getSource()
        == ventaGui.getBorrarArticulosSeleccionados()) { // boton borrar articulos seleccionados
      int[] rows = ventaGui.getTablaFactura().getSelectedRows();
      if (rows.length > 0) {
        Integer[] idABorrar = new Integer[rows.length];
        for (int i = 0; i < rows.length; i++) {
          idABorrar[i] = (Integer) tablafac.getValueAt(rows[i], 0);
        }
        int i = 0;
        int cantABorrar = 0;
        while (cantABorrar < rows.length) {
          while (i < ventaGui.getTablaFactura().getRowCount()) {
            if ((Integer) ventaGui.getTablaFactura().getValueAt(i, 0) == idABorrar[cantABorrar]) {
              ventaGui.getTablaFacturaDefault().removeRow(i);
              cantABorrar++;
            }
            i++;
          }
          i = 0;
        }
        actualizarPrecio();
      }
    }

    if (e.getSource() == ventaGui.getRealizarVenta()) { // Boton realizar venta
      if (ventaGui.getClienteFactura().getText().equals("")
          || ventaGui.getCalenFacturaText().getText().equals("")) {
        JOptionPane.showMessageDialog(
            ventaGui, "Fecha o cliente vacios", "Error!", JOptionPane.ERROR_MESSAGE);
      } else {
        Venta v = new Venta();
        LinkedList<Pair> parDeProductos = new LinkedList();
        String laFecha = ventaGui.getCalenFacturaText().getText(); // saco la fecha
        String cliente = ventaGui.getClienteFactura().getText();
        Integer idCliente = Integer.valueOf(cliente.split(" ")[0]); // saco el id cliente
        for (int i = 0; i < ventaGui.getTablaFactura().getRowCount(); i++) {
          abrirBase();
          Producto producto = Producto.findFirst("numero_producto = ?", tablafac.getValueAt(i, 0));
          if (Base.hasConnection()) {
            Base.close();
          }
          Integer cantidad = (Integer) tablafac.getValueAt(i, 1); // saco la cantidad
          BigDecimal precioFinal = (BigDecimal) tablafac.getValueAt(i, 3);
          Pair parCantYPrecioFinal = new Pair(cantidad, precioFinal.doubleValue());
          Pair par = new Pair(producto, parCantYPrecioFinal); // creo el par
          parDeProductos.add(par); // meto el par a la lista
        }
        v.set("fecha", laFecha);
        v.set("cliente_id", idCliente);
        v.setProductos(parDeProductos);
        abrirBase();
        if (abmVenta.alta(v)) {
          if (JOptionPane.showConfirmDialog(
                  ventaGui,
                  "¿Desea abrir el dialogo de impresión?",
                  "¡Venta exitosa!",
                  JOptionPane.YES_NO_OPTION)
              == 0) {
            try {
              reporteFactura.mostrarFactura(abmVenta.getUltimoIdVenta());
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JRException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
          ventaGui.limpiarVentana();
        } else {
          JOptionPane.showMessageDialog(
              ventaGui, "Ocurrió un error inesperado, venta no realizada");
        }
      }
      if (Base.hasConnection()) {
        Base.close();
      }
    }

    if (e.getSource() == ventaGui.getFacturaNueva()) {
      ventaGui.limpiarVentana();
      ventaGui.getModificar().setEnabled(false);
      ventaGui.getRealizarVenta().setEnabled(true);
    }

    if (e.getSource() == ventaGui.getModificar()) {
      if (ventaGui.getClienteFactura().getText().equals("")
          || ventaGui.getCalenFacturaText().getText().equals("")) {
        JOptionPane.showMessageDialog(
            ventaGui, "Fecha o cliente vacios", "Error!", JOptionPane.ERROR_MESSAGE);
      } else {
        Venta v = new Venta();
        LinkedList<Pair> parDeProductos = new LinkedList();
        String laFecha = ventaGui.getCalenFacturaText().getText(); // saco la fecha
        String cliente = ventaGui.getClienteFactura().getText();
        Integer idCliente = Integer.valueOf(cliente.split(" ")[0]); // saco el id cliente
        for (int i = 0; i < ventaGui.getTablaFactura().getRowCount(); i++) {
          abrirBase();
          Producto producto = Producto.findFirst("numero_producto = ?", tablafac.getValueAt(i, 0));
          if (Base.hasConnection()) {
            Base.close();
          }
          Integer cantidad = (Integer) tablafac.getValueAt(i, 1); // saco la cantidad
          BigDecimal precioFinal = (BigDecimal) tablafac.getValueAt(i, 3);
          Pair parCantYPrecioFinal = new Pair(cantidad, precioFinal.doubleValue());
          Pair par = new Pair(producto, parCantYPrecioFinal); // creo el par
          parDeProductos.add(par); // meto el par a la lista
        }
        v.set("fecha", laFecha);
        v.set("cliente_id", idCliente);
        v.setProductos(parDeProductos);
        System.out.print(idFacturaAModificar);
        v.set("id", idFacturaAModificar);
        abrirBase();
        if (abmVenta.modificar(v)) {
          if (JOptionPane.showConfirmDialog(
                  ventaGui,
                  "¿Desea abrir el dialogo de impresión?",
                  "¡Venta modificada!",
                  JOptionPane.YES_NO_OPTION)
              == 0) {
            try {
              reporteFactura.mostrarFactura(idFacturaAModificar);
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JRException ex) {
              Logger.getLogger(VentaControlador.class.getName()).log(Level.SEVERE, null, ex);
            }
          }

          ventaGui.limpiarVentana();
          ventaGui.getModificar().setEnabled(false);
          ventaGui.getRealizarVenta().setEnabled(true);

        } else {
          JOptionPane.showMessageDialog(
              ventaGui, "Ocurrió un error inesperado, venta no realizada");
        }
      }
      if (Base.hasConnection()) {
        Base.close();
      }
    }
    ventasControlador.actualizarListaFacturas();
  }
Пример #7
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == prodGui.getModificar()) { // Modificar producto
      prodGui.getGuardar().setEnabled(true);
      modificarPulsado = true;
      nuevoPulsado = false;
      prodGui.habilitarCampos(true);
      prodGui.getIdArticulo().setEditable(false);
      prodGui.getProveedores().removeAllItems();
      abrirBase();
      int r = tabla.getSelectedRow();
      if (r > -1) {
        Producto p = Producto.first("numero_producto = ?", tabla.getValueAt(r, 0));

        LazyList<Proveedor> l = Proveedor.findAll();
        Iterator<Proveedor> it = l.iterator();
        while (it.hasNext()) {
          Proveedor prov = it.next();
          String nom = prov.getString("nombre");
          String cuil = prov.getString("cuil");
          String prove = nom + ";" + cuil;
          prodGui.getProveedores().addItem(prove);
        }
        if (p != null) {
          prodGui.CargarCampos(p);
          Proveedor prov = Proveedor.findById(p.getInteger("proveedor_id"));
          if (prov != null) {
            String nom = prov.getString("nombre");
            String cuil = prov.getString("cuil");
            String pr = nom + ";" + cuil;
            prodGui.getProveedores().setSelectedItem(pr);
          }
        }
      }
      if (Base.hasConnection()) Base.close();

      // Agregar al combo todos los proveedores!
    }
    if (e.getSource() == prodGui.getNuevo()) { // Producto nuevo
      prodGui.getGuardar().setEnabled(true);
      nuevoPulsado = true;
      modificarPulsado = false;
      prodGui.getModificar().setEnabled(false);
      prodGui.getBorrar().setEnabled(false);
      prodGui.limpiarCampos();
      prodGui.habilitarCampos(true);
      prodGui.getProveedores().removeAllItems();
      abrirBase();
      LazyList<Proveedor> l = Proveedor.findAll();
      Iterator<Proveedor> it = l.iterator();
      while (it.hasNext()) {
        Proveedor prov = it.next();
        String nom = prov.getString("nombre");
        String cuil = prov.getString("cuil");
        String prove = nom + ";" + cuil;
        prodGui.getProveedores().addItem(prove);
      }
      if (Base.hasConnection()) Base.close();
      // Agregar al combo todos los proveedores
    }
    if (e.getSource() == prodGui.getGuardar() && modificarPulsado) {
      String id = prodGui.getIdArticulo().getText();
      abrirBase();
      Producto p = Producto.first("numero_producto = ?", id);
      cargarDatosProd(p, false);
      if (Base.hasConnection()) Base.close();
      String prov = (String) prodGui.getProveedores().getSelectedItem();
      String[] proveedor = prov.split(";");
      p.setCuilProveedor(proveedor[1]);
      // p.set("priveedor_id");
      abrirBase();
      Proveedor proveed = Proveedor.first("cuil = ?", proveedor[1]);
      p.set("proveedor_id", proveed.get("id"));
      if (abmProd.modificar(p)) {
        JOptionPane.showMessageDialog(apgui, "Producto modificado exitosamente.");
        pl = pb.filtroProducto("", "", "");
        actualizarLista();
        modificarPulsado = false;
        prodGui.habilitarCampos(false);
        prodGui.getModificar().setEnabled(false);
        prodGui.getGuardar().setEnabled(false);
      } else {
        JOptionPane.showMessageDialog(prodGui, "El número de producto ya existe");
      }
    }
    if (e.getSource() == prodGui.getGuardar() && nuevoPulsado) {
      Producto p = new Producto();
      cargarDatosProd(p, false);
      String prov = (String) prodGui.getProveedores().getSelectedItem();
      String[] proveedor = prov.split(";");
      p.setCuilProveedor(proveedor[1]);
      if (p.getString("nombre").equals("") || p.getString("marca").equals("")) {
        JOptionPane.showMessageDialog(prodGui, "Un producto debe tener nombre y marca");
      }
      abrirBase();
      if (abmProd.alta(p)) {
        JOptionPane.showMessageDialog(prodGui, "Producto registrado exitosamente");
        p = abmProd.getProducto(p);
        agregarFila(p);
        nuevoPulsado = false;
        prodGui.habilitarCampos(false);
        prodGui.getGuardar().setEnabled(false);
      } else {
        JOptionPane.showMessageDialog(prodGui, "Producto existente");
      }
      vc.actualizarListaProd();
      if (Base.hasConnection()) Base.close();
    }

    if (e.getSource() == prodGui.getBorrar()) {
      confirmarBorrar =
          JOptionPane.showConfirmDialog(
              prodGui, "¿borrar producto?", "Confirmar Borrado", JOptionPane.YES_NO_OPTION);
      if (JOptionPane.OK_OPTION == confirmarBorrar) {
        abrirBase();
        Producto p = Producto.first("numero_producto = ?", prodGui.getIdArticulo().getText());
        if (abmProd.baja(p)) {
          JOptionPane.showMessageDialog(prodGui, "Producto borrado exitosamente");
          pl = pb.filtroProducto("", "", "");
          actualizarLista();
          prodGui.limpiarCampos();
          prodGui.getBorrar().setEnabled(false);
          prodGui.getModificar().setEnabled(false);
          prodGui.getGuardar().setEnabled(false);
        } else {
          JOptionPane.showMessageDialog(prodGui, "No se ha borrado el producto");
        }
      }
    }
    if (e.getSource() == prodGui.getAnterior()) {
      prodGui.getProveedores().removeAllItems();
      int r = tabla.getSelectedRow();
      if (r > 0) {
        tabla.changeSelection(tabla.getSelectedRow() - 1, 0, false, false);
        r--;
        abrirBase();
        Producto c = Producto.first("numero_producto =?", tabla.getValueAt(r, 0));
        Proveedor p = Proveedor.first("id = ?", c.getString("proveedor_id"));
        if (Base.hasConnection()) Base.close();

        prodGui.CargarCampos(c);
        String nom = p.getString("nombre");
        String cuil = p.getString("cuil");
        String pr = nom + ";" + cuil;
        prodGui.getProveedores().addItem(pr);
        prodGui.repaint();
      }
    }

    if (e.getSource()
        == prodGui.getSiguiente()) { // permite avanzar al siguiente cliente de la lista
      prodGui.getProveedores().removeAllItems();
      int r = tabla.getSelectedRow();
      if (tablaProductos.getRowCount() - 1 > r) {
        tabla.changeSelection(r + 1, 0, false, false);
        r++;
        abrirBase();
        Producto c = Producto.first("numero_producto =?", tabla.getValueAt(r, 0));
        Proveedor p = Proveedor.first("id = ?", c.getString("proveedor_id"));
        if (Base.hasConnection()) Base.close();
        prodGui.CargarCampos(c);
        String nom = p.getString("nombre");
        String cuil = p.getString("cuil");
        String pr = nom + ";" + cuil;
        prodGui.getProveedores().addItem(pr);
      }
    }

    if (e.getSource() == prodGui.getModificarPrecios()) {
      DefaultTableModel t = mpp.getTablaArticulos();
      t.setRowCount(0);
      abrirBase();
      LazyList<Producto> prod = Producto.findAll();
      Iterator<Producto> it = prod.iterator();
      while (it.hasNext()) {
        Producto a = it.next();
        Object row[] = new Object[7];
        row[0] = a.getString("numero_producto");
        row[1] = a.getString("nombre");
        row[2] = a.getString("marca");
        row[3] = a.getString("tipo");
        row[4] = a.getString("precio_compra");
        row[5] = BigDecimal.valueOf(Double.valueOf(a.getString("precio_venta")));
        row[6] = BigDecimal.valueOf(Double.valueOf(a.getString("precio_venta")));
        t.addRow(row);
      }
      if (Base.hasConnection()) Base.close();
      mpp.setLocationRelativeTo(prodGui);
      mpp.setVisible(true);
      if (mpp.getReturnStatus() == 1) {
        Iterator<Pair> list = mpp.getProductosModificados().iterator();
        while (list.hasNext()) {
          Pair par = list.next();
          abrirBase();
          Producto p = Producto.findFirst("numero_producto =?", (String) par.first());
          p.set("precio_venta", par.second());
          if (p.saveIt()) {
            JOptionPane.showMessageDialog(
                prodGui,
                "Precios modificados exitosamente",
                "Precios modificados",
                JOptionPane.INFORMATION_MESSAGE);
          }
          if (Base.hasConnection()) Base.close();
        }
      }
    }
    vc.actualizarListaProd();
    cc.actualizarListaProd();
    vrc.actualizarListaFacturas();
    crc.actualizarListaCompras();
    /*if(e.getSource() == mpp.getAceptar()){
    int srow = prodGui.getTabla().getSelectedRow();
    Object id = prodGui.getTablaArticulos().getValueAt(srow, 0);
    Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/sexshop", "root", "root");
    Producto p = Producto.first("id = ?", id);
    p.set("precio_venta", mpp.getPesos().getText());
    p.saveIt();
    if (Base.hasConnection())
    Base.close();
    mpp.dispose();
    JOptionPane.showMessageDialog(apgui, "Precio modificado exitosamente.");

    }
    if(e.getSource() == mpp.getCancelar()){
    mpp.dispose();
    }
    */
  }