Ejemplo n.º 1
0
        private void calculateButton_Click(object sender, EventArgs e)
        {
            BudgetPlanChecker planChecker = new BudgetPlanChecker();

            if (calculationModeComboBox.SelectedIndex == 1)
            {
                int inputPercentage = Convert.ToInt32(inputValueOrPercentageTextBox.Text);

                //Checks if the percentage input value exceds 100%(only if the "Input percentage to value" mode is selected)
                if (inputPercentage > 100)
                {
                    MessageBox.Show("The input percentage cannot exceed 100%! Please change the value and try again.", "Plan management calculator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                int totalIncomes = Convert.ToInt32(totalIncomesTextBox.Text);

                int result = planChecker.calculateValueFromPercentage(totalIncomes, inputPercentage);

                resultTextBox.Text = Convert.ToString(result);
            }
            else if (calculationModeComboBox.SelectedIndex == 2)
            {
                int inputValue   = Convert.ToInt32(inputValueOrPercentageTextBox.Text);
                int totalIncomes = Convert.ToInt32(totalIncomesTextBox.Text);

                int result = planChecker.calculateCurrentItemPercentageValue(inputValue, totalIncomes);

                resultTextBox.Text = Convert.ToString(result);
            }
        }
Ejemplo n.º 2
0
        //Method for creating a tuple array based on the data extracted from the DataTable object
        private Tuple <String, int, int, int, int, int>[] prepareDataForInfoGridView(int[] extractedData)
        {
            if (extractedData == null)
            {
                return(null);
            }


            BudgetPlanChecker planChecker = new BudgetPlanChecker();
            String            item1       = "Expenses";
            String            item2       = "Debts";
            String            item3       = "Savings";

            //Data extracted from the array provided as argument
            int totalExpenses           = extractedData[0];
            int expensesPercentageLimit = extractedData[1];
            int totalDebts             = extractedData[2];
            int debtsPercentageLimit   = extractedData[3];
            int totalSavings           = extractedData[4];
            int savingsPercentageLimit = extractedData[5];
            int totalIncomes           = extractedData[6];

            //Max value limit calculation for each item
            int maxValueExpenses = planChecker.calculateMaxLimitValue(totalIncomes, expensesPercentageLimit);
            int maxValueDebts    = planChecker.calculateMaxLimitValue(totalIncomes, debtsPercentageLimit);
            int maxValueSavings  = planChecker.calculateMaxLimitValue(totalIncomes, savingsPercentageLimit);

            //Calculating the current percentage of each item from the previously calculated max limit value
            int expensesPercentageFromMaxValue = planChecker.calculateCurrentItemPercentageValue(totalExpenses, maxValueExpenses);
            int debtsPercentageFromMaxValue    = planChecker.calculateCurrentItemPercentageValue(totalDebts, maxValueDebts);
            int savingsPercentageFromMaxValue  = planChecker.calculateCurrentItemPercentageValue(totalSavings, maxValueSavings);

            //Creating the tuple containing the data that will be used to fill the DataGridView that displays the info about the currently selected budget plan
            Tuple <String, int, int, int, int, int>[] gridViewData =
            {
                new Tuple <String, int, int, int, int, int> (item1, totalExpenses, expensesPercentageFromMaxValue, expensesPercentageLimit, maxValueExpenses, totalIncomes),
                new Tuple <String, int, int, int, int, int> (item2, totalDebts,    debtsPercentageFromMaxValue,    debtsPercentageLimit,    maxValueDebts,    totalIncomes),
                new Tuple <String, int, int, int, int, int> (item3, totalSavings,  savingsPercentageFromMaxValue,  savingsPercentageLimit,  maxValueSavings,  totalIncomes)
            };


            return(gridViewData);
        }