Mensaje de confirmacion al generarse el informe
This commit is contained in:
@@ -30,7 +30,9 @@ import danielcortes.xyz.views.InformesView;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@@ -55,13 +57,15 @@ public class InformesController {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
String formatedName = month.format(formatter);
|
||||
String capitalized = formatedName.substring(0, 1).toUpperCase() + formatedName.substring(1);
|
||||
File saveFile = askForFile("Informe "+ capitalized);
|
||||
File saveFile = askForFile("Informe " + capitalized);
|
||||
if (saveFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
InformeMensual informeMensual = new InformeMensual(month, saveFile);
|
||||
informeMensual.generarInforme();
|
||||
File generatedFile = informeMensual.generarInforme();
|
||||
|
||||
this.showConfirmation(generatedFile);
|
||||
}
|
||||
|
||||
private LocalDate askForMonth() {
|
||||
@@ -76,7 +80,7 @@ public class InformesController {
|
||||
private File askForFile(String suggestedName) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
chooser.setSelectedFile(new File(suggestedName+".xls"));
|
||||
chooser.setSelectedFile(new File(suggestedName + ".xls"));
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
|
||||
|
||||
if (chooser.showSaveDialog(this.view.getContentPanel()) == JFileChooser.APPROVE_OPTION) {
|
||||
@@ -90,4 +94,22 @@ public class InformesController {
|
||||
}
|
||||
}
|
||||
|
||||
private void showConfirmation(File file) {
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
this.view.getContentPanel(),
|
||||
"El informe se a generado\n" +
|
||||
"¿Desea abrirlo?",
|
||||
"Confirmacion",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (result == 0) {
|
||||
try {
|
||||
Desktop.getDesktop().open(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,16 +133,18 @@ public class InformeMensual {
|
||||
}
|
||||
}
|
||||
|
||||
public void generarInforme(){
|
||||
public File generarInforme(){
|
||||
fillData();
|
||||
fillHeaders();
|
||||
setStyles();
|
||||
|
||||
try (OutputStream fileOut = new FileOutputStream(this.saveFile)) {
|
||||
wb.write(fileOut);
|
||||
return this.saveFile;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user