private void CalculateMinimum()
        {
            decimal moneySum   = 0;
            decimal percentSum = 0;

            for (int x = 0; x < this.budgetPlan.list.Count; x++)
            {
                Budgeter budgeter = this.budgetPlan.list.ElementAt(x);
                // Add money if it's dollars
                if (budgeter.type == 0)
                {
                    moneySum += budgeter.value;
                }
                // Add percentages if it's percent
                if (budgeter.type == 1)
                {
                    percentSum += budgeter.value;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (numericUpDown1.Value > 0 && comboBox1.SelectedIndex >= 0)
            {
                Budgeter budgeter = new Budgeter();

                if (rbPercent.Checked)
                {
                    budgeter.type = 1;
                    //
                    //Make sure that the percent won't go over 100
                    //

                    //Calculate current percent value
                    decimal percentSum = 0;
                    for (int x = 0; x < this.budgetPlan.list.Count; x++)
                    {
                        Budgeter budgeteer = this.budgetPlan.list.ElementAt(x);

                        // Add percentages if it's percent
                        if (budgeteer.type == 1)
                        {
                            percentSum += budgeteer.value;
                        }
                    }
                    if (percentSum + numericUpDown1.Value >= 100)
                    {
                        MessageBox.Show("Error: This action will cause the total percent allocation to meet or exceed 100%.  Please define a smaller amount or remove a budget.");
                        return;
                    }

                    budgeter.value  = numericUpDown1.Value;
                    budgeter.budget = Data.getActiveBList().ElementAt(comboBox1.SelectedIndex);
                    budgetPlan.list.Add(budgeter);
                }

                CalculateMinimum();
                Update_BudgeterList();
            }
        }
Example #3
0
        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)
                    {
                        if (listView1.SelectedIndices[0] > 0)
                        {
                            Data.getSelectedBudget().balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value));
                            Data.getActiveBList().ElementAt(0).balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value));
                        }
                        else
                        {
                            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 an expense 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);


                    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;
                    Data.totalBudget();
                    //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 income plan to deposit to.");
                }
            }
            else if (rBCapital.Checked)
            {
                if (listView2.SelectedIndices.Count > 0)
                {
                    if (listView2.SelectedIndices[0] >= 0)
                    {
                        if (listView2.SelectedIndices[0] > 0)
                        {
                            Data.getSelectedCapital().balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value));
                            Data.getActiveCList().ElementAt(0).balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value));
                        }
                        else
                        {
                            Data.getSelectedCapital().balance += Convert.ToDecimal(string.Format("{0:0.00}", numericUpDown1.Value));
                        }
                        //Update the display
                        int select = listView2.SelectedIndices[0];
                        Update_Capitalview();
                        listView2.SelectedIndices.Add(select);
                    }
                }
                else
                {
                    MessageBox.Show("Please select a capital source to deposit to");
                }
            }

            Save.Saveall();
        }