private void RevertDataSet(GiftBatchTDS AMainDS, GiftBatchTDS ABackupDS, int ASelectRowInGrid = 0) { if ((ABackupDS != null) && (AMainDS != null)) { AMainDS.RejectChanges(); AMainDS.Merge(ABackupDS); if (ASelectRowInGrid > 0) { SelectRowInGrid(ASelectRowInGrid); } } }
/// <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> /// Deletes the current row and optionally populates a completion message /// </summary> /// <param name="ARowToDelete">the currently selected row to delete</param> /// <param name="AFPrevRow">Is FPreviouslySelectedDetailRow</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> /// <returns>true if row deletion is successful</returns> public bool DeleteRowManual(ARecurringGiftBatchRow ARowToDelete, ref ARecurringGiftBatchRow AFPrevRow, ref string ACompletionMessage) { bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(false); } int CurrentBatchNo = ARowToDelete.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the changes to allow rollback BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(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.DELETING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(); string msg = String.Format(Catalog.GetString("Recurring Batch {0} has not been deleted."), CurrentBatchNo); MessageBox.Show(msg, "Recurring Gift Batch Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForDeleting(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteRecurringBatchGiftData(CurrentBatchNo); // Delete the recurring batch row and save again after deleting the batch row. ARowToDelete.Delete(); ACompletionMessage = String.Format(Catalog.GetString("Recurring Gift Batch no.: {0} deleted successfully."), CurrentBatchNo); AFPrevRow = null; DeletionSuccessful = 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(DeletionSuccessful); }
public static void SubmitRecurringGiftBatch(Hashtable requestParams) { GiftBatchTDS GMainDS = new GiftBatchTDS(); Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"]; Int32 ABatchNumber = (Int32)requestParams["ABatchNumber"]; DateTime AEffectiveDate = (DateTime)requestParams["AEffectiveDate"]; Decimal AExchangeRateToBase = (Decimal)requestParams["AExchangeRateToBase"]; Decimal AExchangeRateIntlToBase = (Decimal)requestParams["AExchangeRateIntlToBase"]; bool TaxDeductiblePercentageEnabled = Convert.ToBoolean( TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, "FALSE")); bool TransactionInIntlCurrency = false; int NewGiftBatchNumber = -1; GiftBatchTDS RMainDS = LoadRecurringGiftTransactionsForBatch(ALedgerNumber, ABatchNumber); TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); ARecurringGiftBatchAccess.LoadByPrimaryKey(RMainDS, ALedgerNumber, ABatchNumber, Transaction); // Assuming all relevant data is loaded in RMainDS foreach (ARecurringGiftBatchRow recBatch in RMainDS.ARecurringGiftBatch.Rows) { if ((recBatch.BatchNumber == ABatchNumber) && (recBatch.LedgerNumber == ALedgerNumber)) { Decimal batchTotal = 0; AGiftBatchRow batch = TGiftBatchFunctions.CreateANewGiftBatchRow(ref GMainDS, ref Transaction, ref LedgerTable, ALedgerNumber, AEffectiveDate); NewGiftBatchNumber = batch.BatchNumber; batch.BatchDescription = recBatch.BatchDescription; batch.BankCostCentre = recBatch.BankCostCentre; batch.BankAccountCode = recBatch.BankAccountCode; batch.ExchangeRateToBase = AExchangeRateToBase; batch.MethodOfPaymentCode = recBatch.MethodOfPaymentCode; batch.GiftType = recBatch.GiftType; batch.HashTotal = recBatch.HashTotal; batch.CurrencyCode = recBatch.CurrencyCode; TransactionInIntlCurrency = (batch.CurrencyCode == LedgerTable[0].IntlCurrency); foreach (ARecurringGiftRow recGift in RMainDS.ARecurringGift.Rows) { if ((recGift.BatchNumber == ABatchNumber) && (recGift.LedgerNumber == ALedgerNumber) && recGift.Active) { //Look if there is a detail which is in the donation period (else continue) bool foundDetail = false; foreach (ARecurringGiftDetailRow recGiftDetail in RMainDS.ARecurringGiftDetail.Rows) { if ((recGiftDetail.GiftTransactionNumber == recGift.GiftTransactionNumber) && (recGiftDetail.BatchNumber == ABatchNumber) && (recGiftDetail.LedgerNumber == ALedgerNumber) && ((recGiftDetail.StartDonations == null) || (AEffectiveDate >= recGiftDetail.StartDonations)) && ((recGiftDetail.EndDonations == null) || (AEffectiveDate <= recGiftDetail.EndDonations)) ) { foundDetail = true; break; } } if (!foundDetail) { continue; } // make the gift from recGift AGiftRow gift = GMainDS.AGift.NewRowTyped(); gift.LedgerNumber = batch.LedgerNumber; gift.BatchNumber = batch.BatchNumber; gift.GiftTransactionNumber = ++batch.LastGiftNumber; gift.DonorKey = recGift.DonorKey; gift.MethodOfGivingCode = recGift.MethodOfGivingCode; gift.DateEntered = AEffectiveDate; if (gift.MethodOfGivingCode.Length == 0) { gift.SetMethodOfGivingCodeNull(); } gift.MethodOfPaymentCode = recGift.MethodOfPaymentCode; if (gift.MethodOfPaymentCode.Length == 0) { gift.SetMethodOfPaymentCodeNull(); } gift.Reference = recGift.Reference; gift.ReceiptLetterCode = recGift.ReceiptLetterCode; GMainDS.AGift.Rows.Add(gift); //TODO (not here, but in the client or while posting) Check for Ex-OM Partner //TODO (not here, but in the client or while posting) Check for expired key ministry (while Posting) foreach (ARecurringGiftDetailRow recGiftDetail in RMainDS.ARecurringGiftDetail.Rows) { //decimal amtIntl = 0M; decimal amtBase = 0M; decimal amtTrans = 0M; if ((recGiftDetail.GiftTransactionNumber == recGift.GiftTransactionNumber) && (recGiftDetail.BatchNumber == ABatchNumber) && (recGiftDetail.LedgerNumber == ALedgerNumber) && ((recGiftDetail.StartDonations == null) || (recGiftDetail.StartDonations <= AEffectiveDate)) && ((recGiftDetail.EndDonations == null) || (recGiftDetail.EndDonations >= AEffectiveDate)) ) { AGiftDetailRow detail = GMainDS.AGiftDetail.NewRowTyped(); detail.LedgerNumber = gift.LedgerNumber; detail.BatchNumber = gift.BatchNumber; detail.GiftTransactionNumber = gift.GiftTransactionNumber; detail.DetailNumber = ++gift.LastDetailNumber; amtTrans = recGiftDetail.GiftAmount; detail.GiftTransactionAmount = amtTrans; batchTotal += amtTrans; amtBase = GLRoutines.Divide((decimal)amtTrans, AExchangeRateToBase); detail.GiftAmount = amtBase; if (!TransactionInIntlCurrency) { detail.GiftAmountIntl = GLRoutines.Divide((decimal)amtBase, AExchangeRateIntlToBase); } else { detail.GiftAmountIntl = amtTrans; } detail.RecipientKey = recGiftDetail.RecipientKey; detail.RecipientLedgerNumber = recGiftDetail.RecipientLedgerNumber; detail.ChargeFlag = recGiftDetail.ChargeFlag; detail.ConfidentialGiftFlag = recGiftDetail.ConfidentialGiftFlag; detail.TaxDeductible = recGiftDetail.TaxDeductible; detail.MailingCode = recGiftDetail.MailingCode; if (detail.MailingCode.Length == 0) { detail.SetMailingCodeNull(); } detail.MotivationGroupCode = recGiftDetail.MotivationGroupCode; detail.MotivationDetailCode = recGiftDetail.MotivationDetailCode; detail.GiftCommentOne = recGiftDetail.GiftCommentOne; detail.CommentOneType = recGiftDetail.CommentOneType; detail.GiftCommentTwo = recGiftDetail.GiftCommentTwo; detail.CommentTwoType = recGiftDetail.CommentTwoType; detail.GiftCommentThree = recGiftDetail.GiftCommentThree; detail.CommentThreeType = recGiftDetail.CommentThreeType; if (TaxDeductiblePercentageEnabled) { // Sets TaxDeductiblePct and uses it to calculate the tax deductibility amounts for a Gift Detail TGift.SetDefaultTaxDeductibilityData(ref detail, gift.DateEntered, Transaction); } GMainDS.AGiftDetail.Rows.Add(detail); } } batch.BatchTotal = batchTotal; } } } } AGiftBatchAccess.SubmitChanges(GMainDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(LedgerTable, Transaction); AGiftAccess.SubmitChanges(GMainDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(GMainDS.AGiftDetail, Transaction); DBAccess.GDBAccessObj.CommitTransaction(); GMainDS.AcceptChanges(); } catch (Exception Exc) { TLogging.Log("An Exception occured during the submission of a Recurring Gift Batch:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); GMainDS.RejectChanges(); throw; } }