-
Notifications
You must be signed in to change notification settings - Fork 0
/
donAjout.java
175 lines (145 loc) · 5.29 KB
/
donAjout.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import com.codename1.components.InfiniteProgress;
import com.codename1.io.MultipartRequest;
import com.codename1.io.NetworkManager;
import com.codename1.ui.Button;
import com.codename1.ui.ComboBox;
import com.codename1.ui.Dialog;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.TextArea;
import com.codename1.ui.TextField;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.list.DefaultListModel;
import com.codename1.ui.validation.LengthConstraint;
import com.codename1.ui.validation.NumericConstraint;
import com.codename1.ui.validation.Validator;
import entity.don;
import java.io.IOException;
import services.ServiceDon;
//import gui.SendSMS;
/**
*
* @author Nesrine
*/
public class donAjout {
TextField tfNom ;
TextField tfPrenom ;
TextField tfEmail ;
TextField tfDescription;
TextField tfObjet;
// ComboBox<String> tfObjet;
Button btnajout ;
Form f;
Dialog dd ;
public donAjout() {
f = new Form("home", BoxLayout.y());
tfNom = new TextField("","nom");
tfPrenom = new TextField("","prenom");
tfEmail = new TextField("","email");
tfObjet = new TextField("","objet");
tfDescription = new TextField("","description");
f.getToolbar().addCommandToRightBar("back", null, (et) -> {
donAjout h = new donAjout();
h.getF().show();
});
btnajout = new Button("Ajouter");
f.add(tfNom);
f.add(tfPrenom);
f.add(tfEmail);
f.add(tfDescription);
f.add(tfObjet);
f.add(btnajout);
btnajout.addActionListener((ActionEvent e) -> {
ServiceDon ser = new ServiceDon();
don et = new don(tfNom.getText(),tfPrenom.getText(),tfEmail.getText(),
tfObjet.getText(),tfDescription.getText());
if(validation( et)){
ser.addDon(et);
Dialog d = new Dialog("Succes!");
TextArea popupBody = new TextArea("don Ajouter avec succes", 3, 10);
popupBody.setUIID("PopupBody");
popupBody.setEditable(false);
Button ok = new Button("OK");
ok.addActionListener((ActionEvent ee) -> {
donAjout a = null;
a = new donAjout();
System.out.println("erreuur");
a.getF().show();
});
d.setLayout(new BorderLayout());
d.addComponent(BorderLayout.SOUTH, ok);
d.add(BorderLayout.CENTER, popupBody);
d.show();
}
});
}
public Form getF() {
return f;
}
public void setF(Form f) {
this.f = f;
}
public boolean validation(don e){
boolean a = false ;
ServiceDon es = new ServiceDon();
if(!e.getNom().equals("")){
for (don ev : es.getAllDons()) {
if(e.getNom().equals(ev.getNom())){
dd = new Dialog("Erreur");
TextArea popupBody = new TextArea("Le Nom existe deja !", 3, 10);
popupBody.setUIID("PopupBody");
popupBody.setEditable(false);
Button close = new Button("OK");
close.addActionListener((ActionEvent ee) -> {
dd.dispose();
});
dd.setLayout(new BorderLayout());
dd.add( BorderLayout.SOUTH,close);
dd.add(BorderLayout.CENTER, popupBody);
dd.show();
return false ;
}
}
}else {
dd = new Dialog("Erreur");
TextArea popupBody = new TextArea("Nom ne peut pas etre null !", 3, 10);
popupBody.setUIID("PopupBody");
popupBody.setEditable(false);
Button close = new Button("OK");
close.addActionListener((ActionEvent ee) -> {
dd.dispose();
});
dd.setLayout(new BorderLayout());
dd.add( BorderLayout.SOUTH,close);
dd.add(BorderLayout.CENTER, popupBody);
dd.show();
return false ;
}
if(e.getDescription().equals("") ){
dd = new Dialog("Erreur");
TextArea popupBody = new TextArea("Description ne peut pas etre null !", 3, 10);
popupBody.setUIID("PopupBody");
popupBody.setEditable(false);
Button close = new Button("OK");
close.addActionListener((ActionEvent ee) -> {
dd.dispose();
});
dd.setLayout(new BorderLayout());
dd.add( BorderLayout.SOUTH,close);
dd.add(BorderLayout.CENTER, popupBody);
dd.show();
return false ;
}
return true ;
}
}