OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 177 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.component.AdresseSQLComponent;
16
import org.openconcerto.erp.core.common.component.AdresseSQLComponent;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseClientItemTable;
18
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseClientItemTable;
19
import org.openconcerto.erp.core.sales.product.element.ClientCodeArticleTable;
19
import org.openconcerto.erp.core.sales.product.element.ClientCodeArticleTable;
-
 
20
import org.openconcerto.erp.core.sales.product.ui.CustomerProductQtyPriceListTable;
20
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
21
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
21
import org.openconcerto.erp.utils.TM;
22
import org.openconcerto.erp.utils.TM;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.ElementSQLObject;
24
import org.openconcerto.sql.element.ElementSQLObject;
24
import org.openconcerto.sql.element.GroupSQLComponent;
25
import org.openconcerto.sql.element.GroupSQLComponent;
25
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.UndefinedRowValuesCache;
31
import org.openconcerto.sql.model.UndefinedRowValuesCache;
31
import org.openconcerto.sql.sqlobject.JUniqueTextField;
32
import org.openconcerto.sql.sqlobject.JUniqueTextField;
32
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
33
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
33
import org.openconcerto.sql.ui.textmenu.TextFieldWithMenu;
34
import org.openconcerto.sql.ui.textmenu.TextFieldWithMenu;
34
import org.openconcerto.sql.ui.textmenu.TextFieldWithMenuItemsTableFetcher;
35
import org.openconcerto.sql.ui.textmenu.TextFieldWithMenuItemsTableFetcher;
35
import org.openconcerto.sql.ui.textmenu.TextFieldWithWebBrowsing;
36
import org.openconcerto.sql.ui.textmenu.TextFieldWithWebBrowsing;
36
import org.openconcerto.sql.view.EditFrame;
37
import org.openconcerto.sql.view.EditFrame;
37
import org.openconcerto.sql.view.EditPanel.EditMode;
38
import org.openconcerto.sql.view.EditPanel.EditMode;
38
import org.openconcerto.sql.view.IListFrame;
39
import org.openconcerto.sql.view.IListFrame;
39
import org.openconcerto.sql.view.ListeAddPanel;
40
import org.openconcerto.sql.view.ListeAddPanel;
40
import org.openconcerto.ui.DefaultGridBagConstraints;
41
import org.openconcerto.ui.DefaultGridBagConstraints;
41
import org.openconcerto.ui.FrameUtil;
42
import org.openconcerto.ui.FrameUtil;
42
import org.openconcerto.ui.JDate;
43
import org.openconcerto.ui.JDate;
43
import org.openconcerto.ui.JLabelBold;
44
import org.openconcerto.ui.JLabelBold;
44
import org.openconcerto.ui.component.ComboLockedMode;
45
import org.openconcerto.ui.component.ComboLockedMode;
45
import org.openconcerto.ui.component.ITextArea;
46
import org.openconcerto.ui.component.ITextArea;
46
import org.openconcerto.ui.component.InteractionMode;
47
import org.openconcerto.ui.component.InteractionMode;
47
import org.openconcerto.utils.ExceptionHandler;
48
import org.openconcerto.utils.ExceptionHandler;
48
 
49
 
49
import java.awt.Component;
50
import java.awt.Component;
50
import java.awt.Dimension;
51
import java.awt.Dimension;
51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.GridBagLayout;
53
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
55
import java.awt.event.ActionListener;
55
import java.sql.SQLException;
56
import java.sql.SQLException;
56
import java.util.HashSet;
57
import java.util.HashSet;
57
import java.util.Set;
58
import java.util.Set;
58
 
59
 
59
import javax.swing.AbstractAction;
60
import javax.swing.AbstractAction;
60
import javax.swing.Icon;
61
import javax.swing.Icon;
61
import javax.swing.JCheckBox;
62
import javax.swing.JCheckBox;
62
import javax.swing.JComponent;
63
import javax.swing.JComponent;
63
import javax.swing.JLabel;
64
import javax.swing.JLabel;
64
import javax.swing.JOptionPane;
65
import javax.swing.JOptionPane;
65
import javax.swing.JPanel;
66
import javax.swing.JPanel;
66
import javax.swing.JTabbedPane;
67
import javax.swing.JTabbedPane;
67
import javax.swing.JTextField;
68
import javax.swing.JTextField;
68
import javax.swing.SwingUtilities;
69
import javax.swing.SwingUtilities;
69
import javax.swing.event.DocumentEvent;
70
import javax.swing.event.DocumentEvent;
70
import javax.swing.event.DocumentListener;
71
import javax.swing.event.DocumentListener;
71
 
72
 
72
import com.lowagie.text.Font;
73
import com.lowagie.text.Font;
73
 
74
 
74
public class CustomerSQLComponent extends GroupSQLComponent {
75
public class CustomerSQLComponent extends GroupSQLComponent {
75
    private ContactItemTable table;
76
    private ContactItemTable table;
76
    private ClientCodeArticleTable tableCustomProduct;
77
    private ClientCodeArticleTable tableCustomProduct;
77
    private AdresseClientItemTable adresseTable = new AdresseClientItemTable();
78
    private AdresseClientItemTable adresseTable = new AdresseClientItemTable();
-
 
79
 
78
    private SQLTable contactTable = Configuration.getInstance().getDirectory().getElement("CONTACT").getTable();
80
    private SQLTable contactTable = Configuration.getInstance().getDirectory().getElement("CONTACT").getTable();
79
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
81
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
80
    private final JUniqueTextField code = new JUniqueTextField(20) {
82
    private final JUniqueTextField code = new JUniqueTextField(20) {
81
        @Override
83
        @Override
82
        public String getAutoRefreshNumber() {
84
        public String getAutoRefreshNumber() {
83
            if (getMode() == Mode.INSERTION) {
85
            if (getMode() == Mode.INSERTION) {
84
                return NumerotationAutoSQLElement.getNextNumero(getElement().getClass());
86
                return NumerotationAutoSQLElement.getNextNumero(getElement().getClass());
85
            } else {
87
            } else {
86
                return null;
88
                return null;
87
            }
89
            }
88
        }
90
        }
89
    };
91
    };
90
 
92
 
-
 
93
    private CustomerProductQtyPriceListTable clienTarifTable = new CustomerProductQtyPriceListTable();
91
    private SQLRowValues defaultContactRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(this.contactTable));
94
    private SQLRowValues defaultContactRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(this.contactTable));
92
    private JCheckBox checkAdrLivraison, checkAdrFacturation;
95
    private JCheckBox checkAdrLivraison, checkAdrFacturation;
93
 
96
 
94
    public CustomerSQLComponent(SQLElement element) {
97
    public CustomerSQLComponent(SQLElement element) {
95
        super(element);
98
        super(element);
96
        this.table = new ContactItemTable(this.defaultContactRowVals);
99
        this.table = new ContactItemTable(this.defaultContactRowVals);
97
        this.tableCustomProduct = new ClientCodeArticleTable();
100
        this.tableCustomProduct = new ClientCodeArticleTable();
98
        this.table.setPreferredSize(new Dimension(this.table.getSize().width, 150));
101
        this.table.setPreferredSize(new Dimension(this.table.getSize().width, 150));
99
    }
102
    }
100
 
103
 
101
    @Override
104
    @Override
102
    protected Set<String> createRequiredNames() {
105
    protected Set<String> createRequiredNames() {
103
        final Set<String> s = new HashSet<String>();
106
        final Set<String> s = new HashSet<String>();
104
        s.add("NOM");
107
        s.add("NOM");
105
        s.add("ID_ADRESSE");
108
        s.add("ID_ADRESSE");
106
        s.add("ID_MODE_REGLEMENT");
109
        s.add("ID_MODE_REGLEMENT");
107
        return s;
110
        return s;
108
    }
111
    }
109
 
112
 
110
    @Override
113
    @Override
111
    protected SQLRowValues createDefaults() {
114
    protected SQLRowValues createDefaults() {
112
 
115
 
113
        SQLRowValues rowVals = new SQLRowValues(getTable());
116
        SQLRowValues rowVals = new SQLRowValues(getTable());
114
        rowVals.put("CODE", NumerotationAutoSQLElement.getNextNumero(getElement().getClass()));
117
        rowVals.put("CODE", NumerotationAutoSQLElement.getNextNumero(getElement().getClass()));
115
        // Mode de règlement par defaut
118
        // Mode de règlement par defaut
116
        try {
119
        try {
117
            SQLRow r = ModeReglementDefautPrefPanel.getDefaultRow(true);
120
            SQLRow r = ModeReglementDefautPrefPanel.getDefaultRow(true);
118
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
121
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
119
            if (r.getID() > 1) {
122
            if (r.getID() > 1) {
120
                SQLRowValues rowValsMR = eltModeReglement.createCopy(r, null);
123
                SQLRowValues rowValsMR = eltModeReglement.createCopy(r, null);
121
                rowVals.put("ID_MODE_REGLEMENT", rowValsMR);
124
                rowVals.put("ID_MODE_REGLEMENT", rowValsMR);
122
            }
125
            }
123
        } catch (SQLException e) {
126
        } catch (SQLException e) {
124
            System.err.println("Impossible de sélectionner le mode de règlement par défaut du client.");
127
            System.err.println("Impossible de sélectionner le mode de règlement par défaut du client.");
125
            e.printStackTrace();
128
            e.printStackTrace();
126
        }
129
        }
127
        return rowVals;
130
        return rowVals;
128
    }
131
    }
129
 
132
 
130
    @Override
133
    @Override
131
    public JComponent createEditor(String id) {
134
    public JComponent createEditor(String id) {
132
        if (id.equals("CATEGORIES")) {
135
        if (id.equals("CATEGORIES")) {
133
            TextFieldWithMenuItemsTableFetcher itemsFetcher = new TextFieldWithMenuItemsTableFetcher(getTable().getTable("CATEGORIE_CLIENT").getField("NOM"));
136
            TextFieldWithMenuItemsTableFetcher itemsFetcher = new TextFieldWithMenuItemsTableFetcher(getTable().getTable("CATEGORIE_CLIENT").getField("NOM"));
134
            TextFieldWithMenu t = new TextFieldWithMenu(itemsFetcher, false);
137
            TextFieldWithMenu t = new TextFieldWithMenu(itemsFetcher, false);
135
            t.addAction(new AbstractAction(TM.tr("add")) {
138
            t.addAction(new AbstractAction(TM.tr("add")) {
136
 
139
 
137
                @Override
140
                @Override
138
                public void actionPerformed(ActionEvent e) {
141
                public void actionPerformed(ActionEvent e) {
139
                    EditFrame frame = new EditFrame(getElement().getDirectory().getElement("CATEGORIE_CLIENT"), EditMode.CREATION);
142
                    EditFrame frame = new EditFrame(getElement().getDirectory().getElement("CATEGORIE_CLIENT"), EditMode.CREATION);
140
                    FrameUtil.showPacked(frame);
143
                    FrameUtil.showPacked(frame);
141
 
144
 
142
                }
145
                }
143
            });
146
            });
144
            t.addAction(new AbstractAction(TM.tr("modify.or.delete")) {
147
            t.addAction(new AbstractAction(TM.tr("modify.or.delete")) {
145
 
148
 
146
                @Override
149
                @Override
147
                public void actionPerformed(ActionEvent e) {
150
                public void actionPerformed(ActionEvent e) {
148
                    final SQLElement element = getElement().getDirectory().getElement("CATEGORIE_CLIENT");
151
                    final SQLElement element = getElement().getDirectory().getElement("CATEGORIE_CLIENT");
149
 
152
 
150
                    ListeAddPanel p = new ListeAddPanel(element);
153
                    ListeAddPanel p = new ListeAddPanel(element);
151
                    // EditFrame frame = new EditFrame(element, EditMode.CREATION);
154
                    // EditFrame frame = new EditFrame(element, EditMode.CREATION);
152
                    IListFrame frame = new IListFrame(p);
155
                    IListFrame frame = new IListFrame(p);
153
                    FrameUtil.showPacked(frame);
156
                    FrameUtil.showPacked(frame);
154
 
157
 
155
                }
158
                }
156
            });
159
            });
157
            return t;
160
            return t;
158
        } else if (id.equals("GROUPE") || id.equals("FORME_JURIDIQUE") || id.equals("CENTRE_GESTION") || id.equals("METHODE_RELANCE")) {
161
        } else if (id.equals("GROUPE") || id.equals("FORME_JURIDIQUE") || id.equals("CENTRE_GESTION") || id.equals("METHODE_RELANCE")) {
159
            return new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, 1, 20, false);
162
            return new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, 1, 20, false);
160
        } else if (id.equals("SITE_INTERNET")) {
163
        } else if (id.equals("SITE_INTERNET")) {
161
            return new TextFieldWithWebBrowsing();
164
            return new TextFieldWithWebBrowsing();
162
        } else if (id.equals("SIRET")) {
165
        } else if (id.equals("SIRET")) {
163
            return new JTextField(20);
166
            return new JTextField(20);
164
        } else if (id.equals("DATE")) {
167
        } else if (id.equals("DATE")) {
165
            return new JDate(true);
168
            return new JDate(true);
166
        } else if (id.equals("customerrelationship.customer.contacts")) {
169
        } else if (id.equals("customerrelationship.customer.contacts")) {
167
            return this.table;
170
            return this.table;
168
        } else if (id.equals("customerrelationship.customer.customproduct")) {
171
        } else if (id.equals("customerrelationship.customer.customproduct")) {
169
            return this.tableCustomProduct;
172
            return this.tableCustomProduct;
-
 
173
        } else if (id.equals("customerrelationship.customer.customtarif")) {
-
 
174
            return this.clienTarifTable;
170
        } else if (id.equals("customerrelationship.customer.addresses")) {
175
        } else if (id.equals("customerrelationship.customer.addresses")) {
171
            return createAdressesComponent();
176
            return createAdressesComponent();
172
        } else if (id.equals("NOM")) {
177
        } else if (id.equals("NOM")) {
173
            return super.createEditor(id);
178
            return super.createEditor(id);
174
        }
179
        }
175
        if (id.equals("CODE")) {
180
        if (id.equals("CODE")) {
176
 
181
 
177
            return this.code;
182
            return this.code;
178
        } else if (id.equals("INFOS")) {
183
        } else if (id.equals("INFOS")) {
179
            return new ITextArea(4, 40);
184
            return new ITextArea(4, 40);
180
        } else if (id.equals("COMMENTAIRES")) {
185
        } else if (id.equals("COMMENTAIRES")) {
181
            return new ITextArea(10, 40);
186
            return new ITextArea(10, 40);
182
        } else if (id.equals("TEL")) {
187
        } else if (id.equals("TEL")) {
183
            final JTextField textTel = new JTextField(25);
188
            final JTextField textTel = new JTextField(25);
184
            textTel.getDocument().addDocumentListener(new DocumentListener() {
189
            textTel.getDocument().addDocumentListener(new DocumentListener() {
185
 
190
 
186
                public void changedUpdate(DocumentEvent e) {
191
                public void changedUpdate(DocumentEvent e) {
187
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
192
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
188
                }
193
                }
189
 
194
 
190
                public void insertUpdate(DocumentEvent e) {
195
                public void insertUpdate(DocumentEvent e) {
191
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
196
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
192
                }
197
                }
193
 
198
 
194
                public void removeUpdate(DocumentEvent e) {
199
                public void removeUpdate(DocumentEvent e) {
195
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
200
                    defaultContactRowVals.put("TEL_DIRECT", textTel.getText());
196
                }
201
                }
197
 
202
 
198
            });
203
            });
199
            return textTel;
204
            return textTel;
200
        } else if (id.equals("FAX")) {
205
        } else if (id.equals("FAX")) {
201
            final JTextField textFax = new JTextField(25);
206
            final JTextField textFax = new JTextField(25);
202
            textFax.getDocument().addDocumentListener(new DocumentListener() {
207
            textFax.getDocument().addDocumentListener(new DocumentListener() {
203
 
208
 
204
                public void changedUpdate(DocumentEvent e) {
209
                public void changedUpdate(DocumentEvent e) {
205
                    defaultContactRowVals.put("FAX", textFax.getText());
210
                    defaultContactRowVals.put("FAX", textFax.getText());
206
                }
211
                }
207
 
212
 
208
                public void insertUpdate(DocumentEvent e) {
213
                public void insertUpdate(DocumentEvent e) {
209
                    defaultContactRowVals.put("FAX", textFax.getText());
214
                    defaultContactRowVals.put("FAX", textFax.getText());
210
                }
215
                }
211
 
216
 
212
                public void removeUpdate(DocumentEvent e) {
217
                public void removeUpdate(DocumentEvent e) {
213
                    defaultContactRowVals.put("FAX", textFax.getText());
218
                    defaultContactRowVals.put("FAX", textFax.getText());
214
                }
219
                }
215
 
220
 
216
            });
221
            });
217
            return textFax;
222
            return textFax;
218
        }
223
        }
219
        JComponent c = super.createEditor(id);
224
        JComponent c = super.createEditor(id);
220
        return c;
225
        return c;
221
    }
226
    }
222
 
227
 
223
    @Override
228
    @Override
224
    public JComponent getLabel(String id) {
229
    public JComponent getLabel(String id) {
225
        if (id.equals("ID_MODE_REGLEMENT") || id.equals("INFOS") || id.startsWith("ID_ADRESSE")) {
230
        if (id.equals("ID_MODE_REGLEMENT") || id.equals("INFOS") || id.startsWith("ID_ADRESSE")) {
226
            JLabel l = (JLabel) super.getLabel(id);
231
            JLabel l = (JLabel) super.getLabel(id);
227
            l.setFont(l.getFont().deriveFont(Font.BOLD));
232
            l.setFont(l.getFont().deriveFont(Font.BOLD));
228
            return l;
233
            return l;
229
        }
234
        }
230
        if (id.equals("customerrelationship.customer.contact")) {
235
        if (id.equals("customerrelationship.customer.contact")) {
231
            return new JLabelBold("Contacts");
236
            return new JLabelBold("Contacts");
232
        } else if (id.equals("customerrelationship.customer.payment")) {
237
        } else if (id.equals("customerrelationship.customer.payment")) {
233
            return new JLabelBold("Mode de règlement");
238
            return new JLabelBold("Mode de règlement");
234
        } else if (id.equals("customerrelationship.customer.address")) {
239
        } else if (id.equals("customerrelationship.customer.address")) {
235
            return new JLabelBold("Adresses du client");
240
            return new JLabelBold("Adresses du client");
236
        }
241
        }
237
        JComponent c = super.getLabel(id);
242
        JComponent c = super.getLabel(id);
238
        return c;
243
        return c;
239
    }
244
    }
240
 
245
 
241
    @Override
246
    @Override
242
    public void update() {
247
    public void update() {
243
        super.update();
248
        super.update();
244
        final int selectedID = getSelectedID();
249
        final int selectedID = getSelectedID();
245
        this.table.updateField("ID_CLIENT", selectedID);
250
        this.table.updateField("ID_CLIENT", selectedID);
-
 
251
        this.clienTarifTable.updateField("ID_CLIENT", selectedID);
246
        this.tableCustomProduct.updateField("ID_CLIENT", selectedID);
252
        this.tableCustomProduct.updateField("ID_CLIENT", selectedID);
247
        this.adresseTable.updateField("ID_CLIENT", selectedID);
253
        this.adresseTable.updateField("ID_CLIENT", selectedID);
248
    }
254
    }
249
 
255
 
250
    @Override
256
    @Override
251
    public void select(SQLRowAccessor r) {
257
    public void select(SQLRowAccessor r) {
252
        super.select(r);
258
        super.select(r);
253
        this.checkAdrLivraison.setSelected(r == null || !r.getFields().contains("ID_ADRESSE_L") || r.isForeignEmpty("ID_ADRESSE_L"));
259
        this.checkAdrLivraison.setSelected(r == null || !r.getFields().contains("ID_ADRESSE_L") || r.isForeignEmpty("ID_ADRESSE_L"));
254
        this.checkAdrFacturation.setSelected(r == null || !r.getFields().contains("ID_ADRESSE_F") || r.isForeignEmpty("ID_ADRESSE_F"));
260
        this.checkAdrFacturation.setSelected(r == null || !r.getFields().contains("ID_ADRESSE_F") || r.isForeignEmpty("ID_ADRESSE_F"));
255
        if (r != null) {
261
        if (r != null) {
256
            this.table.insertFrom("ID_CLIENT", r.asRowValues());
262
            this.table.insertFrom("ID_CLIENT", r.asRowValues());
-
 
263
            this.clienTarifTable.insertFrom("ID_CLIENT", r.asRowValues());
257
            this.tableCustomProduct.insertFrom("ID_CLIENT", r.asRowValues());
264
            this.tableCustomProduct.insertFrom("ID_CLIENT", r.asRowValues());
258
            this.adresseTable.insertFrom("ID_CLIENT", r.asRowValues());
265
            this.adresseTable.insertFrom("ID_CLIENT", r.asRowValues());
259
        }
266
        }
260
    }
267
    }
261
 
268
 
262
    @Override
269
    @Override
263
    public int insert(SQLRow order) {
270
    public int insert(SQLRow order) {
264
        int id;
271
        int id;
265
 
272
 
266
        int attempt = 0;
273
        int attempt = 0;
267
        // on verifie qu'un client du meme numero n'a pas été inséré entre temps
274
        // on verifie qu'un client du meme numero n'a pas été inséré entre temps
268
        if (this.code.getText().trim().length() > 0 && !this.code.checkValidation(false)) {
275
        if (this.code.getText().trim().length() > 0 && !this.code.checkValidation(false)) {
269
            while (attempt < JUniqueTextField.RETRY_COUNT) {
276
            while (attempt < JUniqueTextField.RETRY_COUNT) {
270
                String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass());
277
                String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass());
271
                this.code.setText(num);
278
                this.code.setText(num);
272
                attempt++;
279
                attempt++;
273
                if (this.code.checkValidation(false)) {
280
                if (this.code.checkValidation(false)) {
274
                    System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
281
                    System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
275
                    break;
282
                    break;
276
                }
283
                }
277
                try {
284
                try {
278
                    Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
285
                    Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
279
                } catch (InterruptedException e) {
286
                } catch (InterruptedException e) {
280
                    e.printStackTrace();
287
                    e.printStackTrace();
281
                }
288
                }
282
            }
289
            }
283
        }
290
        }
284
        final String num = this.code.getText();
291
        final String num = this.code.getText();
285
        if (attempt == JUniqueTextField.RETRY_COUNT) {
292
        if (attempt == JUniqueTextField.RETRY_COUNT) {
286
            id = getSelectedID();
293
            id = getSelectedID();
287
            ExceptionHandler.handle("Impossible d'ajouter, numéro de client existant.");
294
            ExceptionHandler.handle("Impossible d'ajouter, numéro de client existant.");
288
            final Object root = SwingUtilities.getRoot(this);
295
            final Object root = SwingUtilities.getRoot(this);
289
            if (root instanceof EditFrame) {
296
            if (root instanceof EditFrame) {
290
                final EditFrame frame = (EditFrame) root;
297
                final EditFrame frame = (EditFrame) root;
291
                frame.getPanel().setAlwaysVisible(true);
298
                frame.getPanel().setAlwaysVisible(true);
292
            }
299
            }
293
        } else {
300
        } else {
294
            id = super.insert(order);
301
            id = super.insert(order);
295
            this.table.updateField("ID_CLIENT", id);
302
            this.table.updateField("ID_CLIENT", id);
296
            this.tableCustomProduct.updateField("ID_CLIENT", id);
303
            this.tableCustomProduct.updateField("ID_CLIENT", id);
-
 
304
            this.clienTarifTable.updateField("ID_CLIENT", id);
297
            this.adresseTable.updateField("ID_CLIENT", id);
305
            this.adresseTable.updateField("ID_CLIENT", id);
298
            if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass()).equalsIgnoreCase(this.code.getText().trim())) {
306
            if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass()).equalsIgnoreCase(this.code.getText().trim())) {
299
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
307
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
300
                final SQLRow rowNumAuto = this.tableNum.getRow(2);
308
                final SQLRow rowNumAuto = this.tableNum.getRow(2);
301
                if (rowNumAuto.getObject("CLIENT_START") != null) {
309
                if (rowNumAuto.getObject("CLIENT_START") != null) {
302
                    int val = rowNumAuto.getInt("CLIENT_START");
310
                    int val = rowNumAuto.getInt("CLIENT_START");
303
                    val++;
311
                    val++;
304
                    rowVals.put("CLIENT_START", new Integer(val));
312
                    rowVals.put("CLIENT_START", new Integer(val));
305
 
313
 
306
                    try {
314
                    try {
307
                        rowVals.update(2);
315
                        rowVals.update(2);
308
                    } catch (SQLException e) {
316
                    } catch (SQLException e) {
309
                        e.printStackTrace();
317
                        e.printStackTrace();
310
                    }
318
                    }
311
                }
319
                }
312
            }
320
            }
313
            if (attempt > 0) {
321
            if (attempt > 0) {
314
                SwingUtilities.invokeLater(new Runnable() {
322
                SwingUtilities.invokeLater(new Runnable() {
315
                    public void run() {
323
                    public void run() {
316
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
324
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
317
                    }
325
                    }
318
                });
326
                });
319
            }
327
            }
320
        }
328
        }
321
        return id;
329
        return id;
322
    }
330
    }
323
 
331
 
324
    private JComponent createAdressesComponent() {
332
    private JComponent createAdressesComponent() {
325
        final JTabbedPane tabbedAdresse = new JTabbedPane() {
333
        final JTabbedPane tabbedAdresse = new JTabbedPane() {
326
            public void insertTab(String title, Icon icon, Component component, String tip, int index) {
334
            public void insertTab(String title, Icon icon, Component component, String tip, int index) {
327
                if (component instanceof JComponent) {
335
                if (component instanceof JComponent) {
328
                    ((JComponent) component).setOpaque(false);
336
                    ((JComponent) component).setOpaque(false);
329
                }
337
                }
330
                super.insertTab(title, icon, component, tip, index);
338
                super.insertTab(title, icon, component, tip, index);
331
            }
339
            }
332
 
340
 
333
        };
341
        };
334
 
342
 
335
        // Adr principale
343
        // Adr principale
336
 
344
 
337
        final JPanel panelAdressePrincipale = new JPanel(new GridBagLayout());
345
        final JPanel panelAdressePrincipale = new JPanel(new GridBagLayout());
338
        GridBagConstraints cPanel = new DefaultGridBagConstraints();
346
        GridBagConstraints cPanel = new DefaultGridBagConstraints();
339
        cPanel.weightx = 1;
347
        cPanel.weightx = 1;
340
        cPanel.weighty = 1;
348
        cPanel.weighty = 1;
341
        cPanel.anchor = GridBagConstraints.NORTH;
349
        cPanel.anchor = GridBagConstraints.NORTH;
342
        this.addView("ID_ADRESSE", REQ + ";" + DEC + ";" + SEP);
350
        this.addView("ID_ADRESSE", REQ + ";" + DEC + ";" + SEP);
343
 
351
 
344
        final ElementSQLObject componentPrincipale = (ElementSQLObject) this.getView("ID_ADRESSE");
352
        final ElementSQLObject componentPrincipale = (ElementSQLObject) this.getView("ID_ADRESSE");
345
        ((AdresseSQLComponent) componentPrincipale.getSQLChild()).setDestinataireVisible(true);
353
        ((AdresseSQLComponent) componentPrincipale.getSQLChild()).setDestinataireVisible(true);
346
        componentPrincipale.setOpaque(false);
354
        componentPrincipale.setOpaque(false);
347
        panelAdressePrincipale.add(componentPrincipale, cPanel);
355
        panelAdressePrincipale.add(componentPrincipale, cPanel);
348
        tabbedAdresse.add(getLabelFor("ID_ADRESSE"), panelAdressePrincipale);
356
        tabbedAdresse.add(getLabelFor("ID_ADRESSE"), panelAdressePrincipale);
349
        tabbedAdresse.setOpaque(false);
357
        tabbedAdresse.setOpaque(false);
350
 
358
 
351
        // Adresse de facturation
359
        // Adresse de facturation
352
 
360
 
353
        tabbedAdresse.add(getLabelFor("ID_ADRESSE_F"), createFacturationPanel());
361
        tabbedAdresse.add(getLabelFor("ID_ADRESSE_F"), createFacturationPanel());
354
 
362
 
355
        // Adresse de livraison
363
        // Adresse de livraison
356
 
364
 
357
        tabbedAdresse.add(getLabelFor("ID_ADRESSE_L"), createLivraisonPanel());
365
        tabbedAdresse.add(getLabelFor("ID_ADRESSE_L"), createLivraisonPanel());
358
 
366
 
359
        // Adresses supplémentaires
367
        // Adresses supplémentaires
360
        String labelAdrSuppl = TM.tr("additional.address");
368
        String labelAdrSuppl = TM.tr("additional.address");
361
        tabbedAdresse.add(labelAdrSuppl, this.adresseTable);
369
        tabbedAdresse.add(labelAdrSuppl, this.adresseTable);
362
 
370
 
363
        return tabbedAdresse;
371
        return tabbedAdresse;
364
    }
372
    }
365
 
373
 
366
    private Component createLivraisonPanel() {
374
    private Component createLivraisonPanel() {
367
        final JPanel panel = new JPanel(new GridBagLayout());
375
        final JPanel panel = new JPanel(new GridBagLayout());
368
        final GridBagConstraints c = new DefaultGridBagConstraints();
376
        final GridBagConstraints c = new DefaultGridBagConstraints();
369
        final String field = "ID_ADRESSE_L";
377
        final String field = "ID_ADRESSE_L";
370
 
378
 
371
        this.addView(field, DEC + ";" + SEP);
379
        this.addView(field, DEC + ";" + SEP);
372
        final ElementSQLObject component = (ElementSQLObject) this.getView(field);
380
        final ElementSQLObject component = (ElementSQLObject) this.getView(field);
373
        final AdresseSQLComponent adresseSQLComponent = (AdresseSQLComponent) component.getSQLChild();
381
        final AdresseSQLComponent adresseSQLComponent = (AdresseSQLComponent) component.getSQLChild();
374
        adresseSQLComponent.setDestinataireVisible(true);
382
        adresseSQLComponent.setDestinataireVisible(true);
375
        System.err.println("CustomerSQLComponent.createLivraisonPanel()" + component + " " + System.identityHashCode(component));
383
        System.err.println("CustomerSQLComponent.createLivraisonPanel()" + component + " " + System.identityHashCode(component));
376
        System.err.println("CustomerSQLComponent.createLivraisonPanel()" + adresseSQLComponent + " " + System.identityHashCode(adresseSQLComponent));
384
        System.err.println("CustomerSQLComponent.createLivraisonPanel()" + adresseSQLComponent + " " + System.identityHashCode(adresseSQLComponent));
377
        component.setOpaque(false);
385
        component.setOpaque(false);
378
        c.weightx = 1;
386
        c.weightx = 1;
379
        this.checkAdrLivraison = new JCheckBox(TM.tr("delivery.address.same.main.address"));
387
        this.checkAdrLivraison = new JCheckBox(TM.tr("delivery.address.same.main.address"));
380
        this.checkAdrLivraison.setOpaque(false);
388
        this.checkAdrLivraison.setOpaque(false);
381
        panel.add(component, c);
389
        panel.add(component, c);
382
 
390
 
383
        c.gridy++;
391
        c.gridy++;
384
        c.weighty = 1;
392
        c.weighty = 1;
385
        c.anchor = GridBagConstraints.NORTH;
393
        c.anchor = GridBagConstraints.NORTH;
386
        panel.add(this.checkAdrLivraison, c);
394
        panel.add(this.checkAdrLivraison, c);
387
        // Listener
395
        // Listener
388
        this.checkAdrLivraison.addActionListener(new ActionListener() {
396
        this.checkAdrLivraison.addActionListener(new ActionListener() {
389
 
397
 
390
            public void actionPerformed(java.awt.event.ActionEvent e) {
398
            public void actionPerformed(java.awt.event.ActionEvent e) {
391
                boolean b = checkAdrLivraison.isSelected();
399
                boolean b = checkAdrLivraison.isSelected();
392
                System.err.println("CustomerSQLComponent.createAdressesComponent().new ActionListener() {...}.actionPerformed() checkAdrLivraison " + b);
400
                System.err.println("CustomerSQLComponent.createAdressesComponent().new ActionListener() {...}.actionPerformed() checkAdrLivraison " + b);
393
                component.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
401
                component.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
394
                component.setCreated(!b);
402
                component.setCreated(!b);
395
            };
403
            };
396
        });
404
        });
397
        panel.setOpaque(false);
405
        panel.setOpaque(false);
398
        return panel;
406
        return panel;
399
    }
407
    }
400
 
408
 
401
    private Component createFacturationPanel() {
409
    private Component createFacturationPanel() {
402
        final JPanel panel = new JPanel(new GridBagLayout());
410
        final JPanel panel = new JPanel(new GridBagLayout());
403
        final GridBagConstraints c = new DefaultGridBagConstraints();
411
        final GridBagConstraints c = new DefaultGridBagConstraints();
404
        final String field = "ID_ADRESSE_F";
412
        final String field = "ID_ADRESSE_F";
405
 
413
 
406
        this.addView(field, DEC + ";" + SEP);
414
        this.addView(field, DEC + ";" + SEP);
407
        final ElementSQLObject component = (ElementSQLObject) this.getView(field);
415
        final ElementSQLObject component = (ElementSQLObject) this.getView(field);
408
        final AdresseSQLComponent adresseSQLComponent = (AdresseSQLComponent) component.getSQLChild();
416
        final AdresseSQLComponent adresseSQLComponent = (AdresseSQLComponent) component.getSQLChild();
409
        System.err.println("CustomerSQLComponent.createFacturationPanel()" + component + " " + System.identityHashCode(component));
417
        System.err.println("CustomerSQLComponent.createFacturationPanel()" + component + " " + System.identityHashCode(component));
410
        System.err.println("CustomerSQLComponent.createFacturationPanel()" + adresseSQLComponent + " " + System.identityHashCode(adresseSQLComponent));
418
        System.err.println("CustomerSQLComponent.createFacturationPanel()" + adresseSQLComponent + " " + System.identityHashCode(adresseSQLComponent));
411
        adresseSQLComponent.setDestinataireVisible(true);
419
        adresseSQLComponent.setDestinataireVisible(true);
412
        component.setOpaque(false);
420
        component.setOpaque(false);
413
        c.weightx = 1;
421
        c.weightx = 1;
414
        this.checkAdrFacturation = new JCheckBox(TM.tr("invoice.address.same.main.address"));
422
        this.checkAdrFacturation = new JCheckBox(TM.tr("invoice.address.same.main.address"));
415
        this.checkAdrFacturation.setOpaque(false);
423
        this.checkAdrFacturation.setOpaque(false);
416
        c.anchor = GridBagConstraints.NORTH;
424
        c.anchor = GridBagConstraints.NORTH;
417
        panel.add(component, c);
425
        panel.add(component, c);
418
 
426
 
419
        c.gridy++;
427
        c.gridy++;
420
        c.weighty = 1;
428
        c.weighty = 1;
421
        c.anchor = GridBagConstraints.NORTH;
429
        c.anchor = GridBagConstraints.NORTH;
422
        panel.add(this.checkAdrFacturation, c);
430
        panel.add(this.checkAdrFacturation, c);
423
        // Listener
431
        // Listener
424
        this.checkAdrFacturation.addActionListener(new ActionListener() {
432
        this.checkAdrFacturation.addActionListener(new ActionListener() {
425
 
433
 
426
            public void actionPerformed(java.awt.event.ActionEvent e) {
434
            public void actionPerformed(java.awt.event.ActionEvent e) {
427
                boolean b = checkAdrFacturation.isSelected();
435
                boolean b = checkAdrFacturation.isSelected();
428
                System.err.println("CustomerSQLComponent.createAdressesComponent().new ActionListener() {...}.actionPerformed() checkAdrFacturation " + b);
436
                System.err.println("CustomerSQLComponent.createAdressesComponent().new ActionListener() {...}.actionPerformed() checkAdrFacturation " + b);
429
                component.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
437
                component.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
430
                component.setCreated(!b);
438
                component.setCreated(!b);
431
            };
439
            };
432
        });
440
        });
433
        panel.setOpaque(false);
441
        panel.setOpaque(false);
434
        return panel;
442
        return panel;
435
    }
443
    }
436
 
444
 
437
}
445
}