Esempio n. 1
0
  public CargaProductoCompra(CompraDetalle compradetalle, final Sgc_capa_web mainWindow) {

    VLayout layout = new VLayout(10);

    final DynamicForm form = new DynamicForm();
    form.setBackgroundColor("#006633");
    form.setBorder("2px");
    form.setAutoFocus(true);
    form.setNumCols(3);
    form.setWidth(500);

    Label label = new Label();
    label.setBackgroundColor("#99ffcc");
    label.setHeight(30);
    label.setWidth(500);
    label.setPadding(10);
    label.setAlign(Alignment.CENTER);
    label.setValign(VerticalAlignment.CENTER);
    label.setWrap(false);
    label.setShowEdges(true);
    label.setContents(
        "<div style='color:black;font-size:15'><b>Carga de Productos de la Compra</b></div>");

    TextItem codigoText = new TextItem("codigo");
    codigoText.setTitleStyle("{font-color:white;font-weigh:bold;font-size:14}");
    codigoText.setTitle("Codigo");
    codigoText.setDisabled(true);
    codigoText.setWrapTitle(false);

    final TextItem productoText = new TextItem("producto");
    productoText.setTitle("Producto");
    productoText.setDefaultValue(new Date());
    productoText.setTitleStyle("{font-color:white;font-weigh:bold;font-size:14}");
    productoText.setWrapTitle(false);

    final TextItem cantidadText = new TextItem("cantidad");
    cantidadText.setTitle("Cantidad");
    cantidadText.setTitleStyle("{font-color:white;font-weigh:bold;font-size:14}");
    cantidadText.setWrapTitle(false);

    final TextItem preciocompraText = new TextItem("preciocompra");
    preciocompraText.setTitle("Precio");
    preciocompraText.setTitleStyle("{font-color:white;font-weigh:bold;font-size:14}");
    preciocompraText.setWrapTitle(false);

    ButtonItem button = new ButtonItem("save", "Aceptar");
    button.setStartRow(false);
    button.setWidth(80);
    button.setIcon("approve.png");
    button.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {

            CompraDetalleServiceAsync service = GWT.create(CompraDetalleService.class);
            ServiceDefTarget serviceDef = (ServiceDefTarget) service;
            serviceDef.setServiceEntryPoint(GWT.getModuleBaseURL() + "compradetalleService");
            CompraDetalle compradetalle = new CompraDetalle();
            compradetalle.setId_producto(Integer.parseInt(form.getValueAsString("producto")));
            compradetalle.setCantidad(Integer.parseInt(form.getValueAsString("cantidad")));
            compradetalle.setPrecioCompra(
                Double.parseDouble(form.getValueAsString("preciocompra")));
            // compra.setTotalCompra(Integer.parseInt("15000"));
            if (form.getValueAsString("codigo") != null) {
              compradetalle.setIdCompDet(Integer.valueOf(form.getValueAsString("codigo")));
            }

            try {
              service.guardar(
                  compradetalle,
                  new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(Throwable caught) {
                      Window.alert(
                          "Ocurrio un error: "
                              + caught.getClass().getName()
                              + " "
                              + caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Void result) {
                      new CargaProductoCompra(mainWindow);
                    }
                  });
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    if (compradetalle != null) {
      codigoText.setDefaultValue(String.valueOf(compradetalle.getIdCompDet()));
      productoText.setDefaultValue(compradetalle.getId_producto());
      cantidadText.setDefaultValue(compradetalle.getCantidad());
      preciocompraText.setDefaultValue(((Object) compradetalle.getPrecioCompra()).toString());
    }

    form.setFields(codigoText, productoText, cantidadText, preciocompraText, button);
    layout.addMember(label);
    layout.addMember(form);
    mainWindow.showDialog(layout);
  }
Esempio n. 2
0
  public ListaVentas(final Sgc_capa_web mainWindow) {

    String PATH_IMG = "/sgc_capa_web/images/";
    VLayout layout = new VLayout(10);
    layout.setBackgroundColor("#006633");
    final ListGrid facturaGrid = new ListGrid();

    facturaGrid.setWidth(500);
    facturaGrid.setHeight(224);
    facturaGrid.setShowAllRecords(true);
    facturaGrid.setAlternateRecordStyles(true);
    facturaGrid.setShowEdges(true);
    facturaGrid.setBorder("0px");
    facturaGrid.setBodyStyleName("normal");
    facturaGrid.setLeaveScrollbarGap(false);
    facturaGrid.setBackgroundColor("#99ffcc");

    /*-Buscar ------------------------------*/
    DynamicForm buscarFields = new DynamicForm();
    // buscarFields.setBackgroundColor("#99ffcc");
    buscarFields.setItemLayout(FormLayoutType.ABSOLUTE);

    final TextItem codigoText = new TextItem("codigo");
    codigoText.setWrapTitle(false);
    codigoText.setLeft(10);
    codigoText.setWidth(43);
    codigoText.addKeyPressHandler(
        new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if ("Enter".equals(event.getKeyName())) {
              /* buscar por el campo correspondiente */
              if (codigoText.getValue() != null) {

                Factura factura = new Factura();
                factura.setId(Integer.parseInt(codigoText.getValue().toString()));
                listar(facturaGrid, factura, "codigo");
              }
            }
          }
        });

    ButtonItem buscarButton = new ButtonItem("find", "");
    buscarButton.setIcon("view.png");
    buscarButton.setWidth(50);
    buscarButton.setLeft(443);
    buscarButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            /* buscar por el campo correspondiente */
            Factura factura = new Factura();

            if (codigoText.getValue() != null)
              factura.setId(Integer.parseInt(codigoText.getValue().toString()));
            /*if(nombreusuarioText.getValue() != null)
            cliente.setNombreusuario(nombreusuarioText.getValue().toString());*/
            listar(facturaGrid, factura, "nombre");
          }
        });

    buscarFields.setFields(codigoText, buscarButton);
    /*--------------------------------------*/

    ListGridField codigoField = new ListGridField("codigo", "Codigo");
    ListGridField fechaField = new ListGridField("fecha", "Fecha");
    ListGridField numeroField = new ListGridField("numero", "Numero");
    ListGridField pendienteField = new ListGridField("pendiente", "Pendiente");
    ListGridField saldoField = new ListGridField("saldo", "Saldo");
    ListGridField editarField = new ListGridField("edit", "Editar");
    ListGridField borrarField = new ListGridField("remove", "Borrar");

    codigoField.setAlign(Alignment.CENTER);
    editarField.setAlign(Alignment.CENTER);
    borrarField.setAlign(Alignment.CENTER);

    editarField.setType(ListGridFieldType.IMAGE);
    borrarField.setType(ListGridFieldType.IMAGE);

    editarField.setImageURLPrefix(PATH_IMG);
    borrarField.setImageURLPrefix(PATH_IMG);

    editarField.setImageURLSuffix(".png");
    borrarField.setImageURLSuffix(".png");

    facturaGrid.addCellClickHandler(
        new CellClickHandler() {
          @Override
          public void onCellClick(CellClickEvent event) {
            ListGridRecord record = event.getRecord();
            int col = event.getColNum();
            if (col > 4) {

              Factura factura = new Factura();
              factura.setId(record.getAttributeAsInt("codigo"));
              factura.setFecha(record.getAttributeAsDate("fecha"));
              factura.setNumero(Integer.parseInt(record.getAttribute("numero")));
              factura.setPendiente(record.getAttribute("pendiente"));
              factura.setSaldo(Double.parseDouble(record.getAttribute("saldo")));

              if (col == 5) {
                /* Editar */

                new VentaDetalle(factura, mainWindow);

              } else {
                /* Borrar */

                FacturaServiceAsync service = GWT.create(FacturaService.class);
                ServiceDefTarget serviceDef = (ServiceDefTarget) service;
                serviceDef.setServiceEntryPoint(GWT.getModuleBaseURL() + "facturaService");
                try {
                  service.eliminar(
                      record.getAttributeAsInt("codigo"),
                      new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                          Window.alert(
                              "Ocurrio un error y no se puedo eliminar (objeto referenciado)"); // "
                          // +
                          // caught.getClass().getName() + " " + caught.getMessage()) ;
                        }

                        @Override
                        public void onSuccess(Void result) {
                          new ListaVentas(mainWindow);
                        }
                      });
                } catch (NumberFormatException e) {
                  e.printStackTrace();
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
        });

    codigoField.setWidth(50);
    fechaField.setWidth(180);
    numeroField.setWidth(50);
    pendienteField.setWidth(50);
    saldoField.setWidth(50);
    facturaGrid.setFields(
        codigoField, fechaField, numeroField, pendienteField, saldoField, editarField, borrarField);
    facturaGrid.setCanResizeFields(true);

    ButtonItem button = new ButtonItem("add", "Agregar");
    button.setStartRow(false);
    button.setWidth(80);
    button.setIcon("add.png");
    button.setAlign(Alignment.CENTER);
    button.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            new VentaDetalle(mainWindow);
          }
        });

    listar(facturaGrid, new Factura(), "nombre");

    Label label = new Label();
    label.setBackgroundColor("#99ffcc");
    label.setHeight(30);
    label.setWidth(500);
    label.setPadding(10);
    label.setAlign(Alignment.CENTER);
    label.setValign(VerticalAlignment.CENTER);
    label.setWrap(false);
    label.setShowEdges(true);
    label.setContents("<div style='color:black;font-size:15'><b>Lista de Ventas</b></div>");

    layout.addMember(label);
    layout.addMember(buscarFields);
    layout.addMember(facturaGrid);

    DynamicForm form = new DynamicForm();
    // form.setBackgroundColor("#99ffcc");
    form.setWidth(300);
    form.setItems(button);
    layout.addMember(form);
    mainWindow.showDialog(layout);
  }