-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrentistaSC.java
More file actions
432 lines (401 loc) · 19.4 KB
/
Copy pathFrentistaSC.java
File metadata and controls
432 lines (401 loc) · 19.4 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* FrentistaSC.java
*
* Created on Nov 18, 2010, 11:06:17 AM
*/
package relatorpostoeaton.screens;
import com.tomtessier.scrollabledesktop.BaseInternalFrame;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import relatorpostoeaton.business.ColaboradorController;
import relatorpostoeaton.business.FrentistaController;
import relatorpostoeaton.business.datamodels.ColaboradorDataModel;
import relatorpostoeaton.business.jpa.ColaboradorJpaController;
import relatorpostoeaton.business.jpa.FrentistaJpaController;
import relatorpostoeaton.business.jpa.exceptions.NonexistentEntityException;
import relatorpostoeaton.business.jpa.exceptions.PreexistingEntityException;
import relatorpostoeaton.entities.Colaborador;
import relatorpostoeaton.entities.Frentista;
/**
*
* @author icarlos
*/
public final class FrentistaSC extends BaseInternalFrame {
private static final long serialVersionUID = 1L;
public static JRadioButton getSelection(ButtonGroup group) {
for (Enumeration e = group.getElements(); e.hasMoreElements();) {
JRadioButton b = (JRadioButton) e.nextElement();
if (b.getModel() == group.getSelection()) {
return b;
}
}
return null;
}
private static FrentistaSC instanceFrentistaSC;
private FrentistaController fc;
private ColaboradorController colc;
private LinkedList<String> tagList = new LinkedList<String>();
private List<Colaborador> colabList = new LinkedList<Colaborador>();
private WindowFindTagCards wftc = new WindowFindTagCards();
private Boolean operControl = false; // false igual criar
public void refreshTable() {
ColaboradorJpaController cjc = new ColaboradorJpaController();
colabList.clear();
colabList.addAll(cjc.findColaboradorEntities());
ColaboradorDataModel cdm = new ColaboradorDataModel(cjc.findColaboradorEntities());
this.jTabelaFrentista.setModel(cdm);
}
public static FrentistaSC getInstanceFrentistaSC() {
if (instanceFrentistaSC == null) {
instanceFrentistaSC = new FrentistaSC();
instanceFrentistaSC.setTitle("COLABORADOR");
}
return instanceFrentistaSC;
}
/** Creates new form FrentistaSC */
public FrentistaSC() {
initComponents();
refreshTable();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void jBtnNovoActionPerformed(java.awt.event.ActionEvent evt) {
setFc(FrentistaController.getInstance());
getFc().setCurrentFrentista(new Frentista());
setColc(ColaboradorController.getInstance());
getColc().setCurrentColaborador(new Colaborador());
jTxtFldNomeColaborador.setText("");
jTxtFldApelidoColaborador.setText("");
jTxtFldNumeroCadastro.setText("");
jFrmTxtFldDataNasc.setText("");
jTxtFldNumeroTag.setText("");
operControl = false;
JOptionPane.showMessageDialog(this, "Campos Apagados Com Sucesso!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
}
private void jBtnSairActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jBtnExcluirActionPerformed(java.awt.event.ActionEvent evt) {
try {
if (jChBxFrentista.isSelected()) {
FrentistaJpaController fjc = new FrentistaJpaController();
int die = JOptionPane.showConfirmDialog(this, "Deseja Excluir o Campo Selecionado ?", "AVISO", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (die == JOptionPane.YES_OPTION) {
fjc.destroy(fc.getCurrentFrentista().getColaboradorPK());
refreshTable();
JOptionPane.showMessageDialog(this, "Cadastro Apagado com Sucesso!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
}
} else {
ColaboradorJpaController cjc = new ColaboradorJpaController();
int kill = JOptionPane.showConfirmDialog(this, "Deseja excluir o campo selecionado?", "AVISO", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (kill == JOptionPane.YES_OPTION) {
cjc.destroy(colc.getCurrentColaborador().getColaboradorPK());
refreshTable();
JOptionPane.showMessageDialog(this, "Cadastro Apagado com Sucesso !", "AVISO", JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (NonexistentEntityException ex) {
Logger.getLogger(FrentistaSC.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void criar() {
if (jChBxFrentista.isSelected()) {
FrentistaJpaController fjc = new FrentistaJpaController();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
setFc(FrentistaController.getInstance());
fc.getCurrentFrentista().setNomFun(jTxtFldNomeColaborador.getText());
fc.getCurrentFrentista().setApeFun(jTxtFldApelidoColaborador.getText());
try {
fc.getCurrentFrentista().setDatNas(sdf.parse(jFrmTxtFldDataNasc.getText()));
} catch (ParseException ex) {
Logger.getLogger(FrentistaSC.class.getName()).log(Level.SEVERE, null, ex);
}
fc.getCurrentFrentista().getColaboradorPK().setNumCad(Integer.parseInt(jTxtFldNumeroCadastro.getText()));
fc.getCurrentFrentista().getColaboradorPK().setNumEmp(new Short("1"));
fc.getCurrentFrentista().setTag(jTxtFldNumeroTag.getText());
fc.getCurrentFrentista().getColaboradorPK().setTipCol(Short.parseShort("" + jCmbBxTipoDeColaborador.getSelectedIndex()));
if (getSelection(btGrpSexo).equals(jBtnGrpSexoMasculino)) {
fc.getCurrentFrentista().setTipSex("M");
} else {
fc.getCurrentFrentista().setTipSex("F");
}
if (getSelection(btGrpRegsLocal).equals(jBtnGrpRegsLocalSim)) {
fc.getCurrentFrentista().setAtivo(true);
} else {
fc.getCurrentFrentista().setAtivo(false);
}
try {
fjc.create(getFc().getCurrentFrentista());
refreshTable();
JOptionPane.showMessageDialog(this, "Campos Gravados Com Sucesso!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (PreexistingEntityException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Campos Não Inseridos e/ou Gravados,Tente Novamente!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
ColaboradorJpaController cjc = new ColaboradorJpaController();
setColc(ColaboradorController.getInstance());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
colc.getCurrentColaborador().setNomFun(jTxtFldNomeColaborador.getText());
colc.getCurrentColaborador().setApeFun(jTxtFldApelidoColaborador.getText());
try {
colc.getCurrentColaborador().setDatNas(sdf.parse(jFrmTxtFldDataNasc.getText()));
} catch (ParseException ex) {
Logger.getLogger(FrentistaSC.class.getName()).log(Level.SEVERE, null, ex);
}
colc.getCurrentColaborador().getColaboradorPK().setNumCad(Integer.parseInt(jTxtFldNumeroCadastro.getText()));
colc.getCurrentColaborador().setTag(jTxtFldNumeroTag.getText());
colc.getCurrentColaborador().getColaboradorPK().setRegLocal(new Short("1"));
colc.getCurrentColaborador().getColaboradorPK().setTipCol(Short.parseShort("" + jCmbBxTipoDeColaborador.getSelectedIndex()));
if (getSelection(btGrpSexo).equals(jBtnGrpSexoMasculino)) {
colc.getCurrentColaborador().setTipSex("M");
} else {
colc.getCurrentColaborador().setTipSex("F");
}
if (getSelection(btGrpRegsLocal).equals(jBtnGrpRegsLocalSim)) {
colc.getCurrentColaborador().setAtivo(true);
} else {
colc.getCurrentColaborador().setAtivo(false);
}
try {
cjc.create(getColc().getCurrentColaborador());
refreshTable();
JOptionPane.showMessageDialog(this, "Campos Gravados Com Sucesso!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (PreexistingEntityException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Campos Não Inseridos e/ou Gravados,Tente Novamente!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void editar() {
if (jChBxFrentista.isSelected()) {
FrentistaJpaController fjc = new FrentistaJpaController();
setFc(FrentistaController.getInstance());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
fc.getCurrentFrentista().setNomFun(jTxtFldNomeColaborador.getText());
fc.getCurrentFrentista().setApeFun(jTxtFldApelidoColaborador.getText());
try {
fc.getCurrentFrentista().setDatNas(sdf.parse(jFrmTxtFldDataNasc.getText()));
} catch (ParseException ex) {
Logger.getLogger(FrentistaSC.class.getName()).log(Level.SEVERE, null, ex);
}
fc.getCurrentFrentista().getColaboradorPK().setNumCad(Integer.parseInt(jTxtFldNumeroCadastro.getText()));
fc.getCurrentFrentista().setTag(jTxtFldNumeroTag.getText());
fc.getCurrentFrentista().getColaboradorPK().setRegLocal(new Short("1"));
fc.getCurrentFrentista().getColaboradorPK().setTipCol(Short.parseShort("" + jCmbBxTipoDeColaborador.getSelectedIndex()));
if (getSelection(btGrpSexo).equals(jBtnGrpSexoMasculino)) {
fc.getCurrentFrentista().setTipSex("M");
} else {
fc.getCurrentFrentista().setTipSex("F");
}
if (getSelection(btGrpRegsLocal).equals(jBtnGrpRegsLocalSim)) {
fc.getCurrentFrentista().setAtivo(true);
} else {
fc.getCurrentFrentista().setAtivo(false);
}
try {
fjc.edit(getFc().getCurrentFrentista());
refreshTable();
JOptionPane.showMessageDialog(this, "Campos Gravados Com Sucesso!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (PreexistingEntityException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Campos Não Inseridos e/ou Gravados,Tente Novamente!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
ColaboradorJpaController cjc = new ColaboradorJpaController();
setColc(ColaboradorController.getInstance());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
colc.getCurrentColaborador().setNomFun(jTxtFldNomeColaborador.getText());
colc.getCurrentColaborador().setApeFun(jTxtFldApelidoColaborador.getText());
try {
colc.getCurrentColaborador().setDatNas(sdf.parse(jFrmTxtFldDataNasc.getText()));
} catch (ParseException ex) {
Logger.getLogger(FrentistaSC.class.getName()).log(Level.SEVERE, null, ex);
}
colc.getCurrentColaborador().getColaboradorPK().setNumCad(Integer.parseInt(jTxtFldNumeroCadastro.getText()));
colc.getCurrentColaborador().setTag(jTxtFldNumeroTag.getText());
colc.getCurrentColaborador().getColaboradorPK().setRegLocal(new Short("1"));
colc.getCurrentColaborador().getColaboradorPK().setTipCol(Short.parseShort("" + jCmbBxTipoDeColaborador.getSelectedIndex()));
if (getSelection(btGrpSexo).equals(jBtnGrpSexoMasculino)) {
colc.getCurrentColaborador().setTipSex("M");
} else {
colc.getCurrentColaborador().setTipSex("F");
}
if (getSelection(btGrpRegsLocal).equals(jBtnGrpRegsLocalSim)) {
colc.getCurrentColaborador().setAtivo(true);
} else {
colc.getCurrentColaborador().setAtivo(false);
}
try {
cjc.edit(getColc().getCurrentColaborador());
refreshTable();
JOptionPane.showMessageDialog(this, "Campos Gravados Com Sucesso!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (PreexistingEntityException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Campos Não Inseridos e/ou Gravados,Tente Novamente!", "AVISO", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void tagAntenna() {
try {
tagList.clear();
Socket socket = new Socket("127.0.0.1", 8080);
System.out.println("Connected to server...sending echo string");
ColaboradorJpaController colabjc = new ColaboradorJpaController();
OutputStream out = socket.getOutputStream();
out.write("select id from tag_id;\n".getBytes("US-ASCII"));
String tagColab;
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
boolean sair = false;
while (!sair) {
tagColab = br.readLine();
System.out.println("====Render====\n" + tagColab);
if (tagColab.length() <= 0) {
sair = true;
br.close();
} else {
jTxtFldNumeroTag.setText(tagColab);
}
}
socket.close();
} catch (UnknownHostException ex) {
ex.printStackTrace();
Logger.getLogger(MenuLateralSC.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
ex.printStackTrace();
Logger.getLogger(MenuLateralSC.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jBtnSalvarActionPerformed(java.awt.event.ActionEvent evt) {
if (!operControl) {
criar();
} else {
editar();
}
}
private void jCmbBxTipoDeColaboradorActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTabelaFrentistaMouseClicked(java.awt.event.MouseEvent evt) {
fc = FrentistaController.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
colc = ColaboradorController.getInstance();
Colaborador tc = colabList.get(jTabelaFrentista.getSelectedRow());
operControl = true;
if (tc instanceof Frentista) {
fc.setCurrentFrentista((Frentista) tc);
jChBxFrentista.setSelected(true);
} else {
colc.setCurrentColaborador(tc);
jChBxFrentista.setSelected(false);
}
jTxtFldNomeColaborador.setText(tc.getNomFun());
jTxtFldApelidoColaborador.setText(tc.getApeFun());
jFrmTxtFldDataNasc.setText(sdf.format(tc.getDatNas()));
jTxtFldNumeroTag.setText(tc.getColaboradorPK().getNumEmp() + "");
jTxtFldNumeroCadastro.setText(tc.getColaboradorPK().getNumCad() + "");
jCmbBxTipoDeColaborador.setSelectedIndex(tc.getColaboradorPK().getTipCol());
if (tc.getTipSex().compareTo("M") == 0) {
jBtnGrpSexoMasculino.setSelected(true);
} else {
jBtnGrpSexoFeminino.setSelected(true);
}
if (tc.getAtivo()) {
jBtnGrpRegsLocalSim.setSelected(true);
} else {
jBtnGrpRegsLocalNao.setSelected(true);
}
}
private void jBtnOKActionPerformed(java.awt.event.ActionEvent evt) {
tagAntenna();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrentistaSC().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel apelidoColaborador;
private javax.swing.ButtonGroup btGrpRegsLocal;
private javax.swing.ButtonGroup btGrpSexo;
private javax.swing.JLabel dataNascimento;
private javax.swing.JButton jBtnExcluir;
private javax.swing.JRadioButton jBtnGrpRegsLocalNao;
private javax.swing.JRadioButton jBtnGrpRegsLocalSim;
private javax.swing.JRadioButton jBtnGrpSexoFeminino;
private javax.swing.JRadioButton jBtnGrpSexoMasculino;
private javax.swing.JButton jBtnNovo;
private javax.swing.JButton jBtnOK;
private javax.swing.JButton jBtnSair;
private javax.swing.JButton jBtnSalvar;
private javax.swing.JCheckBox jChBxFrentista;
private javax.swing.JComboBox jCmbBxTipoDeColaborador;
private javax.swing.JFormattedTextField jFrmTxtFldDataNasc;
private javax.swing.JPanel jPanelBtnSelecionar;
private javax.swing.JPanel jPanelFrentista;
private javax.swing.JPanel jPanelRegsLocal;
private javax.swing.JPanel jPanelSexo;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTabelaFrentista;
private javax.swing.JTextField jTxtFldApelidoColaborador;
private javax.swing.JTextField jTxtFldNomeColaborador;
private javax.swing.JTextField jTxtFldNumeroCadastro;
private javax.swing.JTextField jTxtFldNumeroTag;
private javax.swing.JLabel nomeColaborador;
private javax.swing.JLabel numeroCadastro;
private javax.swing.JLabel numeroTag;
private javax.swing.JLabel tipoColaborador;
// End of variables declaration
/**
* @return the fc
*/
public FrentistaController getFc() {
return fc;
}
/**
* @param fc the fc to set
*/
public void setFc(FrentistaController fc) {
this.fc = fc;
}
public ColaboradorController getColc() {
return colc;
}
private void setColc(ColaboradorController colc) {
this.colc = colc;
}
}