Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringBatchRow ARowToDelete, ref string ACompletionMessage)
        {
            int BatchNumber = ARowToDelete.BatchNumber;

            // Delete on client side data through views that is already loaded. Data that is not
            // loaded yet will be deleted with cascading delete on server side so we don't have
            // to worry about this here.

            ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."),
                                               BatchNumber);

            // Delete the associated recurring transaction analysis attributes
            DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);

            viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                   ARecurringTransAnalAttribTable.GetLedgerNumberDBName(),
                                                                   FLedgerNumber,
                                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                   BatchNumber);

            foreach (DataRowView row in viewRecurringTransAnalAttrib)
            {
                row.Delete();
            }

            // Delete the associated recurring transactions
            DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);

            viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                               ARecurringTransactionTable.GetLedgerNumberDBName(),
                                                               FLedgerNumber,
                                                               ARecurringTransactionTable.GetBatchNumberDBName(),
                                                               BatchNumber);

            foreach (DataRowView row in viewRecurringTransaction)
            {
                row.Delete();
            }

            // Delete the associated recurring journals
            DataView viewRecurringJournal = new DataView(FMainDS.ARecurringJournal);

            viewRecurringJournal.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                           ARecurringJournalTable.GetLedgerNumberDBName(),
                                                           FLedgerNumber,
                                                           ARecurringJournalTable.GetBatchNumberDBName(),
                                                           BatchNumber);

            foreach (DataRowView row in viewRecurringJournal)
            {
                row.Delete();
            }

            // Delete the recurring batch row.
            ARowToDelete.Delete();

            UpdateRecordNumberDisplay();

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringBatchRow ARowToDelete, ref string ACompletionMessage)
        {
            //Assign default value(s)
            bool DeletionSuccessful = false;

            if (ARowToDelete == null)
            {
                return(DeletionSuccessful);
            }

            int BatchNumber = ARowToDelete.BatchNumber;

            //Backup the Dataset for reversion purposes
            GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy();

            BackupMainDS.Merge(FMainDS);

            if (ARowToDelete.RowState != DataRowState.Added)
            {
                //Reject any changes which may fail validation
                ARowToDelete.RejectChanges();
                ShowDetails(ARowToDelete);
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;

                ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."),
                                                   BatchNumber);

                // Delete the associated recurring transaction analysis attributes
                DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);
                viewRecurringTransAnalAttrib.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                       ARecurringTransAnalAttribTable.GetLedgerNumberDBName(),
                                                                       FLedgerNumber,
                                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                       BatchNumber);

                foreach (DataRowView row in viewRecurringTransAnalAttrib)
                {
                    row.Delete();
                }

                // Delete the associated recurring transactions
                DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);
                viewRecurringTransaction.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                   ARecurringTransactionTable.GetLedgerNumberDBName(),
                                                                   FLedgerNumber,
                                                                   ARecurringTransactionTable.GetBatchNumberDBName(),
                                                                   BatchNumber);

                foreach (DataRowView row in viewRecurringTransaction)
                {
                    row.Delete();
                }

                // Delete the associated recurring journals
                DataView viewRecurringJournal = new DataView(FMainDS.ARecurringJournal);
                viewRecurringJournal.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                               ARecurringJournalTable.GetLedgerNumberDBName(),
                                                               FLedgerNumber,
                                                               ARecurringJournalTable.GetBatchNumberDBName(),
                                                               BatchNumber);

                foreach (DataRowView row in viewRecurringJournal)
                {
                    row.Delete();
                }

                // Delete the recurring batch row.
                ARowToDelete.Delete();

                DeletionSuccessful = true;
            }
            catch (Exception ex)
            {
                ACompletionMessage = ex.Message;
                MessageBox.Show(ACompletionMessage,
                                "Deletion Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                //Revert to previous state
                FMainDS.Merge(BackupMainDS);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            UpdateRecordNumberDisplay();

            return(DeletionSuccessful);
        }