-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_CriaFatura.java
More file actions
838 lines (736 loc) · 30.3 KB
/
GUI_CriaFatura.java
File metadata and controls
838 lines (736 loc) · 30.3 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
/**
*Text genereted by Simple GUI Extension for BlueJ
*/
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.border.Border;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.util.ArrayList;
import javax.swing.table.*;
import java.util.Arrays;
import java.util.List;
import java.text.*;
public class GUI_CriaFatura extends JFrame {
/**Variaveis de instancia*/
private JMenuBar menuBar;
private JButton AdicionarButton;
private JButton removerbotao;
private JButton testanifButton;
private JButton CriarFacturaButton;
private JLabel TextAtividadeEco;
private JLabel TextData;
private JLabel TextEmailEmpresa;
private JTextField TextFEmailCliente;
private JTextField TextFMoradaCliente;
private JTextField TextFNifCliente;
private JTextField TextFNomeCliente;
private JTextField TextFPreco;
private JTextField TextFProduto;
private JTextField TextFQuantidade;
private JLabel TextMoradaEmpresa;
private JLabel TextNifEmpresa;
private JLabel TextNomeEmpresa;
private JLabel label1;
private JLabel label10;
private JLabel label11;
private JLabel label12;
private JLabel label13;
private JLabel label14;
private JLabel label15;
private JLabel label16;
private JLabel label2;
private JLabel label23;
private JLabel label3;
private JLabel label4;
private JLabel label5;
private JLabel label6;
private JLabel label7;
private JLabel label8;
private JLabel label9;
private JTable table;
private JTextField textfield2;
private String faturaID;
private String nomeCliente;
private String moradaCliente;
private String emailCliente;
private String nifCliente;
private String produto;
private String quantidade;
private String preco;
private FichaCliente ficha;
private GestaoFichas gestorfichas;
private GestaoFaturas gestorfaturas;
private FichaCliente fichaAssociada;
private GUI_FichaCliente guificha;
private ArrayList<Triple> produtos;
private String[] colunas = {"Produto","Quantidade","Preço(€)"};
private DefaultTableModel dtm = new DefaultTableModel(null,colunas){
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
/**Construtor vazio da classe*/
public GUI_CriaFatura(FichaCliente ficha,GestaoFichas gestorfichas,GestaoFaturas gestorfaturas,GUI_FichaCliente guificha){
this.gestorfichas = gestorfichas;
this.gestorfaturas = gestorfaturas;
this.guificha = guificha;
faturaID = "";
nomeCliente = "n/a";
moradaCliente = "n/a";
emailCliente = "n/a";
nifCliente = "";
produto = "";
quantidade = "";
preco = "";
produtos = new ArrayList<Triple>();
this.ficha=ficha;
EntidadeEmpresas fichaE = (EntidadeEmpresas) ficha;
this.setTitle("GUI_project");
this.setSize(695,664);
//menu generate method
generateMenu();
this.setJMenuBar(menuBar);
//pane with null layout
JPanel contentPane = new JPanel(null);
contentPane.setPreferredSize(new Dimension(695,664));
contentPane.setBackground(new Color(192,192,192));
testanifButton = new JButton();
testanifButton.setBounds(314,452,90,35);
testanifButton.setBackground(new Color(214,217,223));
testanifButton.setForeground(new Color(0,0,0));
testanifButton.setEnabled(true);
testanifButton.setFont(new Font("sansserif",0,12));
testanifButton.setText("Testar Nif");
testanifButton.setVisible(true);
//Set methods for mouse events
//Call defined methods
testanifButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
OnTestaNif(evt);
}
});
AdicionarButton = new JButton();
AdicionarButton.setBounds(587,509,90,35);
AdicionarButton.setBackground(new Color(214,217,223));
AdicionarButton.setForeground(new Color(0,0,0));
AdicionarButton.setEnabled(true);
AdicionarButton.setFont(new Font("sansserif",0,12));
AdicionarButton.setText("Adicionar");
AdicionarButton.setVisible(true);
//Set methods for mouse events
//Call defined methods
AdicionarButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
OnProdutoAddedd(evt);
}
});
removerbotao = new JButton();
removerbotao.setBounds(460,410,90,35);
removerbotao.setBackground(new Color(214,217,223));
removerbotao.setForeground(new Color(0,0,0));
removerbotao.setEnabled(true);
removerbotao.setFont(new Font("sansserif",0,12));
removerbotao.setText("Remover");
removerbotao.setVisible(true);
removerbotao.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
OnProdutoRemoved(evt);
}
});
CriarFacturaButton = new JButton();
CriarFacturaButton.setBounds(291,587,100,35);
CriarFacturaButton.setBackground(new Color(214,217,223));
CriarFacturaButton.setForeground(new Color(0,0,0));
CriarFacturaButton.setEnabled(false);
CriarFacturaButton.setFont(new Font("sansserif",0,12));
CriarFacturaButton.setText("Criar Fatura");
CriarFacturaButton.setVisible(true);
//Set methods for mouse events
//Call defined methods
CriarFacturaButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OnClickedCriarFatura(e);
}
});
String atividades = Arrays.toString(fichaE.getActividadeEconomica().toArray());
atividades=atividades.substring(1,atividades.length()-1);
;
TextAtividadeEco = new JLabel();
TextAtividadeEco.setBounds(172,201,150,35);
TextAtividadeEco.setBackground(new Color(214,217,223));
TextAtividadeEco.setForeground(new Color(0,0,0));
TextAtividadeEco.setEnabled(true);
TextAtividadeEco.setFont(new Font("sansserif",0,12));
TextAtividadeEco.setText(atividades);
TextAtividadeEco.setVisible(true);
TextData = new JLabel();
TextData.setBounds(172,151,150,35);
TextData.setBackground(new Color(214,217,223));
TextData.setForeground(new Color(0,0,0));
TextData.setEnabled(true);
TextData.setFont(new Font("sansserif",0,12));
TextData.setText(getdatastring());
TextData.setVisible(true);
TextEmailEmpresa = new JLabel();
TextEmailEmpresa.setBounds(172,248,150,35);
TextEmailEmpresa.setBackground(new Color(214,217,223));
TextEmailEmpresa.setForeground(new Color(0,0,0));
TextEmailEmpresa.setEnabled(true);
TextEmailEmpresa.setFont(new Font("sansserif",0,12));
TextEmailEmpresa.setText(ficha.getEmail());
TextEmailEmpresa.setVisible(true);
TextFEmailCliente = new JTextField();
TextFEmailCliente.setBounds(163,413,150,35);
TextFEmailCliente.setBackground(new Color(255,255,255));
TextFEmailCliente.setForeground(new Color(0,0,0));
TextFEmailCliente.setEnabled(true);
TextFEmailCliente.setFont(new Font("sansserif",0,12));
TextFEmailCliente.setText("");
TextFEmailCliente.setVisible(true);
TextFEmailCliente.setEditable(false);
//Set action for key events
//Call defined method
TextFEmailCliente.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedEmailCliente(evt);
}
});
TextFMoradaCliente = new JTextField();
TextFMoradaCliente.setBounds(163,374,150,35);
TextFMoradaCliente.setBackground(new Color(255,255,255));
TextFMoradaCliente.setForeground(new Color(0,0,0));
TextFMoradaCliente.setEnabled(true);
TextFMoradaCliente.setFont(new Font("sansserif",0,12));
TextFMoradaCliente.setText("");
TextFMoradaCliente.setVisible(true);
TextFMoradaCliente.setEditable(false);
//Set action for key events
//Call defined method
TextFMoradaCliente.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedMoradaCliente(evt);
}
});
TextFNifCliente = new JTextField();
TextFNifCliente.setBounds(163,452,150,35);
TextFNifCliente.setBackground(new Color(255,255,255));
TextFNifCliente.setForeground(new Color(0,0,0));
TextFNifCliente.setEnabled(true);
TextFNifCliente.setFont(new Font("sansserif",0,12));
TextFNifCliente.setText("");
TextFNifCliente.setVisible(true);
//Set action for key events
//Call defined method
TextFNifCliente.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedNifCliente(evt);
}
});
TextFNomeCliente = new JTextField();
TextFNomeCliente.setBounds(164,331,150,35);
TextFNomeCliente.setBackground(new Color(255,255,255));
TextFNomeCliente.setForeground(new Color(0,0,0));
TextFNomeCliente.setEnabled(true);
TextFNomeCliente.setFont(new Font("sansserif",0,12));
TextFNomeCliente.setText("");
TextFNomeCliente.setVisible(true);
TextFNomeCliente.setEditable(false);
//Set action for key events
//Call defined method
TextFNomeCliente.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedNomeCliente(evt);
}
});
TextFPreco = new JTextField();
TextFPreco.setBounds(474,509,90,35);
TextFPreco.setBackground(new Color(255,255,255));
TextFPreco.setForeground(new Color(0,0,0));
TextFPreco.setEnabled(true);
TextFPreco.setFont(new Font("sansserif",0,12));
TextFPreco.setText("");
TextFPreco.setVisible(true);
//Set action for key events
//Call defined method
TextFPreco.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedPreco(evt);
}
});
TextFProduto = new JTextField();
TextFProduto.setBounds(89,509,135,35);
TextFProduto.setBackground(new Color(255,255,255));
TextFProduto.setForeground(new Color(0,0,0));
TextFProduto.setEnabled(true);
TextFProduto.setFont(new Font("sansserif",0,12));
TextFProduto.setText("");
TextFProduto.setVisible(true);
//Set action for key events
//Call defined method
TextFProduto.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedProduto(evt);
}
});
TextFQuantidade = new JTextField();
TextFQuantidade.setBounds(314,509,90,35);
TextFQuantidade.setBackground(new Color(255,255,255));
TextFQuantidade.setForeground(new Color(0,0,0));
TextFQuantidade.setEnabled(true);
TextFQuantidade.setFont(new Font("sansserif",0,12));
TextFQuantidade.setText("");
TextFQuantidade.setVisible(true);
//Set action for key events
//Call defined method
TextFQuantidade.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedQuantidade(evt);
}
});
TextMoradaEmpresa = new JLabel();
TextMoradaEmpresa.setBounds(172,224,150,35);
TextMoradaEmpresa.setBackground(new Color(214,217,223));
TextMoradaEmpresa.setForeground(new Color(0,0,0));
TextMoradaEmpresa.setEnabled(true);
TextMoradaEmpresa.setFont(new Font("sansserif",0,12));
TextMoradaEmpresa.setText(ficha.getMorada());
TextMoradaEmpresa.setVisible(true);
TextNifEmpresa = new JLabel();
TextNifEmpresa.setBounds(172,273,150,35);
TextNifEmpresa.setBackground(new Color(214,217,223));
TextNifEmpresa.setForeground(new Color(0,0,0));
TextNifEmpresa.setEnabled(true);
TextNifEmpresa.setFont(new Font("sansserif",0,12));
TextNifEmpresa.setText(Integer.toString(ficha.getnif()));
TextNifEmpresa.setVisible(true);
TextNomeEmpresa = new JLabel();
TextNomeEmpresa.setBounds(172,176,150,35);
TextNomeEmpresa.setBackground(new Color(214,217,223));
TextNomeEmpresa.setForeground(new Color(0,0,0));
TextNomeEmpresa.setEnabled(true);
TextNomeEmpresa.setFont(new Font("sansserif",0,12));
TextNomeEmpresa.setText(ficha.getNome());
TextNomeEmpresa.setVisible(true);
label1 = new JLabel();
label1.setBounds(223,34,300,35);
label1.setBackground(new Color(214,217,223));
label1.setForeground(new Color(0,0,0));
label1.setEnabled(true);
label1.setFont(new Font("SansSerif",0,30));
label1.setText("Crie a sua fatura");
label1.setVisible(true);
label10 = new JLabel();
label10.setBounds(45,373,150,35);
label10.setBackground(new Color(214,217,223));
label10.setForeground(new Color(0,0,0));
label10.setEnabled(true);
label10.setFont(new Font("sansserif",0,12));
label10.setText("Morada do Cliente:");
label10.setVisible(true);
label11 = new JLabel();
label11.setBounds(55,414,150,35);
label11.setBackground(new Color(214,217,223));
label11.setForeground(new Color(0,0,0));
label11.setEnabled(true);
label11.setFont(new Font("sansserif",0,12));
label11.setText("Email do Cliente:");
label11.setVisible(true);
label12 = new JLabel();
label12.setBounds(69,453,150,35);
label12.setBackground(new Color(214,217,223));
label12.setForeground(new Color(0,0,0));
label12.setEnabled(true);
label12.setFont(new Font("sansserif",0,12));
label12.setText("Nif de Cliente:");
label12.setVisible(true);
label13 = new JLabel();
label13.setBounds(319,492,90,35);
label13.setBackground(new Color(214,217,223));
label13.setForeground(new Color(0,0,0));
label13.setEnabled(true);
label13.setFont(new Font("sansserif",0,12));
label13.setText("Quantidade:");
label13.setVisible(false);
label14 = new JLabel();
label14.setBounds(31,509,90,35);
label14.setBackground(new Color(214,217,223));
label14.setForeground(new Color(0,0,0));
label14.setEnabled(true);
label14.setFont(new Font("sansserif",0,12));
label14.setText("Produto:");
label14.setVisible(true);
label15 = new JLabel();
label15.setBounds(426,509,114,39);
label15.setBackground(new Color(214,217,223));
label15.setForeground(new Color(0,0,0));
label15.setEnabled(true);
label15.setFont(new Font("sansserif",0,12));
label15.setText("Preco:");
label15.setVisible(true);
label16 = new JLabel();
label16.setBounds(238,509,90,35);
label16.setBackground(new Color(214,217,223));
label16.setForeground(new Color(0,0,0));
label16.setEnabled(true);
label16.setFont(new Font("sansserif",0,12));
label16.setText("Quantidade:");
label16.setVisible(true);
label2 = new JLabel();
label2.setBounds(104,119,90,35);
label2.setBackground(new Color(214,217,223));
label2.setForeground(new Color(0,0,0));
label2.setEnabled(true);
label2.setFont(new Font("sansserif",0,12));
label2.setText("FaturaID:");
label2.setVisible(true);
label23 = new JLabel();
label23.setBounds(413,151,200,50);
label23.setBackground(new Color(214,217,223));
label23.setForeground(new Color(0,0,0));
label23.setEnabled(true);
label23.setFont(new Font("SansSerif",0,20));
label23.setText("Produtos Adiconados");
label23.setVisible(true);
label3 = new JLabel();
label3.setBounds(123,151,90,35);
label3.setBackground(new Color(214,217,223));
label3.setForeground(new Color(0,0,0));
label3.setEnabled(true);
label3.setFont(new Font("sansserif",0,12));
label3.setText("Data:");
label3.setVisible(true);
label4 = new JLabel();
label4.setBounds(46,176,150,35);
label4.setBackground(new Color(214,217,223));
label4.setForeground(new Color(0,0,0));
label4.setEnabled(true);
label4.setFont(new Font("sansserif",0,12));
label4.setText("Nome da Empresa:");
label4.setVisible(true);
label5 = new JLabel();
label5.setBounds(38,200,150,35);
label5.setBackground(new Color(214,217,223));
label5.setForeground(new Color(0,0,0));
label5.setEnabled(true);
label5.setFont(new Font("sansserif",0,12));
label5.setText("Atividade Economica:");
label5.setVisible(true);
label6 = new JLabel();
label6.setBounds(39,225,150,35);
label6.setBackground(new Color(214,217,223));
label6.setForeground(new Color(0,0,0));
label6.setEnabled(true);
label6.setFont(new Font("sansserif",0,12));
label6.setText("Morada da Empresa:");
label6.setVisible(true);
label7 = new JLabel();
label7.setBounds(46,250,150,35);
label7.setBackground(new Color(214,217,223));
label7.setForeground(new Color(0,0,0));
label7.setEnabled(true);
label7.setFont(new Font("sansserif",0,12));
label7.setText("Email Da Empresa:");
label7.setVisible(true);
label8 = new JLabel();
label8.setBounds(65,274,150,35);
label8.setBackground(new Color(214,217,223));
label8.setForeground(new Color(0,0,0));
label8.setEnabled(true);
label8.setFont(new Font("sansserif",0,12));
label8.setText("Nif da Empresa:");
label8.setVisible(true);
label9 = new JLabel();
label9.setBounds(71,333,90,35);
label9.setBackground(new Color(214,217,223));
label9.setForeground(new Color(0,0,0));
label9.setEnabled(true);
label9.setFont(new Font("sansserif",0,12));
label9.setText("Nome Cliente:");
label9.setVisible(true);
String[][] tprodutos = new String[produtos.size()][3];
int i = 0;
for(Triple a : produtos){
tprodutos[i][0] = a.getproduto();
tprodutos[i][1] = Integer.toString(a.getquantidade());
tprodutos[i][2] = Double.toString(a.getprecounitario());
i++;
}
table = new JTable(dtm);
table.setBackground(new Color(255,255,255));
table.setForeground(new Color(0,0,0));
table.setEnabled(true);
table.setFont(new Font("sansserif",0,12));
table.setVisible(true);
table.getTableHeader().setReorderingAllowed(false);
JScrollPane scrollProdutos = new JScrollPane();
scrollProdutos.setViewportView(table);
scrollProdutos.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollProdutos.setBounds(379,197,264,196);
textfield2 = new JTextField();
textfield2.setBounds(167,117,150,35);
textfield2.setBackground(new Color(255,255,255));
textfield2.setForeground(new Color(0,0,0));
textfield2.setEnabled(true);
textfield2.setFont(new Font("sansserif",0,12));
textfield2.setText("");
textfield2.setVisible(true);
textfield2.setEditable(false);
//Set action for key events
//Call defined method
textfield2.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent evt){
onKeyReleasedFaturaID(evt);
}
});
//adding components to contentPane panel
contentPane.add(AdicionarButton);
contentPane.add(CriarFacturaButton);
contentPane.add(TextAtividadeEco);
contentPane.add(TextData);
contentPane.add(TextEmailEmpresa);
contentPane.add(TextFEmailCliente);
contentPane.add(TextFMoradaCliente);
contentPane.add(TextFNifCliente);
contentPane.add(TextFNomeCliente);
contentPane.add(TextFPreco);
contentPane.add(TextFProduto);
contentPane.add(TextFQuantidade);
contentPane.add(TextMoradaEmpresa);
contentPane.add(TextNifEmpresa);
contentPane.add(TextNomeEmpresa);
contentPane.add(label1);
contentPane.add(label10);
contentPane.add(label11);
contentPane.add(label12);
contentPane.add(label13);
contentPane.add(label14);
contentPane.add(label15);
contentPane.add(label16);
contentPane.add(label2);
contentPane.add(label23);
contentPane.add(label3);
contentPane.add(label4);
contentPane.add(label5);
contentPane.add(label6);
contentPane.add(label7);
contentPane.add(label8);
contentPane.add(label9);
contentPane.add(scrollProdutos);
contentPane.add(textfield2);
contentPane.add(removerbotao);
contentPane.add(testanifButton);
//adding panel to JFrame and seting of window position and close operation
this.add(contentPane);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
this.pack();
this.setVisible(true);
Container c = getContentPane();
JScrollPane scroll = new JScrollPane( c );
setContentPane( scroll );
}
/** Metodo que transforma um LocalDate numa string.
* @return um LocalDate em forma de string
*/
public String getdatastring(){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/LLLL/yyyy");
String formattedString = LocalDate.now().format(formatter);
return formattedString;
}
/** Metodo que testa se é possivel criar fatura num determinado nif.
* @param evt Click do rato.
*/
private void OnTestaNif(MouseEvent evt){
if(!nifCliente.matches("[0-9]+") || nifCliente == "" || nifCliente.length()>9 ){
JOptionPane.showMessageDialog(null,"Nif de Cliente Invalido.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
int nif = Integer.parseInt(nifCliente);
if(nif==ficha.getnif()){
JOptionPane.showMessageDialog(null,"Impossivel Criar faturas em nome proprio!", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
if(gestorfichas.existeFicha(nif)){
fichaAssociada = gestorfichas.getFicha(nif);
nomeCliente=fichaAssociada.getNome();
emailCliente = fichaAssociada.getEmail();
moradaCliente = fichaAssociada.getMorada();
TextFNomeCliente.setText(nomeCliente);
TextFMoradaCliente.setText(moradaCliente);
TextFEmailCliente.setText(emailCliente);
textfield2.setText(Integer.toString(gestorfaturas.getkey()));
CriarFacturaButton.setEnabled(true);
}
else{
JOptionPane.showMessageDialog(null,"Nif de Cliente Nao Registado!", "Message", JOptionPane.ERROR_MESSAGE);
}
}
/** Metodo para adicionar um produto.
* @param evt Click do rato.
*/
private void OnProdutoAddedd (MouseEvent evt) {
if(produto == ""){
JOptionPane.showMessageDialog(null,"Produto Invalido.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
if(!quantidade.matches("[0-9]+") || quantidade == ""){
JOptionPane.showMessageDialog(null,"Quantidade Invalida.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
if(!preco.matches("\\d*\\.?\\d*") || preco == ""){
JOptionPane.showMessageDialog(null,"Preco Invalido.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
Triple h = new Triple (produto,Integer.parseInt(quantidade),Double.parseDouble(preco));
produtos.add(h);
dtm.addRow(new String[3]);
table.setValueAt(produto,table.getRowCount()-1,0);
table.setValueAt(quantidade,table.getRowCount()-1,1);
table.setValueAt(preco,table.getRowCount()-1,2);
produto = "";
quantidade ="";
preco = "";
TextFProduto.setText("");
TextFQuantidade.setText("");
TextFPreco.setText("");
}
/** Metodo para remover um produto.
* @param evt Click do rato.
*/
private void OnProdutoRemoved (MouseEvent evt) {
int row = table.getSelectedRow();
String auxproduto = table.getModel().getValueAt(row, 0).toString();
int auxquantidade = Integer.parseInt(table.getModel().getValueAt(row, 1).toString());
double auxpreco = Double.parseDouble(table.getModel().getValueAt(row, 2).toString());
Triple h = new Triple (auxproduto,auxquantidade,auxpreco);
produtos.remove(h);
dtm.removeRow(row);
}
/** Metodo que cria uma fatura.
* @param evt Evento da ação.
*/
private void OnClickedCriarFatura (ActionEvent evt) {
if(!nifCliente.matches("[0-9]+")){
JOptionPane.showMessageDialog(null,"Nif de Cliente Invalido.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
if(table.getRowCount()<1){
JOptionPane.showMessageDialog(null,"Nenhum produto adiconado.", "Message", JOptionPane.ERROR_MESSAGE);
return;
}
EntidadeEmpresas fichaE = (EntidadeEmpresas) ficha;
Fatura c = new Fatura (ficha.getNome(), ficha.getMorada(), ficha.getEmail(),ficha.getnif(), produtos,fichaE.getActividadeEconomica(), nomeCliente, moradaCliente, emailCliente, Integer.parseInt(nifCliente), ficha.getimposto(),fichaE.getregiao(),fichaAssociada);
gestorfaturas.addnewFaturas(c);
fichaAssociada.adicionaDinheiroGasto(c.getvalortotal());
gestorfichas.addFicha(fichaAssociada);
fichaE.valorFaturacao(c.getvalortotal());
fichaE.adicionafatura();
fichaE.adicionadeducaofat(c.getdeducaofat());
gestorfichas.addFicha(ficha);
DecimalFormat df = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null,"Fatura criada com sucesso!", "Message" , JOptionPane.INFORMATION_MESSAGE);
Botao botao = new Botao(Integer.toString(c.getfaturaID())+" "+c.getnomeEmpresa(),c,ficha,guificha);
guificha.getlistModel().addElement(botao);
guificha.getDeducaoqueficienteFiscalText().setText(df.format(fichaE.getdeducaofaturacao())+"€");
guificha.getfaturacaototaltext2().setText(df.format(fichaE.getFaturacao())+"€");
dispose();
}
/** Metodo que define o email do Cliente.
* @param evt Evento da ação.
*/
private void onKeyReleasedEmailCliente (KeyEvent evt) {
emailCliente = TextFEmailCliente.getText();
}
/** Metodo que define a morada do Cliente.
* @param evt Evento da ação.
*/
private void onKeyReleasedMoradaCliente (KeyEvent evt) {
moradaCliente = TextFMoradaCliente.getText();
}
/** Metodo que define a nif do Cliente.
* @param evt Evento da ação.
*/
private void onKeyReleasedNifCliente (KeyEvent evt) {
nifCliente = TextFNifCliente.getText();
nomeCliente="";
emailCliente = "";
moradaCliente = "";
TextFNomeCliente.setText("");
TextFMoradaCliente.setText("");
TextFEmailCliente.setText("");
CriarFacturaButton.setEnabled(false);
}
/** Metodo que define o nome do Cliente.
* @param evt Evento da ação.
*/
private void onKeyReleasedNomeCliente (KeyEvent evt) {
nomeCliente = TextFNomeCliente.getText();
}
/** Metodo que define o preco do produto.
* @param evt Evento da ação.
*/
private void onKeyReleasedPreco (KeyEvent evt) {
preco = TextFPreco.getText();
}
/** Metodo que define o nome do produto.
* @param evt Evento da ação.
*/
private void onKeyReleasedProduto (KeyEvent evt) {
produto = TextFProduto.getText();
}
/** Metodo que define a quantidade do produto.
* @param evt Evento da ação.
*/
private void onKeyReleasedQuantidade (KeyEvent evt) {
quantidade = TextFQuantidade.getText();
}
/** Metodo que define o ID da fatura.
* @param evt Evento da ação.
*/
private void onKeyReleasedFaturaID (KeyEvent evt) {
faturaID = textfield2.getText();
}
/** Metodo que cria uma ToolBar.
*/
public void generateMenu(){
menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenu tools = new JMenu("Tools");
JMenu help = new JMenu("Help");
JMenuItem open = new JMenuItem("Open ");
JMenuItem save = new JMenuItem("Save ");
JMenuItem exit = new JMenuItem("Exit ");
JMenuItem preferences = new JMenuItem("Preferences ");
JMenuItem about = new JMenuItem("About ");
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
tools.add(preferences);
help.add(about);
menuBar.add(file);
menuBar.add(tools);
menuBar.add(help);
}
public static void main(String[] args){
System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new GUI_CriaFatura(null,null,null,null);
}
});
}
}