-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelo_donacion.java
99 lines (81 loc) · 3.06 KB
/
modelo_donacion.java
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
package bloodbanks.donaciones;
import bloodbanks.Main;
import bloodbanks.donadores.modelo_searchDonador;
import db.dbop;
import entities.donacion;
import entities.donador;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
import javafx.scene.Scene;
import javafx.stage.Stage;
import utilerias.msg;
import utilerias.mydate;
public class modelo_donacion {
private Controller_donacion base = null;
private donacion d;
private dbop db;
private Stage stage;
public modelo_donacion(){
this.base = Main.manager.openFXML("/bloodbanks/donaciones/FXMLdonacion.fxml","Agregar Donacion", false, false).getController();
this.db = new dbop();
this.stage = (Stage)this.base.btnaceptar.getScene().getWindow();
this.initData();
this.base.modelo = this;
}
private void initData(){
this.base.txtid.setText(String.valueOf(this.db.getCurrentDonacion()));
this.base.txtbanco.setText(String.valueOf(Main.banco.id));
this.base.txtusuario.setText(String.valueOf(Main.usuario.id));
this.base.dpfecha.setValue(LocalDate.now());
this.base.txtnss.setText("");
this.base.txtcomentarios.setText("");
this.base.txtdetalles.setText("");
this.base.txtnss.requestFocus();
}
private boolean fillData(){
this.d = new donacion();
String nss = this.base.txtnss.getText().trim();
if((!"".equals(nss))&&(this.db.existeDonador(new donador(nss)))){
this.d.setNssdonador(nss);
}
else{
msg.error("Numero de seguridad Social Invalido!");
this.base.txtnss.requestFocus();
return false;
}
LocalDate date =this.base.dpfecha.getValue();
this.d.setFecha(date!=null?date.format(mydate.formato).trim():null);
this.d.setDetalles(this.base.txtdetalles.getText());
this.d.setComentarios(this.base.txtcomentarios.getText());
this.d.setIdbanco(Integer.valueOf(this.base.txtbanco.getText().trim()));
this.d.setIdusuario(Integer.valueOf(this.base.txtusuario.getText().trim()));
return true;
}
public void btnsearch(){
modelo_searchDonador d = new modelo_searchDonador();
}
public void btncancelar(){
this.initData();
}
public void insertarDonacion(){
if(this.fillData()){
if(this.db.insertDonacion(this.d)){
msg.ok("Donacion registrada.");
if(!this.base.cbclose.selectedProperty().getValue()){
this.initData();
}
else{
this.stage.close();
}
}
else{
msg.error("Error al registrar donacion.");
this.base.txtnss.requestFocus();
}
}
}
public void close(){
this.stage.close();
}
}