18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.pos.ui;
|
|
|
15 |
|
80 |
ilm |
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
18 |
ilm |
17 |
import org.openconcerto.erp.config.ServerFinderConfig;
|
|
|
18 |
import org.openconcerto.erp.config.ServerFinderPanel;
|
132 |
ilm |
19 |
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
|
|
|
20 |
import org.openconcerto.erp.core.sales.pos.io.ESCSerialPrinter;
|
18 |
ilm |
21 |
import org.openconcerto.sql.model.DBRoot;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
23 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
|
|
24 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
25 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
26 |
import org.openconcerto.ui.JLabelBold;
|
|
|
27 |
|
|
|
28 |
import java.awt.Component;
|
|
|
29 |
import java.awt.Dimension;
|
|
|
30 |
import java.awt.GridBagConstraints;
|
|
|
31 |
import java.awt.GridBagLayout;
|
132 |
ilm |
32 |
import java.awt.event.ActionEvent;
|
|
|
33 |
import java.awt.event.ActionListener;
|
18 |
ilm |
34 |
import java.awt.event.ComponentEvent;
|
|
|
35 |
import java.awt.event.ComponentListener;
|
|
|
36 |
import java.awt.event.ItemEvent;
|
|
|
37 |
import java.awt.event.ItemListener;
|
132 |
ilm |
38 |
import java.util.ArrayList;
|
18 |
ilm |
39 |
import java.util.List;
|
|
|
40 |
import java.util.Vector;
|
|
|
41 |
|
142 |
ilm |
42 |
import javax.print.PrintService;
|
|
|
43 |
import javax.print.PrintServiceLookup;
|
18 |
ilm |
44 |
import javax.swing.ComboBoxModel;
|
|
|
45 |
import javax.swing.DefaultComboBoxModel;
|
|
|
46 |
import javax.swing.DefaultListCellRenderer;
|
132 |
ilm |
47 |
import javax.swing.JButton;
|
18 |
ilm |
48 |
import javax.swing.JComboBox;
|
|
|
49 |
import javax.swing.JLabel;
|
|
|
50 |
import javax.swing.JList;
|
|
|
51 |
import javax.swing.JOptionPane;
|
|
|
52 |
import javax.swing.JPanel;
|
132 |
ilm |
53 |
import javax.swing.JTabbedPane;
|
18 |
ilm |
54 |
import javax.swing.JTextField;
|
|
|
55 |
import javax.swing.SwingConstants;
|
|
|
56 |
import javax.swing.SwingUtilities;
|
|
|
57 |
|
|
|
58 |
public class ConfigCaissePanel extends JPanel {
|
132 |
ilm |
59 |
|
156 |
ilm |
60 |
private final POSConfiguration configuration;
|
18 |
ilm |
61 |
private int userId;
|
|
|
62 |
private int societeId;
|
|
|
63 |
private int caisseId;
|
|
|
64 |
private final ServerFinderPanel serverFinderPanel;
|
|
|
65 |
private final JComboBox comboSociete;
|
|
|
66 |
private final JComboBox comboCaisse;
|
|
|
67 |
private final JComboBox comboUtilisateur;
|
|
|
68 |
private final TicketLineTable headerTable;
|
|
|
69 |
private final TicketLineTable footerTable;
|
83 |
ilm |
70 |
private JTextField textTerminalCB;
|
18 |
ilm |
71 |
|
132 |
ilm |
72 |
// Ticket printers
|
|
|
73 |
private final TicketPrinterConfigPanel ticketPanel1;
|
|
|
74 |
private final TicketPrinterConfigPanel ticketPanel2;
|
|
|
75 |
// LCD
|
142 |
ilm |
76 |
private JComboBox comboLCDType;
|
|
|
77 |
private JTextField textLCDPort;
|
132 |
ilm |
78 |
private JTextField textLCDLine1;
|
|
|
79 |
private JTextField textLCDLine2;
|
|
|
80 |
|
18 |
ilm |
81 |
public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
|
|
|
82 |
this.serverFinderPanel = serverFinderPanel;
|
156 |
ilm |
83 |
try {
|
|
|
84 |
this.configuration = POSConfiguration.setInstance();
|
|
|
85 |
} catch (Exception e) {
|
|
|
86 |
throw new IllegalStateException("Couldn't initialise POSConfiguration", e);
|
|
|
87 |
}
|
132 |
ilm |
88 |
|
18 |
ilm |
89 |
setOpaque(false);
|
|
|
90 |
|
|
|
91 |
setLayout(new GridBagLayout());
|
|
|
92 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
93 |
c.weighty = 0;
|
25 |
ilm |
94 |
// Fichier
|
|
|
95 |
c.weightx = 0;
|
|
|
96 |
this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
|
|
|
97 |
c.gridx++;
|
|
|
98 |
c.gridwidth = 3;
|
|
|
99 |
c.weightx = 1;
|
|
|
100 |
JTextField textConfigurationFile = new JTextField("");
|
142 |
ilm |
101 |
if (this.configuration.getConfigFile() != null) {
|
|
|
102 |
textConfigurationFile.setText(this.configuration.getConfigFile().getAbsolutePath());
|
25 |
ilm |
103 |
}
|
|
|
104 |
textConfigurationFile.setEditable(false);
|
|
|
105 |
this.add(textConfigurationFile, c);
|
|
|
106 |
|
18 |
ilm |
107 |
// Connexion
|
25 |
ilm |
108 |
c.gridy++;
|
|
|
109 |
c.gridx = 0;
|
18 |
ilm |
110 |
final JLabelBold titleConnexion = new JLabelBold("Connexion");
|
|
|
111 |
c.gridwidth = 2;
|
|
|
112 |
this.add(titleConnexion, c);
|
|
|
113 |
c.gridy++;
|
|
|
114 |
c.gridwidth = 1;
|
|
|
115 |
c.weightx = 0;
|
|
|
116 |
this.add(new JLabel("Société", SwingConstants.RIGHT), c);
|
|
|
117 |
c.gridx++;
|
|
|
118 |
c.weightx = 1;
|
|
|
119 |
this.comboSociete = new JComboBox();
|
|
|
120 |
this.comboSociete.setRenderer(new DefaultListCellRenderer() {
|
|
|
121 |
@Override
|
|
|
122 |
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
|
|
|
123 |
final SQLRow r = (SQLRow) value;
|
|
|
124 |
String label = "";
|
|
|
125 |
if (r != null) {
|
|
|
126 |
label = r.getString("NOM") + " (" + r.getString("ID") + ")";
|
|
|
127 |
}
|
|
|
128 |
return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
|
|
|
129 |
}
|
|
|
130 |
});
|
|
|
131 |
this.add(this.comboSociete, c);
|
|
|
132 |
c.gridx = 0;
|
|
|
133 |
c.gridy++;
|
|
|
134 |
c.weightx = 0;
|
|
|
135 |
this.add(new JLabel("Caisse", SwingConstants.RIGHT), c);
|
|
|
136 |
c.gridx++;
|
|
|
137 |
this.comboCaisse = new JComboBox();
|
|
|
138 |
this.comboCaisse.setRenderer(new DefaultListCellRenderer() {
|
|
|
139 |
@Override
|
|
|
140 |
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
|
|
|
141 |
final SQLRow r = (SQLRow) value;
|
|
|
142 |
String label = "";
|
|
|
143 |
if (r != null) {
|
|
|
144 |
label = r.getString("NOM") + " (" + r.getString("ID") + ")";
|
|
|
145 |
}
|
|
|
146 |
return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
|
|
|
147 |
}
|
|
|
148 |
});
|
|
|
149 |
this.add(this.comboCaisse, c);
|
|
|
150 |
c.gridx = 0;
|
|
|
151 |
c.gridy++;
|
|
|
152 |
c.weightx = 0;
|
|
|
153 |
this.add(new JLabel("Utilisateur", SwingConstants.RIGHT), c);
|
|
|
154 |
c.gridx++;
|
|
|
155 |
this.comboUtilisateur = new JComboBox();
|
|
|
156 |
this.comboUtilisateur.setRenderer(new DefaultListCellRenderer() {
|
|
|
157 |
@Override
|
|
|
158 |
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
|
|
|
159 |
final SQLRow r = (SQLRow) value;
|
|
|
160 |
String label = "";
|
|
|
161 |
if (r != null) {
|
|
|
162 |
label = r.getString("NOM") + " " + r.getString("PRENOM") + " (" + r.getString("ID") + ")";
|
|
|
163 |
}
|
|
|
164 |
return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
|
|
|
165 |
}
|
|
|
166 |
});
|
|
|
167 |
this.add(this.comboUtilisateur, c);
|
|
|
168 |
|
|
|
169 |
// Ticket
|
|
|
170 |
final JLabelBold titleTicket = new JLabelBold("Ticket");
|
|
|
171 |
c.gridwidth = 2;
|
|
|
172 |
c.gridx = 0;
|
|
|
173 |
c.gridy++;
|
|
|
174 |
c.weightx = 0;
|
|
|
175 |
this.add(titleTicket, c);
|
132 |
ilm |
176 |
|
|
|
177 |
final JTabbedPane tabsTicket = new JTabbedPane();
|
18 |
ilm |
178 |
c.gridy++;
|
132 |
ilm |
179 |
c.gridwidth = 2;
|
18 |
ilm |
180 |
c.weightx = 0;
|
132 |
ilm |
181 |
c.fill = GridBagConstraints.BOTH;
|
18 |
ilm |
182 |
c.anchor = GridBagConstraints.NORTHWEST;
|
|
|
183 |
this.headerTable = new TicketLineTable();
|
132 |
ilm |
184 |
tabsTicket.addTab("Entête", this.headerTable);
|
|
|
185 |
this.footerTable = new TicketLineTable();
|
|
|
186 |
tabsTicket.addTab("Pied de page", this.footerTable);
|
|
|
187 |
this.add(tabsTicket, c);
|
18 |
ilm |
188 |
|
132 |
ilm |
189 |
// Périphérique
|
|
|
190 |
final JLabelBold titleImprimante = new JLabelBold("Périphériques");
|
18 |
ilm |
191 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
192 |
c.anchor = GridBagConstraints.WEST;
|
|
|
193 |
c.gridwidth = 2;
|
|
|
194 |
c.gridx = 0;
|
|
|
195 |
c.gridy++;
|
|
|
196 |
c.weightx = 0;
|
|
|
197 |
this.add(titleImprimante, c);
|
|
|
198 |
c.gridy++;
|
132 |
ilm |
199 |
//
|
|
|
200 |
JTabbedPane tabs = new JTabbedPane();
|
|
|
201 |
ticketPanel1 = new TicketPrinterConfigPanel();
|
|
|
202 |
ticketPanel1.setOpaque(false);
|
|
|
203 |
ticketPanel2 = new TicketPrinterConfigPanel();
|
|
|
204 |
ticketPanel2.setOpaque(false);
|
|
|
205 |
tabs.addTab("Imprimante ticket principale", ticketPanel1);
|
|
|
206 |
tabs.addTab("Imprimante ticket secondaire", ticketPanel2);
|
|
|
207 |
tabs.addTab("Terminal CB", createCreditCardPanel());
|
|
|
208 |
tabs.addTab("Afficheur LCD", createLCDPanel());
|
|
|
209 |
this.add(tabs, c);
|
|
|
210 |
//
|
18 |
ilm |
211 |
|
|
|
212 |
// Spacer
|
|
|
213 |
c.gridx = 0;
|
|
|
214 |
c.gridy++;
|
|
|
215 |
c.weighty = 1;
|
|
|
216 |
c.fill = GridBagConstraints.BOTH;
|
|
|
217 |
final JPanel spacer = new JPanel();
|
|
|
218 |
spacer.setOpaque(false);
|
|
|
219 |
spacer.setPreferredSize(new Dimension(10, 10));
|
|
|
220 |
|
|
|
221 |
add(spacer, c);
|
|
|
222 |
|
|
|
223 |
// Listeners
|
|
|
224 |
this.comboSociete.addItemListener(new ItemListener() {
|
|
|
225 |
|
|
|
226 |
@Override
|
|
|
227 |
public void itemStateChanged(final ItemEvent e) {
|
|
|
228 |
if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
|
229 |
ConfigCaissePanel.this.societeId = ((SQLRow) e.getItem()).getID();
|
|
|
230 |
reloadCaisses();
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
});
|
|
|
234 |
this.comboCaisse.addItemListener(new ItemListener() {
|
|
|
235 |
@Override
|
|
|
236 |
public void itemStateChanged(final ItemEvent e) {
|
|
|
237 |
if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
|
238 |
ConfigCaissePanel.this.caisseId = ((SQLRow) e.getItem()).getID();
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
});
|
|
|
242 |
this.comboUtilisateur.addItemListener(new ItemListener() {
|
|
|
243 |
@Override
|
|
|
244 |
public void itemStateChanged(final ItemEvent e) {
|
|
|
245 |
if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
|
246 |
ConfigCaissePanel.this.userId = ((SQLRow) e.getItem()).getID();
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
});
|
|
|
250 |
}
|
|
|
251 |
|
132 |
ilm |
252 |
private Component createLCDPanel() {
|
|
|
253 |
final JPanel p = new JPanel();
|
|
|
254 |
p.setOpaque(false);
|
|
|
255 |
|
|
|
256 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
257 |
p.setLayout(new GridBagLayout());
|
|
|
258 |
c.gridx = 0;
|
|
|
259 |
c.gridy++;
|
|
|
260 |
c.weightx = 0;
|
|
|
261 |
c.gridwidth = 1;
|
|
|
262 |
c.anchor = GridBagConstraints.EAST;
|
|
|
263 |
c.fill = GridBagConstraints.NONE;
|
142 |
ilm |
264 |
p.add(new JLabel("Type", SwingConstants.RIGHT), c);
|
132 |
ilm |
265 |
c.gridx++;
|
142 |
ilm |
266 |
c.weightx = 0;
|
|
|
267 |
c.fill = GridBagConstraints.NONE;
|
|
|
268 |
c.anchor = GridBagConstraints.WEST;
|
|
|
269 |
comboLCDType = new JComboBox(new String[] { "Port série", "Emulation imprimante" });
|
|
|
270 |
|
|
|
271 |
p.add(comboLCDType, c);
|
|
|
272 |
c.gridy++;
|
|
|
273 |
c.gridx = 0;
|
|
|
274 |
c.anchor = GridBagConstraints.EAST;
|
|
|
275 |
final JLabel labelType = new JLabel("Port", SwingConstants.RIGHT);
|
|
|
276 |
p.add(labelType, c);
|
|
|
277 |
c.gridx++;
|
132 |
ilm |
278 |
c.weightx = 1;
|
|
|
279 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
280 |
|
142 |
ilm |
281 |
this.textLCDPort = new JTextField(20);
|
|
|
282 |
p.add(this.textLCDPort, c);
|
132 |
ilm |
283 |
c.weightx = 0;
|
|
|
284 |
c.gridx++;
|
|
|
285 |
final JButton selectPortButton = new JButton("Sélectionner");
|
|
|
286 |
selectPortButton.addActionListener(new ActionListener() {
|
|
|
287 |
|
|
|
288 |
@Override
|
|
|
289 |
public void actionPerformed(ActionEvent e) {
|
|
|
290 |
List<String> choices = new ArrayList<String>();
|
|
|
291 |
final String title;
|
|
|
292 |
final String message;
|
142 |
ilm |
293 |
if (comboLCDType.getSelectedIndex() == 1) {
|
|
|
294 |
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
|
|
|
295 |
for (PrintService printer : printServices) {
|
|
|
296 |
choices.add(printer.getName());
|
|
|
297 |
}
|
|
|
298 |
title = "Afficheur LCD";
|
|
|
299 |
message = "Choisissez l'imprimante correspondante à l'afficheur LCD";
|
|
|
300 |
} else if (comboLCDType.getSelectedIndex() == 0) {
|
|
|
301 |
choices.addAll(ESCSerialPrinter.getSerialPortNames());
|
|
|
302 |
title = "Port série";
|
|
|
303 |
message = "Choisissez le port série lié à l'afficheur LCD";
|
|
|
304 |
} else {
|
|
|
305 |
return;
|
|
|
306 |
}
|
132 |
ilm |
307 |
if (choices.isEmpty()) {
|
|
|
308 |
return;
|
|
|
309 |
}
|
|
|
310 |
String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
|
142 |
ilm |
311 |
|
132 |
ilm |
312 |
// If a string was returned
|
|
|
313 |
if ((s != null) && (s.length() > 0)) {
|
142 |
ilm |
314 |
textLCDPort.setText(s);
|
132 |
ilm |
315 |
}
|
142 |
ilm |
316 |
|
132 |
ilm |
317 |
}
|
|
|
318 |
});
|
|
|
319 |
p.add(selectPortButton, c);
|
|
|
320 |
|
|
|
321 |
c.gridx = 0;
|
|
|
322 |
c.gridy++;
|
|
|
323 |
c.gridwidth = 3;
|
|
|
324 |
p.add(new JLabel("Message d'accueil de l'afficheur"), c);
|
|
|
325 |
//
|
|
|
326 |
c.gridy++;
|
|
|
327 |
c.gridwidth = 1;
|
|
|
328 |
p.add(new JLabel("Ligne 1", SwingConstants.RIGHT), c);
|
|
|
329 |
c.gridx++;
|
|
|
330 |
this.textLCDLine1 = new JTextField(20);
|
|
|
331 |
p.add(textLCDLine1, c);
|
|
|
332 |
|
|
|
333 |
c.gridx = 0;
|
|
|
334 |
c.gridy++;
|
|
|
335 |
p.add(new JLabel("Ligne 2", SwingConstants.RIGHT), c);
|
|
|
336 |
c.gridx++;
|
|
|
337 |
this.textLCDLine2 = new JTextField(20);
|
|
|
338 |
p.add(textLCDLine2, c);
|
|
|
339 |
|
|
|
340 |
final JPanel spacer = new JPanel();
|
|
|
341 |
spacer.setOpaque(false);
|
|
|
342 |
c.gridy++;
|
|
|
343 |
c.weighty = 1;
|
|
|
344 |
p.add(spacer, c);
|
|
|
345 |
return p;
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
private JPanel createCreditCardPanel() {
|
|
|
349 |
final JPanel p = new JPanel();
|
|
|
350 |
p.setOpaque(false);
|
|
|
351 |
p.setLayout(new GridBagLayout());
|
|
|
352 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
353 |
|
|
|
354 |
c.gridx = 0;
|
|
|
355 |
c.gridy++;
|
|
|
356 |
c.weightx = 0;
|
|
|
357 |
c.gridwidth = 1;
|
|
|
358 |
c.anchor = GridBagConstraints.EAST;
|
|
|
359 |
c.fill = GridBagConstraints.NONE;
|
|
|
360 |
p.add(new JLabel("Port série", SwingConstants.RIGHT), c);
|
|
|
361 |
c.gridx++;
|
|
|
362 |
c.weightx = 1;
|
|
|
363 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
364 |
|
|
|
365 |
this.textTerminalCB = new JTextField(20);
|
|
|
366 |
p.add(this.textTerminalCB, c);
|
|
|
367 |
c.weightx = 0;
|
|
|
368 |
c.gridx++;
|
|
|
369 |
final JButton selectPortButton = new JButton("Sélectionner");
|
|
|
370 |
selectPortButton.addActionListener(new ActionListener() {
|
|
|
371 |
|
|
|
372 |
@Override
|
|
|
373 |
public void actionPerformed(ActionEvent e) {
|
|
|
374 |
List<String> choices = new ArrayList<String>();
|
|
|
375 |
final String title;
|
|
|
376 |
final String message;
|
|
|
377 |
|
|
|
378 |
choices.addAll(ESCSerialPrinter.getSerialPortNames());
|
|
|
379 |
title = "Port série";
|
|
|
380 |
message = "Choisissez le port série lié au terminal CB";
|
|
|
381 |
if (choices.isEmpty()) {
|
|
|
382 |
return;
|
|
|
383 |
}
|
|
|
384 |
String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
|
|
|
385 |
// If a string was returned
|
|
|
386 |
if ((s != null) && (s.length() > 0)) {
|
|
|
387 |
textTerminalCB.setText(s);
|
|
|
388 |
}
|
|
|
389 |
}
|
|
|
390 |
});
|
|
|
391 |
p.add(selectPortButton, c);
|
|
|
392 |
|
|
|
393 |
final JPanel spacer = new JPanel();
|
|
|
394 |
spacer.setOpaque(false);
|
|
|
395 |
c.gridy++;
|
|
|
396 |
c.weighty = 1;
|
|
|
397 |
p.add(spacer, c);
|
|
|
398 |
|
|
|
399 |
return p;
|
|
|
400 |
}
|
|
|
401 |
|
18 |
ilm |
402 |
protected void reloadCaisses() {
|
|
|
403 |
this.comboCaisse.setEnabled(false);
|
|
|
404 |
final int id = this.societeId;
|
|
|
405 |
final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
|
|
|
406 |
if (!config.isOnline()) {
|
|
|
407 |
JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
|
|
|
408 |
return;
|
|
|
409 |
}
|
|
|
410 |
|
80 |
ilm |
411 |
System.out.println("Reloading POS information from: " + config);
|
|
|
412 |
ComptaPropsConfiguration conf = config.createConf();
|
18 |
ilm |
413 |
try {
|
|
|
414 |
// Sociétés
|
80 |
ilm |
415 |
conf.setUpSocieteStructure(id);
|
|
|
416 |
final SQLRow societe = conf.getRowSociete();
|
65 |
ilm |
417 |
if (societe != null) {
|
|
|
418 |
final String name = societe.getString("DATABASE_NAME");
|
18 |
ilm |
419 |
// Caisses
|
80 |
ilm |
420 |
final SQLSelect sel = new SQLSelect();
|
|
|
421 |
sel.addSelectStar(conf.getRootSociete().getTable("CAISSE"));
|
18 |
ilm |
422 |
final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
|
25 |
ilm |
423 |
// Stock l'id de la caisse pour que la reslectionne soit correcte
|
|
|
424 |
final int idCaisseToSelect = this.caisseId;
|
18 |
ilm |
425 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
426 |
@Override
|
|
|
427 |
public void run() {
|
25 |
ilm |
428 |
ConfigCaissePanel.this.caisseId = idCaisseToSelect;
|
18 |
ilm |
429 |
if (caisses.isEmpty()) {
|
|
|
430 |
JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
|
|
|
431 |
}
|
|
|
432 |
ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
|
|
|
433 |
ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
|
|
|
434 |
ConfigCaissePanel.this.comboCaisse.setEnabled(true);
|
|
|
435 |
final ComboBoxModel model = ConfigCaissePanel.this.comboCaisse.getModel();
|
|
|
436 |
final int stop = model.getSize();
|
|
|
437 |
if (stop > 0) {
|
|
|
438 |
// Force la reselection si la valeur n'existe plus,
|
|
|
439 |
// nécessité de recuperer l'id
|
|
|
440 |
ConfigCaissePanel.this.caisseId = ((SQLRow) model.getElementAt(0)).getID();
|
|
|
441 |
}
|
|
|
442 |
for (int i = 0; i < stop; i++) {
|
|
|
443 |
final SQLRow r = (SQLRow) model.getElementAt(i);
|
25 |
ilm |
444 |
if (r.getID() == idCaisseToSelect) {
|
18 |
ilm |
445 |
ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
|
|
|
446 |
break;
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
}
|
|
|
450 |
|
|
|
451 |
});
|
|
|
452 |
} else {
|
|
|
453 |
JOptionPane.showMessageDialog(this, "Impossible de trouver la société d'ID " + id);
|
|
|
454 |
}
|
|
|
455 |
} catch (final Exception e) {
|
|
|
456 |
e.printStackTrace();
|
80 |
ilm |
457 |
} finally {
|
|
|
458 |
conf.destroy();
|
18 |
ilm |
459 |
}
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
public void loadConfiguration() {
|
|
|
463 |
|
142 |
ilm |
464 |
final POSConfiguration configuration = this.configuration;
|
132 |
ilm |
465 |
// Terminal CB
|
|
|
466 |
this.textTerminalCB.setText(configuration.getCreditCardPort());
|
|
|
467 |
// Afficheur LCD
|
142 |
ilm |
468 |
final String lcdType = configuration.getLCDType();
|
|
|
469 |
if (lcdType.equals("serial")) {
|
|
|
470 |
this.comboLCDType.setSelectedIndex(0);
|
|
|
471 |
} else {
|
|
|
472 |
this.comboLCDType.setSelectedIndex(1);
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
this.textLCDPort.setText(configuration.getLCDPort());
|
132 |
ilm |
476 |
this.textLCDLine1.setText(configuration.getLCDLine1());
|
|
|
477 |
this.textLCDLine2.setText(configuration.getLCDLine2());
|
|
|
478 |
|
|
|
479 |
this.userId = configuration.getUserID();
|
|
|
480 |
this.societeId = configuration.getCompanyID();
|
|
|
481 |
this.caisseId = configuration.getPosID();
|
|
|
482 |
this.headerTable.fillFrom(configuration.getHeaderLines());
|
|
|
483 |
this.footerTable.fillFrom(configuration.getFooterLines());
|
|
|
484 |
this.ticketPanel1.setConfiguration(configuration.getTicketPrinterConfiguration1());
|
|
|
485 |
this.ticketPanel2.setConfiguration(configuration.getTicketPrinterConfiguration2());
|
|
|
486 |
|
18 |
ilm |
487 |
addComponentListener(new ComponentListener() {
|
|
|
488 |
@Override
|
|
|
489 |
public void componentHidden(final ComponentEvent event) {
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
@Override
|
|
|
493 |
public void componentMoved(final ComponentEvent event) {
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
@Override
|
|
|
497 |
public void componentResized(final ComponentEvent event) {
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
@Override
|
|
|
501 |
public void componentShown(final ComponentEvent event) {
|
|
|
502 |
final Thread t = new Thread(new Runnable() {
|
|
|
503 |
|
|
|
504 |
@Override
|
|
|
505 |
public void run() {
|
|
|
506 |
ConfigCaissePanel.this.comboSociete.setEnabled(false);
|
|
|
507 |
ConfigCaissePanel.this.comboUtilisateur.setEnabled(false);
|
|
|
508 |
ConfigCaissePanel.this.comboCaisse.setEnabled(false);
|
|
|
509 |
final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
|
|
|
510 |
if (!config.isOnline()) {
|
|
|
511 |
JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
|
|
|
512 |
return;
|
|
|
513 |
}
|
80 |
ilm |
514 |
final ComptaPropsConfiguration server = config.createConf();
|
18 |
ilm |
515 |
try {
|
80 |
ilm |
516 |
final DBRoot root = server.getRoot();
|
18 |
ilm |
517 |
|
|
|
518 |
// Sociétés
|
80 |
ilm |
519 |
SQLSelect sel = new SQLSelect();
|
|
|
520 |
sel.addSelectStar(root.findTable("SOCIETE_COMMON"));
|
18 |
ilm |
521 |
final List<SQLRow> societes = SQLRowListRSH.execute(sel);
|
|
|
522 |
|
|
|
523 |
// Utilisateurs
|
80 |
ilm |
524 |
sel = new SQLSelect();
|
|
|
525 |
sel.addSelectStar(root.findTable("USER_COMMON"));
|
18 |
ilm |
526 |
final List<SQLRow> utilisateurs = SQLRowListRSH.execute(sel);
|
|
|
527 |
|
|
|
528 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
529 |
@Override
|
|
|
530 |
public void run() {
|
|
|
531 |
ConfigCaissePanel.this.comboSociete.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(societes)));
|
|
|
532 |
ConfigCaissePanel.this.comboUtilisateur.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(utilisateurs)));
|
|
|
533 |
|
|
|
534 |
ConfigCaissePanel.this.comboSociete.setEnabled(true);
|
|
|
535 |
ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
|
|
|
536 |
|
25 |
ilm |
537 |
// Societe
|
18 |
ilm |
538 |
ComboBoxModel model = ConfigCaissePanel.this.comboSociete.getModel();
|
|
|
539 |
int stop = model.getSize();
|
25 |
ilm |
540 |
boolean societeFound = false;
|
18 |
ilm |
541 |
for (int i = 0; i < stop; i++) {
|
|
|
542 |
final SQLRow r = (SQLRow) model.getElementAt(i);
|
|
|
543 |
if (r.getID() == ConfigCaissePanel.this.societeId) {
|
|
|
544 |
ConfigCaissePanel.this.comboSociete.setSelectedItem(r);
|
25 |
ilm |
545 |
ConfigCaissePanel.this.societeId = r.getID();
|
|
|
546 |
societeFound = true;
|
18 |
ilm |
547 |
break;
|
|
|
548 |
}
|
|
|
549 |
}
|
25 |
ilm |
550 |
|
|
|
551 |
if (!societeFound && stop > 0) {
|
|
|
552 |
ConfigCaissePanel.this.comboSociete.setSelectedItem(model.getElementAt(0));
|
|
|
553 |
ConfigCaissePanel.this.societeId = ((SQLRow) model.getElementAt(0)).getID();
|
|
|
554 |
}
|
|
|
555 |
// Utilisateur
|
18 |
ilm |
556 |
model = ConfigCaissePanel.this.comboUtilisateur.getModel();
|
|
|
557 |
stop = model.getSize();
|
25 |
ilm |
558 |
boolean utilisateurFound = false;
|
18 |
ilm |
559 |
for (int i = 0; i < stop; i++) {
|
|
|
560 |
final SQLRow r = (SQLRow) model.getElementAt(i);
|
|
|
561 |
if (r.getID() == ConfigCaissePanel.this.userId) {
|
|
|
562 |
ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(r);
|
25 |
ilm |
563 |
ConfigCaissePanel.this.userId = r.getID();
|
|
|
564 |
utilisateurFound = true;
|
18 |
ilm |
565 |
break;
|
|
|
566 |
}
|
|
|
567 |
}
|
25 |
ilm |
568 |
|
|
|
569 |
if (!utilisateurFound && stop > 0) {
|
|
|
570 |
ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(model.getElementAt(0));
|
|
|
571 |
ConfigCaissePanel.this.userId = ((SQLRow) model.getElementAt(0)).getID();
|
|
|
572 |
}
|
132 |
ilm |
573 |
final Thread t = new Thread() {
|
|
|
574 |
public void run() {
|
|
|
575 |
reloadCaisses();
|
|
|
576 |
};
|
|
|
577 |
};
|
|
|
578 |
t.start();
|
25 |
ilm |
579 |
|
18 |
ilm |
580 |
}
|
|
|
581 |
|
|
|
582 |
});
|
|
|
583 |
|
|
|
584 |
} catch (final Exception e) {
|
|
|
585 |
e.printStackTrace();
|
80 |
ilm |
586 |
} finally {
|
|
|
587 |
server.destroy();
|
156 |
ilm |
588 |
server.tearDownLogging(true);
|
18 |
ilm |
589 |
}
|
|
|
590 |
}
|
|
|
591 |
});
|
|
|
592 |
t.setDaemon(true);
|
|
|
593 |
t.start();
|
|
|
594 |
}
|
|
|
595 |
});
|
|
|
596 |
}
|
|
|
597 |
|
25 |
ilm |
598 |
public void dumpConfiguration() {
|
|
|
599 |
System.out.println("Societe: id:" + this.societeId);
|
|
|
600 |
System.out.println("Caisse: id:" + this.caisseId);
|
|
|
601 |
System.out.println("Utilisateur: id:" + this.userId);
|
|
|
602 |
}
|
|
|
603 |
|
18 |
ilm |
604 |
public void saveConfiguration() {
|
142 |
ilm |
605 |
final POSConfiguration configuration = this.configuration;
|
132 |
ilm |
606 |
this.ticketPanel1.commitValues();
|
|
|
607 |
this.ticketPanel2.commitValues();
|
|
|
608 |
configuration.setUserID(this.userId);
|
|
|
609 |
configuration.setCompanyID(this.societeId);
|
|
|
610 |
configuration.setPosID(this.caisseId);
|
|
|
611 |
configuration.setHeaderLines(this.headerTable.getLines());
|
|
|
612 |
configuration.setFooterLines(this.footerTable.getLines());
|
|
|
613 |
// Terminal CB
|
|
|
614 |
configuration.setCreditCardPort(this.textTerminalCB.getText());
|
|
|
615 |
// LCD
|
142 |
ilm |
616 |
final int selectedIndex = this.comboLCDType.getSelectedIndex();
|
|
|
617 |
if (selectedIndex == 0) {
|
|
|
618 |
configuration.setLCDType("serial");
|
|
|
619 |
} else {
|
|
|
620 |
configuration.setLCDType("printer");
|
|
|
621 |
}
|
|
|
622 |
configuration.setLCDPort(this.textLCDPort.getText());
|
132 |
ilm |
623 |
configuration.setLCDLine1(this.textLCDLine1.getText());
|
|
|
624 |
configuration.setLCDLine2(this.textLCDLine2.getText());
|
|
|
625 |
// Save
|
|
|
626 |
configuration.saveConfiguration();
|
18 |
ilm |
627 |
}
|
|
|
628 |
}
|