private void DeleteCurrentBatchGiftData(Int32 ABatchNumber) { DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { dr.Delete(); } DataView giftView = new DataView(FMainDS.AGift); giftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); giftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in giftView) { dr.Delete(); } }
private bool OnPreDeleteManual(GiftBatchTDSAGiftDetailRow ARowToDelete, ref string ADeletionQuestion) { bool allowDeletion = true; FGift = GetGiftRow(ARowToDelete.GiftTransactionNumber); FFilterAllDetailsOfGift = String.Format("{0}={1} and {2}={3}", AGiftDetailTable.GetBatchNumberDBName(), FPreviouslySelectedDetailRow.BatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), FPreviouslySelectedDetailRow.GiftTransactionNumber); FGiftDetailView = new DataView(FMainDS.AGiftDetail); FGiftDetailView.RowFilter = FFilterAllDetailsOfGift; FGiftDetailView.Sort = AGiftDetailTable.GetDetailNumberDBName() + " ASC"; String formattedDetailAmount = StringHelper.FormatUsingCurrencyCode(ARowToDelete.GiftTransactionAmount, GetBatchRow().CurrencyCode); if (FGiftDetailView.Count == 1) { ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete gift no. {1} from Gift Batch no. {2}?" + "\n\r\n\r" + " From: {3}" + "\n\r" + " To: {4}" + "\n\r" + "Amount: {5}"), ARowToDelete.DetailNumber, ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber, ARowToDelete.DonorName, ARowToDelete.RecipientDescription, formattedDetailAmount); } else if (FGiftDetailView.Count > 1) { ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete detail line: {0} from gift no. {1} in Gift Batch no. {2}?" + "\n\r\n\r" + " From: {3}" + "\n\r" + " To: {4}" + "\n\r" + "Amount: {5}"), ARowToDelete.DetailNumber, ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber, ARowToDelete.DonorName, ARowToDelete.RecipientDescription, formattedDetailAmount); } else //this should never happen { ADeletionQuestion = String.Format(Catalog.GetString("Gift no. {0} in Batch no. {1} has no detail rows in the Gift Detail table!"), ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber); allowDeletion = false; } return(allowDeletion); }
public static bool CheckGiftsNotPreviouslyReversed(GiftBatchTDS AGiftDS, out TVerificationResultCollection AMessages) { string Message = string.Empty; int GiftCount = 0; AMessages = new TVerificationResultCollection(); // sort gifts AGiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView RowView in AGiftDS.AGiftDetail.DefaultView) { AGiftDetailRow GiftDetailRow = (AGiftDetailRow)RowView.Row; if (GiftDetailRow.ModifiedDetail) { Message += "\n" + String.Format(Catalog.GetString("Gift {0} with Detail {1} in Batch {2}"), GiftDetailRow.GiftTransactionNumber, GiftDetailRow.DetailNumber, GiftDetailRow.BatchNumber); GiftCount++; } } if (GiftCount != 0) { if (GiftCount > 1) { Message = String.Format(Catalog.GetString("Cannot reverse or adjust the following gifts:")) + "\n" + Message + "\n\n" + Catalog.GetString("They have already been adjusted or reversed."); } else if (GiftCount == 1) { Message = String.Format(Catalog.GetString("Cannot reverse or adjust the following gift:")) + "\n" + Message + "\n\n" + Catalog.GetString("It has already been adjusted or reversed."); } AMessages.Add(new TVerificationResult(null, Message, TResultSeverity.Resv_Critical)); return(false); } return(true); }
private void SetGiftDetailDefaultView() { if (FBatchNumber != -1) { string rowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), FBatchNumber); FFilterAndFindObject.FilterPanelControls.SetBaseFilter(rowFilter, true); FMainDS.AGiftDetail.DefaultView.RowFilter = rowFilter; FFilterAndFindObject.CurrentActiveFilter = rowFilter; // We don't apply the filter yet! FMainDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); FMainDS.AGift.DefaultView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), FBatchNumber); } }
private void DeleteCurrentBatchGiftData(Int32 ABatchNumber, ref List <string> AModifiedDetailKeyRows) { DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { AGiftDetailRow gdr = (AGiftDetailRow)dr.Row; if ((gdr.ModifiedDetailKey != null) && (gdr.ModifiedDetailKey.Length > 0)) { AModifiedDetailKeyRows.Add(gdr.ModifiedDetailKey); } dr.Delete(); } DataView giftView = new DataView(FMainDS.AGift); giftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); giftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in giftView) { dr.Delete(); } }
/// <summary> /// Delete data from current gift batch /// </summary> /// <param name="ABatchNumber"></param> /// <param name="AModifiedDetailKeyRows"></param> public void DeleteBatchGiftData(Int32 ABatchNumber, ref List <string> AModifiedDetailKeyRows) { DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { AGiftDetailRow gdr = (AGiftDetailRow)dr.Row; if (gdr.ModifiedDetail && !string.IsNullOrEmpty(gdr.ModifiedDetailKey)) { AModifiedDetailKeyRows.Add(gdr.ModifiedDetailKey); } dr.Delete(); } DataView GiftView = new DataView(FMainDS.AGift); GiftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); GiftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in GiftView) { dr.Delete(); } }
public static bool GiftRevertAdjust(Hashtable requestParams, out TVerificationResultCollection AMessages) { AMessages = new TVerificationResultCollection(); Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"]; Boolean batchSelected = (Boolean)requestParams["NewBatchSelected"]; Int32 ANewBatchNumber = 0; bool TaxDeductiblePercentageEnabled = Convert.ToBoolean( TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, "FALSE")); if (batchSelected) { ANewBatchNumber = (Int32)requestParams["NewBatchNumber"]; } String Function = (String)requestParams["Function"]; Int32 AGiftDetailNumber = (Int32)requestParams["GiftDetailNumber"]; Int32 AGiftNumber = (Int32)requestParams["GiftNumber"]; Int32 ABatchNumber = (Int32)requestParams["BatchNumber"]; //decimal batchHashTotal = 0; decimal batchGiftTotal = 0; GiftBatchTDS MainDS = new GiftBatchTDS(); TDBTransaction Transaction = null; DateTime ADateEffective; Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; if (!batchSelected) { ADateEffective = (DateTime)requestParams["GlEffectiveDate"]; AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); AGiftBatchRow oldGiftBatch = MainDS.AGiftBatch[0]; TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref Transaction, ref LedgerTable, ALedgerNumber, ADateEffective); giftBatch = MainDS.AGiftBatch[1]; giftBatch.BankAccountCode = oldGiftBatch.BankAccountCode; giftBatch.BankCostCentre = oldGiftBatch.BankCostCentre; giftBatch.CurrencyCode = oldGiftBatch.CurrencyCode; giftBatch.ExchangeRateToBase = oldGiftBatch.ExchangeRateToBase; giftBatch.MethodOfPaymentCode = oldGiftBatch.MethodOfPaymentCode; giftBatch.HashTotal = 0; if (giftBatch.MethodOfPaymentCode.Length == 0) { giftBatch.SetMethodOfPaymentCodeNull(); } giftBatch.BankCostCentre = oldGiftBatch.BankCostCentre; giftBatch.GiftType = oldGiftBatch.GiftType; if (Function.Equals("AdjustGift")) { giftBatch.BatchDescription = Catalog.GetString("Gift Adjustment"); } else { giftBatch.BatchDescription = Catalog.GetString("Reverse Gift"); } } else { AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = MainDS.AGiftBatch[0]; ADateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrive the existing batch total batchGiftTotal = giftBatch.BatchTotal; } if (Function.Equals("ReverseGiftBatch")) { AGiftAccess.LoadViaAGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); foreach (AGiftRow gift in MainDS.AGift.Rows) { AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, gift.GiftTransactionNumber, Transaction); } } else { AGiftAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction); if (Function.Equals("ReverseGiftDetail")) { AGiftDetailAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, AGiftDetailNumber, Transaction); } else { AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction); } } //assuming new elements are added after these static borders int cycle = 0; MainDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); MainDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); do { foreach (DataRowView giftRow in MainDS.AGift.DefaultView) { AGiftRow oldGift = (AGiftRow)giftRow.Row; if ((oldGift.BatchNumber == ABatchNumber) && (oldGift.LedgerNumber == ALedgerNumber) && (Function.Equals("ReverseGiftBatch") || (oldGift.GiftTransactionNumber == AGiftNumber))) { AGiftRow gift = MainDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; gift.DateEntered = ADateEffective; gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LastDetailNumber = 0; MainDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in MainDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == ABatchNumber) && (oldGiftDetail.LedgerNumber == ALedgerNumber) && (!Function.Equals("ReverseGiftDetail") || (oldGiftDetail.DetailNumber == AGiftDetailNumber))) { if ((cycle == 0) && oldGiftDetail.ModifiedDetail) { AMessages.Add(new TVerificationResult( String.Format(Catalog.GetString("Cannot reverse or adjust Gift {0} with Detail {1} in Batch {2}"), oldGiftDetail.GiftTransactionNumber, oldGiftDetail.DetailNumber, oldGiftDetail.BatchNumber), String.Format(Catalog.GetString("It was already adjusted or reversed.")), TResultSeverity.Resv_Critical)); DBAccess.GDBAccessObj.RollbackTransaction(); return(false); } AGiftDetailRow giftDetail = MainDS.AGiftDetail.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGiftDetail, giftDetail); giftDetail.DetailNumber = ++gift.LastDetailNumber; giftDetail.LedgerNumber = gift.LedgerNumber; giftDetail.BatchNumber = giftBatch.BatchNumber; giftDetail.GiftTransactionNumber = gift.GiftTransactionNumber; //Identify the reversal source giftDetail.ModifiedDetailKey = "|" + oldGiftDetail.BatchNumber.ToString() + "|" + oldGiftDetail.GiftTransactionNumber.ToString() + "|" + oldGiftDetail.DetailNumber.ToString(); decimal signum = (cycle == 0) ? -1 : 1; giftDetail.GiftTransactionAmount = signum * oldGiftDetail.GiftTransactionAmount; batchGiftTotal += giftDetail.GiftTransactionAmount; giftDetail.GiftAmount = signum * oldGiftDetail.GiftAmount; giftDetail.GiftAmountIntl = signum * oldGiftDetail.GiftAmountIntl; if (TaxDeductiblePercentageEnabled) { giftDetail.TaxDeductibleAmount = signum * oldGiftDetail.TaxDeductibleAmount; giftDetail.TaxDeductibleAmountBase = signum * oldGiftDetail.TaxDeductibleAmountBase; giftDetail.TaxDeductibleAmountIntl = signum * oldGiftDetail.TaxDeductibleAmountIntl; giftDetail.NonDeductibleAmount = signum * oldGiftDetail.NonDeductibleAmount; giftDetail.NonDeductibleAmountBase = signum * oldGiftDetail.NonDeductibleAmountBase; giftDetail.NonDeductibleAmountIntl = signum * oldGiftDetail.NonDeductibleAmountIntl; } giftDetail.GiftCommentOne = (String)requestParams["ReversalCommentOne"]; giftDetail.GiftCommentTwo = (String)requestParams["ReversalCommentTwo"]; giftDetail.GiftCommentThree = (String)requestParams["ReversalCommentThree"]; giftDetail.CommentOneType = (String)requestParams["ReversalCommentOneType"]; giftDetail.CommentTwoType = (String)requestParams["ReversalCommentTwoType"]; giftDetail.CommentThreeType = (String)requestParams["ReversalCommentThreeType"]; // This is used to mark both as a Reverted giftDetails, except the adjusted (new) gift giftDetail.ModifiedDetail = (cycle == 0); oldGiftDetail.ModifiedDetail = (cycle == 0); MainDS.AGiftDetail.Rows.Add(giftDetail); } } } } cycle++; } while ((cycle < 2) && Function.Equals("AdjustGift")); //When reversing into a new or existing batch, set batch total if (!Function.Equals("AdjustGift")) { giftBatch.BatchTotal = batchGiftTotal; } // save everything at the end AGiftBatchAccess.SubmitChanges(MainDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(LedgerTable, Transaction); AGiftAccess.SubmitChanges(MainDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(MainDS.AGiftDetail, Transaction); MainDS.AGiftBatch.AcceptChanges(); DBAccess.GDBAccessObj.CommitTransaction(); return(true); } catch (Exception Exc) { TLogging.Log("An Exception occured while performing Gift Reverse/Adjust:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), Exc); } }
public static bool GiftRevertAdjust( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftDetailNumber, bool ABatchSelected, Int32 ANewBatchNumber, DateTime?ANewGLDateEffective, GiftAdjustmentFunctionEnum AFunction, bool ANoReceipt, Decimal ANewPct, out int AAdjustmentBatchNumber) { AAdjustmentBatchNumber = 0; int AdjustmentBatchNo = AAdjustmentBatchNumber; GiftBatchTDS GiftDS = new GiftBatchTDS(); decimal batchGiftTotal = 0; ANewBatchNumber = ABatchSelected ? ANewBatchNumber : 0; TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GiftRevertAdjust"); bool SubmissionOK = false; try { db.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { // load the original gifts and gift details AGiftAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction); AGiftDetailAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction); ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; DateTime DateEffective; if (ANewGLDateEffective.HasValue) { DateEffective = ANewGLDateEffective.Value; } else { AGiftBatchTable OriginalGiftBatch = AGiftBatchAccess.LoadByPrimaryKey(ALedgerNumber, ABatchNumber, Transaction); DateEffective = OriginalGiftBatch[0].GlEffectiveDate; } // if we need to create a new gift batch if (!ABatchSelected) { giftBatch = CreateNewGiftBatch( ALedgerNumber, ABatchNumber, DateEffective, AFunction, ref GiftDS, ref ledgerTable, Transaction); } else // using an existing gift batch { AGiftBatchAccess.LoadByPrimaryKey(GiftDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = GiftDS.AGiftBatch[0]; DateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrieve the existing batch total batchGiftTotal = giftBatch.BatchTotal; } AdjustmentBatchNo = giftBatch.BatchNumber; //assuming new elements are added after these static borders GiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); GiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView giftRow in GiftDS.AGift.DefaultView) { int cycle = 0; // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed) do { AGiftRow oldGift = (AGiftRow)giftRow.Row; if (oldGift.RowState != DataRowState.Added) { AGiftRow gift = GiftDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; // keep the same DateEntered as in the original gift if it is in the same period as the batch if ((gift.DateEntered.Year != DateEffective.Year) || (gift.DateEntered.Month != DateEffective.Month)) { gift.DateEntered = DateEffective; } gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LinkToPreviousGift = (cycle != 0); gift.LastDetailNumber = 0; gift.FirstTimeGift = false; // do not print a receipt for reversed gifts if (cycle == 0) { gift.ReceiptPrinted = true; gift.PrintReceipt = false; } else { gift.ReceiptPrinted = false; gift.PrintReceipt = !ANoReceipt; } GiftDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in GiftDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; // if gift detail belongs to gift if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == oldGift.BatchNumber) && (AFunction != GiftAdjustmentFunctionEnum.ReverseGiftDetail) || (oldGiftDetail.DetailNumber == AGiftDetailNumber)) { AddDuplicateGiftDetailToGift(ref GiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction, AFunction, ANewPct); batchGiftTotal += ((cycle == 0) ? 0 : oldGiftDetail.GiftTransactionAmount); // original gift also gets marked as a reversal oldGiftDetail.ModifiedDetail = true; } } } cycle++; } while ((cycle < 2) && (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGift) || AFunction.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) || AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))); } //When reversing into a new or existing batch, set batch total giftBatch.BatchTotal = batchGiftTotal; // save everything at the end AGiftBatchAccess.SubmitChanges(GiftDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(ledgerTable, Transaction); AGiftAccess.SubmitChanges(GiftDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(GiftDS.AGiftDetail, Transaction); GiftDS.AGiftBatch.AcceptChanges(); SubmissionOK = true; }); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex); } AAdjustmentBatchNumber = AdjustmentBatchNo; db.CloseDBConnection(); return(SubmissionOK); }
/// <summary> /// Main method to post a specified batch /// </summary> /// <param name="ACurrentBatchRow">The batch row to post</param> /// <param name="APostingAlreadyConfirmed">True means ask user if they want to post</param> /// <param name="AWarnOfInactiveValues">True means user is warned if inactive values exist</param> /// <param name="ADonorZeroIsValid"></param> /// <param name="ARecipientZeroIsValid"></param> /// <returns>True if the batch was successfully posted</returns> public bool PostBatch(AGiftBatchRow ACurrentBatchRow, bool APostingAlreadyConfirmed = false, bool AWarnOfInactiveValues = true, bool ADonorZeroIsValid = false, bool ARecipientZeroIsValid = false) { //This assumes that all gift data etc is loaded into the batch before arriving here bool RetVal = false; if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(RetVal); } FSelectedBatchNumber = ACurrentBatchRow.BatchNumber; TVerificationResultCollection Verifications; try { //Make sure that all control data is in dataset FMyForm.GetControlDataForPosting(); GiftBatchTDSAGiftDetailTable batchGiftDetails = new GiftBatchTDSAGiftDetailTable(); DataView batchGiftDetailsDV = new DataView(FMainDS.AGiftDetail); batchGiftDetailsDV.RowFilter = string.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber); batchGiftDetailsDV.Sort = string.Format("{0} ASC, {1} ASC, {2} ASC", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in batchGiftDetailsDV) { GiftBatchTDSAGiftDetailRow gBRow = (GiftBatchTDSAGiftDetailRow)drv.Row; batchGiftDetails.Rows.Add((object[])gBRow.ItemArray.Clone()); } bool CancelledDueToExWorkerOrAnonDonor; // save first, then post if (!FMyForm.SaveChangesForPosting(batchGiftDetails, out CancelledDueToExWorkerOrAnonDonor)) { FMyForm.Cursor = Cursors.Default; if (!CancelledDueToExWorkerOrAnonDonor) { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString("The batch was not posted due to problems during saving; ") + Environment.NewLine + Catalog.GetString("Please first correct and save the batch, and then post it!")); } return(RetVal); } } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } //Check for missing international exchange rate bool IsTransactionInIntlCurrency = false; FMyForm.WarnAboutMissingIntlExchangeRate = true; if (FMyForm.InternationalCurrencyExchangeRate(ACurrentBatchRow, out IsTransactionInIntlCurrency, true) == 0) { return(RetVal); } //Check for zero Donors or Recipients if (!ADonorZeroIsValid) { DataView batchGiftDV = new DataView(FMainDS.AGift); batchGiftDV.RowFilter = string.Format("{0}={1} And {2}=0", AGiftTable.GetBatchNumberDBName(), FSelectedBatchNumber, AGiftTable.GetDonorKeyDBName()); int numDonorZeros = batchGiftDV.Count; if (numDonorZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Gift Batch {0} contains {1} gift detail(s) with Donor 0000000. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numDonorZeros, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift" + Environment.NewLine; listOfOffendingRows += "------------"; foreach (DataRowView drv in batchGiftDV) { AGiftRow giftRow = (AGiftRow)drv.Row; listOfOffendingRows += String.Format("{0}{1:0000}", Environment.NewLine, giftRow.GiftTransactionNumber); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); extendedMessageBox.ShowDialog((messageListOfOffendingGifts + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(RetVal); } } if (!ARecipientZeroIsValid) { DataView batchGiftDetailsDV = new DataView(FMainDS.AGiftDetail); batchGiftDetailsDV.RowFilter = string.Format("{0}={1} And {2}=0", AGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber, AGiftDetailTable.GetRecipientKeyDBName()); int numRecipientZeros = batchGiftDetailsDV.Count; if (numRecipientZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Gift Batch {0} contains {1} gift detail(s) with Recipient 0000000. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numRecipientZeros, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift Detail" + Environment.NewLine; listOfOffendingRows += "-------------------"; foreach (DataRowView drv in batchGiftDetailsDV) { AGiftDetailRow giftDetailRow = (AGiftDetailRow)drv.Row; listOfOffendingRows += String.Format("{0}{1:0000} {2:00}", Environment.NewLine, giftDetailRow.GiftTransactionNumber, giftDetailRow.DetailNumber); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); extendedMessageBox.ShowDialog((messageListOfOffendingGifts + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(RetVal); } } //Check for inactive KeyMinistries DataTable GiftsWithInactiveKeyMinistries; bool ModifiedDetails = false; if (AWarnOfInactiveValues && TRemote.MFinance.Gift.WebConnectors.InactiveKeyMinistriesFoundInBatch(FLedgerNumber, FSelectedBatchNumber, out GiftsWithInactiveKeyMinistries, false)) { int numInactiveValues = GiftsWithInactiveKeyMinistries.Rows.Count; string messageNonModifiedBatch = String.Format(Catalog.GetString("Gift Batch {0} contains {1} inactive key ministries. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numInactiveValues, Environment.NewLine); string messageModifiedBatch = String.Format(Catalog.GetString( "Reversal/Adjustment Gift Batch {0} contains {1} inactive key ministries. Do you still want to post?{2}{2}"), FSelectedBatchNumber, numInactiveValues, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift Detail Recipient KeyMinistry" + Environment.NewLine; listOfOffendingRows += "-------------------------------------------------------------------------------"; foreach (DataRow dr in GiftsWithInactiveKeyMinistries.Rows) { listOfOffendingRows += String.Format("{0}{1:0000} {2:00} {3:00000000000} {4}", Environment.NewLine, dr[0], dr[1], dr[2], dr[3]); bool isModified = Convert.ToBoolean(dr[4]); if (isModified) { ModifiedDetails = true; } } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); if (ModifiedDetails) { if (extendedMessageBox.ShowDialog((messageModifiedBatch + listOfOffendingRows), Catalog.GetString("Post Batch"), string.Empty, TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiWarning) == TFrmExtendedMessageBox.TResult.embrYes) { APostingAlreadyConfirmed = true; } else { return(RetVal); } } else { extendedMessageBox.ShowDialog((messageNonModifiedBatch + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(RetVal); } } // ask if the user really wants to post the batch if (!APostingAlreadyConfirmed && (MessageBox.Show(String.Format(Catalog.GetString("Do you really want to post gift batch {0}?"), FSelectedBatchNumber), Catalog.GetString("Confirm posting of Gift Batch"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)) { return(RetVal); } Verifications = new TVerificationResultCollection(); try { FPostingInProgress = true; Thread postingThread = new Thread(() => PostGiftBatch(out Verifications)); using (TProgressDialog dialog = new TProgressDialog(postingThread)) { dialog.ShowDialog(); } if (!TVerificationHelper.IsNullOrOnlyNonCritical(Verifications)) { TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); StringBuilder errorMessages = new StringBuilder(); int counter = 0; errorMessages.AppendLine(Catalog.GetString("________________________Gift Posting Errors________________________")); errorMessages.AppendLine(); foreach (TVerificationResult verif in Verifications) { counter++; errorMessages.AppendLine(counter.ToString("000") + " - " + verif.ResultText); errorMessages.AppendLine(); } extendedMessageBox.ShowDialog(errorMessages.ToString(), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); } else { MessageBox.Show(Catalog.GetString("The batch has been posted successfully!")); RetVal = true; } } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FPostingInProgress = false; } return(RetVal); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { //Assign default value(s) bool CancellationSuccessful = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(CancellationSuccessful); } int CurrentBatchNo = ACurrentBatchRow.BatchNumber; 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(CancellationSuccessful); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); try { FMyForm.Cursor = Cursors.WaitCursor; //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); FMyForm.GetBatchControl().UndoModifiedBatchRow(ACurrentBatchRow, true); //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Delete transactions DataView GiftDV = new DataView(FMainDS.AGift); DataView GiftDetailDV = new DataView(FMainDS.AGiftDetail); GiftDV.AllowDelete = true; GiftDetailDV.AllowDelete = true; GiftDV.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDV.Sort = AGiftTable.GetGiftTransactionNumberDBName() + " DESC"; GiftDetailDV.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDetailDV.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in GiftDetailDV) { AGiftDetailRow gdr = (AGiftDetailRow)drv.Row; // if the gift detail being cancelled is a reversed gift if (gdr.ModifiedDetail && !string.IsNullOrEmpty(gdr.ModifiedDetailKey)) { ModifiedDetailKeys.Add(gdr.ModifiedDetailKey); } gdr.Delete(); } for (int i = 0; i < GiftDV.Count; i++) { GiftDV.Delete(i); } //Batch is only cancelled and never deleted ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.LastGiftNumber = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; FPetraUtilsObject.SetChangedFlag(); // save first if (FMyForm.SaveChanges()) { if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state FMainDS.Merge(BackupMainDS); CompletionMessage = ex.Message; MessageBox.Show(CompletionMessage, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Main method to post a specified batch /// </summary> /// <param name="ACurrentBatchRow">The batch row to post</param> /// <param name="ARefreshGUIAfterPosting">Will be set to true if the GUI should be updated. Can be true even if Posting fails /// <param name="AWarnOfInactiveValues">True means user is warned if inactive values exist</param> /// <param name="ADonorZeroIsValid"></param> /// <param name="ARecipientZeroIsValid"></param> /// <param name="APostingAlreadyConfirmed">True means ask user if they want to post</param> /// if the server gets a SerializableTransactionException</param> /// <returns>True if the batch was successfully posted</returns> public bool PostBatch(AGiftBatchRow ACurrentBatchRow, out bool ARefreshGUIAfterPosting, bool AWarnOfInactiveValues = true, bool ADonorZeroIsValid = false, bool ARecipientZeroIsValid = false, bool APostingAlreadyConfirmed = false) { ARefreshGUIAfterPosting = false; if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } FSelectedBatchNumber = ACurrentBatchRow.BatchNumber; //Make sure that all control data is in dataset FMyForm.GetLatestControlData(); //Copy all batch data to new table GiftBatchTDSAGiftDetailTable BatchGiftDetails = new GiftBatchTDSAGiftDetailTable(); DataView BatchGiftDetailsDV = new DataView(FMainDS.AGiftDetail); BatchGiftDetailsDV.RowFilter = string.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber); BatchGiftDetailsDV.Sort = string.Format("{0} ASC, {1} ASC, {2} ASC", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in BatchGiftDetailsDV) { GiftBatchTDSAGiftDetailRow gBRow = (GiftBatchTDSAGiftDetailRow)drv.Row; BatchGiftDetails.Rows.Add((object[])gBRow.ItemArray.Clone()); } //Save and check for inactive values and ex-workers and anonymous gifts if (FPetraUtilsObject.HasChanges) { //Keep this conditional check separate from the one above so that it only gets called // when necessary and doesn't result in the executon of the same method if (!FMyForm.SaveChangesForPosting(BatchGiftDetails)) { return(false); } else { APostingAlreadyConfirmed = true; } } else { //This has to be called here because if there are no changes then the DataSavingValidating // method which calls the method below, will not run. if (!FMyForm.GetBatchControl().AllowInactiveFieldValues(ref APostingAlreadyConfirmed, TExtraGiftBatchChecks.GiftBatchAction.POSTING) || FMyForm.GiftHasExWorkerOrAnon(BatchGiftDetails) ) { return(false); } } //Check hash total validity if ((ACurrentBatchRow.HashTotal != 0) && (ACurrentBatchRow.BatchTotal != ACurrentBatchRow.HashTotal)) { MessageBox.Show(String.Format(Catalog.GetString( "The gift batch total ({0}) for batch {1} does not equal the hash total ({2})!"), StringHelper.FormatUsingCurrencyCode(ACurrentBatchRow.BatchTotal, ACurrentBatchRow.CurrencyCode), ACurrentBatchRow.BatchNumber, StringHelper.FormatUsingCurrencyCode(ACurrentBatchRow.HashTotal, ACurrentBatchRow.CurrencyCode)), "Post Gift Batch"); return(false); } //Check for missing international exchange rate bool IsTransactionInIntlCurrency = false; FMyForm.WarnAboutMissingIntlExchangeRate = true; if (FMyForm.InternationalCurrencyExchangeRate(ACurrentBatchRow, out IsTransactionInIntlCurrency, true) == 0) { return(false); } //Check for zero Donors or Recipients if (!ADonorZeroIsValid) { DataView batchGiftDV = new DataView(FMainDS.AGift); batchGiftDV.RowFilter = string.Format("{0}={1} And {2}=0", AGiftTable.GetBatchNumberDBName(), FSelectedBatchNumber, AGiftTable.GetDonorKeyDBName()); int numDonorZeros = batchGiftDV.Count; if (numDonorZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Gift Batch {0} contains {1} gift detail(s) with Donor 0000000. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numDonorZeros, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift" + Environment.NewLine; listOfOffendingRows += "------------"; foreach (DataRowView drv in batchGiftDV) { AGiftRow giftRow = (AGiftRow)drv.Row; listOfOffendingRows += String.Format("{0}{1:0000}", Environment.NewLine, giftRow.GiftTransactionNumber); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); extendedMessageBox.ShowDialog((messageListOfOffendingGifts + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(false); } } if (!ARecipientZeroIsValid) { DataView batchGiftDetailsDV = new DataView(FMainDS.AGiftDetail); batchGiftDetailsDV.RowFilter = string.Format("{0}={1} And {2}=0", AGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber, AGiftDetailTable.GetRecipientKeyDBName()); int numRecipientZeros = batchGiftDetailsDV.Count; if (numRecipientZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Gift Batch {0} contains {1} gift detail(s) with Recipient 0000000. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numRecipientZeros, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift Detail" + Environment.NewLine; listOfOffendingRows += "-------------------"; foreach (DataRowView drv in batchGiftDetailsDV) { AGiftDetailRow giftDetailRow = (AGiftDetailRow)drv.Row; listOfOffendingRows += String.Format("{0}{1:0000} {2:00}", Environment.NewLine, giftDetailRow.GiftTransactionNumber, giftDetailRow.DetailNumber); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); extendedMessageBox.ShowDialog((messageListOfOffendingGifts + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(false); } } //Check for inactive KeyMinistries DataTable GiftsWithInactiveKeyMinistries; bool ModifiedDetails = false; if (AWarnOfInactiveValues && TRemote.MFinance.Gift.WebConnectors.InactiveKeyMinistriesFoundInBatch(FLedgerNumber, FSelectedBatchNumber, out GiftsWithInactiveKeyMinistries, false)) { int numInactiveValues = GiftsWithInactiveKeyMinistries.Rows.Count; string messageNonModifiedBatch = String.Format(Catalog.GetString("Gift Batch {0} contains {1} inactive key ministries. Please fix before posting!{2}{2}"), FSelectedBatchNumber, numInactiveValues, Environment.NewLine); string messageModifiedBatch = String.Format(Catalog.GetString( "Reversal/Adjustment Gift Batch {0} contains {1} inactive key ministries. Do you still want to post?{2}{2}"), FSelectedBatchNumber, numInactiveValues, Environment.NewLine); string listOfOffendingRows = string.Empty; listOfOffendingRows += "Gift Detail Recipient KeyMinistry" + Environment.NewLine; listOfOffendingRows += "-------------------------------------------------------------------------------"; foreach (DataRow dr in GiftsWithInactiveKeyMinistries.Rows) { listOfOffendingRows += String.Format("{0}{1:0000} {2:00} {3:00000000000} {4}", Environment.NewLine, dr[0], dr[1], dr[2], dr[3]); bool isModified = Convert.ToBoolean(dr[4]); if (isModified) { ModifiedDetails = true; } } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); if (ModifiedDetails) { if (extendedMessageBox.ShowDialog((messageModifiedBatch + listOfOffendingRows), Catalog.GetString("Post Batch"), string.Empty, TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiWarning) == TFrmExtendedMessageBox.TResult.embrYes) { APostingAlreadyConfirmed = true; } else { return(false); } } else { extendedMessageBox.ShowDialog((messageNonModifiedBatch + listOfOffendingRows), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(false); } } // ask if the user really wants to post the batch if (!APostingAlreadyConfirmed && (MessageBox.Show(String.Format(Catalog.GetString("Do you really want to post gift batch {0}?"), FSelectedBatchNumber), Catalog.GetString("Confirm posting of Gift Batch"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)) { return(false); } TVerificationResultCollection Verifications = new TVerificationResultCollection(); try { FPostingInProgress = true; Thread postingThread = new Thread(() => PostGiftBatch(out Verifications)); postingThread.SetApartmentState(ApartmentState.STA); using (TProgressDialog dialog = new TProgressDialog(postingThread)) { dialog.ShowDialog(); } if (TVerificationHelper.ResultsContainErrorCode(Verifications, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); ARefreshGUIAfterPosting = true; return(false); } else if (!TVerificationHelper.IsNullOrOnlyNonCritical(Verifications)) { TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); StringBuilder errorMessages = new StringBuilder(); int counter = 0; errorMessages.AppendLine(Catalog.GetString("________________________Gift Posting Errors________________________")); errorMessages.AppendLine(); foreach (TVerificationResult verif in Verifications) { counter++; errorMessages.AppendLine(counter.ToString("000") + " - " + verif.ResultText); errorMessages.AppendLine(); } extendedMessageBox.ShowDialog(errorMessages.ToString(), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); } else { MessageBox.Show(Catalog.GetString("The batch has been posted successfully!")); ARefreshGUIAfterPosting = true; } } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FPostingInProgress = false; } return(true); }
/// <summary> /// Clear the gift data of the current batch without marking records for delete /// </summary> private bool RefreshBatchGiftData(Int32 ABatchNumber, bool AAcceptChanges = false, bool AHandleDataSetBackup = false) { bool RetVal = false; //Copy and backup the current dataset GiftBatchTDS BackupDS = null; GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); if (AHandleDataSetBackup) { BackupDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); } try { this.Cursor = Cursors.WaitCursor; //Remove current batch gift data DataView giftDetailView = new DataView(TempDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { dr.Delete(); } DataView giftView = new DataView(TempDS.AGift); giftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); giftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in giftView) { dr.Delete(); } TempDS.AcceptChanges(); //Clear all gift data from Main dataset gift tables FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Bring data back in from other batches if it exists if (TempDS.AGift.Count > 0) { FMainDS.AGift.Merge(TempDS.AGift); FMainDS.AGiftDetail.Merge(TempDS.AGiftDetail); } //TODO: Confirm I need to AcceptChanges FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ABatchNumber)); if (AAcceptChanges) { FMainDS.AcceptChanges(); } RetVal = true; } catch (Exception ex) { //If not revert on error then calling method will if (AHandleDataSetBackup) { RevertDataSet(FMainDS, BackupDS); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { this.Cursor = Cursors.Default; } return(RetVal); }
/// <summary> /// Get Unsaved Batch Rows in a list /// </summary> /// <param name="ABatchToInclude">If > 0 then include in list even if unchanged</param> /// <returns></returns> public List <AGiftBatchRow> GetUnsavedBatchRowsList(int ABatchToInclude = 0) { List <AGiftBatchRow> RetVal = new List <AGiftBatchRow>(); List <int> BatchesWithChangesList = new List <int>(); string BatchesWithChangesString = string.Empty; DataView GiftBatchesDV = new DataView(FMainDS.AGiftBatch); GiftBatchesDV.RowFilter = String.Format("{0}='{1}'", AGiftBatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED); GiftBatchesDV.Sort = AGiftBatchTable.GetBatchNumberDBName() + " ASC"; DataView GiftDV = new DataView(FMainDS.AGift); DataView GiftDetailsDV = new DataView(FMainDS.AGiftDetail); GiftDV.Sort = String.Format("{0} ASC, {1} ASC", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); GiftDetailsDV.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); //Add the batch number(s) of changed gift rows foreach (DataRowView dRV in GiftDV) { AGiftRow gR = (AGiftRow)dRV.Row; if (!BatchesWithChangesList.Contains(gR.BatchNumber) && (gR.RowState != DataRowState.Unchanged)) { BatchesWithChangesList.Add(gR.BatchNumber); } } //Generate string of all batches found with changes if (BatchesWithChangesList.Count > 0) { BatchesWithChangesString = String.Join(",", BatchesWithChangesList); //Add any other batch number(s) of changed gift details GiftDetailsDV.RowFilter = String.Format("{0} NOT IN ({1})", AGiftDetailTable.GetBatchNumberDBName(), BatchesWithChangesString); } foreach (DataRowView dRV in GiftDetailsDV) { AGiftDetailRow gDR = (AGiftDetailRow)dRV.Row; if (!BatchesWithChangesList.Contains(gDR.BatchNumber) && (gDR.RowState != DataRowState.Unchanged)) { BatchesWithChangesList.Add(gDR.BatchNumber); } } BatchesWithChangesList.Sort(); //Get batch rows foreach (DataRowView dRV in GiftBatchesDV) { AGiftBatchRow giftBatchRow = (AGiftBatchRow)dRV.Row; if ((giftBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED) && ((giftBatchRow.BatchNumber == ABatchToInclude) || BatchesWithChangesList.Contains(giftBatchRow.BatchNumber) || (giftBatchRow.RowState != DataRowState.Unchanged))) { RetVal.Add(giftBatchRow); } } return(RetVal); }
private bool OnPreDeleteManual(GiftBatchTDSAGiftDetailRow ARowToDelete, ref string ADeletionQuestion) { // Using a button's keyboard shortcut results in a different sequence of Events from clicking it with the mouse. If the current control is in pnlDetails, // then when the New or Delete button's processing attempts to save the current record and calls TFrmPetraUtils.ForceOnLeaveForActiveControl(), // it inadvertently re-raises the pnlDetails.Enter event which activates BeginEditMode() at a point when it's not supposed to be activated, putting // TCmbAutoComplete controls in a state they're not supposed to be in, resulting in a NullReferenceException from FPreviouslySelectedDetailRow // in UC_GiftTransactions.Motivation.ManualCode.cs, MotivationDetailChanged(). // To fix it, put the focus outside pnlDetails, preventing the whole chain of events from happening. grdDetails.Focus(); bool AllowDeletion = true; FGift = GetGiftRow(ARowToDelete.GiftTransactionNumber); FFilterAllDetailsOfGift = String.Format("{0}={1} and {2}={3}", AGiftDetailTable.GetBatchNumberDBName(), FPreviouslySelectedDetailRow.BatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), FPreviouslySelectedDetailRow.GiftTransactionNumber); FGiftDetailView = new DataView(FMainDS.AGiftDetail); FGiftDetailView.RowFilter = FFilterAllDetailsOfGift; FGiftDetailView.Sort = AGiftDetailTable.GetDetailNumberDBName() + " ASC"; String formattedDetailAmount = StringHelper.FormatUsingCurrencyCode(ARowToDelete.GiftTransactionAmount, GetBatchRow().CurrencyCode); if (FGiftDetailView.Count == 1) { ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete gift no. {1} from Gift Batch no. {2}?" + "\n\r\n\r" + " From: {3}" + "\n\r" + " To: {4}" + "\n\r" + "Amount: {5}"), ARowToDelete.DetailNumber, ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber, ARowToDelete.DonorName, ARowToDelete.RecipientDescription, formattedDetailAmount); } else if (FGiftDetailView.Count > 1) { ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete detail line: {0} from gift no. {1} in Gift Batch no. {2}?" + "\n\r\n\r" + " From: {3}" + "\n\r" + " To: {4}" + "\n\r" + "Amount: {5}"), ARowToDelete.DetailNumber, ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber, ARowToDelete.DonorName, ARowToDelete.RecipientDescription, formattedDetailAmount); } else //this should never happen { ADeletionQuestion = String.Format(Catalog.GetString("Gift no. {0} in Batch no. {1} has no detail rows in the Gift Detail table!"), ARowToDelete.GiftTransactionNumber, ARowToDelete.BatchNumber); AllowDeletion = false; } return(AllowDeletion); }
public static bool GiftRevertAdjust(Hashtable requestParams, out int AAdjustmentBatchNumber, GiftBatchTDS AGiftDS) { AAdjustmentBatchNumber = 0; int AdjustmentBatchNo = AAdjustmentBatchNumber; if ((AGiftDS == null) || (AGiftDS.AGiftDetail == null) || (AGiftDS.AGiftDetail.Rows.Count == 0)) { TLogging.Log("Empty dataset sent to GiftRevertAdjust"); return(false); } Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"]; Boolean BatchSelected = (Boolean)requestParams["NewBatchSelected"]; GiftAdjustmentFunctionEnum Function = (GiftAdjustmentFunctionEnum)requestParams["Function"]; Int32 GiftDetailNumber = (Int32)requestParams["GiftDetailNumber"]; bool NoReceipt = (Boolean)requestParams["NoReceipt"]; DateTime DateEffective; decimal batchGiftTotal = 0; Int32 ANewBatchNumber = (BatchSelected ? (Int32)requestParams["NewBatchNumber"] : 0); TDBTransaction Transaction = null; bool SubmissionOK = false; try { DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; // if we need to create a new gift batch if (!BatchSelected) { giftBatch = CreateNewGiftBatch(requestParams, ref AGiftDS, out DateEffective, ref ledgerTable, Transaction); } else // using an existing gift batch { AGiftBatchAccess.LoadByPrimaryKey(AGiftDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = AGiftDS.AGiftBatch[0]; DateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrive the existing batch total batchGiftTotal = giftBatch.BatchTotal; } AdjustmentBatchNo = giftBatch.BatchNumber; //assuming new elements are added after these static borders AGiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); AGiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView giftRow in AGiftDS.AGift.DefaultView) { int cycle = 0; // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed) do { AGiftRow oldGift = (AGiftRow)giftRow.Row; if (oldGift.RowState != DataRowState.Added) { AGiftRow gift = AGiftDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; gift.DateEntered = DateEffective; gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LinkToPreviousGift = (cycle != 0); gift.LastDetailNumber = 0; // do not print a receipt for reversed gifts if (cycle == 0) { gift.ReceiptPrinted = true; gift.PrintReceipt = false; } else { gift.ReceiptPrinted = false; gift.PrintReceipt = !NoReceipt; } AGiftDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in AGiftDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; // if gift detail belongs to gift if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == oldGift.BatchNumber) && (!Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftDetail) || (oldGiftDetail.DetailNumber == GiftDetailNumber))) { AddDuplicateGiftDetailToGift(ref AGiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction, requestParams); batchGiftTotal += oldGiftDetail.GiftTransactionAmount * ((cycle == 0) ? -1 : 1); // original gift also gets marked as a reversal oldGiftDetail.ModifiedDetail = true; } } } cycle++; } while ((cycle < 2) && (Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift) || Function.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) || Function.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))); } //When reversing into a new or existing batch, set batch total if (!Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift)) { giftBatch.BatchTotal = batchGiftTotal; } // save everything at the end AGiftBatchAccess.SubmitChanges(AGiftDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(ledgerTable, Transaction); AGiftAccess.SubmitChanges(AGiftDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(AGiftDS.AGiftDetail, Transaction); AGiftDS.AGiftBatch.AcceptChanges(); SubmissionOK = true; }); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex); } AAdjustmentBatchNumber = AdjustmentBatchNo; return(SubmissionOK); }