/// <summary> /// Delete data from current recurring gift batch /// </summary> /// <param name="ABatchNumber"></param> public void DeleteRecurringBatchGiftData(Int32 ABatchNumber) { DataView RecurringGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail); RecurringGiftDetailView.RowFilter = String.Format("{0}={1}", ARecurringGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); RecurringGiftDetailView.Sort = String.Format("{0} DESC, {1} DESC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), ARecurringGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in RecurringGiftDetailView) { ARecurringGiftDetailRow gdr = (ARecurringGiftDetailRow)dr.Row; dr.Delete(); } DataView RecurringGiftView = new DataView(FMainDS.ARecurringGift); RecurringGiftView.RowFilter = String.Format("{0}={1}", ARecurringGiftTable.GetBatchNumberDBName(), ABatchNumber); RecurringGiftView.Sort = String.Format("{0} DESC", ARecurringGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in RecurringGiftView) { dr.Delete(); } }
/// <summary> /// find a special gift detail /// </summary> public void FindGiftDetail(ARecurringGiftDetailRow gdr) { //TODO add to other forms //ucoRecurringBatches.SelectBatchNumber(gdr.BatchNumber); //ucoRecurringTransactions.SelectGiftDetailNumber(gdr.GiftTransactionNumber, gdr.DetailNumber); //standardTabIndex = 1; // later we switch to the detail tab }
/// create new recurring gift info public static ARecurringGiftBatchRow CreateNewRecurringGiftInfo(Int64 APartnerKey, ref GiftBatchTDS AGiftDS) { ALedgerAccess.LoadAll(AGiftDS, DBAccess.GDBAccessObj.Transaction); AGiftDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(AGiftDS.ALedger[0].LedgerNumber); // Create a new RecurringGiftBatch ARecurringGiftBatchRow Batch = AGiftDS.ARecurringGiftBatch[0]; Batch.BankAccountCode = "6000"; Batch.CurrencyCode = "EUR"; // Create a new RecurringGift record ARecurringGiftRow RecurringGift = AGiftDS.ARecurringGift.NewRowTyped(); RecurringGift.LedgerNumber = Batch.LedgerNumber; RecurringGift.BatchNumber = Batch.BatchNumber; RecurringGift.GiftTransactionNumber = 1; RecurringGift.DonorKey = APartnerKey; AGiftDS.ARecurringGift.Rows.Add(RecurringGift); // Create a new RecurringGiftDetail record ARecurringGiftDetailRow RecurringGiftDetail = AGiftDS.ARecurringGiftDetail.NewRowTyped(); RecurringGiftDetail.LedgerNumber = Batch.LedgerNumber; RecurringGiftDetail.BatchNumber = Batch.BatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = APartnerKey; RecurringGiftDetail.RecipientLedgerNumber = APartnerKey; AGiftDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); return(Batch); }
/// create new recurring gift info public static ARecurringGiftBatchRow CreateNewRecurringGiftInfo(Int64 APartnerKey, ref GiftBatchTDS AGiftDS, TDataBase ADataBase = null) { TDataBase db = DBAccess.Connect("CreateNewRecurringGiftInfo", ADataBase); bool NewTransaction; TDBTransaction Transaction = db.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction); ALedgerAccess.LoadAll(AGiftDS, Transaction); AGiftDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(AGiftDS.ALedger[0].LedgerNumber, db); if (NewTransaction) { Transaction.Rollback(); } // Create a new RecurringGiftBatch ARecurringGiftBatchRow Batch = AGiftDS.ARecurringGiftBatch[0]; Batch.BankAccountCode = "6000"; Batch.CurrencyCode = "EUR"; // Create a new RecurringGift record ARecurringGiftRow RecurringGift = AGiftDS.ARecurringGift.NewRowTyped(); RecurringGift.LedgerNumber = Batch.LedgerNumber; RecurringGift.BatchNumber = Batch.BatchNumber; RecurringGift.GiftTransactionNumber = 1; RecurringGift.DonorKey = APartnerKey; AGiftDS.ARecurringGift.Rows.Add(RecurringGift); // Create a new RecurringGiftDetail record ARecurringGiftDetailRow RecurringGiftDetail = AGiftDS.ARecurringGiftDetail.NewRowTyped(); RecurringGiftDetail.LedgerNumber = Batch.LedgerNumber; RecurringGiftDetail.BatchNumber = Batch.BatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = 43000000; RecurringGiftDetail.RecipientLedgerNumber = APartnerKey; RecurringGiftDetail.GiftAmount = 10; AGiftDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); return(Batch); }
/// <summary> /// Main method to Submit a specified batch /// </summary> /// <param name="ACurrentRecurringBatchRow">The batch row to Submit</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 Submited</returns> public bool SubmitBatch(ARecurringGiftBatchRow ACurrentRecurringBatchRow, bool AWarnOfInactiveValues = true, bool ADonorZeroIsValid = false, bool ARecipientZeroIsValid = false) { if (ACurrentRecurringBatchRow == null) { return(false); } FSelectedBatchNumber = ACurrentRecurringBatchRow.BatchNumber; //Make sure that all control data is in dataset FMyForm.GetLatestControlData(); //Copy all batch data to new table GiftBatchTDSARecurringGiftDetailTable RecurringBatchGiftDetails = new GiftBatchTDSARecurringGiftDetailTable(); //Filter ARecurringGiftDetail DataView RecurringGiftDetailDV = new DataView(FMainDS.ARecurringGiftDetail); RecurringGiftDetailDV.RowFilter = string.Format("{0}={1}", ARecurringGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber); RecurringGiftDetailDV.Sort = string.Format("{0} ASC, {1} ASC, {2} ASC", ARecurringGiftDetailTable.GetBatchNumberDBName(), ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), ARecurringGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dRV in RecurringGiftDetailDV) { GiftBatchTDSARecurringGiftDetailRow rGBR = (GiftBatchTDSARecurringGiftDetailRow)dRV.Row; RecurringBatchGiftDetails.Rows.Add((object[])rGBR.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.SaveChangesForSubmitting(RecurringBatchGiftDetails)) { return(false); } } 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(TExtraGiftBatchChecks.GiftBatchAction.SUBMITTING) || FMyForm.GiftHasExWorkerOrAnon(RecurringBatchGiftDetails) ) { return(false); } } //Check hash total validity if ((ACurrentRecurringBatchRow.HashTotal != 0) && (ACurrentRecurringBatchRow.BatchTotal != ACurrentRecurringBatchRow.HashTotal)) { MessageBox.Show(String.Format(Catalog.GetString( "The recurring gift batch total ({0}) for batch {1} does not equal the hash total ({2})."), StringHelper.FormatUsingCurrencyCode(ACurrentRecurringBatchRow.BatchTotal, ACurrentRecurringBatchRow.CurrencyCode), ACurrentRecurringBatchRow.BatchNumber, StringHelper.FormatUsingCurrencyCode(ACurrentRecurringBatchRow.HashTotal, ACurrentRecurringBatchRow.CurrencyCode)), "Submit Recurring Gift Batch"); FMyForm.GetBatchControl().Controls["txtDetailHashTotal"].Focus(); FMyForm.GetBatchControl().Controls["txtDetailHashTotal"].Select(); return(false); } //Check for zero Donors or Recipients if (!ADonorZeroIsValid) { DataView recurringBatchGiftDV = new DataView(FMainDS.ARecurringGift); recurringBatchGiftDV.RowFilter = string.Format("{0}={1} And {2}=0", ARecurringGiftTable.GetBatchNumberDBName(), FSelectedBatchNumber, ARecurringGiftTable.GetDonorKeyDBName()); int numDonorZeros = recurringBatchGiftDV.Count; if (numDonorZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Recurring 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 recurringBatchGiftDV) { ARecurringGiftRow giftRow = (ARecurringGiftRow)drv.Row; listOfOffendingRows += String.Format("{0}{1:0000}", Environment.NewLine, giftRow.GiftTransactionNumber); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); extendedMessageBox.ShowDialog((messageListOfOffendingGifts + listOfOffendingRows), Catalog.GetString("Submit Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(false); } } if (!ARecipientZeroIsValid) { DataView recurringBatchGiftDetailsDV = new DataView(FMainDS.ARecurringGiftDetail); recurringBatchGiftDetailsDV.RowFilter = string.Format("{0}={1} And {2}=0", ARecurringGiftDetailTable.GetBatchNumberDBName(), FSelectedBatchNumber, ARecurringGiftDetailTable.GetRecipientKeyDBName()); int numRecipientZeros = recurringBatchGiftDetailsDV.Count; if (numRecipientZeros > 0) { string messageListOfOffendingGifts = String.Format(Catalog.GetString( "Recurring 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 recurringBatchGiftDetailsDV) { ARecurringGiftDetailRow giftDetailRow = (ARecurringGiftDetailRow)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("Submit Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); return(false); } } //Check for inactive KeyMinistries DataTable GiftsWithInactiveKeyMinistries; if (TRemote.MFinance.Gift.WebConnectors.InactiveKeyMinistriesFoundInBatch(FLedgerNumber, FSelectedBatchNumber, out GiftsWithInactiveKeyMinistries, true)) { int numInactiveValues = GiftsWithInactiveKeyMinistries.Rows.Count; string listOfOffendingRows = String.Format(Catalog.GetString( "{0} inactive key ministries found in Recurring Gift Batch {1}. Do you still want to submit?{2}{2}"), numInactiveValues, FSelectedBatchNumber, Environment.NewLine); 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]); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm()); if (extendedMessageBox.ShowDialog(listOfOffendingRows.ToString(), Catalog.GetString("Submit Batch"), string.Empty, TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiWarning) != TFrmExtendedMessageBox.TResult.embrYes) { return(false); } } TFrmRecurringGiftBatchSubmit SubmitForm = new TFrmRecurringGiftBatchSubmit(FPetraUtilsObject.GetForm()); try { FMyForm.ShowInTaskbar = false; SubmitForm.MainDS = FMainDS; SubmitForm.BatchRow = ACurrentRecurringBatchRow; SubmitForm.ShowDialog(); } finally { SubmitForm.Dispose(); FMyForm.ShowInTaskbar = true; } return(true); }
/// <summary> /// Undo all changes to the specified batch ready to delete it. /// This avoids unecessary validation errors when deleting. /// </summary> /// <param name="ABatchToDelete"></param> /// <param name="ARedisplay"></param> public void PrepareBatchDataForDeleting(Int32 ABatchToDelete, bool ARedisplay) { //This code will only be called when the Batch tab is active. DataView GiftBatchDV = new DataView(FMainDS.ARecurringGiftBatch); DataView GiftDV = new DataView(FMainDS.ARecurringGift); DataView GiftDetailDV = new DataView(FMainDS.ARecurringGiftDetail); GiftBatchDV.RowFilter = String.Format("{0}={1}", ARecurringGiftBatchTable.GetBatchNumberDBName(), ABatchToDelete); GiftDV.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchToDelete); GiftDetailDV.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchToDelete); //Work from lowest level up if (GiftDetailDV.Count > 0) { GiftDetailDV.Sort = String.Format("{0}, {1}", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), ARecurringGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in GiftDetailDV) { ARecurringGiftDetailRow gDR = (ARecurringGiftDetailRow)drv.Row; if (gDR.RowState == DataRowState.Added) { //Do nothing } else if (gDR.RowState != DataRowState.Unchanged) { gDR.RejectChanges(); } } } if (GiftDV.Count > 0) { GiftDV.Sort = String.Format("{0}", ARecurringGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView drv in GiftDV) { ARecurringGiftRow gR = (ARecurringGiftRow)drv.Row; if (gR.RowState == DataRowState.Added) { //Do nothing } else if (gR.RowState != DataRowState.Unchanged) { gR.RejectChanges(); } } } if (GiftBatchDV.Count > 0) { ARecurringGiftBatchRow gB = (ARecurringGiftBatchRow)GiftBatchDV[0].Row; //No need to check for Added state as new batches are always saved // on creation if (gB.RowState != DataRowState.Unchanged) { gB.RejectChanges(); } if (ARedisplay) { ShowDetails(gB); } } if (GiftDetailDV.Count == 0) { //Load all related data for batch ready to delete FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadRecurringGiftTransactionsForBatch(FLedgerNumber, ABatchToDelete)); } }
public static bool MaintainSponsorshipRecurringGifts( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftTransactionNumber, Int32 ADetailNumber, Int64 ARecipientKey, Int64 ADonorKey, String AMotivationGroupCode, String AMotivationDetailCode, decimal AGiftAmount, DateTime AStartDonations, DateTime?AEndDonations, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); if (ADonorKey <= 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the donor", "", "MaintainChildren.ErrMissingDonor", TResultSeverity.Resv_Critical)); } if (AGiftAmount <= 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid amount", "", "MaintainChildren.ErrMissingAmount", TResultSeverity.Resv_Critical)); } if ((AMotivationDetailCode == "") || (AMotivationDetailCode == null)) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the motivation", "", "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical)); } if (AVerificationResult.HasCriticalErrors) { return(false); } TDBTransaction Transaction = new TDBTransaction(); SponsorshipTDS MainDS = new SponsorshipTDS(); TDataBase DB = DBAccess.Connect("MaintainRecurringGifts"); bool MotivationExists = false; // load batches and their transactions based on their id / batch number DB.ReadTransaction(ref Transaction, delegate { // we overwrite the user input, since the user can't really send the right batch number on create ABatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction); ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); MotivationExists = AMotivationDetailAccess.Exists(ALedgerNumber, AMotivationGroupCode, AMotivationDetailCode, Transaction); }); if (!MotivationExists) { AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid motivation", "", "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical)); return(false); } // try to get a row with requested id, aka edit else make a new ARecurringGiftRow EditGiftRow = null; foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows) { if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber) { EditGiftRow = CheckGiftRow; break; } } // we did not find a Transaction in this Batch, so we create one if (EditGiftRow == null) { // TODO: we could look for a gift transaction of the same donor??? EditGiftRow = MainDS.ARecurringGift.NewRowTyped(true); EditGiftRow.DonorKey = ADonorKey; EditGiftRow.BatchNumber = ABatchNumber; EditGiftRow.LedgerNumber = ALedgerNumber; EditGiftRow.GiftTransactionNumber = MainDS.ARecurringGiftBatch[0].LastGiftNumber + 1; MainDS.ARecurringGiftBatch[0].LastGiftNumber++; MainDS.ARecurringGift.Rows.Add(EditGiftRow); } // load stuff based on the current edit row DB.ReadTransaction(ref Transaction, delegate { ARecurringGiftDetailAccess.LoadViaARecurringGift(MainDS, ALedgerNumber, ABatchNumber, EditGiftRow.GiftTransactionNumber, Transaction); }); DB.CloseDBConnection(); // try to get a row with requested id, aka edit else make a new ARecurringGiftDetailRow EditGiftDetailRow = null; foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows) { if (CheckGiftDetailRow.DetailNumber == ADetailNumber) { EditGiftDetailRow = CheckGiftDetailRow; break; } } // none found, make one if (EditGiftDetailRow == null) { EditGiftDetailRow = MainDS.ARecurringGiftDetail.NewRowTyped(true); EditGiftDetailRow.LedgerNumber = ALedgerNumber; EditGiftDetailRow.BatchNumber = ABatchNumber; EditGiftDetailRow.RecipientKey = ARecipientKey; EditGiftDetailRow.GiftTransactionNumber = EditGiftRow.GiftTransactionNumber; EditGiftDetailRow.DetailNumber = EditGiftRow.LastDetailNumber + 1; EditGiftRow.LastDetailNumber++; MainDS.ARecurringGiftDetail.Rows.Add(EditGiftDetailRow); } EditGiftRow.DonorKey = ADonorKey; EditGiftDetailRow.GiftAmount = AGiftAmount; EditGiftDetailRow.MotivationGroupCode = AMotivationGroupCode; EditGiftDetailRow.MotivationDetailCode = AMotivationDetailCode; EditGiftDetailRow.EndDonations = AEndDonations; EditGiftDetailRow.StartDonations = AStartDonations; try { SponsorshipTDSAccess.SubmitChanges(MainDS); return(true); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } }
public static bool DeleteSponsorshipRecurringGift( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftTransactionNumber, Int32 ADetailNumber, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); TDBTransaction Transaction = new TDBTransaction(); SponsorshipTDS MainDS = new SponsorshipTDS(); TDataBase DB = DBAccess.Connect("DeleteRecurringGift"); // load batches and their transactions based on their id / batch number DB.ReadTransaction(ref Transaction, delegate { ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); }); try { bool LastDetail = true; ARecurringGiftDetailRow DetailToDelete = null; ARecurringGiftRow GiftToDelete = null; foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows) { if (CheckGiftDetailRow.GiftTransactionNumber == AGiftTransactionNumber) { if (CheckGiftDetailRow.DetailNumber == ADetailNumber) { DetailToDelete = CheckGiftDetailRow; DetailToDelete.DetailNumber = 20000; } else { LastDetail = false; if (CheckGiftDetailRow.DetailNumber > ADetailNumber) { CheckGiftDetailRow.DetailNumber--; } } } } foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows) { if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber) { if (LastDetail) { GiftToDelete = CheckGiftRow; } else { CheckGiftRow.LastDetailNumber--; } } } // delete the detail if (DetailToDelete != null) { DetailToDelete.Delete(); } // delete the gift if (GiftToDelete != null) { // we keep the gift transaction numbers, and live with gaps. GiftToDelete.Delete(); } SponsorshipTDSAccess.SubmitChanges(MainDS, DB); return(true); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } finally { DB.CloseDBConnection(); } }
public void TestRecurringBatchLoadingRecalculations() { TVerificationResultCollection VerificationResult; Int64 RecipientKey; Int64 RealRecipientLedgerNumber; Int64 FalseRecipientLedgerNumber; Int32 RecurringGiftBatchNumber; // // Arrange: Create all data needed for this test (Recurring Gift Detail will have 'fake' RecipientLedgerNumber) // TestRecurringBatchSubmitRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber, out FalseRecipientLedgerNumber, out RecurringGiftBatchNumber); // // Act: Load the batch // GiftBatchTDS GiftBatchDS = TGiftTransactionWebConnector.LoadARecurringGiftBatchAndRelatedData(FLedgerNumber, RecurringGiftBatchNumber); // // Assert // // Initial Assert: Tests that the load returns results Assert.IsNotNull(GiftBatchDS, "TestRecurringBatchLoadingRecalculations fail: Loading GiftBatch failed"); Assert.IsNotNull(GiftBatchDS.ARecurringGiftDetail, "TestRecurringBatchLoadingRecalculations fail: Loading GiftBatch failed"); // Primary Assert: Chaeck that the gift has the correct RecipientLedgerNumber TDBTransaction Transaction = null; ARecurringGiftDetailRow RecurringGiftDetailRow = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { RecurringGiftDetailRow = ARecurringGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, RecurringGiftBatchNumber, 1, 1, Transaction)[0]; }); Assert.IsNotNull( RecurringGiftDetailRow, "TestRecurringBatchLoadingRecalculations fail: Obtaining RecurringGiftDetailRow from database failed"); Assert.AreEqual(RealRecipientLedgerNumber, RecurringGiftDetailRow.RecipientLedgerNumber, "TestRecurringBatchLoadingRecalculations fail: RecipientLedgerNumber for RecurringGiftDetailRow is incorrect"); // Cleanup: Delete test records bool SubmissionOK = true; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK, delegate { ARecurringGiftDetailAccess.DeleteRow(ARecurringGiftDetailTable.TableId, RecurringGiftDetailRow, Transaction); }); TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult); TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult); TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult); }
/// <summary> /// Creates data needed to test posting recalculations /// </summary> /// <param name="ARecipientKey">Partner Key of the recipient.</param> /// <param name="ARealRecipientLedgerNumber">What the RecipientLedgerNumber should be.</param> /// <param name="AFalseRecipientLedgerNumber">What the RecipientLedgerNumber is.</param> /// <param name="ARecurringGiftBatchNumber">Batch Number.</param> private void TestRecurringBatchSubmitRecalculations_Arrange(out long ARecipientKey, out long ARealRecipientLedgerNumber, out long AFalseRecipientLedgerNumber, out Int32 ARecurringGiftBatchNumber) { TVerificationResultCollection VerificationResult; TSubmitChangesResult Result; DataSet ResponseDS; TPartnerEditUIConnector PartnerEditUIUIConnector = new TPartnerEditUIConnector(); GiftBatchTDS MainDS = new GiftBatchTDS(); PartnerEditTDS PartnerEditDS = new PartnerEditTDS(); // this is a family partner in the test database const Int64 DONORKEY = 43005001; // create a new recipient TCreateTestPartnerData.CreateNewFamilyPartner(PartnerEditDS); ARecipientKey = PartnerEditDS.PFamily[0].PartnerKey; // create two new Unit partners TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); AFalseRecipientLedgerNumber = PartnerEditDS.PPartner[0].PartnerKey; ARealRecipientLedgerNumber = PartnerEditDS.PPartner[1].PartnerKey; // create a Gift Destination for family PPartnerGiftDestinationRow GiftDestination = PartnerEditDS.PPartnerGiftDestination.NewRowTyped(true); GiftDestination.Key = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); GiftDestination.PartnerKey = ARecipientKey; GiftDestination.DateEffective = new DateTime(2011, 01, 01); GiftDestination.FieldKey = ARealRecipientLedgerNumber; PartnerEditDS.PPartnerGiftDestination.Rows.Add(GiftDestination); // Guard Assertions Assert.That(PartnerEditDS.PFamily[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[1], Is.Not.Null); // Submit the new PartnerEditTDS records to the database ResponseDS = new PartnerEditTDS(); Result = PartnerEditUIUIConnector.SubmitChanges(ref PartnerEditDS, ref ResponseDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SubmitChanges for PartnerEditDS failed: " + VerificationResult.BuildVerificationResultString()); // link unit to Cost Centre DataTable PartnerCostCentreTbl = TGLSetupWebConnector.LoadCostCentrePartnerLinks(FLedgerNumber, 0); DataRow PartnerCostCentreRow = PartnerCostCentreTbl.NewRow(); PartnerCostCentreRow["PartnerKey"] = ARealRecipientLedgerNumber; PartnerCostCentreRow["IsLinked"] = 4300; PartnerCostCentreTbl.Rows.Add(PartnerCostCentreRow); TGLSetupWebConnector.SaveCostCentrePartnerLinks(FLedgerNumber, PartnerCostCentreTbl); // create a new Recurring Gift Batch MainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); ARecurringGiftBatchNumber = MainDS.ARecurringGiftBatch[0].BatchNumber; // create a new recurring gifts ARecurringGiftRow RecurringGiftRow = MainDS.ARecurringGift.NewRowTyped(true); RecurringGiftRow.LedgerNumber = FLedgerNumber; RecurringGiftRow.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftRow.DonorKey = DONORKEY; RecurringGiftRow.GiftTransactionNumber = 1; RecurringGiftRow.LastDetailNumber = 1; MainDS.ARecurringGift.Rows.Add(RecurringGiftRow); // create a new RecurringGiftDetail ARecurringGiftDetailRow RecurringGiftDetail = MainDS.ARecurringGiftDetail.NewRowTyped(true); RecurringGiftDetail.LedgerNumber = FLedgerNumber; RecurringGiftDetail.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.DetailNumber = 1; RecurringGiftDetail.RecipientLedgerNumber = AFalseRecipientLedgerNumber; RecurringGiftDetail.GiftAmount = 100; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = ARecipientKey; MainDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); // Submit the new GiftBatchTDS records to the database Result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref MainDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SaveGiftBatchTDS failed: " + VerificationResult.BuildVerificationResultString()); }
private void UpdateTotals() { if ((FPetraUtilsObject == null)) { return; } Decimal SumTransactions = 0; Decimal SumBatch = 0; Int32 GiftNumber = 0; //Sometimes a change in an unbound textbox causes a data changed condition bool SaveButtonWasEnabled = FPetraUtilsObject.HasChanges; bool DataChanges = false; if (FPreviouslySelectedDetailRow == null) { if ((txtGiftTotal.NumberValueDecimal.HasValue && (txtGiftTotal.NumberValueDecimal.Value != 0)) || (txtBatchTotal.NumberValueDecimal.HasValue && (txtBatchTotal.NumberValueDecimal.Value != 0))) { txtGiftTotal.NumberValueDecimal = 0; txtBatchTotal.NumberValueDecimal = 0; } //If all details have been deleted if ((FLedgerNumber != -1) && (FBatchRow != null) && (grdDetails.Rows.Count == 1)) { //((TFrmRecurringGiftBatch) this.ParentForm).GetBatchControl().UpdateBatchTotal(0, FBatchRow.BatchNumber); //Now we look at the batch and update the batch data if (FBatchRow.BatchTotal != SumBatch) { FBatchRow.BatchTotal = SumBatch; DataChanges = true; } } } else { GiftNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber; DataView giftDetailDV = new DataView(FMainDS.ARecurringGiftDetail); giftDetailDV.RowStateFilter = DataViewRowState.CurrentRows; giftDetailDV.RowFilter = String.Format("{0}={1}", ARecurringGiftDetailTable.GetBatchNumberDBName(), FBatchNumber); foreach (DataRowView drv in giftDetailDV) { ARecurringGiftDetailRow gdr = (ARecurringGiftDetailRow)drv.Row; if (gdr.GiftTransactionNumber == GiftNumber) { if (FPreviouslySelectedDetailRow.DetailNumber == gdr.DetailNumber) { SumTransactions += Convert.ToDecimal(txtDetailGiftAmount.NumberValueDecimal); SumBatch += Convert.ToDecimal(txtDetailGiftAmount.NumberValueDecimal); } else { SumTransactions += gdr.GiftAmount; SumBatch += gdr.GiftAmount; } } else { SumBatch += gdr.GiftAmount; } } if ((txtGiftTotal.NumberValueDecimal.HasValue == false) || (txtGiftTotal.NumberValueDecimal.Value != SumTransactions)) { txtGiftTotal.NumberValueDecimal = SumTransactions; } txtGiftTotal.CurrencyCode = txtDetailGiftAmount.CurrencyCode; txtGiftTotal.ReadOnly = true; //Now we look at the batch and update the batch data if (FBatchRow.BatchTotal != SumBatch) { FBatchRow.BatchTotal = SumBatch; DataChanges = true; } } if (txtBatchTotal.NumberValueDecimal.Value != SumBatch) { txtBatchTotal.NumberValueDecimal = SumBatch; } if (!DataChanges && !SaveButtonWasEnabled && FPetraUtilsObject.HasChanges) { FPetraUtilsObject.DisableSaveButton(); } }
public void TestRecurringBatchSubmitRecalculations() { TVerificationResultCollection VerificationResult; Int64 RecipientKey; Int64 RealRecipientLedgerNumber; Int64 FalseRecipientLedgerNumber; Int32 RecurringGiftBatchNumber; Int32 GiftBatchNumber = -1; // // Arrange: Create all data needed for this test (Recurring Gift Detail will have 'fake' RecipientLedgerNumber) // TestRecurringBatchSubmitRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber, out FalseRecipientLedgerNumber, out RecurringGiftBatchNumber); // // Act: Submit the batch // Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("ABatchNumber", RecurringGiftBatchNumber); requestParams.Add("AEffectiveDate", DateTime.Today); requestParams.Add("AExchangeRateToBase", (decimal)1); requestParams.Add("AExchangeRateIntlToBase", (decimal)1); TGiftTransactionWebConnector.SubmitRecurringGiftBatch(requestParams); // // Assert // // Primary Assert: Chaeck that the RecurringGiftDetail and the newly created GiftDetail have the correct RecipientLedgerNumber TDBTransaction Transaction = null; ARecurringGiftDetailRow RecurringGiftDetailRow = null; AGiftDetailRow GiftDetailRow = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { RecurringGiftDetailRow = ARecurringGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, RecurringGiftBatchNumber, 1, 1, Transaction)[0]; GiftBatchNumber = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, Transaction)[0].LastGiftBatchNumber; GiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 1, 1, Transaction)[0]; }); Assert.IsNotNull( RecurringGiftDetailRow, "TestRecurringBatchSubmitRecalculations fail: Obtaining RecurringGiftDetailRow from database failed"); Assert.IsNotNull( GiftDetailRow, "TestRecurringBatchSubmitRecalculations fail: Obtaining GiftDetailRow from database failed"); Assert.AreEqual(RealRecipientLedgerNumber, RecurringGiftDetailRow.RecipientLedgerNumber, "TestRecurringBatchSubmitRecalculations fail: RecipientLedgerNumber for RecurringGiftDetailRow is incorrect"); Assert.AreEqual(RealRecipientLedgerNumber, GiftDetailRow.RecipientLedgerNumber, "TestRecurringBatchSubmitRecalculations fail: RecipientLedgerNumber for GiftDetailRow is incorrect"); // Cleanup: Delete test records bool SubmissionOK = true; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK, delegate { AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, GiftDetailRow, Transaction); ARecurringGiftDetailAccess.DeleteRow(ARecurringGiftDetailTable.TableId, RecurringGiftDetailRow, Transaction); }); TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult); TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult); TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult); }
/// <summary> /// Validates the Recurring Gift Detail data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> /// <param name="ARecipientField">Optional</param> /// <returns>True if the validation found no data validation errors, otherwise false.</returns> public static bool ValidateRecurringGiftDetailManual(object AContext, ARecurringGiftDetailRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict, Int64 ARecipientField = -1) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; object ValidationContext; int VerifResultCollAddedCount = 0; bool ValidPartner = true; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return true; } // Check if valid donor ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnRecipientKeyId]; ValidationContext = String.Format("Batch no. {0}, gift no. {1}, detail no. {2}", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); VerificationResult = TSharedPartnerValidation_Partner.IsValidPartner( ARow.RecipientKey, new TPartnerClass[] { TPartnerClass.FAMILY, TPartnerClass.UNIT }, true, "Recipient of " + THelper.NiceValueDescription(ValidationContext.ToString()), AContext, ValidationColumn, null); if (VerificationResult != null) { AVerificationResultCollection.Remove(ValidationColumn); AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult); ValidPartner = false; } // 'Gift amount must be non-zero ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnGiftAmountId]; ValidationContext = String.Format("Batch Number {0} (transaction:{1} detail:{2})", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.GiftAmount, ValidationControlsData.ValidationControlLabel + " of " + ValidationContext, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } // If recipient is non-zero, field must also be non-zero. Only check for valid recipient keys. ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnRecipientLedgerNumberId]; ValidationContext = String.Format("batch:{0} transaction:{1} detail:{2}", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if ((ARow.RecipientKey > 0) && ValidPartner && (ARow.RecipientLedgerNumber == 0)) { VerificationResult = TNumericalChecks.IsGreaterThanZero(ARow.RecipientLedgerNumber, "Recipient field of " + ValidationContext + " is 0", AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } } // Motivation Detail must not be null ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnMotivationDetailCodeId]; ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (ARow.IsMotivationDetailCodeNull() || (ARow.MotivationDetailCode == String.Empty)) { VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.MotivationDetailCode, "Motivation Detail code " + ValidationContext, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } } // Detail comments type 1 must not be null if associated comment is not null ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnCommentOneTypeId]; ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsGiftCommentOneNull() && (ARow.GiftCommentOne != String.Empty)) { VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentOneType, "Comment 1 type " + ValidationContext, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } } // Detail comments type 2 must not be null if associated comment is not null ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnCommentTwoTypeId]; ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsGiftCommentTwoNull() && (ARow.GiftCommentTwo != String.Empty)) { VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentTwoType, "Comment 2 type " + ValidationContext, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } } // Detail comments type 3 must not be null if associated comment is not null ValidationColumn = ARow.Table.Columns[ARecurringGiftDetailTable.ColumnCommentThreeTypeId]; ValidationContext = String.Format("(batch:{0} transaction:{1} detail:{2})", ARow.BatchNumber, ARow.GiftTransactionNumber, ARow.DetailNumber); if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsGiftCommentThreeNull() && (ARow.GiftCommentThree != String.Empty)) { VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.CommentThreeType, "Comment 3 type " + ValidationContext, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } } return VerifResultCollAddedCount == 0; }
public void TestDeleteSavedGiftBatch() { Int64 donorKey = 43005001; Int64 recipKey = 43000000; int giftTransNumber = 1; int giftTranDetailNumber = 1; decimal giftAmount = 100.50M; string motivationGroupCode = "GIFT"; string motivationDetailCode = "SUPPORT"; //Create the recurring gift batch FMainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); FRecurringBatchNumberToDelete = FMainDS.ARecurringGiftBatch[0].BatchNumber; //Create the recurring gift batch's single gift header ARecurringGiftRow newRow = FMainDS.ARecurringGift.NewRowTyped(true); newRow.LedgerNumber = FLedgerNumber; newRow.BatchNumber = FRecurringBatchNumberToDelete; newRow.DonorKey = donorKey; newRow.GiftTransactionNumber = giftTransNumber; newRow.LastDetailNumber = giftTransNumber; FMainDS.ARecurringGift.Rows.Add(newRow); //Create the recurring gift batch's single gift detail ARecurringGiftDetailRow newDetailRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true); newDetailRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true); newDetailRow.LedgerNumber = FLedgerNumber; newDetailRow.BatchNumber = FRecurringBatchNumberToDelete; newDetailRow.GiftTransactionNumber = giftTransNumber; newDetailRow.DetailNumber = giftTranDetailNumber; newDetailRow.RecipientKey = recipKey; newDetailRow.GiftAmount = giftAmount; newDetailRow.MotivationGroupCode = motivationGroupCode; newDetailRow.MotivationDetailCode = motivationDetailCode; FMainDS.ARecurringGiftDetail.Rows.Add(newDetailRow); //Save changes GiftBatchTDSAccess.SubmitChanges(FMainDS); FMainDS.AcceptChanges(); // Delete the associated recurring gift detail rows. DataView viewGiftDetail = new DataView(FMainDS.ARecurringGiftDetail); viewGiftDetail.RowFilter = string.Empty; foreach (DataRowView row in viewGiftDetail) { row.Delete(); } Assert.AreNotEqual(0, FMainDS.ARecurringGiftDetail.Rows.Count, "after deletion the row should still exist"); // Delete the associated recurring gift rows. DataView viewGift = new DataView(FMainDS.ARecurringGift); viewGift.RowFilter = string.Empty; foreach (DataRowView row in viewGift) { row.Delete(); } Assert.AreNotEqual(0, FMainDS.ARecurringGiftBatch.Rows.Count, "after deletion the batch row should still exist"); // Delete the recurring batch row. FMainDS.ARecurringGiftBatch.Rows[0].Delete(); Assert.AreNotEqual(0, FMainDS.ARecurringGiftBatch.Rows.Count, "after deletion the batch row should still exist"); //Save changes GiftBatchTDSAccess.SubmitChanges(FMainDS); }
private void ValidateDataDetailsManual(ARecurringGiftDetailRow ARow) { if ((ARow == null) || (GetCurrentRecurringBatchRow() == null) || (GetCurrentRecurringBatchRow().BatchNumber != ARow.BatchNumber)) { return; } TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TSharedFinanceValidation_Gift.ValidateRecurringGiftDetailManual(this, ARow, ref VerificationResultCollection, FValidationControlsDict, Convert.ToInt64(txtDetailRecipientLedgerNumber.Text)); //It is necessary to validate the unbound control for date entered. This requires us to pass the control. ARecurringGiftRow giftRow = GetRecurringGiftRow(ARow.GiftTransactionNumber); TSharedFinanceValidation_Gift.ValidateRecurringGiftManual(this, giftRow, ref VerificationResultCollection, FValidationControlsDict); }
private void UpdateControlsProtection(ARecurringGiftDetailRow ARow) { bool firstIsEnabled = (ARow != null) && (ARow.DetailNumber == 1); bool pnlDetailsEnabledState = false; chkDetailActive.Enabled = firstIsEnabled; txtDetailDonorKey.Enabled = firstIsEnabled; cmbDetailMethodOfGivingCode.Enabled = firstIsEnabled; cmbDetailMethodOfPaymentCode.Enabled = firstIsEnabled && !BatchHasMethodOfPayment(); txtDetailReference.Enabled = firstIsEnabled; cmbDetailReceiptLetterCode.Enabled = firstIsEnabled; if (FBatchRow == null) { FBatchRow = GetCurrentRecurringBatchRow(); } if (ARow == null) { PnlDetailsProtected = true; } else { PnlDetailsProtected = (ARow != null && ARow.GiftAmount < 0 ); // taken from old petra } pnlDetailsEnabledState = (!PnlDetailsProtected && grdDetails.Rows.Count > 1); pnlDetails.Enabled = pnlDetailsEnabledState; btnDelete.Enabled = pnlDetailsEnabledState; }
/// <summary> /// Get Unsaved Recurring Batch Rows in a list /// </summary> /// <param name="ABatchToInclude">If > 0 then include in list even if unchanged</param> /// <returns></returns> public List <ARecurringGiftBatchRow> GetUnsavedBatchRowsList(int ABatchToInclude = 0) { List <ARecurringGiftBatchRow> RetVal = new List <ARecurringGiftBatchRow>(); List <int> BatchesWithChangesList = new List <int>(); string BatchesWithChangesString = string.Empty; DataView GiftBatchesDV = new DataView(FMainDS.ARecurringGiftBatch); GiftBatchesDV.Sort = ARecurringGiftBatchTable.GetBatchNumberDBName() + " ASC"; DataView GiftDV = new DataView(FMainDS.ARecurringGift); DataView GiftDetailsDV = new DataView(FMainDS.ARecurringGiftDetail); GiftDV.Sort = String.Format("{0} ASC, {1} ASC", ARecurringGiftTable.GetBatchNumberDBName(), ARecurringGiftTable.GetGiftTransactionNumberDBName()); GiftDetailsDV.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC", ARecurringGiftDetailTable.GetBatchNumberDBName(), ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), ARecurringGiftDetailTable.GetDetailNumberDBName()); //Add the batch number(s) of changed gift rows foreach (DataRowView dRV in GiftDV) { ARecurringGiftRow gR = (ARecurringGiftRow)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})", ARecurringGiftDetailTable.GetBatchNumberDBName(), BatchesWithChangesString); } foreach (DataRowView dRV in GiftDetailsDV) { ARecurringGiftDetailRow gDR = (ARecurringGiftDetailRow)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) { ARecurringGiftBatchRow giftBatchRow = (ARecurringGiftBatchRow)dRV.Row; if ((giftBatchRow.BatchNumber == ABatchToInclude) || BatchesWithChangesList.Contains(giftBatchRow.BatchNumber) || (giftBatchRow.RowState != DataRowState.Unchanged)) { RetVal.Add(giftBatchRow); } } return(RetVal); }