76 |
ilm |
1 |
/*
|
|
|
2 |
* Créé le 1 juin 2012
|
|
|
3 |
*/
|
|
|
4 |
package org.openconcerto.modules.subscription.element;
|
|
|
5 |
|
|
|
6 |
import java.awt.Component;
|
|
|
7 |
import java.awt.GridBagConstraints;
|
|
|
8 |
import java.awt.GridBagLayout;
|
|
|
9 |
import java.awt.event.ActionEvent;
|
|
|
10 |
import java.awt.event.ActionListener;
|
96 |
ilm |
11 |
import java.sql.SQLException;
|
|
|
12 |
import java.util.Date;
|
76 |
ilm |
13 |
|
|
|
14 |
import javax.swing.JCheckBox;
|
|
|
15 |
import javax.swing.JComponent;
|
|
|
16 |
import javax.swing.JLabel;
|
|
|
17 |
import javax.swing.JPanel;
|
|
|
18 |
import javax.swing.JTabbedPane;
|
|
|
19 |
import javax.swing.JTextField;
|
|
|
20 |
import javax.swing.SwingConstants;
|
|
|
21 |
|
96 |
ilm |
22 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
|
76 |
ilm |
23 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
24 |
import org.openconcerto.sql.element.SQLElement;
|
96 |
ilm |
25 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
26 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
27 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
28 |
import org.openconcerto.sql.model.SQLTable;
|
76 |
ilm |
29 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
96 |
ilm |
30 |
import org.openconcerto.sql.sqlobject.JUniqueTextField;
|
76 |
ilm |
31 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
32 |
import org.openconcerto.ui.JDate;
|
|
|
33 |
import org.openconcerto.ui.component.ITextArea;
|
|
|
34 |
|
|
|
35 |
public class SubscriptionSQLComponent extends BaseSQLComponent {
|
|
|
36 |
|
|
|
37 |
private static final long serialVersionUID = 4274010869219769289L;
|
96 |
ilm |
38 |
private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
|
76 |
ilm |
39 |
|
96 |
ilm |
40 |
final JLabel labelNumero = new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT);
|
|
|
41 |
final JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
|
|
|
42 |
final JDate date = new JDate(true);
|
|
|
43 |
final JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT);
|
|
|
44 |
final ElementComboBox client = new ElementComboBox();
|
|
|
45 |
|
76 |
ilm |
46 |
public SubscriptionSQLComponent(SQLElement element) {
|
|
|
47 |
super(element);
|
|
|
48 |
}
|
|
|
49 |
|
96 |
ilm |
50 |
public void setLightUI(boolean b) {
|
|
|
51 |
labelClient.setVisible(b);
|
|
|
52 |
labelNumero.setVisible(b);
|
|
|
53 |
labelDate.setVisible(b);
|
|
|
54 |
textNumero.setVisible(b);
|
|
|
55 |
date.setVisible(b);
|
|
|
56 |
client.setVisible(b);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
final JUniqueTextField textNumero = new JUniqueTextField(8);
|
|
|
60 |
|
76 |
ilm |
61 |
@Override
|
|
|
62 |
public void addViews() {
|
|
|
63 |
|
|
|
64 |
this.setLayout(new GridBagLayout());
|
|
|
65 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
66 |
// Numéro
|
|
|
67 |
c.weightx = 0;
|
96 |
ilm |
68 |
|
|
|
69 |
this.add(labelNumero, c);
|
76 |
ilm |
70 |
c.gridx++;
|
|
|
71 |
c.weightx = 1;
|
|
|
72 |
this.add(textNumero, c);
|
96 |
ilm |
73 |
|
76 |
ilm |
74 |
// Date
|
|
|
75 |
c.gridx++;
|
|
|
76 |
c.weightx = 0;
|
96 |
ilm |
77 |
this.add(labelDate, c);
|
76 |
ilm |
78 |
c.gridx++;
|
|
|
79 |
c.weightx = 1;
|
96 |
ilm |
80 |
|
76 |
ilm |
81 |
this.add(date, c);
|
|
|
82 |
// Libellé
|
|
|
83 |
c.gridy++;
|
|
|
84 |
c.gridx = 0;
|
|
|
85 |
c.weightx = 0;
|
|
|
86 |
this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
|
|
|
87 |
c.gridx++;
|
|
|
88 |
c.weightx = 1;
|
|
|
89 |
c.gridwidth = 3;
|
|
|
90 |
final JTextField textNom = new JTextField();
|
|
|
91 |
this.add(textNom, c);
|
|
|
92 |
|
|
|
93 |
// Libellé
|
|
|
94 |
c.gridy++;
|
|
|
95 |
c.gridx = 0;
|
|
|
96 |
c.weightx = 0;
|
|
|
97 |
c.gridwidth = 1;
|
|
|
98 |
this.add(new JLabel(getLabelFor("INTITULE_FACTURE"), SwingConstants.RIGHT), c);
|
|
|
99 |
c.gridx++;
|
|
|
100 |
c.weightx = 1;
|
|
|
101 |
c.gridwidth = 3;
|
|
|
102 |
final JTextField intitule = new JTextField();
|
|
|
103 |
this.add(intitule, c);
|
|
|
104 |
this.addView(intitule, "INTITULE_FACTURE");
|
|
|
105 |
|
|
|
106 |
// Description
|
|
|
107 |
c.gridwidth = 1;
|
|
|
108 |
c.gridy++;
|
|
|
109 |
c.gridx = 0;
|
|
|
110 |
c.weightx = 0;
|
|
|
111 |
this.add(new JLabel(getLabelFor("DESCRIPTION"), SwingConstants.RIGHT), c);
|
|
|
112 |
c.gridx++;
|
|
|
113 |
c.weightx = 1;
|
|
|
114 |
c.gridwidth = 3;
|
|
|
115 |
final ITextArea textDescription = new ITextArea();
|
|
|
116 |
this.add(textDescription, c);
|
|
|
117 |
|
|
|
118 |
// Client
|
|
|
119 |
c.gridwidth = 1;
|
|
|
120 |
c.gridy++;
|
|
|
121 |
c.gridx = 0;
|
|
|
122 |
c.weightx = 0;
|
96 |
ilm |
123 |
this.add(labelClient, c);
|
76 |
ilm |
124 |
c.gridx++;
|
|
|
125 |
c.weightx = 1;
|
|
|
126 |
c.gridwidth = 3;
|
96 |
ilm |
127 |
|
76 |
ilm |
128 |
this.add(client, c);
|
|
|
129 |
|
|
|
130 |
//
|
|
|
131 |
c.gridwidth = 4;
|
|
|
132 |
c.gridx = 0;
|
|
|
133 |
c.gridy++;
|
|
|
134 |
|
|
|
135 |
c.weightx = 1;
|
|
|
136 |
c.weighty = 1;
|
|
|
137 |
|
|
|
138 |
final JTabbedPane tabbedPane = new JTabbedPane();
|
|
|
139 |
tabbedPane.add("Facture", createTypeAboComponent("FACTURE", "ID_SAISIE_VENTE_FACTURE"));
|
|
|
140 |
tabbedPane.add("Devis", createTypeAboComponent("DEVIS", "ID_DEVIS"));
|
|
|
141 |
tabbedPane.add("Bon de commande", createTypeAboComponent("COMMANDE", "ID_COMMANDE_CLIENT"));
|
|
|
142 |
|
|
|
143 |
this.add(tabbedPane, c);
|
|
|
144 |
|
|
|
145 |
this.addView(textNumero, "NUMERO", REQ);
|
|
|
146 |
this.addView(date, "DATE");
|
|
|
147 |
this.addView(textNom, "NOM");
|
|
|
148 |
this.addView(textDescription, "DESCRIPTION");
|
|
|
149 |
this.addView(client, "ID_CLIENT");
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
private Component createTypeAboComponent(String type, String idName) {
|
|
|
154 |
final String fieldCreate = "CREATE_" + type;
|
|
|
155 |
final String fieldStart = "DATE_DEBUT_" + type;
|
|
|
156 |
final String fieldStop = "DATE_FIN_" + type;
|
|
|
157 |
final String fieldPeriodicity = "NB_MOIS_" + type;
|
|
|
158 |
|
|
|
159 |
final JPanel panel = new JPanel();
|
|
|
160 |
panel.setOpaque(false);
|
|
|
161 |
|
|
|
162 |
panel.setLayout(new GridBagLayout());
|
|
|
163 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
164 |
|
|
|
165 |
// Checkbox
|
|
|
166 |
c.gridx = 1;
|
|
|
167 |
c.weightx = 1;
|
|
|
168 |
final JCheckBox check = new JCheckBox(getLabelFor(fieldCreate));
|
|
|
169 |
check.setOpaque(false);
|
|
|
170 |
panel.add(check, c);
|
|
|
171 |
|
|
|
172 |
// Item
|
|
|
173 |
c.gridx = 0;
|
|
|
174 |
c.gridy++;
|
|
|
175 |
c.weightx = 0;
|
|
|
176 |
panel.add(new JLabel(getLabelFor(idName), SwingConstants.RIGHT), c);
|
|
|
177 |
c.gridx++;
|
|
|
178 |
c.weightx = 1;
|
|
|
179 |
final ElementComboBox item = new ElementComboBox();
|
|
|
180 |
panel.add(item, c);
|
|
|
181 |
|
|
|
182 |
// Start
|
|
|
183 |
c.gridx = 0;
|
|
|
184 |
c.gridy++;
|
|
|
185 |
c.weightx = 0;
|
|
|
186 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
187 |
panel.add(new JLabel(getLabelFor(fieldStart), SwingConstants.RIGHT), c);
|
|
|
188 |
c.gridx++;
|
|
|
189 |
c.weightx = 1;
|
|
|
190 |
c.fill = GridBagConstraints.NONE;
|
|
|
191 |
final JDate startDate = new JDate(true);
|
|
|
192 |
panel.add(startDate, c);
|
|
|
193 |
|
|
|
194 |
// Stop
|
|
|
195 |
c.gridx = 0;
|
|
|
196 |
c.gridy++;
|
|
|
197 |
c.weightx = 0;
|
|
|
198 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
199 |
panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
|
|
|
200 |
c.gridx++;
|
|
|
201 |
c.weightx = 1;
|
96 |
ilm |
202 |
final JDate stopDate = new JDate();
|
76 |
ilm |
203 |
c.fill = GridBagConstraints.NONE;
|
|
|
204 |
panel.add(stopDate, c);
|
|
|
205 |
|
|
|
206 |
// Periodicity
|
|
|
207 |
c.gridx = 0;
|
|
|
208 |
c.gridy++;
|
|
|
209 |
c.weightx = 0;
|
|
|
210 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
211 |
panel.add(new JLabel(getLabelFor(fieldPeriodicity), SwingConstants.RIGHT), c);
|
|
|
212 |
c.gridx++;
|
|
|
213 |
c.weightx = 1;
|
|
|
214 |
c.fill = GridBagConstraints.NONE;
|
|
|
215 |
final JTextField textPeriod = new JTextField(5);
|
|
|
216 |
panel.add(textPeriod, c);
|
|
|
217 |
|
|
|
218 |
check.addActionListener(new ActionListener() {
|
|
|
219 |
|
|
|
220 |
@Override
|
|
|
221 |
public void actionPerformed(ActionEvent e) {
|
|
|
222 |
setFieldEnabled(item, startDate, stopDate, textPeriod, check.isSelected());
|
|
|
223 |
}
|
|
|
224 |
});
|
|
|
225 |
|
|
|
226 |
this.addView(check, fieldCreate);
|
|
|
227 |
this.addView(item, idName);
|
|
|
228 |
this.addView(startDate, fieldStart);
|
|
|
229 |
this.addView(stopDate, fieldStop);
|
|
|
230 |
this.addView(textPeriod, fieldPeriodicity);
|
|
|
231 |
|
|
|
232 |
setFieldEnabled(item, startDate, stopDate, textPeriod, false);
|
|
|
233 |
return panel;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
|
|
|
237 |
item.setEnabled(b);
|
|
|
238 |
startDate.setEnabled(b);
|
|
|
239 |
stopDate.setEnabled(b);
|
|
|
240 |
textPeriod.setEnabled(b);
|
|
|
241 |
}
|
96 |
ilm |
242 |
|
|
|
243 |
@Override
|
|
|
244 |
protected SQLRowValues createDefaults() {
|
|
|
245 |
SQLRowValues vals = new SQLRowValues(getTable());
|
|
|
246 |
vals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(this.getElement().getClass(), new Date()));
|
|
|
247 |
return vals;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
@Override
|
|
|
251 |
public void select(SQLRowAccessor r) {
|
|
|
252 |
super.select(r);
|
|
|
253 |
if (r != null) {
|
|
|
254 |
this.textNumero.setIdSelected(r.getID());
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
@Override
|
|
|
259 |
public int insert(SQLRow order) {
|
|
|
260 |
int id = super.insert(order);
|
|
|
261 |
// incrémentation du numéro auto
|
169 |
ilm |
262 |
if (NumerotationAutoSQLElement.getNextNumero(SubscriptionSQLElement.class).equalsIgnoreCase(this.textNumero.getText().trim())) {
|
96 |
ilm |
263 |
final SQLRowValues rowVals = new SQLRowValues(this.tableNum);
|
169 |
ilm |
264 |
int val = this.tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(SubscriptionSQLElement.class));
|
96 |
ilm |
265 |
val++;
|
169 |
ilm |
266 |
rowVals.put(NumerotationAutoSQLElement.getLabelNumberFor(SubscriptionSQLElement.class), val);
|
96 |
ilm |
267 |
try {
|
|
|
268 |
rowVals.update(2);
|
|
|
269 |
} catch (final SQLException e) {
|
|
|
270 |
e.printStackTrace();
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
return id;
|
|
|
274 |
}
|
|
|
275 |
|
76 |
ilm |
276 |
}
|