Пример #1
0
        private void deleteButtonBPManagement_Click(object sender, EventArgs e)
        {
            //Asks the user to confirm the delete decision
            DialogResult userOptionConfirmDelete = MessageBox.Show("Are you sure that you want to delete the selected budget plan?", "Budget plan mamagement", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

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

            int itemID = getSelectedItemID();

            if (itemID == -1)
            {
                return;
            }

            //int executionResult = controller.requestDelete("budget_plans", itemID);

            //Providing the false value to the method makes sure that only SINGLE_MONTH/FULL_YEAR options are returned(here we're not interested in the BUDGET_PLAN_INFO option we just want to recreate the query used to fill the main DataGridView)
            //As a result we'll have to get one of the two values used for that, SINGLE_MONTH/FULL_YEAR
            QueryType option = getQueryTypeOption(false);
            //Data container that stores the actual SQL query parameters
            QueryData paramContainer = getDataContainer(option, dateTimePickerBPManagement);
            //The DataTable object that represents the data source of the DataGridView containing the list of budget plans
            DataTable sourceDataTable = (DataTable)dataGridViewBPManagement.DataSource;

            //Deletes the selected row from the DataTable object representing the data source for the DataGridView
            sourceDataTable.Rows[selectedRowIndex].Delete();

            int executionResult = controller.requestDelete(option, paramContainer, sourceDataTable);


            if (executionResult != -1)
            {
                MessageBox.Show("The selected budget plan was successfully deleted!", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Retrieves the row index of the currrently selected cell
                int selectedIndex = dataGridViewBPManagement.CurrentCell.RowIndex;
                //Removes the row at the selected index from the GUI table
                //dataGridViewBPManagement.Rows.RemoveAt(selectedIndex);
            }
            else
            {
                MessageBox.Show("Unable to delete the selected budget plan! Please try again.", "Budget plan management", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            //Getting the selected row index
            int selectedRowIndex = dataGridViewTableDisplay.CurrentCell.RowIndex;
            //The value of the deleted record and its date are saved before the actual deletion takes place because otherwise they would be lost and the update of the corresponding saving account balance record would be impossible
            int selectedRowForDeletionIndex = dataGridViewTableDisplay.CurrentCell.RowIndex;

            //Retrieving the correct column indexes from which data will be extracted
            int[] columnIndexList = getColumnIndexList();

            //deletedRecordValue = getValueFromRow(selectedRowForDeletionIndex, columnIndexList[0]);
            //CHANGE-DGW MANAGEMENT
            deletedRecordValue = gridViewManager.getSingleItemValueFromRow(selectedRowForDeletionIndex, columnIndexList[0]);

            //deletedRecordDate = getDateFromRow(selectedRowForDeletionIndex, columnIndexList[1]);
            //CHANGE-DGW MANAGEMENT
            deletedRecordDate = gridViewManager.getDateFromRow(selectedRowForDeletionIndex, columnIndexList[1]);

            String       confirmationMessage = String.Format("Are you sure that you want to delete row number {0}?", selectedRowIndex);
            DialogResult userOption1         = MessageBox.Show(confirmationMessage, "Data update form", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

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

            //CHANGE-DGW MANAGEMENT
            if (gridViewManager.hasChangedRows())
            {
                MessageBox.Show("You cannot delete the selected row before submitting or discarding the currently pending change/s!", "Data update", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            //Getting the currently selected table name
            String tableName = tableSelectionComboBox.Text;

            //Getting the ID of the selected record from the DataTable object that represents the data source of the table displayed in the GUI
            CurrencyManager currencyManager = (CurrencyManager)dataGridViewTableDisplay.BindingContext[dataGridViewTableDisplay.DataSource, dataGridViewTableDisplay.DataMember];
            DataRowView     selectedDataRow = (DataRowView)currencyManager.Current;
            int             itemID          = selectedDataRow.Row.ItemArray[0] != null?Convert.ToInt32(selectedDataRow.Row.ItemArray[0]) : -1;

            //CHANGE!!!!
            QueryType option         = 0;
            QueryData paramContainer = null;

            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
            }

            //Retrieves the DataTable object representing the data source of the DataGridView
            DataTable sourceDataTable = (DataTable)dataGridViewTableDisplay.DataSource;

            sourceDataTable.Rows[selectedRowIndex].Delete();//Deletes the row from the DataTable object


            int executionResult = controller.requestDelete(option, paramContainer, sourceDataTable);


            //Displaying info message regarding the delete operation result
            if (executionResult != -1)
            {
                MessageBox.Show("The selected data was successfully deleted!", "Data update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Unable to delete the selected data! Please try again.", "Data update", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //Balance record update section
            //BudgetItemType selectedItemType = getSelectedBudgetItemType();
            //if (selectedItemType == BudgetItemType.SAVING_ACCOUNT_EXPENSE || selectedItemType == BudgetItemType.SAVING) {
            //    int month = deletedRecordDate.Month;
            //    int year = deletedRecordDate.Year;

            //    int savingAccountBalanceUpdateResult = updateSavingAccountBalanceTable(userID, month, year, deletedRecordDate, getSelectedBudgetItemType(), true);

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

            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();
        }