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,44 +125,8 @@ 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());
|
||||||
|
|
||||||
if (!pathString.endsWith(".xls")) {
|
|
||||||
pathString = pathString + ".xls";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -192,4 +152,55 @@ public class InformesController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path processFilePath(String pathString){
|
||||||
|
Path path;
|
||||||
|
|
||||||
|
if (!pathString.endsWith(".xls")) {
|
||||||
|
pathString = pathString + ".xls";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
path = Paths.get(pathString);
|
||||||
|
}catch (InvalidPathException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(
|
||||||
|
this.view.getContentPanel(),
|
||||||
|
"El nombre de archivo entregado es invalido",
|
||||||
|
"Error!",
|
||||||
|
JOptionPane.ERROR_MESSAGE
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user