Сохраняем данные ячеек
This commit is contained in:
@@ -3,6 +3,7 @@ package ru.dmitriymx.corrector1s;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
@@ -10,6 +11,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ import java.util.Map;
|
|||||||
public class Corrector1S {
|
public class Corrector1S {
|
||||||
private class ExcelRecord {
|
private class ExcelRecord {
|
||||||
private String name;
|
private String name;
|
||||||
private String addition;
|
private Integer addition;
|
||||||
private Double data;
|
private Double data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +31,9 @@ public class Corrector1S {
|
|||||||
@Setter
|
@Setter
|
||||||
private double honorarium;
|
private double honorarium;
|
||||||
|
|
||||||
private Map<String, ExcelRecord> mapRecords = new HashMap<>(19); // ожидается 19 записей для сохранения
|
private Map<String, ExcelRecord> mapRecords;
|
||||||
|
private Workbook workbook;
|
||||||
|
private Sheet sheet;
|
||||||
|
|
||||||
private String getFileExtension(File file) {
|
private String getFileExtension(File file) {
|
||||||
int i = file.getAbsolutePath().lastIndexOf('.');
|
int i = file.getAbsolutePath().lastIndexOf('.');
|
||||||
@@ -67,4 +71,28 @@ public class Corrector1S {
|
|||||||
throw new FormatFileException(e);
|
throw new FormatFileException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void createSnapshotData() throws IOException, InvalidFormatException {
|
||||||
|
workbook = WorkbookFactory.create(sourceFile);
|
||||||
|
sheet = workbook.getSheetAt(0);
|
||||||
|
mapRecords = new HashMap<>(19); // ожидается 19 записей для сохранения
|
||||||
|
|
||||||
|
Cell cell;
|
||||||
|
loop:
|
||||||
|
for (int c = 10; true; c++) {
|
||||||
|
ExcelRecord record = new ExcelRecord();
|
||||||
|
|
||||||
|
for (int r = 6; r < 9; r++) {
|
||||||
|
cell = sheet.getRow(r).getCell(c);
|
||||||
|
if (cell == null) break loop;
|
||||||
|
|
||||||
|
if (r == 6) record.name = cell.getStringCellValue();
|
||||||
|
else if (r == 7) record.addition = (int) cell.getNumericCellValue();
|
||||||
|
else record.data = cell.getNumericCellValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = (record.addition == 0 ? record.name : record.name + "_" + record.addition);
|
||||||
|
mapRecords.put(key, record);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class Main {
|
|||||||
corrector1S.setTargetFile(targetFile);
|
corrector1S.setTargetFile(targetFile);
|
||||||
corrector1S.setHonorarium((Double) optionSet.valueOf("fee"));
|
corrector1S.setHonorarium((Double) optionSet.valueOf("fee"));
|
||||||
corrector1S.check();
|
corrector1S.check();
|
||||||
|
corrector1S.createSnapshotData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import ru.dmitriymx.corrector1s.Corrector1S;
|
import ru.dmitriymx.corrector1s.Corrector1S;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -59,6 +60,19 @@ public class MainController {
|
|||||||
return fileChooser;
|
return fileChooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableInterface(boolean value) {
|
||||||
|
if (value) {
|
||||||
|
waitPane.setVisible(false);
|
||||||
|
mainPane.setOpacity(1.0d);
|
||||||
|
mainPane.setDisable(false);
|
||||||
|
} else {
|
||||||
|
mainPane.setDisable(true);
|
||||||
|
mainPane.setOpacity(0.3d);
|
||||||
|
waitPane.setVisible(true);
|
||||||
|
progressBar.setProgress(0d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Alert buildErrorDialog(String title, String text, Exception e) {
|
private Alert buildErrorDialog(String title, String text, Exception e) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
alert.setTitle(title);
|
alert.setTitle(title);
|
||||||
@@ -81,6 +95,14 @@ public class MainController {
|
|||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Alert buildInfoDialog(String title, String text) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.setContentText(text);
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
gonorar.setValueFactory(gonorarValueFactory);
|
gonorar.setValueFactory(gonorarValueFactory);
|
||||||
@@ -104,10 +126,7 @@ public class MainController {
|
|||||||
event -> buildFileChooser(saveAsFilePath).showSaveDialog(stage));
|
event -> buildFileChooser(saveAsFilePath).showSaveDialog(stage));
|
||||||
|
|
||||||
btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> {
|
btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> {
|
||||||
mainPane.setDisable(true);
|
enableInterface(false);
|
||||||
mainPane.setOpacity(0.3d);
|
|
||||||
waitPane.setVisible(true);
|
|
||||||
progressBar.setProgress(0d);
|
|
||||||
|
|
||||||
Runnable runnable = () -> {
|
Runnable runnable = () -> {
|
||||||
Corrector1S corrector = new Corrector1S();
|
Corrector1S corrector = new Corrector1S();
|
||||||
@@ -125,13 +144,26 @@ public class MainController {
|
|||||||
corrector.check();
|
corrector.check();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Analize input data", e);
|
log.error("Analize input data", e);
|
||||||
Alert alert = buildErrorDialog("Ошибка", "Ошибка при анализе входных данных", e);
|
buildErrorDialog("Ошибка", "Ошибка при анализе входных данных", e)
|
||||||
alert.showAndWait();
|
.showAndWait();
|
||||||
|
enableInterface(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
waitPane.setVisible(false);
|
try {
|
||||||
mainPane.setOpacity(1.0d);
|
corrector.createSnapshotData();
|
||||||
mainPane.setDisable(false);
|
} catch (IOException | InvalidFormatException e) {
|
||||||
|
log.error("createSnapshotData", e);
|
||||||
|
buildErrorDialog("Ошибка", "Ошибка при обработке данных", e)
|
||||||
|
.showAndWait();
|
||||||
|
enableInterface(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
progressBar.setProgress(1.0d);
|
||||||
|
buildInfoDialog("Информация", "Преобразование завершено успешно")
|
||||||
|
.showAndWait();
|
||||||
|
enableInterface(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
Platform.runLater(runnable);
|
Platform.runLater(runnable);
|
||||||
|
|||||||
Reference in New Issue
Block a user