Ahora si los errores relacionados con archivo son tratados correctamente :3!
This commit is contained in:
BIN
dist/Programa Caja.jar
vendored
Normal file
BIN
dist/Programa Caja.jar
vendored
Normal file
Binary file not shown.
@@ -27,7 +27,6 @@ package danielcortes.xyz.controllers;
|
|||||||
import danielcortes.xyz.informes.InformeEgresos;
|
import danielcortes.xyz.informes.InformeEgresos;
|
||||||
import danielcortes.xyz.informes.InformeLibroDeVentas;
|
import danielcortes.xyz.informes.InformeLibroDeVentas;
|
||||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||||
import danielcortes.xyz.utils.FileUtils;
|
|
||||||
import danielcortes.xyz.utils.StringUtils;
|
import danielcortes.xyz.utils.StringUtils;
|
||||||
import danielcortes.xyz.views.MonthSelectDialog;
|
import danielcortes.xyz.views.MonthSelectDialog;
|
||||||
import danielcortes.xyz.views.InformesView;
|
import danielcortes.xyz.views.InformesView;
|
||||||
@@ -38,10 +37,7 @@ 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.*;
|
||||||
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;
|
||||||
|
|
||||||
@@ -129,15 +125,54 @@ public class InformesController {
|
|||||||
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 pathString = chooser.getSelectedFile().getPath();
|
return processFilePath(chooser.getSelectedFile().getPath());
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showConfirmation(Path path) {
|
||||||
|
int result = JOptionPane.showConfirmDialog(
|
||||||
|
this.view.getContentPanel(),
|
||||||
|
"El informes se a generado\n" +
|
||||||
|
"¿Desea abrirlo?",
|
||||||
|
"Confirmacion",
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.QUESTION_MESSAGE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().open(path.toFile());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path processFilePath(String pathString){
|
||||||
|
Path path;
|
||||||
|
|
||||||
if (!pathString.endsWith(".xls")) {
|
if (!pathString.endsWith(".xls")) {
|
||||||
pathString = pathString + ".xls";
|
pathString = pathString + ".xls";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
path = Paths.get(pathString);
|
||||||
|
}catch (InvalidPathException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
Path path = Paths.get(pathString);
|
JOptionPane.showMessageDialog(
|
||||||
|
this.view.getContentPanel(),
|
||||||
|
"El nombre de archivo entregado es invalido",
|
||||||
|
"Error!",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.createFile(path);
|
Files.createFile(path);
|
||||||
@@ -167,29 +202,5 @@ public class InformesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showConfirmation(Path path) {
|
|
||||||
int result = JOptionPane.showConfirmDialog(
|
|
||||||
this.view.getContentPanel(),
|
|
||||||
"El informes se a generado\n" +
|
|
||||||
"¿Desea abrirlo?",
|
|
||||||
"Confirmacion",
|
|
||||||
JOptionPane.YES_NO_OPTION,
|
|
||||||
JOptionPane.QUESTION_MESSAGE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
try {
|
|
||||||
Desktop.getDesktop().open(path.toFile());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user