Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abmBomberos() {
- initComponents();
- SessionHibernate();
- arranque();
- }
- private Session st;
- private void arranque(){
- txtApe.setText("");
- txtCony.setText("");
- txtDNI.setText("");
- txtDomi.setText("");
- txtFNac.setText("");
- txtHij1.setText("");
- txtHij2.setText("");
- txtHij3.setText("");
- txtHij4.setText("");
- txtHij5.setText("");
- txtLp.setText("");
- txtNacion.setText("");
- txtNom.setText("");
- txtNomMadre.setText("");
- txtNomPadre.setText("");
- txtTel.setText("");
- txtTelTrab.setText("");
- txtTrab.setText("");
- cargaComboCiudad();
- cargaComboProvincias();
- cargaComboGruposanguineo();
- cargaComboEstudios();
- cargaComboEstadoCivil();
- cargaComboCuartelDestino();
- }
- private void SessionHibernate(){
- st = HibernateUtil.getSessionFactory().openSession();
- }
- private void cargaComboCiudad(){
- this.cmbCiudad.removeAllItems();
- List<Tabciudades> lista = (List<Tabciudades>)st.createQuery("From Tabciudades order by nomciudad").list();
- for(Tabciudades tipoList : lista){
- this.cmbCiudad.addItem(tipoList.getNomciudad());
- }
- cmbCiudad.setSelectedIndex(1);
- }
- private void cargaComboProvincias(){
- this.cmbProv.removeAllItems();
- List<Tabprovincias> lista = (List<Tabprovincias>)st.createQuery("From Tabprovincias order by Nomprovin").list();
- for(Tabprovincias tipoList : lista){
- this.cmbProv.addItem(tipoList.getNomprovin());
- }
- }
- private void cargaComboGruposanguineo(){
- this.cmbGrSan.removeAllItems();
- List<Grsangbom> lista = (List<Grsangbom>)st.createQuery("From Grsangbom").list();
- for(Grsangbom tipoList : lista){
- this.cmbGrSan.addItem(tipoList.getGrsangbomcol());
- }
- }
- private void cargaComboEstudios(){
- this.cmbEstud.removeAllItems();
- List<Bomestud> lista = (List<Bomestud>)st.createQuery("From Bomestud").list();
- for(Bomestud tipoList : lista){
- this.cmbEstud.addItem(tipoList.getEstudios());
- }
- }
- private void cargaComboEstadoCivil(){
- this.cmbEstCiv.removeAllItems();
- List<Bomciv> lista = (List<Bomciv>)st.createQuery("From Bomciv").list();
- for(Bomciv tipoList : lista){
- this.cmbEstCiv.addItem(tipoList.getBomcivestado());
- }
- }
- private void cargaComboCuartelDestino(){
- this.cmbCuarDest.removeAllItems();
- List<Tabcuardest> lista = (List<Tabcuardest>)st.createQuery("From Tabcuardest").list();
- for(Tabcuardest tipoList : lista){
- this.cmbCuarDest.addItem(tipoList.getNomcuar());
- }
- }
- private void agregarBombero(){
- st.beginTransaction();
- Abmbomber bombero = new Abmbomber();
- bombero.setIdBom(Integer.parseInt(txtLp.getText()));
- bombero.setNombom(txtNom.getText());
- bombero.setApebom(txtApe.getText());
- bombero.setFhnacbom(txtFNac.getText());
- bombero.setDnibom(txtDNI.getText());
- bombero.setNaciobom(txtNacion.getText());
- Object cid = this.cmbCiudad.getSelectedIndex() + 1;
- Tabciudades ciudadId = ciudadId((Integer) cid);
- bombero.setCiudbomId(ciudadId);
- Object pid = this.cmbProv.getSelectedItem();
- Tabprovincias provinciaId = provinciaId((Integer) pid);
- bombero.setProvbomId(provinciaId);
- st.save(bombero);
- st.getTransaction().commit();
- }
- public Tabciudades ciudadId(Integer ciudad){
- Tabciudades ciudadId = null;
- Integer desTipo = ciudad;
- try {
- Query query = st.createQuery("From Tabciudades t Where t.idCiudad = ?");
- query.setParameter(0, desTipo);
- try {
- ciudadId = (Tabciudades)query.uniqueResult();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- }
- return ciudadId;
- }
- public Tabprovincias provinciaId(Integer provincia){
- Tabprovincias provinciaId = null;
- String desTipo = provincia.toString();
- try {
- Query query = st.createQuery("From Tabprovincias t Where t.idProv = ?");
- query.setParameter(0, desTipo);
- try {
- provinciaId = (Tabprovincias)query.uniqueResult();
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- }
- return provinciaId;
- }
- public class Abmbomber implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @Basic(optional = false)
- @Column(name = "id_bom")
- private Integer idBom;
- @Column(name = "nombom")
- private String nombom;
- @Column(name = "apebom")
- private String apebom;
- @Column(name = "fhnacbom")
- private String fhnacbom;
- @Column(name = "naciobom")
- private String naciobom;
- @Column(name = "domicbom")
- private String domicbom;
- @Column(name = "telbom")
- private String telbom;
- @Column(name = "dnibom")
- private String dnibom;
- @Column(name = "trabjbom")
- private String trabjbom;
- @Column(name = "teltrabbom")
- private String teltrabbom;
- @Column(name = "conyugbom")
- private String conyugbom;
- @Column(name = "hijbom1")
- private String hijbom1;
- @Column(name = "hijbom2")
- private String hijbom2;
- @Column(name = "hijbom3")
- private String hijbom3;
- @Column(name = "hijbom4")
- private String hijbom4;
- @Column(name = "hijbom5")
- private String hijbom5;
- @Column(name = "nompabom")
- private String nompabom;
- @Column(name = "nommabom")
- private String nommabom;
- @JoinColumn(name = "ciudbom_id", referencedColumnName = "id_ciudad")
- @ManyToOne
- private Tabciudades ciudbomId;
- @JoinColumn(name = "estcivbom_id", referencedColumnName = "idbomciv")
- @ManyToOne
- private Bomciv estcivbomId;
- @JoinColumn(name = "curdestbomb_id", referencedColumnName = "id_cuartel")
- @ManyToOne
- private Tabcuardest curdestbombId;
- @JoinColumn(name = "estudbom_id", referencedColumnName = "idestud")
- @ManyToOne
- private Bomestud estudbomId;
- @JoinColumn(name = "provbom_id", referencedColumnName = "id_prov")
- @ManyToOne
- private Tabprovincias provbomId;
- @JoinColumn(name = "grupsagbom_id", referencedColumnName = "idsangbom")
- @ManyToOne
- private Grsangbom grupsagbomId;
- public Abmbomber() {
- }
- public Abmbomber(Integer idBom) {
- this.idBom = idBom;
- }
- public Integer getIdBom() {
- return idBom;
- }
- public void setIdBom(Integer idBom) {
- this.idBom = idBom;
- }
- public String getNombom() {
- return nombom;
- }
- public void setNombom(String nombom) {
- this.nombom = nombom;
- }
- public String getApebom() {
- return apebom;
- }
- public void setApebom(String apebom) {
- this.apebom = apebom;
- }
- public String getFhnacbom() {
- return fhnacbom;
- }
- public void setFhnacbom(String fhnacbom) {
- this.fhnacbom = fhnacbom;
- }
- public String getNaciobom() {
- return naciobom;
- }
- public void setNaciobom(String naciobom) {
- this.naciobom = naciobom;
- }
- public String getDomicbom() {
- return domicbom;
- }
- public void setDomicbom(String domicbom) {
- this.domicbom = domicbom;
- }
- public String getTelbom() {
- return telbom;
- }
- public void setTelbom(String telbom) {
- this.telbom = telbom;
- }
- public String getDnibom() {
- return dnibom;
- }
- public void setDnibom(String dnibom) {
- this.dnibom = dnibom;
- }
- public String getTrabjbom() {
- return trabjbom;
- }
- public void setTrabjbom(String trabjbom) {
- this.trabjbom = trabjbom;
- }
- public String getTeltrabbom() {
- return teltrabbom;
- }
- public void setTeltrabbom(String teltrabbom) {
- this.teltrabbom = teltrabbom;
- }
- public String getConyugbom() {
- return conyugbom;
- }
- public void setConyugbom(String conyugbom) {
- this.conyugbom = conyugbom;
- }
- public String getHijbom1() {
- return hijbom1;
- }
- public void setHijbom1(String hijbom1) {
- this.hijbom1 = hijbom1;
- }
- public String getHijbom2() {
- return hijbom2;
- }
- public void setHijbom2(String hijbom2) {
- this.hijbom2 = hijbom2;
- }
- public String getHijbom3() {
- return hijbom3;
- }
- public void setHijbom3(String hijbom3) {
- this.hijbom3 = hijbom3;
- }
- public String getHijbom4() {
- return hijbom4;
- }
- public void setHijbom4(String hijbom4) {
- this.hijbom4 = hijbom4;
- }
- public String getHijbom5() {
- return hijbom5;
- }
- public void setHijbom5(String hijbom5) {
- this.hijbom5 = hijbom5;
- }
- public String getNompabom() {
- return nompabom;
- }
- public void setNompabom(String nompabom) {
- this.nompabom = nompabom;
- }
- public String getNommabom() {
- return nommabom;
- }
- public void setNommabom(String nommabom) {
- this.nommabom = nommabom;
- }
- public Tabciudades getCiudbomId() {
- return ciudbomId;
- }
- public void setCiudbomId(Tabciudades ciudbomId) {
- this.ciudbomId = ciudbomId;
- }
- public Bomciv getEstcivbomId() {
- return estcivbomId;
- }
- public void setEstcivbomId(Bomciv estcivbomId) {
- this.estcivbomId = estcivbomId;
- }
- public Tabcuardest getCurdestbombId() {
- return curdestbombId;
- }
- public void setCurdestbombId(Tabcuardest curdestbombId) {
- this.curdestbombId = curdestbombId;
- }
- public Bomestud getEstudbomId() {
- return estudbomId;
- }
- public void setEstudbomId(Bomestud estudbomId) {
- this.estudbomId = estudbomId;
- }
- public Tabprovincias getProvbomId() {
- return provbomId;
- }
- public void setProvbomId(Tabprovincias provbomId) {
- this.provbomId = provbomId;
- }
- public Grsangbom getGrupsagbomId() {
- return grupsagbomId;
- }
- public void setGrupsagbomId(Grsangbom grupsagbomId) {
- this.grupsagbomId = grupsagbomId;
- }
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (idBom != null ? idBom.hashCode() : 0);
- return hash;
- }
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Abmbomber)) {
- return false;
- }
- Abmbomber other = (Abmbomber) object;
- if ((this.idBom == null && other.idBom != null) || (this.idBom != null && !this.idBom.equals(other.idBom))) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "hibernatePersistance.Abmbomber[ idBom=" + idBom + " ]";
- }
- public class Tabciudades implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @Basic(optional = false)
- @Column(name = "id_ciudad")
- private Integer idCiudad;
- @Column(name = "nomciudad")
- private String nomciudad;
- @OneToMany(mappedBy = "ciudbomId")
- private Collection<Abmbomber> abmbomberCollection;
- public Tabciudades() {
- }
- public Tabciudades(Integer idCiudad) {
- this.idCiudad = idCiudad;
- }
- public Integer getIdCiudad() {
- return idCiudad;
- }
- public void setIdCiudad(Integer idCiudad) {
- this.idCiudad = idCiudad;
- }
- public String getNomciudad() {
- return nomciudad;
- }
- public void setNomciudad(String nomciudad) {
- this.nomciudad = nomciudad;
- }
- @XmlTransient
- public Collection<Abmbomber> getAbmbomberCollection() {
- return abmbomberCollection;
- }
- public void setAbmbomberCollection(Collection<Abmbomber> abmbomberCollection) {
- this.abmbomberCollection = abmbomberCollection;
- }
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (idCiudad != null ? idCiudad.hashCode() : 0);
- return hash;
- }
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Tabciudades)) {
- return false;
- }
- Tabciudades other = (Tabciudades) object;
- if ((this.idCiudad == null && other.idCiudad != null) || (this.idCiudad != null && !this.idCiudad.equals(other.idCiudad))) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "hibernatePersistance.Tabciudades[ idCiudad=" + idCiudad + " ]";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement