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);
        }
Ejemplo n.º 3
0
        private void submitButtonBPManagement_Click(object sender, EventArgs e)
        {
            //Asks for user to confirm the update decision
            DialogResult userOptionConfirmUpdate = MessageBox.Show("Are you sure that you want to update the selected budget plan?", "Budget plan mamagement", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            //If the user selects the 'No' option then no budget plan is updated
            if (userOptionConfirmUpdate == DialogResult.No)
            {
                return;
            }

            //Checks if the percentage limit for items were correctly set (if the total sum equals 100%)
            //if (calculatePercentagesSum(selectedRowIndex, dataGridViewBPManagement) < 100 || calculatePercentagesSum(selectedRowIndex, dataGridViewBPManagement) > 100) {
            //    MessageBox.Show("The sum of the specified percentages for budget items does not equal 100%! Please amend the necessary limits before continuing.", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            //    return;
            //}
            //CHANGE-DGW MANAGEMENT
            int[] itemColumnIndexes = new int[] { EXPENSE_PERCENTAGE_COLUMN_INDEX, DEBT_PERCENTAGE_COLUMN_INDEX, SAVING_PERCENTAGE_COLUMN_INDEX };
            int   percentagesSum    = gridViewManager.calculateItemsValueSum(selectedRowIndex, itemColumnIndexes);

            if (percentagesSum < 100 || percentagesSum > 100)
            {
                MessageBox.Show("The sum of the specified percentages for budget items does not equal 100%! Please amend the necessary limits before continuing.", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }



            //Creates the planChecker object for accessing the methods inside the BudgetPlanChecker class
            BudgetPlanChecker planChecker = new BudgetPlanChecker(userID, DateTime.Now.ToString("yyyy-MM-dd"));

            //String[] selectedRowDates = getDatesFromSelectedRow(selectedRowIndex, dataGridViewBPManagement);
            //CHANGE-DGW MANAGEMENT
            String[] selectedRowDates = gridViewManager.getDatesFromSelectedRow(selectedRowIndex, START_DATE_COLUMN_INDEX, END_DATE_COLUMN_INDEX);

            if (selectedRowDates == null || selectedRowDates.Length < 2)
            {
                return;
            }

            String startDate = selectedRowDates[0];
            String endDate   = selectedRowDates[1];

            int[] itemTotals = planChecker.getTotalValuesForAllBudgetItems(startDate, endDate);

            if (itemTotals == null || itemTotals.Length != 3)
            {
                return;
            }


            //int[] userSetPercentages = getItemsPercentagesFromSelectedRow(selectedRowIndex, dataGridViewBPManagement);
            //CHANGE-DGW MANAGEMENT
            int[] userSetPercentages = gridViewManager.getMultipleItemValuesFromSelectedRow(selectedRowIndex, itemColumnIndexes);

            //Checks to see if the percentage set by the user is higher/equal to the percentage of the current item total value calculated in relation to the total incomes from the timespan between start date and end date
            if (!planChecker.isLowerThanCurrentItemPercentage(userSetPercentages, itemTotals, startDate, endDate))
            {
                MessageBox.Show("One of the modified item percentages is lower than the actual percentage calculated based on the current item total value! The percentage that you set must be higher or at least equal to the current percentage.", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            bool      hasClickedCell = false;
            QueryType option         = getQueryTypeOption(hasClickedCell);

            //If the option is equal to 0 it means that something went wrong and the control is returns from the method
            if (option == 0)
            {
                return;
            }

            QueryData paramContainer = getDataContainer(option, dateTimePickerBPManagement);

            if (paramContainer == null)
            {
                return;
            }

            //Getting the DataTable object representing the data source for the dataGridView
            DataTable sourceDataTable = (DataTable)dataGridViewBPManagement.DataSource;
            int       executionResult = controller.requestUpdate(option, paramContainer, sourceDataTable);

            if (executionResult != -1)
            {
                MessageBox.Show("The selected data was updated successfully!", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Unable to update the selected data! Please try again", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            submitButtonBPManagement.Enabled = false;
            deleteButtonBPManagement.Enabled = false;
        }