Cambiada la libreria utilizada para manejar los archivos del informe, se usa NIO ahora y deberia estar solucionado los errores con windows.
This commit is contained in:
797
.idea/workspace.xml
generated
797
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
13
caja.iml
13
caja.iml
@@ -4,6 +4,7 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
@@ -24,5 +25,17 @@
|
|||||||
</orderEntry>
|
</orderEntry>
|
||||||
<orderEntry type="library" name="org.mariuszgromada.math:MathParser.org-mXparser:4.2.0" level="project" />
|
<orderEntry type="library" name="org.mariuszgromada.math:MathParser.org-mXparser:4.2.0" level="project" />
|
||||||
<orderEntry type="library" name="org.apache.poi:poi:4.0.1" level="project" />
|
<orderEntry type="library" name="org.apache.poi:poi:4.0.1" level="project" />
|
||||||
|
<orderEntry type="module-library" scope="TEST">
|
||||||
|
<library name="JUnit5.3">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.0-M1/junit-jupiter-api-5.4.0-M1.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.0-M1/junit-platform-commons-1.4.0-M1.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
BIN
dist/caja.jar
vendored
BIN
dist/caja.jar
vendored
Binary file not shown.
@@ -38,6 +38,10 @@ import javax.swing.filechooser.FileNameExtensionFilter;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@@ -64,13 +68,13 @@ public class InformesController {
|
|||||||
String formatedName = month.format(formatter);
|
String formatedName = month.format(formatter);
|
||||||
String capitalized = StringUtils.toUpperCase(formatedName);
|
String capitalized = StringUtils.toUpperCase(formatedName);
|
||||||
|
|
||||||
File saveFile = askForFile("Libro " + capitalized);
|
Path saveFile = askForFile("Libro " + capitalized);
|
||||||
if (saveFile == null) {
|
if (saveFile == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InformeLibroDeVentas informe = new InformeLibroDeVentas(month, saveFile);
|
InformeLibroDeVentas informe = new InformeLibroDeVentas(month, saveFile);
|
||||||
File generatedFile = informe.generarInforme();
|
Path generatedFile = informe.generarInforme();
|
||||||
|
|
||||||
this.showConfirmation(generatedFile);
|
this.showConfirmation(generatedFile);
|
||||||
}
|
}
|
||||||
@@ -89,13 +93,13 @@ public class InformesController {
|
|||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||||
String formatedMonth = month.format(formatter);
|
String formatedMonth = month.format(formatter);
|
||||||
|
|
||||||
File saveFile = askForFile("Informe Egresos - " + tipoEgreso.getNombre() + " - " + StringUtils.toUpperCase(formatedMonth));
|
Path saveFile = askForFile("Informe Egresos - " + tipoEgreso.getNombre() + " - " + StringUtils.toUpperCase(formatedMonth));
|
||||||
if (saveFile == null) {
|
if (saveFile == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InformeEgresos informe = new InformeEgresos(tipoEgreso.getId(), month, saveFile);
|
InformeEgresos informe = new InformeEgresos(tipoEgreso.getId(), month, saveFile);
|
||||||
File generatedFile = informe.generarInforme();
|
Path generatedFile = informe.generarInforme();
|
||||||
|
|
||||||
this.showConfirmation(generatedFile);
|
this.showConfirmation(generatedFile);
|
||||||
}
|
}
|
||||||
@@ -118,28 +122,58 @@ public class InformesController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File askForFile(String suggestedName) {
|
private Path askForFile(String suggestedName) {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||||
chooser.setSelectedFile(new File(suggestedName + ".xls"));
|
chooser.setSelectedFile(new File(suggestedName + ".xls"));
|
||||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
|
chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
|
||||||
|
|
||||||
if (chooser.showSaveDialog(this.view.getContentPanel()) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showSaveDialog(this.view.getContentPanel()) == JFileChooser.APPROVE_OPTION) {
|
||||||
String filename = chooser.getSelectedFile().getPath();
|
String pathString = chooser.getSelectedFile().getPath();
|
||||||
if (!FileUtils.isValidPath(filename)) {
|
|
||||||
JOptionPane.showMessageDialog(this.view.getContentPanel(),"El archivo seleccionado no es valido","Archivo no valido", JOptionPane.ERROR_MESSAGE);
|
if (!pathString.endsWith(".xls")) {
|
||||||
return null;
|
pathString = pathString + ".xls";
|
||||||
} else if (!filename.endsWith(".xls")) {
|
|
||||||
filename += ".xls";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new File(filename);
|
|
||||||
|
Path path = Paths.get(pathString);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.createFile(path);
|
||||||
|
} catch (FileAlreadyExistsException e) {
|
||||||
|
int response = JOptionPane.showConfirmDialog(
|
||||||
|
this.view.getContentPanel(),
|
||||||
|
"El archivo ya existe\n¿Desea sobreescribirlo?",
|
||||||
|
"Confirmacion",
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.WARNING_MESSAGE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response != 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
this.view.getContentPanel(),
|
||||||
|
"No a sido posible crear el archivo",
|
||||||
|
"Error!",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showConfirmation(File file) {
|
private void showConfirmation(Path path) {
|
||||||
int result = JOptionPane.showConfirmDialog(
|
int result = JOptionPane.showConfirmDialog(
|
||||||
this.view.getContentPanel(),
|
this.view.getContentPanel(),
|
||||||
"El informes se a generado\n" +
|
"El informes se a generado\n" +
|
||||||
@@ -148,9 +182,10 @@ public class InformesController {
|
|||||||
JOptionPane.YES_NO_OPTION,
|
JOptionPane.YES_NO_OPTION,
|
||||||
JOptionPane.QUESTION_MESSAGE
|
JOptionPane.QUESTION_MESSAGE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
try {
|
try {
|
||||||
Desktop.getDesktop().open(file);
|
Desktop.getDesktop().open(path.toFile());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -51,7 +53,7 @@ public class InformeEgresos {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private List<InformeEgresosContent> informe;
|
private List<InformeEgresosContent> informe;
|
||||||
private File saveFile;
|
private Path saveFile;
|
||||||
|
|
||||||
//Filas donde se almacenaran los totales
|
//Filas donde se almacenaran los totales
|
||||||
private ArrayList<Row> totalRows;
|
private ArrayList<Row> totalRows;
|
||||||
@@ -68,7 +70,7 @@ public class InformeEgresos {
|
|||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeEgresos(int tipoEgresoId, LocalDate date, File saveFile) {
|
public InformeEgresos(int tipoEgresoId, LocalDate date, Path saveFile) {
|
||||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
new SQLiteCajaDAO().createCajasForMonth(date);
|
||||||
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
|
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
|
||||||
this.saveFile = saveFile;
|
this.saveFile = saveFile;
|
||||||
@@ -275,7 +277,7 @@ public class InformeEgresos {
|
|||||||
return styles;
|
return styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File generarInforme() {
|
public Path generarInforme() {
|
||||||
fillHeaders();
|
fillHeaders();
|
||||||
fillData();
|
fillData();
|
||||||
fillTotales();
|
fillTotales();
|
||||||
@@ -283,7 +285,7 @@ public class InformeEgresos {
|
|||||||
setStyles();
|
setStyles();
|
||||||
addBorders();
|
addBorders();
|
||||||
|
|
||||||
try (OutputStream fileOut = new FileOutputStream(this.saveFile)) {
|
try (OutputStream fileOut = Files.newOutputStream(this.saveFile)){
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
return this.saveFile;
|
return this.saveFile;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -67,14 +69,14 @@ public class InformeLibroDeVentas {
|
|||||||
|
|
||||||
private ArrayList<InformeLibroDeVentasContent> informe;
|
private ArrayList<InformeLibroDeVentasContent> informe;
|
||||||
private int informeSize;
|
private int informeSize;
|
||||||
private File saveFile;
|
private Path saveFile;
|
||||||
|
|
||||||
private Workbook wb;
|
private Workbook wb;
|
||||||
private Sheet sheet;
|
private Sheet sheet;
|
||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeLibroDeVentas(LocalDate date, File saveFile) {
|
public InformeLibroDeVentas(LocalDate date, Path saveFile) {
|
||||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
new SQLiteCajaDAO().createCajasForMonth(date);
|
||||||
|
|
||||||
this.informe = new ArrayList<>(new SQLiteInformeLibroDeVentasContentDAO().getInformeMensual(date));
|
this.informe = new ArrayList<>(new SQLiteInformeLibroDeVentasContentDAO().getInformeMensual(date));
|
||||||
@@ -298,7 +300,7 @@ public class InformeLibroDeVentas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public File generarInforme() {
|
public Path generarInforme() {
|
||||||
sortInforme();
|
sortInforme();
|
||||||
fillData();
|
fillData();
|
||||||
fillHeaders();
|
fillHeaders();
|
||||||
@@ -308,7 +310,7 @@ public class InformeLibroDeVentas {
|
|||||||
setStyles();
|
setStyles();
|
||||||
addBorders();
|
addBorders();
|
||||||
|
|
||||||
try (OutputStream fileOut = new FileOutputStream(this.saveFile)) {
|
try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) {
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
return this.saveFile;
|
return this.saveFile;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -24,15 +24,17 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.utils;
|
package danielcortes.xyz.utils;
|
||||||
|
|
||||||
import java.nio.file.InvalidPathException;
|
import java.io.File;
|
||||||
import java.nio.file.Paths;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
public static boolean isValidPath(String path) {
|
public static boolean isValidPath(String path) {
|
||||||
|
File file = new File(path);
|
||||||
try {
|
try {
|
||||||
Paths.get(path);
|
//noinspection ResultOfMethodCallIgnored
|
||||||
} catch (InvalidPathException | NullPointerException ex) {
|
file.getCanonicalPath();
|
||||||
ex.printStackTrace();
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user