Skip to content
Snippets Groups Projects
Commit 3485ec33 authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Fixed load error by moving saveDataToFile inside if blocks

parent dd03d354
Branches feat/SignUp
No related tags found
1 merge request!43Merging frontend-testing into master
...@@ -51,8 +51,6 @@ public class BudgetController extends FinanceController { ...@@ -51,8 +51,6 @@ public class BudgetController extends FinanceController {
@FXML @FXML
private Button returnToMainMenuBtn; private Button returnToMainMenuBtn;
@FXML
private Button returnBtn;
@FXML @FXML
private Button backBtn; private Button backBtn;
...@@ -303,22 +301,21 @@ public class BudgetController extends FinanceController { ...@@ -303,22 +301,21 @@ public class BudgetController extends FinanceController {
public void switchScene(ActionEvent event) { public void switchScene(ActionEvent event) {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
try { try {
if (event.getSource() == returnToMainMenuBtn || event.getSource() == continueBtn) { if (event.getSource() == returnToMainMenuBtn) {
//Adds unused categories to the table //Adds unused categories to the table
System.out.println(general.getBudgetItems().size());
general.addUnusedCategories(); general.addUnusedCategories();
System.out.println(general.getBudgetItems().size()); loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
//Always saving the data when switching scenes //Always saving the data when switching scenes
saveDataToFile();
} else if (event.getSource() == continueBtn) {
general.addUnusedCategories();
updateBudgetRegister(FileHandlingSelectedBudget.readSelectedBudget()); updateBudgetRegister(FileHandlingSelectedBudget.readSelectedBudget());
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml")); loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
//Always saving the data when switching scenes
saveDataToFile();
} else if (event.getSource() == backBtn) { } else if (event.getSource() == backBtn) {
loader.setLocation(getClass().getResource("/view/dualList.fxml")); loader.setLocation(getClass().getResource("/view/dualList.fxml"));
} else if (event.getSource() == returnBtn) {
loader.setLocation(getClass().getResource("/view/FirstMenu.fxml"));
FileHandlingBudgetArchive.deleteBudgetDirectory(FileHandlingSelectedBudget.readSelectedBudget());
FileHandlingSelectedBudget.clearSelectedBudget();
} }
saveDataToFile();
Parent root = loader.load(); Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root); Scene scene = new Scene(root);
......
...@@ -17,6 +17,7 @@ public class BudgetRegister { ...@@ -17,6 +17,7 @@ public class BudgetRegister {
public void addBudgetName(String name) { public void addBudgetName(String name) {
if (name == null) throw new IllegalArgumentException("Name cannot be null"); if (name == null) throw new IllegalArgumentException("Name cannot be null");
if (name.isBlank()) throw new IllegalArgumentException("Name cannot be blank"); if (name.isBlank()) throw new IllegalArgumentException("Name cannot be blank");
//if(budgetNames.contains(name)) throw new IllegalArgumentException("Duplicate entry");
budgetNames.add(name); budgetNames.add(name);
} }
......
...@@ -7,17 +7,38 @@ import java.io.FileReader; ...@@ -7,17 +7,38 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
//Disable next i dualList før income har blitt lagt til. Kanksje filter som prevneter negativ max amount (if balance < 1)
//Disable next i newBudgetbert til maxamount har blitt burkt opp
//Sette label til total balance i dualList
//HVIS CONTINUE I BUDGET PRESSES, SHOWCONFIRMATION
//VIKTIG_ BALANCE LABEL ER RØD PÅ GRØNN BAKGRUNN!!!
//Binde label to total balance i budget window (newBUdgetBert)
//Popup for edit og delete button
//La next button save dataene i to nye filer for persisterign i tilfelle "back" trykkes i newBudgetbudget
//confirmation for når returnBtn som returner til start. "Are you sure you want to go back. Changes will not be saved"
// FIKSE TRY CATCHES I ALLE METODENE!!!!!!!!!!
//tester for nye klasserr
//resize fordi tabellkolonner er for små, fontsize, font
//set all windows unresizable
//Bytte oversikt på dualList til Monthly ....
//System.out.println(System.getProperty("user.dir") + path); =
//C:\Users\xulr0\IdeaProjects\skoleProsjekter\idatt1002\idatt1002_2023_9src/main/resources/
//(System.getProperty("user.dir") + "/" + path) =
//(path) =
//(src/main/resources)
public class FileHandlingBudgetArchive { public class FileHandlingBudgetArchive {
private static final String filePath = "src/main/resources/budgets/"; private static final String filePath = "src/main/resources/budgets/";
private static final String fileType = ".archive"; private static final String fileType = ".archive";
public static void writeBudgetRegisterToArchive(BudgetRegister budgetNames) throws IOException { public static void writeBudgetRegisterToArchive(BudgetRegister budgetNames) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + "Archive" + fileType))) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + "Archive" + fileType))) {
System.out.println(filePath + "Archive.txt"); System.out.println(filePath + "Archive.archive");
bw.write(budgetNames.toString()); bw.write(budgetNames.toString());
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
throw new IOException("Could not write to file: Archive.txt", ioe); throw new IOException("Could not write to file: Archive.archive", ioe);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment