177 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
177 |
ilm |
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 |
/*
|
|
|
15 |
* Créé le 23 avr. 2012
|
|
|
16 |
*/
|
|
|
17 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
|
|
18 |
|
|
|
19 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
20 |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
|
|
|
21 |
import org.openconcerto.sql.model.SQLDataSource;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
23 |
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
|
|
|
24 |
import org.openconcerto.sql.utils.SQLUtils;
|
|
|
25 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
26 |
import org.openconcerto.ui.SwingThreadUtils;
|
|
|
27 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
28 |
|
|
|
29 |
import java.awt.Component;
|
|
|
30 |
import java.awt.FileDialog;
|
|
|
31 |
import java.awt.Frame;
|
|
|
32 |
import java.awt.GridBagConstraints;
|
|
|
33 |
import java.awt.GridBagLayout;
|
|
|
34 |
import java.awt.Window;
|
|
|
35 |
import java.awt.event.ActionEvent;
|
|
|
36 |
import java.io.File;
|
|
|
37 |
import java.io.IOException;
|
|
|
38 |
import java.sql.SQLException;
|
|
|
39 |
|
|
|
40 |
import javax.swing.AbstractAction;
|
|
|
41 |
import javax.swing.JButton;
|
|
|
42 |
import javax.swing.JLabel;
|
|
|
43 |
import javax.swing.JOptionPane;
|
|
|
44 |
import javax.swing.JPanel;
|
|
|
45 |
import javax.swing.SwingUtilities;
|
|
|
46 |
|
|
|
47 |
public class ImportInventairePanel extends JPanel {
|
|
|
48 |
|
|
|
49 |
public ImportInventairePanel(final SQLElement depotElt) {
|
|
|
50 |
super(new GridBagLayout());
|
|
|
51 |
|
|
|
52 |
final SQLRequestComboBox boxDepot = new SQLRequestComboBox(false);
|
|
|
53 |
boxDepot.uiInit(depotElt.createComboRequest());
|
|
|
54 |
|
|
|
55 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
56 |
JLabel labelCom = new JLabel("Dépôt ");
|
|
|
57 |
this.add(labelCom, c);
|
|
|
58 |
c.gridx++;
|
|
|
59 |
this.add(boxDepot, c);
|
|
|
60 |
|
|
|
61 |
// final JDate dateDeb = new JDate();
|
|
|
62 |
// this.add(dateDeb, c);
|
|
|
63 |
// c.gridx++;
|
|
|
64 |
// JLabel labelD = new JLabel("Début au");
|
|
|
65 |
// final JDate dateDebut = new JDate();
|
|
|
66 |
|
|
|
67 |
final JButton buttonValid = new JButton(new AbstractAction("Valider") {
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public void actionPerformed(ActionEvent e) {
|
|
|
71 |
SQLRowAccessor row = boxDepot.getSelectedRow();
|
|
|
72 |
final SQLRowAccessor rowDepot;
|
|
|
73 |
if (row != null && !row.isUndefined()) {
|
|
|
74 |
rowDepot = boxDepot.getSelectedRow();
|
|
|
75 |
} else {
|
|
|
76 |
rowDepot = depotElt.getTable().getRow(DepotStockSQLElement.DEFAULT_ID);
|
|
|
77 |
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
((Window) SwingUtilities.getRoot(ImportInventairePanel.this)).dispose();
|
|
|
81 |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
|
|
|
82 |
final FileDialog fd = new FileDialog(frame, "Import Inventaire", FileDialog.LOAD);
|
|
|
83 |
fd.setVisible(true);
|
|
|
84 |
if (fd.getFile() != null) {
|
|
|
85 |
final File f = new File(fd.getDirectory(), fd.getFile());
|
|
|
86 |
if (!f.exists()) {
|
|
|
87 |
JOptionPane.showMessageDialog(null, "Le ficher selectionné n'existe pas", "Erreur", JOptionPane.ERROR_MESSAGE);
|
|
|
88 |
} else if (f.isDirectory()) {
|
|
|
89 |
JOptionPane.showMessageDialog(null, "Le fichier selectionné n'est pas valide", "Erreur", JOptionPane.ERROR_MESSAGE);
|
|
|
90 |
} else {
|
|
|
91 |
new Thread(new Runnable() {
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void run() {
|
182 |
ilm |
95 |
// FIXME ajouter une barre de progression
|
185 |
ilm |
96 |
final InventaireFromEtatStockImporter impoter = new InventaireFromEtatStockImporter(depotElt.getDirectory().getElement("ARTICLE"));
|
177 |
ilm |
97 |
try {
|
|
|
98 |
SQLUtils.executeAtomic(depotElt.getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
|
|
|
99 |
@Override
|
|
|
100 |
public Object handle(final SQLDataSource ds) throws SQLException, IOException {
|
|
|
101 |
|
|
|
102 |
impoter.importArticles(f, depotElt.getTable().getDBRoot());
|
|
|
103 |
return null;
|
|
|
104 |
}
|
|
|
105 |
});
|
|
|
106 |
} catch (Exception e1) {
|
|
|
107 |
ExceptionHandler.handle("Erreur lors de l'importation", e1);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
}
|
|
|
111 |
}).start();
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
});
|
|
|
117 |
c.gridx++;
|
|
|
118 |
// buttonValid.setEnabled(false);
|
|
|
119 |
this.add(buttonValid, c);
|
|
|
120 |
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
}
|