174 |
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.invoice.action;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
|
|
|
17 |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
|
|
|
18 |
import org.openconcerto.sql.model.SQLDataSource;
|
|
|
19 |
import org.openconcerto.sql.utils.SQLUtils;
|
|
|
20 |
import org.openconcerto.ui.SwingThreadUtils;
|
|
|
21 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
22 |
|
|
|
23 |
import java.awt.Component;
|
|
|
24 |
import java.awt.FileDialog;
|
|
|
25 |
import java.awt.Frame;
|
|
|
26 |
import java.awt.event.ActionEvent;
|
|
|
27 |
import java.io.File;
|
|
|
28 |
import java.io.IOException;
|
|
|
29 |
import java.sql.SQLException;
|
|
|
30 |
|
|
|
31 |
import javax.swing.AbstractAction;
|
|
|
32 |
import javax.swing.Action;
|
|
|
33 |
import javax.swing.JOptionPane;
|
|
|
34 |
|
|
|
35 |
public class ImportReglementSageAction extends AbstractAction {
|
|
|
36 |
private final EncaisserMontantSQLElement elt;
|
|
|
37 |
|
|
|
38 |
public ImportReglementSageAction(EncaisserMontantSQLElement elt) {
|
|
|
39 |
super();
|
|
|
40 |
this.elt = elt;
|
|
|
41 |
this.putValue(Action.NAME, "Import XML des réglements depuis Sage");
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
@Override
|
|
|
45 |
public void actionPerformed(ActionEvent e) {
|
|
|
46 |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
|
|
|
47 |
final FileDialog fd = new FileDialog(frame, "Import XML des réglements Sage", FileDialog.LOAD);
|
|
|
48 |
if (fd.getFile() != null) {
|
|
|
49 |
try {
|
|
|
50 |
SQLUtils.executeAtomic(this.elt.getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
|
|
|
51 |
@Override
|
|
|
52 |
public Object handle(final SQLDataSource ds) throws SQLException, IOException {
|
|
|
53 |
|
|
|
54 |
ImportReglementSage sageImporter = new ImportReglementSage(ImportReglementSageAction.this.elt);
|
|
|
55 |
try {
|
|
|
56 |
sageImporter.importFromFile(new File(fd.getDirectory(), fd.getFile()));
|
|
|
57 |
} catch (Exception e) {
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
new SQLException(e);
|
|
|
60 |
}
|
|
|
61 |
return null;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
});
|
|
|
65 |
JOptionPane.showMessageDialog(null, "Import des paiements terminés!");
|
|
|
66 |
} catch (IOException exn) {
|
|
|
67 |
ExceptionHandler.handle(frame, "Erreur lors de la lecture du fichier", exn);
|
|
|
68 |
} catch (SQLException exn) {
|
|
|
69 |
ExceptionHandler.handle(frame, "Erreur lors de l'insertion des paiements dans la base", exn);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
}
|
|
|
73 |
fd.setVisible(true);
|
|
|
74 |
|
|
|
75 |
}
|
|
|
76 |
}
|