Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.35 KB | None | 0 0
  1. public abmBomberos() {
  2. initComponents();
  3. SessionHibernate();
  4. arranque();
  5. }
  6.  
  7. private Session st;
  8.  
  9. private void arranque(){
  10. txtApe.setText("");
  11. txtCony.setText("");
  12. txtDNI.setText("");
  13. txtDomi.setText("");
  14. txtFNac.setText("");
  15. txtHij1.setText("");
  16. txtHij2.setText("");
  17. txtHij3.setText("");
  18. txtHij4.setText("");
  19. txtHij5.setText("");
  20. txtLp.setText("");
  21. txtNacion.setText("");
  22. txtNom.setText("");
  23. txtNomMadre.setText("");
  24. txtNomPadre.setText("");
  25. txtTel.setText("");
  26. txtTelTrab.setText("");
  27. txtTrab.setText("");
  28. cargaComboCiudad();
  29. cargaComboProvincias();
  30. cargaComboGruposanguineo();
  31. cargaComboEstudios();
  32. cargaComboEstadoCivil();
  33. cargaComboCuartelDestino();
  34. }
  35.  
  36. private void SessionHibernate(){
  37. st = HibernateUtil.getSessionFactory().openSession();
  38. }
  39.  
  40. private void cargaComboCiudad(){
  41. this.cmbCiudad.removeAllItems();
  42. List<Tabciudades> lista = (List<Tabciudades>)st.createQuery("From Tabciudades order by nomciudad").list();
  43. for(Tabciudades tipoList : lista){
  44. this.cmbCiudad.addItem(tipoList.getNomciudad());
  45. }
  46. cmbCiudad.setSelectedIndex(1);
  47. }
  48.  
  49. private void cargaComboProvincias(){
  50. this.cmbProv.removeAllItems();
  51. List<Tabprovincias> lista = (List<Tabprovincias>)st.createQuery("From Tabprovincias order by Nomprovin").list();
  52. for(Tabprovincias tipoList : lista){
  53. this.cmbProv.addItem(tipoList.getNomprovin());
  54.  
  55. }
  56.  
  57. }
  58.  
  59. private void cargaComboGruposanguineo(){
  60. this.cmbGrSan.removeAllItems();
  61. List<Grsangbom> lista = (List<Grsangbom>)st.createQuery("From Grsangbom").list();
  62. for(Grsangbom tipoList : lista){
  63. this.cmbGrSan.addItem(tipoList.getGrsangbomcol());
  64. }
  65. }
  66.  
  67. private void cargaComboEstudios(){
  68. this.cmbEstud.removeAllItems();
  69. List<Bomestud> lista = (List<Bomestud>)st.createQuery("From Bomestud").list();
  70. for(Bomestud tipoList : lista){
  71. this.cmbEstud.addItem(tipoList.getEstudios());
  72. }
  73. }
  74.  
  75. private void cargaComboEstadoCivil(){
  76. this.cmbEstCiv.removeAllItems();
  77. List<Bomciv> lista = (List<Bomciv>)st.createQuery("From Bomciv").list();
  78. for(Bomciv tipoList : lista){
  79. this.cmbEstCiv.addItem(tipoList.getBomcivestado());
  80. }
  81. }
  82.  
  83. private void cargaComboCuartelDestino(){
  84. this.cmbCuarDest.removeAllItems();
  85. List<Tabcuardest> lista = (List<Tabcuardest>)st.createQuery("From Tabcuardest").list();
  86. for(Tabcuardest tipoList : lista){
  87. this.cmbCuarDest.addItem(tipoList.getNomcuar());
  88. }
  89. }
  90.  
  91. private void agregarBombero(){
  92. st.beginTransaction();
  93. Abmbomber bombero = new Abmbomber();
  94. bombero.setIdBom(Integer.parseInt(txtLp.getText()));
  95. bombero.setNombom(txtNom.getText());
  96. bombero.setApebom(txtApe.getText());
  97. bombero.setFhnacbom(txtFNac.getText());
  98. bombero.setDnibom(txtDNI.getText());
  99. bombero.setNaciobom(txtNacion.getText());
  100. Object cid = this.cmbCiudad.getSelectedIndex() + 1;
  101. Tabciudades ciudadId = ciudadId((Integer) cid);
  102. bombero.setCiudbomId(ciudadId);
  103. Object pid = this.cmbProv.getSelectedItem();
  104. Tabprovincias provinciaId = provinciaId((Integer) pid);
  105. bombero.setProvbomId(provinciaId);
  106. st.save(bombero);
  107. st.getTransaction().commit();
  108.  
  109.  
  110.  
  111.  
  112. }
  113.  
  114.  
  115.  
  116.  
  117. public Tabciudades ciudadId(Integer ciudad){
  118. Tabciudades ciudadId = null;
  119. Integer desTipo = ciudad;
  120. try {
  121. Query query = st.createQuery("From Tabciudades t Where t.idCiudad = ?");
  122. query.setParameter(0, desTipo);
  123. try {
  124. ciudadId = (Tabciudades)query.uniqueResult();
  125. } catch (Exception e) {
  126. JOptionPane.showMessageDialog(null, e);
  127. }
  128.  
  129. } catch (Exception e) {
  130. JOptionPane.showMessageDialog(null, e);
  131. }
  132. return ciudadId;
  133. }
  134.  
  135. public Tabprovincias provinciaId(Integer provincia){
  136. Tabprovincias provinciaId = null;
  137. String desTipo = provincia.toString();
  138. try {
  139. Query query = st.createQuery("From Tabprovincias t Where t.idProv = ?");
  140. query.setParameter(0, desTipo);
  141. try {
  142. provinciaId = (Tabprovincias)query.uniqueResult();
  143. } catch (Exception e) {
  144. JOptionPane.showMessageDialog(null, e);
  145. }
  146.  
  147. } catch (Exception e) {
  148. JOptionPane.showMessageDialog(null, e);
  149. }
  150. return provinciaId;
  151. }
  152.  
  153. public class Abmbomber implements Serializable {
  154.  
  155. private static final long serialVersionUID = 1L;
  156. @Id
  157. @Basic(optional = false)
  158. @Column(name = "id_bom")
  159. private Integer idBom;
  160. @Column(name = "nombom")
  161. private String nombom;
  162. @Column(name = "apebom")
  163. private String apebom;
  164. @Column(name = "fhnacbom")
  165. private String fhnacbom;
  166. @Column(name = "naciobom")
  167. private String naciobom;
  168. @Column(name = "domicbom")
  169. private String domicbom;
  170. @Column(name = "telbom")
  171. private String telbom;
  172. @Column(name = "dnibom")
  173. private String dnibom;
  174. @Column(name = "trabjbom")
  175. private String trabjbom;
  176. @Column(name = "teltrabbom")
  177. private String teltrabbom;
  178. @Column(name = "conyugbom")
  179. private String conyugbom;
  180. @Column(name = "hijbom1")
  181. private String hijbom1;
  182. @Column(name = "hijbom2")
  183. private String hijbom2;
  184. @Column(name = "hijbom3")
  185. private String hijbom3;
  186. @Column(name = "hijbom4")
  187. private String hijbom4;
  188. @Column(name = "hijbom5")
  189. private String hijbom5;
  190. @Column(name = "nompabom")
  191. private String nompabom;
  192. @Column(name = "nommabom")
  193. private String nommabom;
  194. @JoinColumn(name = "ciudbom_id", referencedColumnName = "id_ciudad")
  195. @ManyToOne
  196. private Tabciudades ciudbomId;
  197. @JoinColumn(name = "estcivbom_id", referencedColumnName = "idbomciv")
  198. @ManyToOne
  199. private Bomciv estcivbomId;
  200. @JoinColumn(name = "curdestbomb_id", referencedColumnName = "id_cuartel")
  201. @ManyToOne
  202. private Tabcuardest curdestbombId;
  203. @JoinColumn(name = "estudbom_id", referencedColumnName = "idestud")
  204. @ManyToOne
  205. private Bomestud estudbomId;
  206. @JoinColumn(name = "provbom_id", referencedColumnName = "id_prov")
  207. @ManyToOne
  208. private Tabprovincias provbomId;
  209. @JoinColumn(name = "grupsagbom_id", referencedColumnName = "idsangbom")
  210. @ManyToOne
  211. private Grsangbom grupsagbomId;
  212.  
  213. public Abmbomber() {
  214. }
  215.  
  216. public Abmbomber(Integer idBom) {
  217. this.idBom = idBom;
  218. }
  219.  
  220. public Integer getIdBom() {
  221. return idBom;
  222. }
  223.  
  224. public void setIdBom(Integer idBom) {
  225. this.idBom = idBom;
  226. }
  227.  
  228. public String getNombom() {
  229. return nombom;
  230. }
  231.  
  232. public void setNombom(String nombom) {
  233. this.nombom = nombom;
  234. }
  235.  
  236. public String getApebom() {
  237. return apebom;
  238. }
  239.  
  240. public void setApebom(String apebom) {
  241. this.apebom = apebom;
  242. }
  243.  
  244. public String getFhnacbom() {
  245. return fhnacbom;
  246. }
  247.  
  248. public void setFhnacbom(String fhnacbom) {
  249. this.fhnacbom = fhnacbom;
  250. }
  251.  
  252. public String getNaciobom() {
  253. return naciobom;
  254. }
  255.  
  256. public void setNaciobom(String naciobom) {
  257. this.naciobom = naciobom;
  258. }
  259.  
  260. public String getDomicbom() {
  261. return domicbom;
  262. }
  263.  
  264. public void setDomicbom(String domicbom) {
  265. this.domicbom = domicbom;
  266. }
  267.  
  268. public String getTelbom() {
  269. return telbom;
  270. }
  271.  
  272. public void setTelbom(String telbom) {
  273. this.telbom = telbom;
  274. }
  275.  
  276. public String getDnibom() {
  277. return dnibom;
  278. }
  279.  
  280. public void setDnibom(String dnibom) {
  281. this.dnibom = dnibom;
  282. }
  283.  
  284. public String getTrabjbom() {
  285. return trabjbom;
  286. }
  287.  
  288. public void setTrabjbom(String trabjbom) {
  289. this.trabjbom = trabjbom;
  290. }
  291.  
  292. public String getTeltrabbom() {
  293. return teltrabbom;
  294. }
  295.  
  296. public void setTeltrabbom(String teltrabbom) {
  297. this.teltrabbom = teltrabbom;
  298. }
  299.  
  300. public String getConyugbom() {
  301. return conyugbom;
  302. }
  303.  
  304. public void setConyugbom(String conyugbom) {
  305. this.conyugbom = conyugbom;
  306. }
  307.  
  308. public String getHijbom1() {
  309. return hijbom1;
  310. }
  311.  
  312. public void setHijbom1(String hijbom1) {
  313. this.hijbom1 = hijbom1;
  314. }
  315.  
  316. public String getHijbom2() {
  317. return hijbom2;
  318. }
  319.  
  320. public void setHijbom2(String hijbom2) {
  321. this.hijbom2 = hijbom2;
  322. }
  323.  
  324. public String getHijbom3() {
  325. return hijbom3;
  326. }
  327.  
  328. public void setHijbom3(String hijbom3) {
  329. this.hijbom3 = hijbom3;
  330. }
  331.  
  332. public String getHijbom4() {
  333. return hijbom4;
  334. }
  335.  
  336. public void setHijbom4(String hijbom4) {
  337. this.hijbom4 = hijbom4;
  338. }
  339.  
  340. public String getHijbom5() {
  341. return hijbom5;
  342. }
  343.  
  344. public void setHijbom5(String hijbom5) {
  345. this.hijbom5 = hijbom5;
  346. }
  347.  
  348. public String getNompabom() {
  349. return nompabom;
  350. }
  351.  
  352. public void setNompabom(String nompabom) {
  353. this.nompabom = nompabom;
  354. }
  355.  
  356. public String getNommabom() {
  357. return nommabom;
  358. }
  359.  
  360. public void setNommabom(String nommabom) {
  361. this.nommabom = nommabom;
  362. }
  363.  
  364. public Tabciudades getCiudbomId() {
  365. return ciudbomId;
  366. }
  367.  
  368. public void setCiudbomId(Tabciudades ciudbomId) {
  369. this.ciudbomId = ciudbomId;
  370. }
  371.  
  372. public Bomciv getEstcivbomId() {
  373. return estcivbomId;
  374. }
  375.  
  376. public void setEstcivbomId(Bomciv estcivbomId) {
  377. this.estcivbomId = estcivbomId;
  378. }
  379.  
  380. public Tabcuardest getCurdestbombId() {
  381. return curdestbombId;
  382. }
  383.  
  384. public void setCurdestbombId(Tabcuardest curdestbombId) {
  385. this.curdestbombId = curdestbombId;
  386. }
  387.  
  388. public Bomestud getEstudbomId() {
  389. return estudbomId;
  390. }
  391.  
  392. public void setEstudbomId(Bomestud estudbomId) {
  393. this.estudbomId = estudbomId;
  394. }
  395.  
  396. public Tabprovincias getProvbomId() {
  397. return provbomId;
  398. }
  399.  
  400. public void setProvbomId(Tabprovincias provbomId) {
  401. this.provbomId = provbomId;
  402. }
  403.  
  404. public Grsangbom getGrupsagbomId() {
  405. return grupsagbomId;
  406. }
  407.  
  408. public void setGrupsagbomId(Grsangbom grupsagbomId) {
  409. this.grupsagbomId = grupsagbomId;
  410. }
  411.  
  412. @Override
  413. public int hashCode() {
  414. int hash = 0;
  415. hash += (idBom != null ? idBom.hashCode() : 0);
  416. return hash;
  417. }
  418.  
  419. @Override
  420. public boolean equals(Object object) {
  421. // TODO: Warning - this method won't work in the case the id fields are not set
  422. if (!(object instanceof Abmbomber)) {
  423. return false;
  424. }
  425. Abmbomber other = (Abmbomber) object;
  426. if ((this.idBom == null && other.idBom != null) || (this.idBom != null && !this.idBom.equals(other.idBom))) {
  427. return false;
  428. }
  429. return true;
  430. }
  431.  
  432. @Override
  433. public String toString() {
  434. return "hibernatePersistance.Abmbomber[ idBom=" + idBom + " ]";
  435. }
  436.  
  437. public class Tabciudades implements Serializable {
  438.  
  439. private static final long serialVersionUID = 1L;
  440. @Id
  441. @Basic(optional = false)
  442. @Column(name = "id_ciudad")
  443. private Integer idCiudad;
  444. @Column(name = "nomciudad")
  445. private String nomciudad;
  446. @OneToMany(mappedBy = "ciudbomId")
  447. private Collection<Abmbomber> abmbomberCollection;
  448.  
  449. public Tabciudades() {
  450. }
  451.  
  452. public Tabciudades(Integer idCiudad) {
  453. this.idCiudad = idCiudad;
  454. }
  455.  
  456. public Integer getIdCiudad() {
  457. return idCiudad;
  458. }
  459.  
  460. public void setIdCiudad(Integer idCiudad) {
  461. this.idCiudad = idCiudad;
  462. }
  463.  
  464. public String getNomciudad() {
  465. return nomciudad;
  466. }
  467.  
  468. public void setNomciudad(String nomciudad) {
  469. this.nomciudad = nomciudad;
  470. }
  471.  
  472. @XmlTransient
  473. public Collection<Abmbomber> getAbmbomberCollection() {
  474. return abmbomberCollection;
  475. }
  476.  
  477. public void setAbmbomberCollection(Collection<Abmbomber> abmbomberCollection) {
  478. this.abmbomberCollection = abmbomberCollection;
  479. }
  480.  
  481. @Override
  482. public int hashCode() {
  483. int hash = 0;
  484. hash += (idCiudad != null ? idCiudad.hashCode() : 0);
  485. return hash;
  486. }
  487.  
  488. @Override
  489. public boolean equals(Object object) {
  490. // TODO: Warning - this method won't work in the case the id fields are not set
  491. if (!(object instanceof Tabciudades)) {
  492. return false;
  493. }
  494. Tabciudades other = (Tabciudades) object;
  495. if ((this.idCiudad == null && other.idCiudad != null) || (this.idCiudad != null && !this.idCiudad.equals(other.idCiudad))) {
  496. return false;
  497. }
  498. return true;
  499. }
  500.  
  501. @Override
  502. public String toString() {
  503. return "hibernatePersistance.Tabciudades[ idCiudad=" + idCiudad + " ]";
  504. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement