-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelo_inicio.java
242 lines (177 loc) · 6.02 KB
/
modelo_inicio.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package bloodbanks;
import arduino.ardoSerial;
import arduino.arduinable;
import bloodbanks.central.modeloCentral;
import db.dbop;
import entities.bancosangre;
import entities.usuario;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.EventHandler;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import javax.swing.Timer;
import mail.fxmail;
import tray.notification.NotificationType;
import tray.notification.TrayNotification;
import utilerias.msg;
public class modelo_inicio implements arduinable {
private Controller_Inicio base;
private dbop db = null;
private Stage st;
public ardoSerial ardo;
private modelo_inicio gendowsBase;
private boolean normalLogin;
private fxmail mail;
public Thread secondaryThread;
private Timer t;
public modelo_inicio() {
this.base = Main.manager.openFXML("/bloodbanks/FXMLinicio.fxml", "SGBS INICIO", true, false).getController();
this.gendowsBase = this;
this.rxtx();
this.st = (Stage) this.base.txtcontrol.getScene().getWindow();
this.db = new dbop();
this.base.modelo = this;
this.base.txtcontrol.requestFocus();
this.normalLogin = true;
this.mail = new fxmail();
this.t = new Timer(2000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
ardo.sendToArdo("@");
t.stop();
}
});
}
});
t.start();
this.st.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
if (msg.yesno("Desea Salir?")) {
ardoCloseStage();
Platform.exit();
System.exit(0);
} else {
event.consume();
}
}
});
}
public boolean verifica() {
boolean flag = false;
usuario usr;
if (this.normalLogin) {
usr = this.db.getUsuario(this.base.txtcontrol.getText(), this.base.txtpassword.getText());
} else {
usr = this.db.getUsuario(this.base.txtpassword.getText());
}
if (!(usr == null)) {
flag = true;
usuario.copy(Main.usuario, usr);
bancosangre banco = this.db.getBancoLocal();
if (!(banco == null)) {
bancosangre.copy(Main.banco, banco);
}
modeloCentral c = new modeloCentral(this.ardo);
Main.mail.execute(true);
this.ardo.sendToArdo("1");
this.st.hide();
} else {
Main.mail.execute(false);
this.ardo.sendToArdo("0");
msg.error("Credenciales Incorrectas!");
this.ardo.sendToArdo("D");
this.clearcontrols();
this.base.txtcontrol.requestFocus();
}
return flag;
}
public void ardoCloseStage() {
ardo.sendToArdo("z");
}
private void clearcontrols() {
this.base.txtcontrol.setText("");
this.base.txtpassword.setText("");
}
public void btnaliaskp(KeyEvent e) {
if (e.getCode() == KeyCode.ENTER) {
this.base.txtpassword.requestFocus();
}
}
public void btnpasskp(KeyEvent e) {
if (e.getCode() == KeyCode.ENTER) {
this.verifica();
}
}
public void close() {
this.st.close();
}
public void ardoLogin(boolean stmt) {
if (!stmt) {
this.base.txtardo.setVisible(true);
this.base.txtalias.setVisible(false);
this.base.txtcontrol.setVisible(false);
} else {
this.base.txtardo.setVisible(false);
this.base.txtalias.setVisible(true);
this.base.txtcontrol.setVisible(true);
this.base.txtalias.requestFocus();
}
}
@Override
public void behavior(String a) {
if (this.normalLogin) {
this.btnarduinokp();
}
try {
switch (a) {
case ("#"): {
if (this.base.txtpassword.getText().length() > 0) {
char[] arr = this.base.txtpassword.getText().toCharArray();
String trunc = new String(arr, 0, arr.length - 1);
this.base.txtpassword.setText(trunc);
}
break;
}
case ("*"): {
Platform.runLater(new Runnable() {
@Override
public void run() {
gendowsBase.verifica();
}
});
break;
}
default: {
this.base.txtpassword.setText(this.base.txtpassword.getText() + a);
break;
}
}
} catch (Exception ex) {
msg.error(ex.getMessage());
}
}
public void btnarduinokp() {
this.normalLogin = !this.normalLogin;
this.clearcontrols();
this.ardoLogin(normalLogin);
}
private void rxtx() {
this.secondaryThread = new Thread() {
@Override
public void run() {
ardo = new ardoSerial(gendowsBase);
}
};
this.secondaryThread.start();
}
}