|
@@ -1,240 +0,0 @@
|
|
|
-package u8c.ui.excel;
|
|
|
-
|
|
|
-import convert.handler.ReadExcel;
|
|
|
-import java.awt.Container;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import javax.swing.filechooser.FileFilter;
|
|
|
-
|
|
|
-import nc.bs.framework.common.NCLocator;
|
|
|
-import nc.ui.ml.NCLangRes;
|
|
|
-import nc.ui.pub.beans.MessageDialog;
|
|
|
-import nc.ui.pub.beans.UIFileChooser;
|
|
|
-import nc.vo.cache.CacheManager;
|
|
|
-import nc.vo.cache.ICache;
|
|
|
-import nc.vo.cache.config.CacheConfig;
|
|
|
-import nc.vo.pfxx.util.FileUtils;
|
|
|
-import nc.vo.pub.BusinessException;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import u8c.pubitf.invoke.IInvokeWithExcel;
|
|
|
-import u8c.pubitf.invoke.IInvokeWithExportData;
|
|
|
-import u8c.pubitf.query.IQueryAPIDataEntity;
|
|
|
-
|
|
|
-
|
|
|
-public class ExcelFileProcess {
|
|
|
- private ExportDataDialog dlg;
|
|
|
- private Map<String, String> allFields;
|
|
|
- public static String SUFFIX = ".xlsx";
|
|
|
- private UIFileChooser chooser;
|
|
|
- private Container parent;
|
|
|
- private File selectedFile;
|
|
|
-
|
|
|
- public ExcelFileProcess() {
|
|
|
- }
|
|
|
-
|
|
|
- public ExcelFileProcess(Container parent) {
|
|
|
- this.parent = parent;
|
|
|
- }
|
|
|
-
|
|
|
- public void downLoadDefaultFile(String filePath) {
|
|
|
- this.getFileChooser().setSelectedFile(new File(filePath));
|
|
|
- if (1 != this.getFileChooser().showSaveDialog(this.parent)) {
|
|
|
- File file = this.getFileChooser().getSelectedFile();
|
|
|
- if (file == null) {
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000030"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000031"));
|
|
|
- }
|
|
|
-
|
|
|
- String path = file.getAbsolutePath();
|
|
|
- if (!path.endsWith(SUFFIX) && !path.endsWith("xls")) {
|
|
|
- path = path + SUFFIX;
|
|
|
- }
|
|
|
-
|
|
|
- File svaeFile = new File(path);
|
|
|
- if (!svaeFile.exists() || MessageDialog.showYesNoDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000030"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000032")) != 8) {
|
|
|
- CacheConfig cacheConfig = new CacheConfig();
|
|
|
- cacheConfig.setRegionName("HIDE_ITEM_CACHE");
|
|
|
- cacheConfig.setCacheType(4);
|
|
|
- ICache cache = CacheManager.getInstance().getCache(cacheConfig);
|
|
|
- cache.put("downfilepath", path);
|
|
|
- this.selectedFile = new File(path);
|
|
|
- IInvokeWithExcel service = (IInvokeWithExcel) NCLocator.getInstance().lookup(IInvokeWithExcel.class);
|
|
|
-
|
|
|
- try {
|
|
|
- byte[] bytes = service.downloadFile(filePath);
|
|
|
- FileUtils.writeBytesToFile(bytes, path);
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000033"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000034"));
|
|
|
- } catch (IOException var9) {
|
|
|
- MessageDialog.showWarningDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000033"),
|
|
|
- var9.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void importExcelData(String serverName) {
|
|
|
- this.getFileChooser().setCurrentDirectory(this.selectedFile);
|
|
|
- if (1 != this.getFileChooser().showOpenDialog(this.parent)) {
|
|
|
- this.selectedFile = this.getFileChooser().getSelectedFile();
|
|
|
-
|
|
|
- try {
|
|
|
- String[][] datas = (new ReadExcel()).readDataFromFile(this.selectedFile);
|
|
|
- IInvokeWithExcel service = (IInvokeWithExcel) NCLocator.getInstance().lookup(IInvokeWithExcel.class);
|
|
|
- service.importDatas(serverName, datas);
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000035"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000036"));
|
|
|
- } catch (Exception var4) {
|
|
|
- MessageDialog.showErrorDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000035"), var4.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public String importExcelDataHaveReturn(String serverName) {
|
|
|
- this.getFileChooser().setCurrentDirectory(this.selectedFile);
|
|
|
- if (1 == this.getFileChooser().showOpenDialog(this.parent)) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.selectedFile = this.getFileChooser().getSelectedFile();
|
|
|
-
|
|
|
- try {
|
|
|
- String[][] datas = (new ReadExcel()).readDataFromFile(this.selectedFile);
|
|
|
- IInvokeWithExcel service = (IInvokeWithExcel) NCLocator.getInstance().lookup(IInvokeWithExcel.class);
|
|
|
- return service.importDatas(serverName, datas);
|
|
|
- } catch (Exception var4) {
|
|
|
- MessageDialog.showErrorDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000035"), var4.getMessage());
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void exportExcelData(String billmark, String serverName, String[] ids)
|
|
|
- throws IOException, BusinessException {
|
|
|
- if (ids != null && ids.length != 0) {
|
|
|
- Map<String, String> fieldsData = (Map) (new ExportDataCache()).getExportFieldsCache()
|
|
|
- .get("FIELDS_DATAS_" + billmark);
|
|
|
- if (fieldsData == null) {
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000037"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000039"));
|
|
|
- } else {
|
|
|
- this.getFileChooser().setSelectedFile(new File("default.xlsx"));
|
|
|
- if (1 != this.getFileChooser().showSaveDialog(this.parent)) {
|
|
|
- File file = this.getFileChooser().getSelectedFile();
|
|
|
- if (file == null) {
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000030"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000031"));
|
|
|
- }
|
|
|
-
|
|
|
- String path = file.getAbsolutePath();
|
|
|
- if (!path.endsWith(SUFFIX)) {
|
|
|
- path = path + SUFFIX;
|
|
|
- }
|
|
|
-
|
|
|
- File saveFile = new File(path);
|
|
|
- if (!saveFile.exists() || MessageDialog.showYesNoDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000030"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000032")) != 8) {
|
|
|
- IInvokeWithExportData service = (IInvokeWithExportData) NCLocator.getInstance()
|
|
|
- .lookup(IInvokeWithExportData.class);
|
|
|
- Object[][] exportData = (Object[][]) service.exportDatas(fieldsData, serverName, ids);
|
|
|
- WriteToExcel write = new WriteToExcel();
|
|
|
- Workbook workbook = write.putArrayToWorkbook(exportData);
|
|
|
- write.writeToFile(file, workbook);
|
|
|
-
|
|
|
- try {
|
|
|
- byte[] bytes = FileUtils.getByteFromFile(file);
|
|
|
- FileUtils.writeBytesToFile(bytes, path);
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000040"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000041"));
|
|
|
- } catch (IOException var13) {
|
|
|
- MessageDialog.showWarningDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000040"),
|
|
|
- var13.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000037"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000038"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void onExportDataSetting(String billmark, Map<String, String> mustFields) throws BusinessException {
|
|
|
- if (this.allFields == null) {
|
|
|
- IQueryAPIDataEntity service = (IQueryAPIDataEntity) NCLocator.getInstance()
|
|
|
- .lookup(IQueryAPIDataEntity.class);
|
|
|
- this.allFields = service.queryPropertyByBillmark(billmark);
|
|
|
- if (this.allFields == null) {
|
|
|
- MessageDialog.showHintDlg(this.parent,
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000040"),
|
|
|
- NCLangRes.getInstance().getStrByID("excelimport", "UPPexcelimport-000042"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (this.dlg == null) {
|
|
|
- this.dlg = new ExportDataDialog(this.allFields, mustFields, this.parent, billmark);
|
|
|
- }
|
|
|
-
|
|
|
- this.dlg.showModal();
|
|
|
- }
|
|
|
-
|
|
|
- private UIFileChooser getFileChooser() {
|
|
|
- if (this.chooser == null) {
|
|
|
- CacheConfig cacheConfig = new CacheConfig();
|
|
|
- cacheConfig.setRegionName("HIDE_ITEM_CACHE");
|
|
|
- cacheConfig.setCacheType(4);
|
|
|
- ICache cache = CacheManager.getInstance().getCache(cacheConfig);
|
|
|
- Object obj = cache.get("downfilepath");
|
|
|
- if (obj == null) {
|
|
|
- this.chooser = new UIFileChooser();
|
|
|
- } else {
|
|
|
- this.chooser = new UIFileChooser(obj.toString());
|
|
|
- }
|
|
|
-
|
|
|
- this.chooser.setFileSelectionMode(0);
|
|
|
- this.chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
|
|
|
-
|
|
|
- public boolean accept(File f) {
|
|
|
- if (f.isDirectory()
|
|
|
- || f.getName().toLowerCase().endsWith("xls")) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public String getDescription() {
|
|
|
- return "Excel文件(xls)";
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- return this.chooser;
|
|
|
- }
|
|
|
-
|
|
|
- public File getSelectedFile() {
|
|
|
- return this.selectedFile;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSelectedFile(File selectedFile) {
|
|
|
- this.selectedFile = selectedFile;
|
|
|
- }
|
|
|
-}
|