OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 19 Rev 25
Line 77... Line 77...
77
        setOpaque(false);
77
        setOpaque(false);
78
 
78
 
79
        setLayout(new GridBagLayout());
79
        setLayout(new GridBagLayout());
80
        final GridBagConstraints c = new DefaultGridBagConstraints();
80
        final GridBagConstraints c = new DefaultGridBagConstraints();
81
        c.weighty = 0;
81
        c.weighty = 0;
-
 
82
        // Fichier
-
 
83
        c.weightx = 0;
-
 
84
        this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
-
 
85
        c.gridx++;
-
 
86
        c.gridwidth = 3;
-
 
87
        c.weightx = 1;
-
 
88
        JTextField textConfigurationFile = new JTextField("");
-
 
89
        if (Caisse.getConfigFile() != null) {
-
 
90
            textConfigurationFile.setText(Caisse.getConfigFile().getAbsolutePath());
-
 
91
        }
-
 
92
        textConfigurationFile.setEditable(false);
-
 
93
        this.add(textConfigurationFile, c);
-
 
94
 
82
        // Connexion
95
        // Connexion
-
 
96
        c.gridy++;
-
 
97
        c.gridx = 0;
83
        final JLabelBold titleConnexion = new JLabelBold("Connexion");
98
        final JLabelBold titleConnexion = new JLabelBold("Connexion");
84
        c.gridwidth = 2;
99
        c.gridwidth = 2;
85
        this.add(titleConnexion, c);
100
        this.add(titleConnexion, c);
86
        c.gridy++;
101
        c.gridy++;
87
        c.gridwidth = 1;
102
        c.gridwidth = 1;
Line 273... Line 288...
273
        }
288
        }
274
 
289
 
275
        try {
290
        try {
276
            System.out.println("Reloading POS information from: " + config);
291
            System.out.println("Reloading POS information from: " + config);
277
            SQLServer server = config.createServer("Common");
292
            SQLServer server = config.createServer("Common");
278
            DBSystemRoot r = server.getSystemRoot("OpenConcerto");
293
            DBSystemRoot r = server.getSystemRoot(config.getSystemRoot());
279
            DBRoot root = r.getRoot("Common");
294
            DBRoot root = r.getRoot("Common");
280
            // Sociétés
295
            // Sociétés
281
            SQLSelect sel = new SQLSelect(root.getBase());
296
            SQLSelect sel = new SQLSelect(root.getBase());
282
            sel.addSelectStar(root.getTable("SOCIETE_COMMON"));
297
            sel.addSelectStar(root.getTable("SOCIETE_COMMON"));
283
            sel.setWhere("SOCIETE_COMMON.ID", "=", id);
298
            sel.setWhere("SOCIETE_COMMON.ID", "=", id);
Line 285... Line 300...
285
            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
300
            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
286
            server.destroy();
301
            server.destroy();
287
            if (societes.size() > 0) {
302
            if (societes.size() > 0) {
288
                final String name = societes.get(0).getString("DATABASE_NAME");
303
                final String name = societes.get(0).getString("DATABASE_NAME");
289
                server = config.createServer(name);
304
                server = config.createServer(name);
290
                r = server.getSystemRoot("OpenConcerto");
305
                r = server.getSystemRoot(config.getSystemRoot());
291
                root = r.getRoot(name);
306
                root = r.getRoot(name);
292
                // Caisses
307
                // Caisses
293
                sel = new SQLSelect(root.getBase());
308
                sel = new SQLSelect(root.getBase());
294
                sel.addSelectStar(root.getTable("CAISSE"));
309
                sel.addSelectStar(root.getTable("CAISSE"));
295
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
310
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
296
 
-
 
297
                server.destroy();
311
                server.destroy();
298
 
-
 
-
 
312
                // Stock l'id de la caisse pour que la reslectionne soit correcte
-
 
313
                final int idCaisseToSelect = this.caisseId;
299
                SwingUtilities.invokeLater(new Runnable() {
314
                SwingUtilities.invokeLater(new Runnable() {
300
                    @Override
315
                    @Override
301
                    public void run() {
316
                    public void run() {
-
 
317
                        ConfigCaissePanel.this.caisseId = idCaisseToSelect;
302
                        if (caisses.isEmpty()) {
318
                        if (caisses.isEmpty()) {
303
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
319
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
304
                        }
320
                        }
305
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
321
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
306
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
322
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
Line 312... Line 328...
312
                            // nécessité de recuperer l'id
328
                            // nécessité de recuperer l'id
313
                            ConfigCaissePanel.this.caisseId = ((SQLRow) model.getElementAt(0)).getID();
329
                            ConfigCaissePanel.this.caisseId = ((SQLRow) model.getElementAt(0)).getID();
314
                        }
330
                        }
315
                        for (int i = 0; i < stop; i++) {
331
                        for (int i = 0; i < stop; i++) {
316
                            final SQLRow r = (SQLRow) model.getElementAt(i);
332
                            final SQLRow r = (SQLRow) model.getElementAt(i);
317
                            if (r.getID() == ConfigCaissePanel.this.caisseId) {
333
                            if (r.getID() == idCaisseToSelect) {
318
                                ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
334
                                ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
319
                                break;
335
                                break;
320
                            }
336
                            }
321
                        }
337
                        }
322
                    }
338
                    }
Line 373... Line 389...
373
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
389
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
374
                        if (!config.isOnline()) {
390
                        if (!config.isOnline()) {
375
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
391
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
376
                            return;
392
                            return;
377
                        }
393
                        }
378
                        String result = "Erreur de connexion. \n";
-
 
379
                        try {
394
                        try {
380
 
395
 
381
                            final SQLServer server = config.createServer("Common");
396
                            final SQLServer server = config.createServer("Common");
382
                            final DBSystemRoot r = server.getSystemRoot("OpenConcerto");
397
                            final DBSystemRoot r = server.getSystemRoot(config.getSystemRoot());
383
                            final DBRoot root = r.getRoot("Common");
398
                            final DBRoot root = r.getRoot("Common");
384
                            // Sociétés
399
                            // Sociétés
385
                            SQLSelect sel = new SQLSelect(root.getBase());
400
                            SQLSelect sel = new SQLSelect(root.getBase());
386
                            sel.addSelectStar(root.getTable("SOCIETE_COMMON"));
401
                            sel.addSelectStar(root.getTable("SOCIETE_COMMON"));
387
                            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
402
                            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
Line 400... Line 415...
400
                                    ConfigCaissePanel.this.comboUtilisateur.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(utilisateurs)));
415
                                    ConfigCaissePanel.this.comboUtilisateur.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(utilisateurs)));
401
 
416
 
402
                                    ConfigCaissePanel.this.comboSociete.setEnabled(true);
417
                                    ConfigCaissePanel.this.comboSociete.setEnabled(true);
403
                                    ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
418
                                    ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
404
 
419
 
-
 
420
                                    // Societe
405
                                    ComboBoxModel model = ConfigCaissePanel.this.comboSociete.getModel();
421
                                    ComboBoxModel model = ConfigCaissePanel.this.comboSociete.getModel();
406
                                    int stop = model.getSize();
422
                                    int stop = model.getSize();
-
 
423
                                    boolean societeFound = false;
407
                                    for (int i = 0; i < stop; i++) {
424
                                    for (int i = 0; i < stop; i++) {
408
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
425
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
409
                                        if (r.getID() == ConfigCaissePanel.this.societeId) {
426
                                        if (r.getID() == ConfigCaissePanel.this.societeId) {
410
                                            ConfigCaissePanel.this.comboSociete.setSelectedItem(r);
427
                                            ConfigCaissePanel.this.comboSociete.setSelectedItem(r);
-
 
428
                                            ConfigCaissePanel.this.societeId = r.getID();
-
 
429
                                            societeFound = true;
411
                                            break;
430
                                            break;
412
                                        }
431
                                        }
413
                                    }
432
                                    }
-
 
433
 
-
 
434
                                    if (!societeFound && stop > 0) {
-
 
435
                                        ConfigCaissePanel.this.comboSociete.setSelectedItem(model.getElementAt(0));
-
 
436
                                        ConfigCaissePanel.this.societeId = ((SQLRow) model.getElementAt(0)).getID();
-
 
437
                                    }
-
 
438
                                    // Utilisateur
414
                                    model = ConfigCaissePanel.this.comboUtilisateur.getModel();
439
                                    model = ConfigCaissePanel.this.comboUtilisateur.getModel();
415
                                    stop = model.getSize();
440
                                    stop = model.getSize();
-
 
441
                                    boolean utilisateurFound = false;
416
                                    for (int i = 0; i < stop; i++) {
442
                                    for (int i = 0; i < stop; i++) {
417
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
443
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
418
                                        if (r.getID() == ConfigCaissePanel.this.userId) {
444
                                        if (r.getID() == ConfigCaissePanel.this.userId) {
419
                                            ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(r);
445
                                            ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(r);
-
 
446
                                            ConfigCaissePanel.this.userId = r.getID();
-
 
447
                                            utilisateurFound = true;
420
                                            break;
448
                                            break;
421
                                        }
449
                                        }
422
                                    }
450
                                    }
-
 
451
 
-
 
452
                                    if (!utilisateurFound && stop > 0) {
-
 
453
                                        ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(model.getElementAt(0));
-
 
454
                                        ConfigCaissePanel.this.userId = ((SQLRow) model.getElementAt(0)).getID();
-
 
455
                                    }
-
 
456
 
-
 
457
                                    reloadCaisses();
423
                                }
458
                                }
424
 
459
 
425
                            });
460
                            });
426
 
461
 
427
                        } catch (final Exception e) {
462
                        } catch (final Exception e) {
428
                            result += e.getMessage();
-
 
429
                            e.printStackTrace();
463
                            e.printStackTrace();
430
                        }
464
                        }
431
 
465
 
432
                    }
466
                    }
433
                });
467
                });
Line 435... Line 469...
435
                t.start();
469
                t.start();
436
            }
470
            }
437
        });
471
        });
438
    }
472
    }
439
 
473
 
-
 
474
    public void dumpConfiguration() {
-
 
475
        System.out.println("Societe: id:" + this.societeId);
-
 
476
        System.out.println("Caisse: id:" + this.caisseId);
-
 
477
        System.out.println("Utilisateur:  id:" + this.userId);
-
 
478
    }
-
 
479
 
440
    public void saveConfiguration() {
480
    public void saveConfiguration() {
441
        Caisse.setPrinterType(this.comboType.getSelectedItem().toString());
481
        Caisse.setPrinterType(this.comboType.getSelectedItem().toString());
442
        if (this.comboType.getSelectedIndex() == 0) {
482
        if (this.comboType.getSelectedIndex() == 0) {
443
            // JPOS
483
            // JPOS
444
            Caisse.setJPosPrinter(this.textPort.getText());
484
            Caisse.setJPosPrinter(this.textPort.getText());