private void AddExpensesButton_Click(object sender, RoutedEventArgs e) { AddExpenses win = new AddExpenses(Budget); win.Show(); this.Close(); }
/// <summary> /// A method that opens AddExpenses window provided the user selected a budget from the ComboBox. /// </summary> private void NewExpenseButton_Click(object sender, RoutedEventArgs e) { Budget Budget = new Budget(null, 0); if (existingBudgets.SelectedItem == null) { MessageBox.Show("You haven't selected a budget!"); } else { Budget = (Budget)existingBudgets.SelectedItem; AddExpenses win = new AddExpenses(Budget); win.Show(); this.Close(); } }
/// <summary> /// A method that creates a budget and saves it to a SQL db and a text file provided the form was filled correctly. /// </summary> private void CreateBudgetButton_Click(object sender, RoutedEventArgs e) { if (ValidateForm()) { decimal balance = decimal.Parse(startingBalance.Text); Budget newBudget = new Budget(budgetName.Text, balance); Entry startingBalanceEntry = new Entry(); /* Create a budget entry for all existing connections: */ if (GlobalConfig.sqlConnection && GlobalConfig.textConnection) { newBudget = GlobalConfig.SQLConnection.SaveBudget(newBudget); // pass the modified budget instance (sql added an unique ID to it) to the text file saver: GlobalConfig.TextFileConnection.SaveBudget(newBudget); if (newBudget.Balance != 0) { startingBalanceEntry = new Entry("Starting Balance", (Double)newBudget.Balance, "UserInput", DateTime.Now, newBudget.Id); startingBalanceEntry = GlobalConfig.SQLConnection.SaveEntry(startingBalanceEntry); GlobalConfig.TextFileConnection.SaveEntry(startingBalanceEntry); } } else if (GlobalConfig.sqlConnection) { newBudget = GlobalConfig.SQLConnection.SaveBudget(newBudget); if (newBudget.Balance != 0) { startingBalanceEntry = new Entry("Starting Balance", (Double)newBudget.Balance, "UserInput", DateTime.Now, newBudget.Id); startingBalanceEntry = GlobalConfig.SQLConnection.SaveEntry(startingBalanceEntry); } } else if (GlobalConfig.textConnection) { newBudget.Id = id; id++; GlobalConfig.TextFileConnection.SaveBudget(newBudget); if (newBudget.Balance != 0) { startingBalanceEntry = new Entry("Starting Balance", (Double)newBudget.Balance, "UserInput", DateTime.Now, newBudget.Id); startingBalanceEntry.Id = entry; GlobalConfig.TextFileConnection.SaveEntry(startingBalanceEntry); } } // reset values: startingBalance.Text = "0"; budgetName.Text = "My Budget"; if (addExpense) { AddExpenses window = new AddExpenses(newBudget); window.Show(); this.Close(); } else { BudgetViewer view = new BudgetViewer(newBudget); view.Show(); this.Close(); } } }