Ejemplo n.º 1
0
  public void serialize(DataOutputStream dataOut) throws IOException {
    dataOut.writeInt(idOrcamento);
    dataOut.writeInt(cliente.getIdCliente());
    dataOut.writeUTF(peso);
    dataOut.writeUTF(dimensao);
    dataOut.writeUTF(mensagem);

    long dtCadastro;
    if (dataCadastro == null) {
      dtCadastro = 0;
    } else {
      dtCadastro = dataCadastro.getTimeInMillis();
    }
    dataOut.writeLong(dtCadastro);

    long dtExclusao;
    if (dataExclusao == null) {
      dtExclusao = 0;
    } else {
      dtExclusao = dataExclusao.getTimeInMillis();
    }
    dataOut.writeLong(dtExclusao);

    dataOut.writeUTF(String.valueOf(orcamentoLido));
    dataOut.writeUTF(String.valueOf(orcamentoRespondido));
  }
Ejemplo n.º 2
0
  public void adiciona(Cliente cliente) throws SQLException {
    try (Connection conexao = new ConnectionFactory().getConnection()) {

      /*
       * Statement stmt = conexao.createStatement();
       * stmt.execute(" insert into cliente (idCliente, nmCliente, nrCpf) "
       * + "    values(" + cliente.getIdCliente() + ", '" + cliente.getNmCliente() + "', '" + cliente
       * .getNrCpf() + "') ");
       * stmt.close();
       */

      StringBuilder strbuilder = new StringBuilder();
      strbuilder.append(" insert into cliente ");
      strbuilder.append("(idCliente, nmCliente, nrCPF) values(?,?,?) ");

      PreparedStatement statement = conexao.prepareStatement(strbuilder.toString());

      statement.setLong(1, cliente.getIdCliente());
      statement.setString(2, cliente.getNmCliente());
      statement.setString(3, cliente.getNrCpf());

      statement.execute();

    } catch (SQLException e) {
      throw e;
    }
  }
Ejemplo n.º 3
0
  private void btAceptarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btAceptarActionPerformed

    String nombre, apellidos, direccion, telefono, email, dni;
    nombre = tfNombre.getText();
    apellidos = tfApellidos.getText();
    direccion = tfDireccion.getText();
    telefono = tfTelefono.getText();
    email = tfEmail.getText();
    dni = tfDNI.getText();
    if (nombre.isEmpty()
        || apellidos.isEmpty()
        || direccion.isEmpty()
        || telefono.isEmpty()
        || dni.isEmpty()) {
      JOptionPane.showMessageDialog(
          rootPane, "¡Hay campos obligatorios que están vacíos! Complétalos, por favor.");
      if (nombre.isEmpty()) {
        lbNombre.setText("*Nombre:");
        lbNombre.setForeground(Color.red);
      } else {
        lbNombre.setText("Nombre:");
        lbNombre.setForeground(Color.black);
      }
      if (apellidos.isEmpty()) {
        lbApellidos.setText("*Apellidos:");
        lbApellidos.setForeground(Color.red);
      } else {
        lbApellidos.setText("Apellidos:");
        lbApellidos.setForeground(Color.black);
      }
      if (direccion.isEmpty()) {
        lbDireccion.setText("*Dirección:");
        lbDireccion.setForeground(Color.red);
      } else {
        lbDireccion.setText("Direccion:");
        lbDireccion.setForeground(Color.black);
      }
      if (telefono.isEmpty()) {
        lbTelefono.setText("*Teléfono:");
        lbTelefono.setForeground(Color.red);
      } else {
        lbTelefono.setText("Teléfono:");
        lbTelefono.setForeground(Color.black);
      }
      if (dni.isEmpty()) {
        lbDNI.setText("*DNI:");
        lbDNI.setForeground(Color.red);
      } else {
        lbDNI.setText("DNI:");
        lbDNI.setForeground(Color.black);
      }
      return;
    }

    String update = "";
    if (btLimpiar.isEnabled()) {
      update =
          "INSERT INTO cliente "
              + "(nombre, apellidos, direccion, telefono, email, dni,fechaltacli)"
              + " VALUES('"
              + tfNombre.getText()
              + "','"
              + tfApellidos.getText()
              + "','"
              + tfDireccion.getText()
              + "','"
              + tfTelefono.getText()
              + "','"
              + tfEmail.getText()
              + "','"
              + tfDNI.getText()
              + "', CURRENT_TIMESTAMP)";
    } else {

      update =
          "UPDATE cliente SET nombre='"
              + tfNombre.getText()
              + "', apellidos='"
              + tfApellidos.getText()
              + "', direccion='"
              + tfDireccion.getText()
              + "', telefono='"
              + tfTelefono.getText()
              + "', email='"
              + tfEmail.getText()
              + "', dni='"
              + tfDNI.getText()
              + "' WHERE idcli="
              + cliente.getIdCliente();
    }

    SQLHelper.ejecutarUpdate(update);
    dispose();
  } // GEN-LAST:event_btAceptarActionPerformed