/// ------------------------------------------------------------- /// public void deleteBudgetAction() { Render.setStatus("Which budget do you want to delete?", false); string deleteTitle = InputHandler.processInput("Title"); Budget deleteBudget = null; foreach (Budget budget in budgets) { if (budget.title.ToLower().Equals(deleteTitle.ToLower())) { deleteBudget = budget; break; } } if (deleteBudget != null && !deleteBudget.title.Equals(currentBudget.title)) { string confirmation = InputHandler.processInput("Confirm deletion (y/n)"); if (confirmation.Equals("y")) { budgets.Remove(deleteBudget); } } }
/// ------------------------------------------------------------- /// public void newGoalAction() { Render.setStatus("savings/debt", false); string input = InputHandler.processInput("Goal type"); bool isSavingsGoal = false; if (input.ToLower().Equals("savings")) { isSavingsGoal = true; } Render.setStatus("Enter " + (isSavingsGoal ? "savings" : "debt") + " goal details", false); string title = InputHandler.processInput("Title"); double amount = InputHandler.processNumberInput("Amount", 0); FinanceItem goal = new FinanceItem(title, amount); if (isSavingsGoal) { this.currentBudget.savingsGoals.Add(goal); } else { this.currentBudget.debtGoals.Add(goal); } }
static void Main(string[] args) { string data = DataLoader.readFileContent(filePath); List <Budget> budgets = DataLoader.csvToBudgets(data); NavigationControl navigation = new NavigationControl(budgets); string inputCommand = ""; while (!inputCommand.ToLower().Equals("exit")) { Render.clearScreen(); Render.renderFrame(); Render.renderStatus(); Render.renderPageInfo(navigation.currentPage.pageInfo, navigation.currentPage.currentBudget.title); navigation.currentPage.renderContent(); inputCommand = InputHandler.processInput("Command"); if (!navigation.navigate(inputCommand)) { navigation.currentPage.handleCommand(inputCommand); } } string storeData = DataLoader.budgetsToCsv(budgets); DataLoader.updateBackup(filePath, backupPath); DataLoader.writeFileContent(storeData, filePath); Render.positionInputCursor(); Console.WriteLine("Bye!"); Console.SetCursorPosition(0, Console.WindowHeight); }
/// ------------------------------------------------------------- /// public void deleteGoalAction() { Render.setStatus("Delete goal?", false); string goalTitle = InputHandler.processInput("Goal title"); FinanceItem goal = null; foreach (FinanceItem savingsGoal in currentBudget.savingsGoals) { if (savingsGoal.title.ToLower().Equals(goalTitle.ToLower())) { goal = savingsGoal; break; } } if (goal != null) { currentBudget.savingsGoals.Remove(goal); return; } foreach (FinanceItem debtGoal in currentBudget.debtGoals) { if (debtGoal.title.ToLower().Equals(goalTitle.ToLower())) { goal = debtGoal; break; } } if (goal != null) { currentBudget.debtGoals.Remove(goal); } }
/// ------------------------------------------------------------- /// public void newBudgetAction() { Render.setStatus("Enter budget title", false); Budget newBudget = new Budget(); newBudget.title = InputHandler.processInput("Title"); budgets.Add(newBudget); }
/// ------------------------------------------------------------- /// public void newItemAction() { Render.setStatus("New budget item", false); string itemTitle = InputHandler.processInput("Title"); double itemAmount = InputHandler.processNumberInput("Amount", 0); currentBudget.monthlyBudgetItems.Add(new FinanceItem(itemTitle, itemAmount)); }
/// ------------------------------------------------------------- /// public void deleteItemAction() { Render.setStatus("Which budget item to delete?", false); string itemName = InputHandler.processInput("Title"); FinanceItem deleteItem = currentBudget.getItem(itemName); if (deleteItem != null) { currentBudget.monthlyBudgetItems.Remove(deleteItem); } }
/// ------------------------------------------------------------- /// public void newLoanAction() { Render.setStatus("New loan", false); string title = InputHandler.processInput("Title"); string abr = InputHandler.processInput("Abr (3 letters)"); double amount = InputHandler.processNumberInput("Amount", 0); double interest = InputHandler.processNumberInput("Interest %", 0); double monthlyPayment = InputHandler.processNumberInput("Monthly payment", 0); currentBudget.addLoan(new Loan(title, abr, amount, interest, monthlyPayment)); }
/// ------------------------------------------------------------- /// public void editItemAction() { Render.setStatus("Which budget item to edit?", false); string itemName = InputHandler.processInput("Title"); FinanceItem editItem = currentBudget.getItem(itemName); if (editItem != null) { Render.setStatus("Edit item (" + editItem.title + ")", false); editItem.amount = InputHandler.processNumberInput("Amount", editItem.amount); } }
/// ------------------------------------------------------------- /// public void deleteLoanAction() { Render.setStatus("Which loan do you want to delete?", false); string abr = InputHandler.processInput("Loan abr."); Loan deleteLoan = currentBudget.getLoan(abr); if (deleteLoan != null) { currentBudget.deleteLoanBudgetItems(deleteLoan); currentBudget.loans.Remove(deleteLoan); } }
/// ------------------------------------------------------------- /// public void editLoanAction() { Render.setStatus("Which loan to edit?", false); string abr = InputHandler.processInput("Loan abr."); Loan editLoan = currentBudget.getLoan(abr); if (editLoan != null) { Render.setStatus("Edit loan (" + editLoan.title + ")", false); editLoan.amount = InputHandler.processNumberInput("Amount", editLoan.amount); editLoan.interestPercentage = InputHandler.processNumberInput("Interest %", editLoan.interestPercentage); editLoan.monthlyPayment = InputHandler.processNumberInput("Monthly payment", editLoan.monthlyPayment); currentBudget.refreshLoanBudgetItems(editLoan); } }
/// ------------------------------------------------------------- /// public void switchBudgetAction() { string budgetTitles = ""; budgets.ForEach(budget => budgetTitles += budget.title + " | "); budgetTitles += "(choose budget)"; Render.setStatus(budgetTitles, false); string budgetTitle = InputHandler.processInput("Switch to"); Budget switchBudget = budgets.Find(budget => budget.title.ToLower().Equals(budgetTitle.ToLower())); if (switchBudget != null) { this.budgetPage.currentBudget = switchBudget; this.dashboardPage.currentBudget = switchBudget; this.forecastPage.currentBudget = switchBudget; } }
/// ------------------------------------------------------------- /// public void editTitleAction() { Render.setStatus("Which budget do you want to edit?", false); string editTitle = InputHandler.processInput("Title"); Budget editBudget = null; foreach (Budget budget in budgets) { if (budget.title.ToLower().Equals(editTitle.ToLower())) { editBudget = budget; break; } } if (editBudget != null) { Render.setStatus("Edit budget (" + editBudget.title + ")", false); editBudget.title = InputHandler.processInput("Title"); } }