Exemple #1
0
        //NOTE the returned values can be the following:
        // -1-> the check failed and the data can be inserted(e.g no budget plan)
        // 0 -> the check was successfull, and the next check can be performed
        // 1 -> the check failed and an error message was shown; no data will be inserted
        private int checkBudgetPlanBoundaries(BudgetPlanChecker planChecker)
        {
            int checkResult = -1;
            //Gets the plan data for the currently applicable budget plan
            DataTable budgetPlanDataTable = planChecker.getBudgetPlanData();

            //Extracts the start date and end date of the budget plan into a String array
            String[] budgetPlanBoundaries = planChecker.getBudgetPlanBoundaries(budgetPlanDataTable);

            if (budgetPlanBoundaries != null)
            {
                checkResult = 0;
            }
            else
            {
                MessageBox.Show("Unable to retrieve the start and end dates of the current budget plan! Please revise the plan before trying to insert new data.", "Insert data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                checkResult = 1;
            }

            return(checkResult);
        }
Exemple #2
0
        private int checkBudgetPlanAlarm(BudgetPlanChecker planChecker, QueryData inputData, int valueToInsert)
        {
            int checkResult = -1;
            //Gets the plan data for the currently applicable budget plan
            DataTable budgetPlanDataTable = planChecker.getBudgetPlanData();

            //Extracts the start date and end date of the budget plan into a String array
            String[] budgetPlanBoundaries = planChecker.getBudgetPlanBoundaries(budgetPlanDataTable);

            //Calculates the total incomes for the selected time interval
            int totalIncomes = planChecker.getTotalIncomes(budgetPlanBoundaries[0], budgetPlanBoundaries[1]);
            //Extracts the percentage limit that was set in the budget plan for the currently selected item
            int percentageLimitForItem = planChecker.getPercentageLimitForItem(inputData.BudgetItemType);
            //Calculates the actual limit value for the currently selected item based on the previously extracted percentage
            int limitValueForSelectedItem = planChecker.calculateMaxLimitValue(totalIncomes, percentageLimitForItem);

            //Checks if an alarm was set for the current budget plan
            if (planChecker.hasBudgetPlanAlarm(budgetPlanDataTable))
            {
                checkResult = 0;
            }

            return(checkResult);
        }
Exemple #3
0
        //private void checkInsertedValueAgainstBudgetPlan(BudgetPlanChecker planChecker) {
        //    int checkResult = -1;

        //    //If the plan doesn't contain an alarm a check is made to see if the future total value for the item (user input value + sum of existing database records for the selected item) is greater than the max limit for the selected item(as calculated based on the percentage set in the budget plan)
        //    if (planChecker.exceedsItemLimitValue(entryValue, limitValueForSelectedItem, getSelectedType(budgetItemComboBox), budgetPlanBoundaries[0], budgetPlanBoundaries[1])) {
        //        MessageBox.Show(String.Format("Cannot insert the provided {0} since it would exceed the {1}% limit imposed by the currently applicable budget plan! Please revise the plan or insert a lower value.", selectedItem.ToLower(), percentageLimitForItem), "Insert data form", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //        checkResult = 1;
        //        //If the value is less than the limit then it is inserted in the DB
        //    } else {
        //        //executionResult = insertSelectedItem(selectedItemIndex);

        //        checkResult = -1;
        //    }

        //}


        private int checkInsertedValueAgainstBudgetPlanLimits(BudgetPlanChecker planChecker, QueryData inputData, String selectedItemName, int valueToInsert)
        {
            int checkResult = -1;

            //Gets the plan data for the currently applicable budget plan
            DataTable budgetPlanDataTable = planChecker.getBudgetPlanData();

            //Extracts the start date and end date of the budget plan into a String array
            String[] budgetPlanBoundaries = planChecker.getBudgetPlanBoundaries(budgetPlanDataTable);

            //Extracts the threshold percentage set in the budget plan for the triggering of the alarm
            int thresholdPercentage = planChecker.getThresholdPercentage(budgetPlanDataTable);
            //Calculates the sum of the existing database records for the currently selected item(expense, debt, saving) in the specified time interval
            int currentItemTotalValue = planChecker.getTotalValueForSelectedItem(inputData.BudgetItemType, budgetPlanBoundaries[0], budgetPlanBoundaries[1]);

            //Calculates the total incomes for the selected time interval
            int totalIncomes = planChecker.getTotalIncomes(budgetPlanBoundaries[0], budgetPlanBoundaries[1]);
            //Extracts the percentage limit that was set in the budget plan for the currently selected item
            int percentageLimitForItem = planChecker.getPercentageLimitForItem(inputData.BudgetItemType);

            //Calculates the actual limit value for the currently selected item based on the previously extracted percentage
            int limitValueForSelectedItem = planChecker.calculateMaxLimitValue(totalIncomes, percentageLimitForItem);
            //Calculates the actual threshold value at which the alarm will be triggered
            int thresholdValue = planChecker.calculateValueFromPercentage(limitValueForSelectedItem, thresholdPercentage);

            //Calculates the value which will result after adding the current user input value for the selected item to the sum of the existing database records
            int futureItemTotalValue = currentItemTotalValue + valueToInsert;

            //Checks if the previously calculated value is between the threshold value and the max limit for the selected item(as calculated based on the percentage set in the budget plan)

            if (planChecker.isBetweenThresholdAndMaxLimit(futureItemTotalValue, thresholdValue, limitValueForSelectedItem))
            {
                //Calculates the percentage of the futureItemTotalValue
                int currentItemPercentageValue = planChecker.calculateCurrentItemPercentageValue(futureItemTotalValue, limitValueForSelectedItem);
                //Calculates the difference between the previous percentage value and the threshold percentage(in order to show the percentage by which the threshold is exceeded)
                int          percentageDifference      = currentItemPercentageValue - thresholdPercentage;
                DialogResult userOptionExceedThreshold = MessageBox.Show(String.Format("By inserting the current {0} you will exceed the alarm threshold by {1}%. Are you sure that you want to continue?", selectedItemName, percentageDifference), "Insert data", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                if (userOptionExceedThreshold == DialogResult.No)
                {
                    checkResult = 1;//Check result is set to 1 -> the value cannot be inserted
                }
                else
                {
                    //If the user confirms that he agrees to exceed the threshold the value is inserted in the DB
                    //executionResult = insertSelectedItem(selectedItemIndex);

                    checkResult = -1;//Check result is set to -1 -> a warning message was shown to the user but he decided to continue so the value can be inserted
                }
            }
            else
            {
                //If the futureItemTotalValue is above the limit set in the budget plan a warning message is shown and no value is inserted
                if (planChecker.exceedsItemLimitValue(valueToInsert, limitValueForSelectedItem, inputData.BudgetItemType, budgetPlanBoundaries[0], budgetPlanBoundaries[1]))
                {
                    MessageBox.Show(String.Format("Cannot insert the provided {0} since it would exceed the {1}% limit imposed by the currently applicable budget plan! Please revise the plan or insert a lower value.", selectedItemName, percentageLimitForItem), "Insert data form", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    checkResult = 1;//Check result is set to 1 -> the value cannot be inserted
                    //If the futureItemTotalValue is not between threshold limit and limit value and it doesn't exceed the limit value for the selected item it means that it can be inserted in the DB
                }
                else
                {
                    //executionResult = insertSelectedItem(selectedItemIndex);
                    checkResult = -1;//Check result is set to -1 so the element can be inserted because it does not exceed the limits imposed by the applicable budget plan
                }
            }

            return(checkResult);
        }