-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelo_getDonador.java
More file actions
131 lines (102 loc) · 3.8 KB
/
modelo_getDonador.java
File metadata and controls
131 lines (102 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package bloodbanks.donadores;
import bloodbanks.Main;
import db.dbop;
import entities.donador;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import utilerias.msg;
public class modelo_getDonador {
private Controller_getDonador base = null;
private dbop mydb = null;
private donador d= null;
String tipo = null;
private Stage mystage = null;
public modelo_getDonador(String tipo){
this.base= Main.manager.openFXML("/bloodbanks/donadores/FXMLgetDonador.fxml","Numero de seguridad social", false, false).getController();
this.base.txtnss.requestFocus();
this.mydb = new dbop();
this.tipo = tipo;
this.mystage = (Stage)this.base.txtnss.getScene().getWindow();
switch(this.tipo){
case("DELETE_DONADOR"):{
this.mystage.setTitle("Eliminar Donador");
break;
}
case("UPDATE_DONADOR"):{
this.mystage.setTitle("Actualizar donador");
break;
}
}
this.base.modelo = this;
}
public void decide(){
this.d = new donador(this.base.txtnss.getText().trim());
switch(this.tipo){
case("DELETE_DONADOR"):{
if(this.existDonador()){
if(!this.hasDonations()){
if(msg.yesno("Confirma Eliminar Donador?")){
if(this.mydb.deleteDonador(this.d)){
msg.ok("Donador Eliminado");
this.txtfocus();
}
else{
msg.error("Ha ocurrido un error en el proceso");
this.txtfocus();
}
}
}
else{
msg.danger("Este donador tiene donaciones. \n>>Imposible eliminar.");
this.txtfocus();
}
}
else{
this.txtfocus();
}
break;
}
case("UPDATE_DONADOR"):{
if(this.existDonador()){
updateDonador u = new updateDonador(this.mydb.getDonador(this.d.getNss()));
this.close();
}
break;
}
}
}
private boolean existDonador(){
if(this.mydb.existeDonador(this.d)){
return true;
}
else{
msg.error("No existe este numero de seguridad Social!");
this.base.txtnss.setText("");
this.base.txtnss.requestFocus();
}
return false;
}
private boolean hasDonations(){
if(this.mydb.hasDonaciones(this.d.getNss())){
return true;
}
return false;
}
private void close(){
this.mystage.close();
}
private void txtfocus(){
this.base.txtnss.setText("");
this.base.txtnss.requestFocus();
}
public void onlyEnter(KeyEvent e){
if(!(e.getCode() == KeyCode.ENTER)){
e.consume();
}
else{
this.decide();
}
}
}