OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 76 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 76 Rev 96
Line 6... Line 6...
6
import java.awt.Component;
6
import java.awt.Component;
7
import java.awt.GridBagConstraints;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
8
import java.awt.GridBagLayout;
9
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
10
import java.awt.event.ActionListener;
-
 
11
import java.sql.SQLException;
-
 
12
import java.util.Date;
11
 
13
 
12
import javax.swing.JCheckBox;
14
import javax.swing.JCheckBox;
13
import javax.swing.JComponent;
15
import javax.swing.JComponent;
14
import javax.swing.JLabel;
16
import javax.swing.JLabel;
15
import javax.swing.JPanel;
17
import javax.swing.JPanel;
16
import javax.swing.JTabbedPane;
18
import javax.swing.JTabbedPane;
17
import javax.swing.JTextField;
19
import javax.swing.JTextField;
18
import javax.swing.SwingConstants;
20
import javax.swing.SwingConstants;
19
 
21
 
-
 
22
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
-
 
23
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
20
import org.openconcerto.sql.element.BaseSQLComponent;
24
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
-
 
26
import org.openconcerto.sql.model.SQLRow;
-
 
27
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
28
import org.openconcerto.sql.model.SQLRowValues;
-
 
29
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.sqlobject.ElementComboBox;
30
import org.openconcerto.sql.sqlobject.ElementComboBox;
-
 
31
import org.openconcerto.sql.sqlobject.JUniqueTextField;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.JDate;
33
import org.openconcerto.ui.JDate;
25
import org.openconcerto.ui.component.ITextArea;
34
import org.openconcerto.ui.component.ITextArea;
26
 
35
 
27
public class SubscriptionSQLComponent extends BaseSQLComponent {
36
public class SubscriptionSQLComponent extends BaseSQLComponent {
28
 
37
 
29
    private static final long serialVersionUID = 4274010869219769289L;
38
    private static final long serialVersionUID = 4274010869219769289L;
-
 
39
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
-
 
40
 
-
 
41
    final JLabel labelNumero = new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT);
-
 
42
    final JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
-
 
43
    final JDate date = new JDate(true);
-
 
44
    final JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT);
-
 
45
    final ElementComboBox client = new ElementComboBox();
30
 
46
 
31
    public SubscriptionSQLComponent(SQLElement element) {
47
    public SubscriptionSQLComponent(SQLElement element) {
32
        super(element);
48
        super(element);
33
    }
49
    }
34
 
50
 
-
 
51
    public void setLightUI(boolean b) {
-
 
52
        labelClient.setVisible(b);
-
 
53
        labelNumero.setVisible(b);
-
 
54
        labelDate.setVisible(b);
-
 
55
        textNumero.setVisible(b);
-
 
56
 
-
 
57
        date.setVisible(b);
-
 
58
        client.setVisible(b);
-
 
59
    }
-
 
60
 
-
 
61
    final JUniqueTextField textNumero = new JUniqueTextField(8);
-
 
62
 
35
    @Override
63
    @Override
36
    public void addViews() {
64
    public void addViews() {
37
 
65
 
38
        this.setLayout(new GridBagLayout());
66
        this.setLayout(new GridBagLayout());
39
        final GridBagConstraints c = new DefaultGridBagConstraints();
67
        final GridBagConstraints c = new DefaultGridBagConstraints();
40
        // Numéro
68
        // Numéro
41
        c.weightx = 0;
69
        c.weightx = 0;
-
 
70
 
42
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
71
        this.add(labelNumero, c);
43
        c.gridx++;
72
        c.gridx++;
44
        c.weightx = 1;
73
        c.weightx = 1;
45
        final JTextField textNumero = new JTextField(8);
-
 
46
        this.add(textNumero, c);
74
        this.add(textNumero, c);
-
 
75
 
47
        // Date
76
        // Date
48
        c.gridx++;
77
        c.gridx++;
49
        c.weightx = 0;
78
        c.weightx = 0;
50
        this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c);
79
        this.add(labelDate, c);
51
        c.gridx++;
80
        c.gridx++;
52
        c.weightx = 1;
81
        c.weightx = 1;
53
        final JDate date = new JDate(true);
-
 
-
 
82
 
54
        this.add(date, c);
83
        this.add(date, c);
55
        // Libellé
84
        // Libellé
56
        c.gridy++;
85
        c.gridy++;
57
        c.gridx = 0;
86
        c.gridx = 0;
58
        c.weightx = 0;
87
        c.weightx = 0;
Line 91... Line 120...
91
        // Client
120
        // Client
92
        c.gridwidth = 1;
121
        c.gridwidth = 1;
93
        c.gridy++;
122
        c.gridy++;
94
        c.gridx = 0;
123
        c.gridx = 0;
95
        c.weightx = 0;
124
        c.weightx = 0;
96
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
125
        this.add(labelClient, c);
97
        c.gridx++;
126
        c.gridx++;
98
        c.weightx = 1;
127
        c.weightx = 1;
99
        c.gridwidth = 3;
128
        c.gridwidth = 3;
100
        final ElementComboBox client = new ElementComboBox();
-
 
-
 
129
 
101
        this.add(client, c);
130
        this.add(client, c);
102
 
131
 
103
        //
132
        //
104
        c.gridwidth = 4;
133
        c.gridwidth = 4;
105
        c.gridx = 0;
134
        c.gridx = 0;
Line 176... Line 205...
176
        c.weightx = 0;
205
        c.weightx = 0;
177
        c.fill = GridBagConstraints.HORIZONTAL;
206
        c.fill = GridBagConstraints.HORIZONTAL;
178
        panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
207
        panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
179
        c.gridx++;
208
        c.gridx++;
180
        c.weightx = 1;
209
        c.weightx = 1;
181
        final JDate stopDate = new JDate(true);
210
        final JDate stopDate = new JDate();
182
        c.fill = GridBagConstraints.NONE;
211
        c.fill = GridBagConstraints.NONE;
183
        panel.add(stopDate, c);
212
        panel.add(stopDate, c);
184
 
213
 
185
        // Periodicity
214
        // Periodicity
186
        c.gridx = 0;
215
        c.gridx = 0;
Line 218... Line 247...
218
    // return super.createDefaults();
247
    // return super.createDefaults();
219
    // }
248
    // }
220
 
249
 
221
    public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
250
    public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
222
        System.err.println(b);
251
        System.err.println(b);
223
        Thread.dumpStack();
252
        // Thread.dumpStack();
224
        item.setEnabled(b);
253
        item.setEnabled(b);
225
        startDate.setEnabled(b);
254
        startDate.setEnabled(b);
226
        stopDate.setEnabled(b);
255
        stopDate.setEnabled(b);
227
        textPeriod.setEnabled(b);
256
        textPeriod.setEnabled(b);
228
    }
257
    }
-
 
258
 
-
 
259
    @Override
-
 
260
    protected SQLRowValues createDefaults() {
-
 
261
        SQLRowValues vals = new SQLRowValues(getTable());
-
 
262
        vals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(this.getElement().getClass(), new Date()));
-
 
263
        return vals;
-
 
264
    }
-
 
265
 
-
 
266
    @Override
-
 
267
    public void select(SQLRowAccessor r) {
-
 
268
        // TODO Auto-generated method stub
-
 
269
        super.select(r);
-
 
270
        if (r != null) {
-
 
271
            this.textNumero.setIdSelected(r.getID());
-
 
272
        }
-
 
273
    }
-
 
274
 
-
 
275
    @Override
-
 
276
    public int insert(SQLRow order) {
-
 
277
        // TODO Auto-generated method stub
-
 
278
        int id = super.insert(order);
-
 
279
        // incrémentation du numéro auto
-
 
280
        if (NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class).equalsIgnoreCase(this.textNumero.getText().trim())) {
-
 
281
            final SQLRowValues rowVals = new SQLRowValues(this.tableNum);
-
 
282
            int val = this.tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class));
-
 
283
            val++;
-
 
284
            rowVals.put(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class), new Integer(val));
-
 
285
            try {
-
 
286
                rowVals.update(2);
-
 
287
            } catch (final SQLException e) {
-
 
288
                e.printStackTrace();
-
 
289
            }
-
 
290
        }
-
 
291
        return id;
-
 
292
    }
-
 
293
 
-
 
294
    @Override
-
 
295
    public void update() {
-
 
296
        // TODO Auto-generated method stub
-
 
297
        super.update();
-
 
298
    }
229
}
299
}