/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ABatchRowToCancel"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ABatchRowToCancel) { bool CancellationSuccessful = false; if ((ABatchRowToCancel == null) || (ABatchRowToCancel.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNo = ABatchRowToCancel.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel Gift Batch {0}?"), CurrentBatchNo); if ((MessageBox.Show(CancelMessage, "Cancel Gift Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the Dataset for reversion purposes BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo); //Check if current batch gift details are currently loaded CurrentBatchTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo); //Save and check for inactive values and ex-workers and anonymous gifts // in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(); CompletionMessage = String.Format(Catalog.GetString("Gift Batch {0} has not been cancelled."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForCancelling(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteBatchGiftData(CurrentBatchNo, ref ModifiedDetailKeys); //Batch is only cancelled and never deleted ABatchRowToCancel.BeginEdit(); ABatchRowToCancel.BatchTotal = 0; ABatchRowToCancel.LastGiftNumber = 0; ABatchRowToCancel.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ABatchRowToCancel.EndEdit(); if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } FPetraUtilsObject.SetChangedFlag(); FMyForm.SaveChangesManual(); CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); 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); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { string CancelMessage = string.Empty; string CompletionMessage = string.Empty; string ExistingBatchStatus = string.Empty; decimal ExistingBatchTotal = 0; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } // first save any changes if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING)) { return(false); } try { //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); ExistingBatchTotal = ACurrentBatchRow.BatchTotal; ExistingBatchStatus = ACurrentBatchRow.BatchStatus; //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Clear gifts and details etc for current Batch FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.AcceptChanges(); //Delete gift details for (int i = FMainDS.AGiftDetail.Count - 1; i >= 0; i--) { // if the gift detail being cancelled is a reversed gift if (FMainDS.AGiftDetail[i].ModifiedDetail && !string.IsNullOrEmpty(FMainDS.AGiftDetail[i].ModifiedDetailKey)) { ModifiedDetailKeys.Add(FMainDS.AGiftDetail[i].ModifiedDetailKey); } FMainDS.AGiftDetail[i].Delete(); } //Delete gifts for (int i = FMainDS.AGift.Count - 1; i >= 0; i--) { FMainDS.AGift[i].Delete(); } //Batch is only cancelled and never deleted ACurrentBatchRow.BeginEdit(); ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ACurrentBatchRow.EndEdit(); FPetraUtilsObject.HasChanges = true; // save first, then post if (!FMyForm.SaveChanges()) { ACurrentBatchRow.BeginEdit(); //Should normally be Unposted, but allow for other status values in future ACurrentBatchRow.BatchTotal = ExistingBatchTotal; ACurrentBatchRow.BatchStatus = ExistingBatchStatus; ACurrentBatchRow.EndEdit(); // saving failed, therefore do not try to cancel MessageBox.Show(Catalog.GetString("The cancelled batch failed to save!")); } else { TRemote.MFinance.Gift.WebConnectors.RemoveModifiedDetailOnCancel(FLedgerNumber, ModifiedDetailKeys); MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { CompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { string CancelMessage = string.Empty; string CompletionMessage = string.Empty; string ExistingBatchStatus = string.Empty; decimal ExistingBatchTotal = 0; List <string>ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return false; } CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return false; } // first save any changes if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING)) { return false; } try { //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); ExistingBatchTotal = ACurrentBatchRow.BatchTotal; ExistingBatchStatus = ACurrentBatchRow.BatchStatus; //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Clear gifts and details etc for current Batch FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.AcceptChanges(); //Delete gift details for (int i = FMainDS.AGiftDetail.Count - 1; i >= 0; i--) { // if the gift detail being cancelled is a reversed gift if (FMainDS.AGiftDetail[i].ModifiedDetail && !string.IsNullOrEmpty(FMainDS.AGiftDetail[i].ModifiedDetailKey)) { ModifiedDetailKeys.Add(FMainDS.AGiftDetail[i].ModifiedDetailKey); } FMainDS.AGiftDetail[i].Delete(); } //Delete gifts for (int i = FMainDS.AGift.Count - 1; i >= 0; i--) { FMainDS.AGift[i].Delete(); } //Batch is only cancelled and never deleted ACurrentBatchRow.BeginEdit(); ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ACurrentBatchRow.EndEdit(); FPetraUtilsObject.HasChanges = true; // save first, then post if (!FMyForm.SaveChanges()) { ACurrentBatchRow.BeginEdit(); //Should normally be Unposted, but allow for other status values in future ACurrentBatchRow.BatchTotal = ExistingBatchTotal; ACurrentBatchRow.BatchStatus = ExistingBatchStatus; ACurrentBatchRow.EndEdit(); // saving failed, therefore do not try to cancel MessageBox.Show(Catalog.GetString("The cancelled batch failed to save!")); } else { TRemote.MFinance.Gift.WebConnectors.RemoveModifiedDetailOnCancel(FLedgerNumber, ModifiedDetailKeys); MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { CompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return false; }