Esempio n. 1
0
  private void insertarSolicitud() {
    int cliente = buscaCodClient(cboCliente.getSelectedItem().toString(), "cliente");

    try {
      // Insertar Solicitud
      String sql =
          "INSERT INTO pedido (id, fecha, cliente, fechapedido) VALUES (NULL, '"
              + z.dateFormat(calFecha.getDate())
              + cliente
              + "', NOW())";
      z.snt = z.con.createStatement();
      z.snt.executeUpdate(sql);

      // insertar ítem
      for (int fila = 0; fila < tabla.getRowCount(); fila++) {
        try {
          String sqlitem =
              "INSERT INTO detallepedido (pedido, articulo, cantidad) VALUES ("
                  + modelo.getValueAt(fila, 0)
                  + ", LAST_INSERT_ID(), "
                  + modelo.getValueAt(fila, 2)
                  + ")";
          z.snt = z.con.createStatement();
          z.snt.executeUpdate(sqlitem);
        } catch (SQLException ex) {
          Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    } catch (SQLException ex) {
      Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Esempio n. 2
0
 private void cargaCliente() {
   try {
     String sql =
         "SELECT concat(aombre, ' ', apellido) as cliente FROM cliente order by apellido ";
     z.snt = z.con.createStatement();
     z.rs = z.snt.executeQuery(sql);
     cboCliente.removeAllItems();
     while (z.rs.next()) {
       cboCliente.addItem(z.rs.getString("cliente"));
     }
   } catch (SQLException ex) {
     Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Esempio n. 3
0
  private int buscaCodClient(String des, String tabla) {
    int retorno = 0;
    try {

      String sql =
          "SELECT id FROM "
              + tabla
              + " where concat(cliente.aombre, ' ', cliente.apellido) = '"
              + des
              + "'";
      z.snt = z.con.createStatement();
      z.rs = z.snt.executeQuery(sql);
      z.rs.next();
      retorno = z.rs.getInt("id");

    } catch (SQLException ex) {
      Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
    }
    return retorno;
  }