Beispiel #1
0
        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;
                }
            }
            //Calculate the minimum based on my beautiful formula :)
            decimal minimum = moneySum / (1 - (percentSum / 100));

            //Check if there are more than 2 decimals
            if (Math.Truncate(minimum * 100) != minimum * 100)
            {
                minimum = (Math.Truncate(minimum * 100) + 1) / 100;
            }
            budgetPlan.minimumDeposit = minimum;
            tbMinimumDeposit.Text     = '$' + minimum.ToString();
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (numericUpDown1.Value > 0 && comboBox1.SelectedIndex >= 0)
            {
                Budgeter budgeter = new Budgeter();
                if (rbDollar.Checked)
                {
                    budgeter.type   = 0;
                    budgeter.value  = numericUpDown1.Value;
                    budgeter.budget = Data.getActiveBList().ElementAt(comboBox1.SelectedIndex);
                    budgetPlan.list.Add(budgeter);
                }
                else 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();
            }
        }
Beispiel #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)
                    {
                        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();
        }