// update tax deductibility amounts when the gift amount or the tax deductible percentage has changed
        private void UpdateTaxDeductibilityAmounts(object sender, EventArgs e)
        {
            if (FCreatingNewGift || (txtDeductiblePercentage.NumberValueDecimal == null) || (FPreviouslySelectedDetailRow == null))
            {
                return;
            }

            if (FPreviouslySelectedDetailRow.IsTaxDeductiblePctNull())
            {
                FPreviouslySelectedDetailRow.TaxDeductiblePct = 0;
            }

            if (sender == txtDeductiblePercentage)
            {
                FPreviouslySelectedDetailRow.TaxDeductiblePct = (decimal)txtDeductiblePercentage.NumberValueDecimal;
            }

            AGiftDetailRow giftDetails = (AGiftDetailRow)FPreviouslySelectedDetailRow;

            TaxDeductibility.UpdateTaxDeductibiltyAmounts(ref giftDetails);

            txtTaxDeductAmount.NumberValueDecimal = FPreviouslySelectedDetailRow.TaxDeductibleAmount;
            txtNonDeductAmount.NumberValueDecimal = FPreviouslySelectedDetailRow.NonDeductibleAmount;
        }
        private void OnRecipientKeyChanged(Int64 APartnerKey,
                                           String APartnerShortName,
                                           bool AValidSelection,
                                           out bool ADoValidateRecurringGiftDestination)
        {
            ADoValidateRecurringGiftDestination = false;

            if (FRecipientKeyChangedInProcess ||
                FPetraUtilsObject.SuppressChangeDetection ||
                FShowDetailsInProcess)
            {
                return;
            }

            // get the recipient ledger number
            Int64 RecipientLedgerNumber = 0;

            if (APartnerKey > 0)
            {
                RecipientLedgerNumber = TRemote.MFinance.Gift.WebConnectors.GetRecipientFundNumber(APartnerKey,
                                                                                                   DateTime.Now);
            }

            FRecipientKeyChangedInProcess = true;

            try
            {
                FPreviouslySelectedDetailRow.BeginEdit();
                txtDetailRecipientKeyMinistry.Text                = string.Empty;
                FPreviouslySelectedDetailRow.RecipientKey         = APartnerKey;
                FPreviouslySelectedDetailRow.RecipientDescription = APartnerShortName;
                FPreviouslySelectedDetailRow.RecipientClass       = txtDetailRecipientKey.CurrentPartnerClass.ToString();

                FPetraUtilsObject.SuppressChangeDetection = true;

                //Set RecipientLedgerNumber
                FPreviouslySelectedDetailRow.RecipientLedgerNumber = RecipientLedgerNumber;

                if (!FKeyMinistryChangedInProcess)
                {
                    GetRecipientData(APartnerKey, FMotivationDetailHasChangedFlag);
                    ADoValidateRecurringGiftDestination = true;
                }

                FPetraUtilsObject.SuppressChangeDetection = false;

                // do not want to update motivation comboboxes if recipient key is being changed due to a new Recurring Gift or the motivation detail being changed
                if (!FMotivationDetailHasChangedFlag && !FNewGiftInProcess &&
                    TRemote.MFinance.Gift.WebConnectors.GetMotivationGroupAndDetailForPartner(APartnerKey, ref FMotivationGroup,
                                                                                              ref FMotivationDetail))
                {
                    if (cmbDetailMotivationGroupCode.GetSelectedString() != FMotivationGroup)
                    {
                        // note - this will also update the Motivation Detail
                        cmbDetailMotivationGroupCode.SetSelectedString(FMotivationGroup, -1);
                    }

                    if (cmbMotivationDetailCode.GetSelectedString() != FMotivationDetail)
                    {
                        cmbMotivationDetailCode.SetSelectedString(FMotivationDetail, -1);
                    }

                    FPreviouslySelectedDetailRow.MotivationGroupCode  = FMotivationGroup;
                    FPreviouslySelectedDetailRow.MotivationDetailCode = FMotivationDetail;
                }

                FPetraUtilsObject.SuppressChangeDetection = true;

                if (APartnerKey > 0)
                {
                    ApplyRecipientCostCentreCode();
                }
                else
                {
                    UpdateRecipientKeyText(APartnerKey, FPreviouslySelectedDetailRow, FMotivationGroup, FMotivationDetail);

                    DisplayMotivationDetailCostCentreCode();
                }
            }
            finally
            {
                FRecipientKeyChangedInProcess = false;
                ReconcileKeyMinistryFromCombo(FPreviouslySelectedDetailRow);
                FPreviouslySelectedDetailRow.EndEdit();
                FPetraUtilsObject.SuppressChangeDetection = false;
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new gift or gift detail depending upon the parameter
        /// </summary>
        /// <param name="ACompletelyNewGift"></param>
        private void CreateANewGift(bool ACompletelyNewGift)
        {
            AGiftRow CurrentGiftRow = null;
            bool     IsEmptyGrid    = (grdDetails.Rows.Count == 1);
            bool     HasChanges     = FPetraUtilsObject.HasChanges;
            bool     SelectEndRow   = false;

            bool FPrevRowIsNull = (FPreviouslySelectedDetailRow == null);
            bool CopyDetails    = false;

            bool AutoSaveSuccessful = FAutoSave && HasChanges && ((TFrmGiftBatch)ParentForm).SaveChangesManual();

            FCreatingNewGift = true;

            try
            {
                //May need to copy values down if a new detail row inside current gift
                int    giftTransactionNumber = 0;
                string donorName             = string.Empty;
                string donorClass            = string.Empty;
                bool   confidentialGiftFlag  = false;
                bool   chargeFlag            = false;
                bool   taxDeductible         = false;
                string motivationGroupCode   = string.Empty;
                string motivationDetailCode  = string.Empty;

                if (AutoSaveSuccessful || ((!FAutoSave || !HasChanges) && ValidateAllData(true, TErrorProcessingMode.Epm_IgnoreNonCritical)))
                {
                    if (!ACompletelyNewGift)      //i.e. a gift detail
                    {
                        ACompletelyNewGift = IsEmptyGrid;
                    }

                    CopyDetails = (!ACompletelyNewGift && !FPrevRowIsNull);

                    if (CopyDetails)
                    {
                        //Allow for possibility that FPrev... may have some null column values
                        giftTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber;
                        donorName             = FPreviouslySelectedDetailRow.IsDonorNameNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorName;
                        donorClass            = FPreviouslySelectedDetailRow.IsDonorClassNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorClass;
                        confidentialGiftFlag  =
                            FPreviouslySelectedDetailRow.IsConfidentialGiftFlagNull() ? false : FPreviouslySelectedDetailRow.ConfidentialGiftFlag;
                        chargeFlag          = FPreviouslySelectedDetailRow.IsChargeFlagNull() ? true : FPreviouslySelectedDetailRow.ChargeFlag;
                        taxDeductible       = FPreviouslySelectedDetailRow.IsTaxDeductibleNull() ? true : FPreviouslySelectedDetailRow.TaxDeductible;
                        motivationGroupCode =
                            FPreviouslySelectedDetailRow.IsMotivationGroupCodeNull() ? string.Empty : FPreviouslySelectedDetailRow.
                            MotivationGroupCode;
                        motivationDetailCode =
                            FPreviouslySelectedDetailRow.IsMotivationDetailCodeNull() ? string.Empty : FPreviouslySelectedDetailRow.
                            MotivationDetailCode;
                    }

                    //Set previous row to Null.
                    FPreviouslySelectedDetailRow = null;

                    if (ACompletelyNewGift)
                    {
                        //Run this if a new gift is requested or required.
                        SelectEndRow = true;

                        // we create the row locally, no dataset
                        AGiftRow giftRow = FMainDS.AGift.NewRowTyped(true);

                        giftRow.LedgerNumber          = FBatchRow.LedgerNumber;
                        giftRow.BatchNumber           = FBatchRow.BatchNumber;
                        giftRow.GiftTransactionNumber = ++FBatchRow.LastGiftNumber;
                        giftRow.MethodOfPaymentCode   = FBatchRow.MethodOfPaymentCode;
                        giftRow.LastDetailNumber      = 1;
                        giftRow.DateEntered           = FBatchRow.GlEffectiveDate;

                        FMainDS.AGift.Rows.Add(giftRow);

                        CurrentGiftRow = giftRow;

                        mniDonorHistory.Enabled = false;

                        //Reset textboxes to zero
                        txtGiftTotal.NumberValueDecimal = 0;
                    }
                    else
                    {
                        CurrentGiftRow = GetGiftRow(giftTransactionNumber);
                        CurrentGiftRow.LastDetailNumber++;

                        //If adding detail to current last gift, then new detail will be bottom row in grid
                        if (FBatchRow.LastGiftNumber == giftTransactionNumber)
                        {
                            SelectEndRow = true;
                        }
                    }

                    //New gifts will require a new detail anyway, so this code always runs
                    GiftBatchTDSAGiftDetailRow newRow = FMainDS.AGiftDetail.NewRowTyped(true);

                    newRow.LedgerNumber          = FBatchRow.LedgerNumber;
                    newRow.BatchNumber           = FBatchRow.BatchNumber;
                    newRow.GiftTransactionNumber = CurrentGiftRow.GiftTransactionNumber;
                    newRow.DetailNumber          = CurrentGiftRow.LastDetailNumber;
                    newRow.MethodOfPaymentCode   = CurrentGiftRow.MethodOfPaymentCode;
                    newRow.MethodOfGivingCode    = CurrentGiftRow.MethodOfGivingCode;
                    newRow.DonorKey = CurrentGiftRow.DonorKey;

                    if (CopyDetails)
                    {
                        newRow.DonorName            = donorName;
                        newRow.DonorClass           = donorClass;
                        newRow.ConfidentialGiftFlag = confidentialGiftFlag;
                        newRow.ChargeFlag           = chargeFlag;
                        newRow.TaxDeductible        = taxDeductible;
                        newRow.MotivationGroupCode  = motivationGroupCode;
                        newRow.MotivationDetailCode = motivationDetailCode;

                        // set the auto-populate comment if needed
                        AMotivationDetailRow motivationDetail = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find(
                            new object[] { FLedgerNumber, newRow.MotivationGroupCode, newRow.MotivationDetailCode });

                        if ((motivationDetail != null) && motivationDetail.Autopopdesc)
                        {
                            newRow.GiftCommentOne = motivationDetail.MotivationDetailDesc;
                        }
                    }
                    else
                    {
                        newRow.MotivationGroupCode  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                        newRow.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                    }

                    newRow.DateEntered    = CurrentGiftRow.DateEntered;
                    newRow.ReceiptPrinted = false;
                    newRow.ReceiptNumber  = 0;

                    if (FTaxDeductiblePercentageEnabled)
                    {
                        newRow.TaxDeductiblePct = newRow.TaxDeductible ? 100.0m : 0.0m;

                        //Set unbound textboxes to 0
                        txtTaxDeductAmount.NumberValueDecimal = 0.0m;
                        txtNonDeductAmount.NumberValueDecimal = 0.0m;
                    }

                    FMainDS.AGiftDetail.Rows.Add(newRow);

                    FPetraUtilsObject.SetChangedFlag();

                    if (!SelectEndRow && !SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1))
                    {
                        if (!FFilterAndFindObject.IsActiveFilterEqualToBase)
                        {
                            MessageBox.Show(
                                MCommonResourcestrings.StrNewRecordIsFiltered,
                                MCommonResourcestrings.StrAddNewRecordTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters();

                            if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None)
                            {
                                FFilterAndFindObject.ApplyFilter();
                            }

                            SelectDetailRowByDataTableIndex(FMainDS.AGiftDetail.Rows.Count - 1);
                        }
                    }

                    btnDeleteAll.Enabled = btnDelete.Enabled;
                    UpdateRecordNumberDisplay();
                    FLastDonor = -1;

                    //Select end row
                    if (SelectEndRow)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1);
                    }

                    //Focus accordingly
                    if (ACompletelyNewGift)
                    {
                        txtDetailDonorKey.Focus();
                    }
                    else
                    {
                        txtDetailRecipientKey.Focus();
                    }

                    //FPreviouslySelectedDetailRow should now be pointing to the newly added row
                    TUC_GiftTransactions_Recipient.UpdateRecipientKeyText(0,
                                                                          FPreviouslySelectedDetailRow,
                                                                          cmbDetailMotivationGroupCode.GetSelectedString(),
                                                                          cmbDetailMotivationDetailCode.GetSelectedString());
                    cmbKeyMinistries.Clear();
                    mniRecipientHistory.Enabled = false;
                }
            }
            finally
            {
                FCreatingNewGift = false;

                if (AutoSaveSuccessful)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                }
            }
        }
        /// <summary>
        /// Update the transaction base amount calculation
        /// </summary>
        /// <param name="AUpdateCurrentRowOnly"></param>
        public void UpdateBaseAmount(Boolean AUpdateCurrentRowOnly)
        {
            Int32 LedgerNumber;
            Int32 CurrentBatchNumber;

            DateTime BatchEffectiveDate;

            decimal BatchExchangeRateToBase    = 0;
            string  BatchCurrencyCode          = string.Empty;
            decimal IntlToBaseCurrencyExchRate = 0;
            bool    IsTransactionInIntlCurrency;

            string LedgerBaseCurrency = string.Empty;
            string LedgerIntlCurrency = string.Empty;

            bool TransactionsFromCurrentBatch = false;

            AGiftBatchRow CurrentBatchRow = GetBatchRow();

            if (FShowDetailsInProcess ||
                !(((TFrmGiftBatch)this.ParentForm).GetBatchControl().FBatchLoaded) ||
                (CurrentBatchRow == null) ||
                (CurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED))
            {
                return;
            }

            BatchCurrencyCode       = CurrentBatchRow.CurrencyCode;
            BatchExchangeRateToBase = CurrentBatchRow.ExchangeRateToBase;

            if ((FBatchRow != null) &&
                (CurrentBatchRow.LedgerNumber == FBatchRow.LedgerNumber) &&
                (CurrentBatchRow.BatchNumber == FBatchRow.BatchNumber))
            {
                TransactionsFromCurrentBatch = true;
                FBatchCurrencyCode           = BatchCurrencyCode;
                FBatchExchangeRateToBase     = BatchExchangeRateToBase;
            }

            LedgerNumber       = CurrentBatchRow.LedgerNumber;
            CurrentBatchNumber = CurrentBatchRow.BatchNumber;

            BatchEffectiveDate = CurrentBatchRow.GlEffectiveDate;
            LedgerBaseCurrency = FMainDS.ALedger[0].BaseCurrency;
            LedgerIntlCurrency = FMainDS.ALedger[0].IntlCurrency;

            IntlToBaseCurrencyExchRate = ((TFrmGiftBatch)ParentForm).InternationalCurrencyExchangeRate(CurrentBatchRow,
                                                                                                       out IsTransactionInIntlCurrency);

            if (!LoadGiftDataForBatch(LedgerNumber, CurrentBatchNumber))
            {
                //No transactions exist to process or corporate exchange rate not found
                return;
            }

            //If only updating the currency active row
            if (AUpdateCurrentRowOnly && (FPreviouslySelectedDetailRow != null))
            {
                try
                {
                    FPreviouslySelectedDetailRow.BeginEdit();

                    FPreviouslySelectedDetailRow.GiftAmount = GLRoutines.Divide((decimal)txtDetailGiftTransactionAmount.NumberValueDecimal,
                                                                                BatchExchangeRateToBase);

                    if (!IsTransactionInIntlCurrency)
                    {
                        FPreviouslySelectedDetailRow.GiftAmountIntl = (IntlToBaseCurrencyExchRate == 0) ? 0 : GLRoutines.Divide(
                            FPreviouslySelectedDetailRow.GiftAmount,
                            IntlToBaseCurrencyExchRate);
                    }
                    else
                    {
                        FPreviouslySelectedDetailRow.GiftAmountIntl = FPreviouslySelectedDetailRow.GiftTransactionAmount;
                    }

                    if (FSETUseTaxDeductiblePercentageFlag)
                    {
                        EnableTaxDeductibilityPct(chkDetailTaxDeductible.Checked);
                        UpdateTaxDeductibilityAmounts(this, null);
                    }
                }
                finally
                {
                    FPreviouslySelectedDetailRow.EndEdit();
                }
            }
            else
            {
                if (TransactionsFromCurrentBatch && (FPreviouslySelectedDetailRow != null))
                {
                    try
                    {
                        //Rows already active in transaction tab. Need to set current row as code further below will not update selected row
                        FPreviouslySelectedDetailRow.BeginEdit();

                        FPreviouslySelectedDetailRow.GiftAmount = GLRoutines.Divide(FPreviouslySelectedDetailRow.GiftTransactionAmount,
                                                                                    BatchExchangeRateToBase);

                        if (!IsTransactionInIntlCurrency)
                        {
                            FPreviouslySelectedDetailRow.GiftAmountIntl = (IntlToBaseCurrencyExchRate == 0) ? 0 : GLRoutines.Divide(
                                FPreviouslySelectedDetailRow.GiftAmount,
                                IntlToBaseCurrencyExchRate);
                        }
                        else
                        {
                            FPreviouslySelectedDetailRow.GiftAmountIntl = FPreviouslySelectedDetailRow.GiftTransactionAmount;
                        }
                    }
                    finally
                    {
                        FPreviouslySelectedDetailRow.EndEdit();
                    }
                }

                //Update all transactions
                UpdateTransactionsCurrencyAmounts(CurrentBatchRow, IntlToBaseCurrencyExchRate, IsTransactionInIntlCurrency);
            }
        }
예제 #5
0
        /// <summary>
        /// Creates a new Recurring Gift or Recurring Gift detail depending upon the parameter
        /// </summary>
        /// <param name="ACompletelyNewRecurringGift"></param>
        private void CreateANewRecurringGift(bool ACompletelyNewRecurringGift)
        {
            // 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_RecurringGiftTransactions.Motivation.ManualCode.cs, MotivationDetailChanged().
            // To fix it, put the focus outside pnlDetails, preventing the whole chain of events from happening.
            grdDetails.Focus();

            ARecurringGiftRow CurrentRecurringGiftRow = null;
            bool IsEmptyGrid  = (grdDetails.Rows.Count == 1);
            bool HasChanges   = FPetraUtilsObject.HasChanges;
            bool SelectEndRow = false;

            bool FPrevRowIsNull = (FPreviouslySelectedDetailRow == null);
            bool CopyDetails    = false;

            bool AutoSaveSuccessful = FSETAutoSaveFlag && HasChanges && ((TFrmRecurringGiftBatch)ParentForm).SaveChangesManual();

            FNewGiftInProcess = true;

            try
            {
                //May need to copy values down if a new detail row inside current Recurring Gift
                int    recurringGiftTransactionNumber = 0;
                string donorName  = string.Empty;
                string donorClass = string.Empty;
                bool   confidentialRecurringGiftFlag = false;
                bool   chargeFlag           = false;
                bool   taxDeductible        = false;
                string motivationGroupCode  = string.Empty;
                string motivationDetailCode = string.Empty;

                if (AutoSaveSuccessful || ((!FSETAutoSaveFlag || !HasChanges) && ValidateAllData(true, TErrorProcessingMode.Epm_IgnoreNonCritical)))
                {
                    if (!ACompletelyNewRecurringGift)      //i.e. a RecurringGift detail
                    {
                        ACompletelyNewRecurringGift = IsEmptyGrid;
                    }

                    CopyDetails = (!ACompletelyNewRecurringGift && !FPrevRowIsNull);

                    if (CopyDetails)
                    {
                        //Allow for possibility that FPrev... may have some null column values
                        recurringGiftTransactionNumber = FPreviouslySelectedDetailRow.GiftTransactionNumber;
                        donorName  = FPreviouslySelectedDetailRow.IsDonorNameNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorName;
                        donorClass = FPreviouslySelectedDetailRow.IsDonorClassNull() ? string.Empty : FPreviouslySelectedDetailRow.DonorClass;
                        confidentialRecurringGiftFlag =
                            FPreviouslySelectedDetailRow.IsConfidentialGiftFlagNull() ? false : FPreviouslySelectedDetailRow.ConfidentialGiftFlag;
                        chargeFlag          = FPreviouslySelectedDetailRow.IsChargeFlagNull() ? true : FPreviouslySelectedDetailRow.ChargeFlag;
                        taxDeductible       = FPreviouslySelectedDetailRow.IsTaxDeductibleNull() ? true : FPreviouslySelectedDetailRow.TaxDeductible;
                        motivationGroupCode =
                            FPreviouslySelectedDetailRow.IsMotivationGroupCodeNull() ? string.Empty : FPreviouslySelectedDetailRow.
                            MotivationGroupCode;
                        motivationDetailCode =
                            FPreviouslySelectedDetailRow.IsMotivationDetailCodeNull() ? string.Empty : FPreviouslySelectedDetailRow.
                            MotivationDetailCode;
                    }

                    //Set previous row to Null.
                    FPreviouslySelectedDetailRow = null;

                    if (ACompletelyNewRecurringGift)
                    {
                        //Run this if a new Recurring Gift is requested or required.
                        SelectEndRow = true;

                        // we create the row locally, no dataset
                        ARecurringGiftRow recurringGiftRow = FMainDS.ARecurringGift.NewRowTyped(true);

                        recurringGiftRow.LedgerNumber          = FBatchRow.LedgerNumber;
                        recurringGiftRow.BatchNumber           = FBatchRow.BatchNumber;
                        recurringGiftRow.GiftTransactionNumber = ++FBatchRow.LastGiftNumber;
                        recurringGiftRow.MethodOfPaymentCode   = FBatchRow.MethodOfPaymentCode;
                        recurringGiftRow.Active           = true;
                        recurringGiftRow.LastDetailNumber = 1;

                        FMainDS.ARecurringGift.Rows.Add(recurringGiftRow);

                        CurrentRecurringGiftRow = recurringGiftRow;

                        mniDonorHistory.Enabled = false;

                        //Reset textboxes to zero
                        txtGiftTotal.NumberValueDecimal = 0;
                    }
                    else
                    {
                        CurrentRecurringGiftRow = GetRecurringGiftRow(recurringGiftTransactionNumber);
                        CurrentRecurringGiftRow.LastDetailNumber++;

                        //If adding detail to current last Recurring Gift, then new detail will be bottom row in grid
                        if (FBatchRow.LastGiftNumber == recurringGiftTransactionNumber)
                        {
                            SelectEndRow = true;
                        }
                    }

                    //New Recurring Gifts will require a new detail anyway, so this code always runs
                    GiftBatchTDSARecurringGiftDetailRow newRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true);

                    newRow.LedgerNumber          = FBatchRow.LedgerNumber;
                    newRow.BatchNumber           = FBatchRow.BatchNumber;
                    newRow.GiftTransactionNumber = CurrentRecurringGiftRow.GiftTransactionNumber;
                    newRow.DetailNumber          = CurrentRecurringGiftRow.LastDetailNumber;
                    newRow.DonorKey            = CurrentRecurringGiftRow.DonorKey;
                    newRow.Active              = CurrentRecurringGiftRow.Active;
                    newRow.MethodOfPaymentCode = CurrentRecurringGiftRow.MethodOfPaymentCode;
                    newRow.MethodOfGivingCode  = CurrentRecurringGiftRow.MethodOfGivingCode;
                    newRow.DateEntered         = DateTime.Now;

                    if (CopyDetails)
                    {
                        newRow.DonorName            = donorName;
                        newRow.DonorClass           = donorClass;
                        newRow.ConfidentialGiftFlag = confidentialRecurringGiftFlag;
                        newRow.ChargeFlag           = chargeFlag;
                        newRow.TaxDeductible        = taxDeductible;
                        newRow.MotivationGroupCode  = motivationGroupCode;
                        newRow.MotivationDetailCode = motivationDetailCode;

                        // set the auto-populate comment if needed
                        AMotivationDetailRow motivationDetail = (AMotivationDetailRow)FMainDS.AMotivationDetail.Rows.Find(
                            new object[] { FLedgerNumber, newRow.MotivationGroupCode, newRow.MotivationDetailCode });

                        if ((motivationDetail != null) && motivationDetail.Autopopdesc)
                        {
                            newRow.GiftCommentOne = motivationDetail.MotivationDetailDesc;
                        }
                    }
                    else
                    {
                        newRow.MotivationGroupCode  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                        newRow.MotivationDetailCode = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                    }

                    cmbMotivationDetailCode.SetSelectedString(newRow.MotivationDetailCode, -1);
                    txtDetailMotivationDetailCode.Text = newRow.MotivationDetailCode;

                    FMainDS.ARecurringGiftDetail.Rows.Add(newRow);

                    FPetraUtilsObject.SetChangedFlag();

                    if (!SelectEndRow && !SelectDetailRowByDataTableIndex(FMainDS.ARecurringGiftDetail.Rows.Count - 1))
                    {
                        if (!FFilterAndFindObject.IsActiveFilterEqualToBase)
                        {
                            MessageBox.Show(
                                MCommonResourcestrings.StrNewRecordIsFiltered,
                                MCommonResourcestrings.StrAddNewRecordTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            FFilterAndFindObject.FilterPanelControls.ClearAllDiscretionaryFilters();

                            if (FFilterAndFindObject.FilterFindPanel.ShowApplyFilterButton != TUcoFilterAndFind.FilterContext.None)
                            {
                                FFilterAndFindObject.ApplyFilter();
                            }

                            SelectDetailRowByDataTableIndex(FMainDS.ARecurringGiftDetail.Rows.Count - 1);
                        }
                    }

                    btnDeleteAll.Enabled = btnDelete.Enabled;
                    UpdateRecordNumberDisplay();
                    FLastDonor = -1;

                    //Select end row
                    if (SelectEndRow)
                    {
                        grdDetails.SelectRowInGrid(grdDetails.Rows.Count - 1);
                    }

                    //Focus accordingly
                    if (ACompletelyNewRecurringGift)
                    {
                        txtDetailDonorKey.Focus();
                    }
                    else
                    {
                        txtDetailRecipientKey.Focus();
                    }

                    //FPreviouslySelectedDetailRow should now be pointing to the newly added row
                    UpdateRecipientKeyText(0,
                                           FPreviouslySelectedDetailRow,
                                           cmbDetailMotivationGroupCode.GetSelectedString(),
                                           cmbMotivationDetailCode.GetSelectedString());

                    ClearKeyMinistries();
                    mniRecipientHistory.Enabled = false;
                }
            }
            finally
            {
                FNewGiftInProcess = false;

                if (AutoSaveSuccessful)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                }
            }
        }