package ventas.administracion; import java.sql.*; import librerias.*; public class forma_pago extends mantenimiento { private int fp_codigo ; public void setFp_codigo(int valor){ this.fp_codigo = valor; } public int getFp_codigo(){ return this.fp_codigo; } private String fp_nombre = null; public void setFp_nombre(String valor){ this.fp_nombre = valor; } public String getFp_nombre(){ return this.fp_nombre; } private boolean fp_activo = false; public void setFp_activo(boolean valor){ this.fp_activo = valor; } public boolean isFp_activo(){ return this.fp_activo; } private java.sql.ResultSet result; public java.sql.ResultSet getResult(){ return this.result; } public void setResult(java.sql.ResultSet result){ this.result = result; } private String filter; public String getFilter(){ return this.filter; } public void setFilter(String valor){ this.filter = valor; } public forma_pago(){ } public String AddNew(){ String rpta = "OK"; String ssql = ""; java.sql.PreparedStatement ps; java.sql.Statement stm; java.sql.ResultSet rst; rpta = this.Conectarme(); if (rpta.compareTo("OK") == 0){ try { stm = this.getMyconeccion().createStatement(); rst = stm.executeQuery("select case when max(fp_codigo) is null then 1 else max(fp_codigo)+1 end as id from forma_pago"); rst.next(); this.setFp_codigo(rst.getInt("id")); ssql = "insert into forma_pago(fp_codigo,fp_nombre,fp_activo) values (?,?,?)"; ps = this.getMyconeccion().prepareStatement(ssql); ps.setInt(1,this.getFp_codigo()); ps.setString(2,this.getFp_nombre()); ps.setBoolean(3,this.isFp_activo()); ps.executeUpdate(); } catch (Exception e){ rpta = "ERROR: " + e.getMessage(); } } return rpta; } public String Update(){ String rpta = "OK"; String ssql = ""; java.sql.PreparedStatement ps; rpta = this.Conectarme(); if (rpta.compareTo("OK") == 0){ try { ssql = "update forma_pago set fp_nombre=?,fp_activo=? where fp_codigo=?"; ps = this.getMyconeccion().prepareStatement(ssql); ps.setString(1,this.getFp_nombre()); ps.setBoolean(2,this.isFp_activo()); ps.setInt(3,this.getFp_codigo()); ps.executeUpdate(); } catch (Exception e){ rpta = "ERROR: " + e.getMessage(); } } return rpta; } public String Query(){ String rpta = "OK"; String ssql = ""; java.sql.PreparedStatement ps; java.sql.ResultSet rst; rpta = this.Conectarme(); if (rpta.compareTo("OK") == 0){ try { ssql = "select fp_nombre,fp_activo from forma_pago where fp_codigo=?"; ps = this.getMyconeccion().prepareStatement(ssql); ps.setInt(1,this.getFp_codigo()); rst = ps.executeQuery(); if (rst.next()){ this.setFp_nombre(rst.getString("fp_nombre")); this.setFp_activo(rst.getBoolean("fp_activo")); } } catch (Exception e){ rpta = "ERROR: " + e.getMessage(); } } return rpta; } public String Query_All(){ String rpta = "OK"; String ssql = ""; java.sql.PreparedStatement ps; java.sql.ResultSet rst; rpta = this.Conectarme(); if (rpta.compareTo("OK") == 0){ try { ssql = "select * from forma_pago"; ps = this.getMyconeccion().prepareStatement(ssql); rst = ps.executeQuery(); this.setResult(rst); } catch (Exception e){ this.setResult(null); rpta = "ERROR: " + e.getMessage(); } } return rpta; } public String Filter(){ return ""; } }