-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTelaCadastroHotel.java
More file actions
275 lines (236 loc) · 9.86 KB
/
TelaCadastroHotel.java
File metadata and controls
275 lines (236 loc) · 9.86 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package telacadastrohotel;
import java.util.HashMap;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import static javafx.scene.paint.Color.RED;
import javafx.stage.Stage;
/**
*
* @author breno
*/
public class TelaCadastroHotel extends Application {
@Override
public void start(Stage stage) throws Exception {
Insets padrao = new Insets(0,0,10,0);
VBox layoutRaiz = new VBox(10);
layoutRaiz.setPadding(new Insets(10, 10, 10, 10));
BorderPane layoutNome = new BorderPane();
Label labelNome = new Label ("Nome:");
labelNome.setPadding(padrao);
TextField textNome = new TextField();
layoutNome.setTop(labelNome);
layoutNome.setBottom(textNome);
BorderPane layoutEndereco = new BorderPane();
Label labelEndereco = new Label("Endereço:");
labelEndereco.setPadding(padrao);
TextField textEndereco = new TextField();
layoutEndereco.setTop(labelEndereco);
layoutEndereco.setBottom(textEndereco);
BorderPane layoutRG = new BorderPane();
Label labelRG = new Label("RG:");
labelRG.setPadding(padrao);
TextField textRG = new TextField();
layoutRG.setTop(labelRG);
layoutRG.setBottom(textRG);
BorderPane layoutCPF = new BorderPane();
Label labelCPF = new Label("CPF:");
labelCPF.setPadding(padrao);
TextField textCPF = new TextField();
layoutCPF.setTop(labelCPF);
layoutCPF.setBottom(textCPF);
BorderPane layoutIdade = new BorderPane();
Label labelIdade = new Label("Idade:");
labelIdade.setPadding(padrao);
TextField textIdade = new TextField();
layoutIdade.setTop(labelIdade);
layoutIdade.setBottom(textIdade);
/* O sexo nao foi pedido no modelo, portanto sera excluido
BorderPane layoutSexo = new BorderPane();
Label labelSexo = new Label("Sexo:");
labelSexo.setPadding(padrao);
RadioButton masculino = new RadioButton("M");
RadioButton feminino = new RadioButton("F");
layoutSexo.setTop(labelSexo);
HBox opcoes = new HBox(masculino, feminino);
layoutSexo.setBottom(opcoes);
*/
BorderPane layoutQuarto = new BorderPane();
Label labelQuarto = new Label ("Quarto:");
labelQuarto.setPadding(padrao);
ObservableList <String> quartosDisponiveis =
FXCollections.observableArrayList(
"1","2","3","4","5");
ComboBox quarto = new ComboBox(quartosDisponiveis);
layoutQuarto.setTop(labelQuarto);
layoutQuarto.setBottom(quarto);
HBox layoutBotoes = new HBox(20);
Button btnSalvar = new Button("Salvar");
Button btnCancelar = new Button("Cancelar");
Button btnBuscar = new Button("Buscar");
layoutBotoes.setAlignment(Pos. CENTER);
layoutBotoes.setPadding(new Insets(30, 0, 0, 0));
layoutBotoes.getChildren().addAll(btnSalvar, btnBuscar, btnCancelar);
// Criacao do Label pra informar o resultado da acao
BorderPane layoutResultado = new BorderPane();
Label labelResultado = new Label();
labelResultado.setTextFill(RED);
labelResultado.setMaxWidth(Double.MAX_VALUE);
AnchorPane.setLeftAnchor(labelResultado, 0.0);
AnchorPane.setRightAnchor(labelResultado, 0.0);
labelResultado.setAlignment(Pos. CENTER);
layoutResultado.setTop(labelResultado);
Label labelProcura = new Label();
labelProcura.setTextFill(RED);
labelProcura.setMaxWidth(Double.MAX_VALUE);
AnchorPane.setLeftAnchor(labelProcura, 0.0);
AnchorPane.setRightAnchor(labelProcura, 0.0);
labelProcura.setAlignment(Pos. CENTER);
layoutResultado.setBottom(labelProcura);
//criando o DB
Registrador registro = new Registrador();
// Personalizacao das acoes dos botoes
btnSalvar.setOnAction(new EventHandler() {
@Override
public void handle(Event event) {
boolean verificador =verifica(textNome.getText(), textEndereco.getText(), textRG.getText(), textCPF.getText(), textIdade.getText(), (String) quarto.getValue(), registro);
if (verificador){
Hospede hospede = criaHospede(textNome.getText(), textEndereco.getText(), textRG.getText(), textCPF.getText(), textIdade.getText());
Quarto numQuarto= criaQuarto((String) quarto.getValue(), hospede);
registro.addRegistro(hospede, numQuarto);
// deixando todas as labels em branco novamente
labelResultado.setText("");
labelProcura.setText("");
textNome.setText("");
textIdade.setText("");
textRG.setText("");
textCPF.setText("");
textEndereco.setText("");
}
String text = verificador ? "Hóspede Cadastrado!" : "Falha para cadastrar hóspede.\nPor favor, cheque novamente os dados inseridos.";
labelResultado.setText(text);
}
private Hospede criaHospede(String nome, String endereco, String RG, String CPF, String idade) {
Long RGf = Long.parseLong(RG);
Long CPFf = Long.parseLong(CPF);
int idadef = Integer.parseInt(idade);
Hospede hospede = new Hospede(CPFf, RGf, nome, idadef, endereco);
return hospede;
}
private Quarto criaQuarto(String quartoStr, Hospede hospede){
int numQuarto = Integer.parseInt(quartoStr);
Quarto quarto = new Quarto(numQuarto, hospede);
return quarto;
}
});
btnBuscar.setOnAction(new EventHandler() {
@Override
public void handle(Event event) {
labelResultado.setText("");
labelProcura.setText("");
String mensagemProcura = procuraHospede(textNome.getText(), registro);
labelProcura.setText(mensagemProcura);
}
});
btnCancelar.setOnAction(new EventHandler() {
@Override
public void handle(Event event) {
labelResultado.setText("");
labelProcura.setText("");
textNome.setText("");
textIdade.setText("");
textRG.setText("");
textCPF.setText("");
textEndereco.setText("");
}
});
layoutRaiz.getChildren().addAll(layoutNome, layoutEndereco, layoutRG, layoutCPF, layoutIdade, layoutQuarto, layoutResultado, layoutBotoes);
Scene scene = new Scene(layoutRaiz, 350, 550);
stage.setTitle("Cadastro Hotel");
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch();
}
// fazendo as verificacoes aqui
public static boolean verifica(String nome, String endereco, String RG, String CPF, String idade, String quarto, Registrador registro){
// atribui uma condicao a cada um dos valores, se for algum falso renderiza novamente o formulario
int quartoF = Integer.parseInt(quarto);
boolean c1 = CheckName(nome);
boolean c2 = CheckLong(RG);
boolean c3 = CheckLong(CPF);
boolean c4 = CheckInteger(idade);
if (c1 && c2 && c3 && c4){
return true;
} else {
return false;
}
}
/*
public static Hospede criaHospede(String nome, String endereco, String RG, String CPF, String idade, String quartoStr, Registrador registro){
int numQuarto = Integer.parseInt(quartoStr);
Long.parseLong(RG);
Long.parseLong(CPF);
Integer.parseInt(idade);
Hospede hospede = new Hospede(CPF, RG, nome, idade, endereco);
return hospede;
}
public static Quarto criaQuarto(String quartoStr, Hospede hospede){
int numQuarto = Integer.parseInt(quartoStr);
Quarto quarto = new Quarto(numQuarto, hospede);
return quarto;
}
*/
public static String procuraHospede(String nome, Registrador registro){
return registro.registroToS(nome);
}
public static boolean CheckName(String s){
if (s == null) {
return false;
}
int len = s.length();
for (int i = 0; i < len; i++) {
if ((Character.isDigit(s.charAt(i)))) {
return false;
}
}
return true;
}
public static boolean CheckInteger(String numeroStr){
while (true) {
try{
int numero = Integer.parseInt(numeroStr);
return true;
} catch(NumberFormatException exception) {
return false;
}
}
}
public static boolean CheckLong(String numeroStr){
while (true) {
try{
long numero = Long.parseLong(numeroStr);
return true;
} catch(NumberFormatException exception) {
return false;
}
}
}
}