示例#1
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;
        }
示例#2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //Checks if the timespan selection combobxes are selected before the Submit button is pressed
            if (monthRecordsCheckBox.Checked == false && yearRecordsCheckBox.Checked == false)
            {
                MessageBox.Show("Please select a time interval first!", "Update data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //Displaying a message asking the user to confirm his intention of modifying the data and getting the result of his selection
            DialogResult userOption = MessageBox.Show("Are you sure that you want to submit the changes to the database?", "Data update form", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (userOption == DialogResult.No)
            {
                return;
            }

            //Getting the currently selected table name
            String tableName = tableSelectionComboBox.SelectedItem.ToString();

            QueryType option         = 0;
            QueryData paramContainer = null;

            //Getting the necessary data for restoring the SQL query used for displaying the data present in the table
            //(for generating the commands that will automatically update th DB with the changes that the user made in the GUI)
            if (monthRecordsCheckBox.Checked == true)
            {
                option = QueryType.SINGLE_MONTH;
                int currentMonth = dateTimePickerTimeSpanSelection.Value.Month;
                int currentYear  = dateTimePickerTimeSpanSelection.Value.Year;
                paramContainer = new QueryData.Builder(userID).addMonth(currentMonth).addYear(currentYear).addTableName(tableName).build(); //CHANGE
            }
            else if (yearRecordsCheckBox.Checked == true)
            {
                option = QueryType.FULL_YEAR;
                int currentMonth = dateTimePickerTimeSpanSelection.Value.Month;
                int currentYear  = dateTimePickerTimeSpanSelection.Value.Year;
                paramContainer = new QueryData.Builder(userID).addYear(currentYear).addTableName(tableName).build(); //CHANGE
            }

            //Getting the data source of the table displayed in the GUI
            DataTable sourceDataTable = (DataTable)dataGridViewTableDisplay.DataSource;

            //Sending data to controller and checking the execution result
            int executionResult = controller.requestUpdate(option, paramContainer, sourceDataTable);

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

            //Balance record update section
            BudgetItemType selectedItemType = getSelectedBudgetItemType();

            if (selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE || selectedItemType == BudgetItemType.SAVING)
            {
                //If only the record value is changed by the user then the new record value is set to it
                if (hasChangedRecordDate && !hasChangedRecordValue)
                {
                    //CHANGE
                    //Takes the value from the actual changed row not from the currently selected one which can be different.
                    //If a saving account expense is selected the value is taken from the column 3 of the row and if a saving is selected the value is taken from column 2 of the row.
                    //newRecordValue = selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE ? getValueFromRow(changedRowIndex, 3) : getValueFromRow(changedRowIndex, 2);
                    //CHANGE-DGW MANAGEMENT
                    newRecordValue = selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE ? gridViewManager.getSingleItemValueFromRow(changedRowIndex, 3) : gridViewManager.getSingleItemValueFromRow(changedRowIndex, 2);
                }

                int      month = 0;
                int      year  = 0;
                DateTime selectedRecordDate = DateTime.MinValue;//CHANGE

                //If the record date was modified then the month and year variables will be assigned the corresponding values from the old date otherwise the current date of the record will be used
                if (hasChangedRecordDate)
                {
                    month = oldRecordDate.Month;
                    year  = oldRecordDate.Year;
                    selectedRecordDate = oldRecordDate;//Selected record date will be the old record date since we need to save the date that existed previous to the change
                }
                else
                {
                    //CHANGE
                    //Takes the value from the actual changed row not from the currently selected one which can be different.
                    //If a saving account expense is selected the date is taken from the column 4 of the row and if a saving is selected the date is taken from column 3 of the row.
                    //selectedRecordDate = selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE ? getDateFromRow(changedRowIndex, 4) : getDateFromRow(changedRowIndex, 3);
                    //CHANGE-DGW MANAGEMENT
                    selectedRecordDate = selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE ? gridViewManager.getDateFromRow(changedRowIndex, 4) : gridViewManager.getDateFromRow(changedRowIndex, 3);

                    month = selectedRecordDate.Month;
                    year  = selectedRecordDate.Year;
                }


                //Retrieving the execution result of the method responsible for updating the balance record table
                //TEST TRIGGER DB
                //int savingAccountBalanceUpdateResult = updateSavingAccountBalanceTable(userID, month, year, selectedRecordDate, getSelectedBudgetItemType(), false);

                //if (savingAccountBalanceUpdateResult == -1) {
                //    MessageBox.Show("Unable to update the saving account balance record.", "Data update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //}
            }

            submitButton.Enabled = false; //Disables the Submit button after deleting data from the table
            deleteButton.Enabled = false; //Disables the Delete button after deleting data from the table

            clearFlags();
            resetSavedValues();
        }