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

"Added methods that load and save data in BudgetController"

parent e3144e54
No related branches found
No related tags found
10 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense,!32Added input validation to add dialog boxes.,!30Redesigned scenes,!29Redesigned scenes,!28Redesigned scenes,!26Redesigned Main menu and expense/income windows,!24Merging frontend-testing with master,!23Merging frontend-testing and master
......@@ -14,6 +14,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.BudgetItem;
import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudget;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
......@@ -23,11 +24,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
public class BudgetController {
private DialogMode dialogMode;
private GeneralBudget general = new GeneralBudget(31, 2000);
private GeneralBudget general;
@FXML
private Button addBudget;
......@@ -77,12 +80,13 @@ public class BudgetController {
public void initialize() throws IOException {
budgetList = FXCollections.observableArrayList(general.getBudgetItems());
budgetTableView.setItems(budgetList);
categoryColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, ExpenseCategory>("budgetCategory"));
amountColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, Double>("budgetAmount"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, String>("budgetDescription"));
general = loadIncomeDataFromFile("Budget");
budgetList = FXCollections.observableArrayList(general.getBudgetItems());
budgetTableView.setItems(budgetList);
}
@FXML
public void switchAddBudget(javafx.event.ActionEvent event) throws IOException {
......@@ -167,6 +171,26 @@ public class BudgetController {
}
public GeneralBudget loadIncomeDataFromFile(String fileName) throws IOException {
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
if (fileHandlingBudget.isEmpty(fileName)) {
general = new GeneralBudget(31, 1000);
} else {
try {
general = fileHandlingBudget.readGeneralBudgetFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return general;
}
public void saveDataToFile(String fileName) throws IOException {
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
fileHandlingBudget.writeGeneralBudgetToFile(fileName, general);
}
protected void refreshObservableList(){
budgetTableView.setItems(budgetList);
this.budgetList.setAll(general.getBudgetItems());
......@@ -174,7 +198,7 @@ public class BudgetController {
@FXML
public void switchScene(ActionEvent event) throws IOException {
//saveDataToFile("Income");
//saveDataToFile("Budget");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == expenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
......
......@@ -82,23 +82,22 @@ public class IncomeController {
ObservableList<String> filter;
@FXML
public void initialize()
throws IOException { //TODO SAME REGISTER FOR BOTH, BUT LOAD DIFFERENT DATA DEPENDING ON WHICH IT IS
public void initialize() throws IOException { //TODO SAME REGISTER FOR BOTH, BUT LOAD DIFFERENT DATA DEPENDING ON WHICH IT IS
dateColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("date"));
amountColumn.setCellValueFactory(new PropertyValueFactory<Income, Double>("amount"));
categoryColumn.setCellValueFactory(
new PropertyValueFactory<Income, IncomeCategory>("category"));
categoryColumn.setCellValueFactory(new PropertyValueFactory<Income, IncomeCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Income, Boolean>("recurring"));
filter = FXCollections.observableArrayList("All", "Gift", "Salary", "Student loan",
"Fixed income");
filter = FXCollections.observableArrayList("All", "Gift", "Salary", "Student loan", "Fixed income");
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
show.setItems(filter);
show.setValue("All");
//if budget.register isEmpty -> disable expense
}
@FXML
......@@ -179,10 +178,10 @@ public class IncomeController {
}
public IncomeRegister loadIncomeDataFromFile(String fileName) throws IOException {
//ItemRegister<T extends Item>
FileHandling fileHandling = new FileHandling();
if (fileHandling.isEmpty(fileName)) {
incomeRegister = new IncomeRegister();
System.out.println("hey");
} else {
try {
incomeRegister = fileHandling.readIncomeRegisterFromFile(fileName);
......
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