Beispiel #1
0
        /// <summary>
        /// Method to cancel a specified batch
        /// </summary>
        /// <param name="ABatchRowToCancel">The row to cancel</param>
        /// <returns></returns>
        public bool CancelBatch(ABatchRow ABatchRowToCancel)
        {
            //Assign default value(s)
            bool CancellationSuccessful = false;

            if ((ABatchRowToCancel == null))
            {
                return(CancellationSuccessful);
            }

            int CurrentBatchNumber = ABatchRowToCancel.BatchNumber;

            if ((MessageBox.Show(String.Format(Catalog.GetString("You have chosen to cancel this batch ({0}).\n\nDo you really want to cancel it?"),
                                               CurrentBatchNumber),
                                 Catalog.GetString("Confirm Cancel"),
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question,
                                 MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes))
            {
                return(CancellationSuccessful);
            }

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

            BackupMainDS.Merge(FMainDS);

            bool RowToDeleteIsNew = (ABatchRowToCancel.RowState == DataRowState.Added);

            if (!RowToDeleteIsNew)
            {
                //Remove any changes, which may cause validation issues, before cancelling
                FMyForm.GetBatchControl().UndoModifiedBatchRow(ABatchRowToCancel, true);

                if (!(FMyForm.SaveChanges()))
                {
                    MessageBox.Show(Catalog.GetString("Error in trying to save prior to cancelling current Batch!"),
                                    Catalog.GetString("Cancellation Error"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return(CancellationSuccessful);
                }
            }

            try
            {
                FMyForm.Cursor = Cursors.WaitCursor;

                //clear any transactions currently being editied in the Transaction Tab
                FMyForm.GetTransactionsControl().ClearCurrentSelection();
                //clear any journals currently being editied in the Journals Tab
                FMyForm.GetJournalsControl().ClearCurrentSelection();

                //Clear Journals etc for current Batch
                FMainDS.ATransAnalAttrib.Clear();
                FMainDS.ATransaction.Clear();
                FMainDS.AJournal.Clear();

                //Load tables afresh
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, CurrentBatchNumber));
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransaction(FLedgerNumber, CurrentBatchNumber));
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransAnalAttribForBatch(FLedgerNumber, CurrentBatchNumber));
                FMainDS.AcceptChanges();

                //Delete transactions and analysis attributes
                for (int i = FMainDS.ATransAnalAttrib.Count - 1; i >= 0; i--)
                {
                    FMainDS.ATransAnalAttrib[i].Delete();
                }

                for (int i = FMainDS.ATransaction.Count - 1; i >= 0; i--)
                {
                    FMainDS.ATransaction[i].Delete();
                }

                //Update Journal totals and status
                foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                {
                    if (journal.BatchNumber == CurrentBatchNumber)
                    {
                        journal.BeginEdit();
                        journal.JournalStatus         = MFinanceConstants.BATCH_CANCELLED;
                        journal.JournalCreditTotal    = 0;
                        journal.JournalDebitTotal     = 0;
                        journal.LastTransactionNumber = 0;
                        journal.EndEdit();
                    }
                }

                // Edit the batch row
                ABatchRowToCancel.BeginEdit();

                ABatchRowToCancel.BatchCreditTotal  = 0;
                ABatchRowToCancel.BatchDebitTotal   = 0;
                ABatchRowToCancel.BatchControlTotal = 0;
                ABatchRowToCancel.BatchStatus       = MFinanceConstants.BATCH_CANCELLED;

                ABatchRowToCancel.EndEdit();

                FPetraUtilsObject.SetChangedFlag();

                //Need to call save
                if (FMyForm.SaveChanges())
                {
                    MessageBox.Show(Catalog.GetString("The batch has been cancelled successfully!"),
                                    Catalog.GetString("Success"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    FMyForm.DisableTransactions();
                    FMyForm.DisableJournals();
                }
                else
                {
                    throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry."));
                }

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

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

            return(CancellationSuccessful);
        }
Beispiel #2
0
        /// <summary>
        /// Method to cancel a specified batch
        /// </summary>
        /// <param name="ABatchRowToCancel">The row to cancel</param>
        /// <returns></returns>
        public bool CancelBatch(ABatchRow ABatchRowToCancel)
        {
            bool CancellationSuccessful = false;

            if ((ABatchRowToCancel == null) || (ABatchRowToCancel.BatchStatus != MFinanceConstants.BATCH_UNPOSTED))
            {
                return(false);
            }

            int  CurrentBatchNo = ABatchRowToCancel.BatchNumber;
            bool CurrentBatchJournalsLoadedAndCurrent     = false;
            bool CurrentBatchTransactionsLoadedAndCurrent = false;

            string CancelMessage     = string.Empty;
            string CompletionMessage = string.Empty;

            CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel GL Batch {0}?"),
                                          CurrentBatchNo);

            if ((MessageBox.Show(CancelMessage,
                                 "Cancel GL Batch",
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question,
                                 MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes))
            {
                return(false);
            }

            //Backup the Dataset for reversion purposes
            GLBatchTDS BackupMainDS = null;

            try
            {
                FMyForm.Cursor = Cursors.WaitCursor;

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

                //Don't run an inactive fields check on this batch
                FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo);

                //Check if current batch details are currently loaded
                CurrentBatchJournalsLoadedAndCurrent     = (FMyForm.GetJournalsControl().FBatchNumber == CurrentBatchNo);
                CurrentBatchTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo);

                //Save and check for inactive values in other unsaved Batches
                FPetraUtilsObject.SetChangedFlag();

                if (!FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction, !CurrentBatchJournalsLoadedAndCurrent,
                                               !CurrentBatchTransactionsLoadedAndCurrent))
                {
                    FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary();

                    CompletionMessage = String.Format(Catalog.GetString("GL Batch {0} has not been cancelled."),
                                                      CurrentBatchNo);

                    MessageBox.Show(CompletionMessage,
                                    Catalog.GetString("GL Batch Cancellation"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);

                    return(false);
                }

                //Remove any changes to current batch that may cause validation issues
                FMyForm.GetBatchControl().PrepareBatchDataForCancelling(CurrentBatchNo, true);

                //Clear the journal and trans tabs if current batch data is displayed there
                if (CurrentBatchJournalsLoadedAndCurrent)
                {
                    //Clear any transactions currently being edited in the Transaction Tab
                    FMyForm.GetJournalsControl().ClearCurrentSelection(CurrentBatchNo);
                }

                if (CurrentBatchTransactionsLoadedAndCurrent)
                {
                    //Clear any transactions currently being edited in the Transaction Tab
                    FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo);
                }

                //Delete transactions and attributes
                FMyForm.GetTransactionsControl().DeleteTransactionData(CurrentBatchNo);

                //Journals are not deleted. Update Journal totals and status
                foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                {
                    if (journal.BatchNumber == CurrentBatchNo)
                    {
                        journal.BeginEdit();
                        journal.JournalCreditTotal    = 0;
                        journal.JournalDebitTotal     = 0;
                        journal.LastTransactionNumber = 0;
                        journal.JournalStatus         = MFinanceConstants.BATCH_CANCELLED;
                        journal.EndEdit();
                    }
                }

                // Edit the batch row
                ABatchRowToCancel.BeginEdit();
                ABatchRowToCancel.BatchCreditTotal  = 0;
                ABatchRowToCancel.BatchDebitTotal   = 0;
                ABatchRowToCancel.BatchControlTotal = 0;
                ABatchRowToCancel.BatchStatus       = MFinanceConstants.BATCH_CANCELLED;
                ABatchRowToCancel.EndEdit();

                FPetraUtilsObject.SetChangedFlag();
                FMyForm.SaveChangesManual();

                CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."),
                                                  CurrentBatchNo);

                MessageBox.Show(CompletionMessage,
                                Catalog.GetString("Batch Cancelled"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);

                FMyForm.DisableTransactions();
                FMyForm.DisableJournals();

                CancellationSuccessful = true;
            }
            catch (Exception ex)
            {
                //Revert to previous state
                if (BackupMainDS != null)
                {
                    FMainDS.RejectChanges();
                    FMainDS.Merge(BackupMainDS);

                    FMyForm.GetBatchControl().ShowDetailsRefresh();
                }

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
            finally
            {
                FMyForm.Cursor = Cursors.Default;
            }

            return(CancellationSuccessful);
        }