public New_BPLan(BudgetPlan oldPlan) { InitializeComponent(); budgetPlan = oldPlan; comboBox1.Items.AddRange(Data.getActiveBList().ToArray()); Update_BudgeterList(); textBox1.Text = oldPlan.name; CalculateMinimum(); this.editing = true; }
private void button1_Click(object sender, EventArgs e) { if (rBBudget.Checked) { //Deposit to Budget //Check if there is a selected index if (listView1.SelectedIndices.Count > 0) { if (listView1.SelectedIndices[0] >= 0) { Data.getSelectedBudget().balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value)); //Update the display int select = listView1.SelectedIndices[0]; Update_Budgetview(); listView1.SelectedIndices.Add(select); } } else { MessageBox.Show("Please select a budget to deposit to"); } } else if (rBPlan.Checked) { //Deposit through plan //Check if plan is selected if (comboBox1.SelectedIndex >= 0) { //get reference to selected plan BudgetPlan plan = Data.getActiveAccount().planList.ElementAt(comboBox1.SelectedIndex); if (numericUpDown1.Value < plan.minimumDeposit) { MessageBox.Show("Deposit is too small for this plan. Please increase deposit amount."); return; } decimal toDefault = numericUpDown1.Value; for (int x = 0; x < plan.list.Count; x++) { Budgeter budgeter = plan.list.ElementAt(x); // Add money if it's dollars if (budgeter.type == 0) { budgeter.budget.balance += budgeter.value; toDefault -= budgeter.value; } //Add money if it's percent if (budgeter.type == 1) { budgeter.budget.balance += numericUpDown1.Value * (budgeter.value / 100); toDefault -= numericUpDown1.Value * (budgeter.value / 100); } } Data.getDefaultBudget().balance += toDefault; //Update the display int select = -1; if (listView1.SelectedIndices.Count > 0) { select = listView1.SelectedIndices[0]; } Update_Budgetview(); if (select > -1) { listView1.SelectedIndices.Add(select); } } else { MessageBox.Show("Please select a budget plan to deposit to."); } } Save.Saveall(); }