/// 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);
        }
Exemple #2
0
        private void NewGift(System.Object sender, EventArgs e)
        {
            string Reference = string.Empty;

            //Read currently selected gift's Reference
            if (FPreviouslySelectedDetailRow != null)
            {
                ARecurringGiftRow recurGiftRow = GetRecurringGiftRow(FPreviouslySelectedDetailRow.GiftTransactionNumber);

                if (!recurGiftRow.IsReferenceNull())
                {
                    if (recurGiftRow.Reference == txtDetailReference.Text)
                    {
                        Reference = recurGiftRow.Reference;
                    }
                    else
                    {
                        Reference = txtDetailReference.Text;
                    }
                }
            }

            CreateANewRecurringGift(true);

            //Copy to new record
            txtDetailReference.Text = Reference;
        }
        /// <summary>
        /// Update all donor names in gift details table
        /// </summary>
        /// <param name="ABatchNumber"></param>
        private void UpdateAllDonorNames(Int32 ABatchNumber)
        {
            Dictionary <Int32, Int64>  GiftsDict  = new Dictionary <Int32, Int64>();
            Dictionary <Int64, string> DonorsDict = new Dictionary <Int64, string>();

            DataView GiftDV = new DataView(FMainDS.ARecurringGift);

            GiftDV.RowFilter = string.Format("{0}={1}",
                                             ARecurringGiftTable.GetBatchNumberDBName(),
                                             ABatchNumber);

            GiftDV.Sort = string.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName());

            foreach (DataRowView drv in GiftDV)
            {
                ARecurringGiftRow gr = (ARecurringGiftRow)drv.Row;

                Int64 donorKey = gr.DonorKey;

                GiftsDict.Add(gr.GiftTransactionNumber, donorKey);

                if (!DonorsDict.ContainsKey(donorKey))
                {
                    if (donorKey != 0)
                    {
                        PPartnerRow pr = RetrieveDonorRow(donorKey);

                        if (pr != null)
                        {
                            DonorsDict.Add(donorKey, pr.PartnerShortName);
                        }
                    }
                    else
                    {
                        DonorsDict.Add(0, "");
                    }
                }
            }

            //Add donor info to gift details
            DataView GiftDetailDV = new DataView(FMainDS.ARecurringGiftDetail);

            GiftDetailDV.RowFilter = string.Format("{0}={1}",
                                                   ARecurringGiftDetailTable.GetBatchNumberDBName(),
                                                   ABatchNumber);

            GiftDetailDV.Sort = string.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName());

            foreach (DataRowView drv in GiftDetailDV)
            {
                GiftBatchTDSARecurringGiftDetailRow giftDetail = (GiftBatchTDSARecurringGiftDetailRow)drv.Row;

                Int64 donorKey = GiftsDict[giftDetail.GiftTransactionNumber];

                giftDetail.DonorKey  = donorKey;
                giftDetail.DonorName = DonorsDict[donorKey];
            }
        }
        /// 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);
        }
Exemple #5
0
        private void SetBatchLastGiftNumber()
        {
            DataView dv = new DataView(FMainDS.ARecurringGift);

            dv.RowFilter = String.Format("{0}={1}",
                                         ARecurringGiftTable.GetBatchNumberDBName(),
                                         FBatchNumber);

            dv.Sort = String.Format("{0} DESC",
                                    ARecurringGiftTable.GetGiftTransactionNumberDBName());

            dv.RowStateFilter = DataViewRowState.CurrentRows;

            if (dv.Count > 0)
            {
                ARecurringGiftRow transRow = (ARecurringGiftRow)dv[0].Row;
                FBatchRow.LastGiftNumber = transRow.GiftTransactionNumber;
            }
            else
            {
                FBatchRow.LastGiftNumber = 0;
            }
        }
        /// <summary>
        /// Validation for Recurring Gift table
        /// </summary>
        /// <param name="AContext"></param>
        /// <param name="ARow"></param>
        /// <param name="AVerificationResultCollection"></param>
        /// <param name="AValidationControlsDict"></param>
        /// <returns></returns>
        public static bool ValidateRecurringGiftManual(object AContext, ARecurringGiftRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            //TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;
            object ValidationContext;
            int VerifResultCollAddedCount = 0;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return true;
            }

            // Check if valid donor
            ValidationColumn = ARow.Table.Columns[ARecurringGiftTable.ColumnDonorKeyId];
            ValidationContext = String.Format("Batch no. {0}, gift no. {1}",
                ARow.BatchNumber,
                ARow.GiftTransactionNumber);

            VerificationResult = TSharedPartnerValidation_Partner.IsValidPartner(
                ARow.DonorKey, new TPartnerClass[] { }, true,
                "Donor of " + THelper.NiceValueDescription(ValidationContext.ToString()), AContext, ValidationColumn, null);

            if (VerificationResult != null)
            {
                AVerificationResultCollection.Remove(ValidationColumn);
                AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
            }

            // Handle addition/removal to/from TVerificationResultCollection
            if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
            {
                VerifResultCollAddedCount++;
            }

            return VerifResultCollAddedCount == 0;
        }
Exemple #7
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);
                }
            }
        }
Exemple #8
0
        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();
            }
        }
Exemple #9
0
        public static SponsorshipTDS GetChildDetails(Int64 APartnerKey,
                                                     Int32 ALedgerNumber,
                                                     bool AWithPhoto,
                                                     out string ASponsorshipStatus)
        {
            SponsorshipTDS MainDS = new SponsorshipTDS();

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerReminderAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                if (!AWithPhoto && (MainDS.PFamily.Rows.Count == 1))
                {
                    MainDS.PFamily[0].Photo = "";
                }

                int SponsorshipBatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction);

                if (SponsorshipBatchNumber > -1)
                {
                    ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction);
                    ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction);
                    ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction);

                    GiftBatchTDS GiftDS = new GiftBatchTDS();
                    TGiftTransactionWebConnector.LoadGiftDonorRelatedData(GiftDS, true, ALedgerNumber, SponsorshipBatchNumber, Transaction);

                    for (int i = 0; i < MainDS.ARecurringGiftDetail.Count;)
                    {
                        SponsorshipTDSARecurringGiftDetailRow gdr = MainDS.ARecurringGiftDetail[i];
                        // drop all recurring gift details, that are not related to this child (RecipientKey)
                        if (gdr.RecipientKey != APartnerKey)
                        {
                            MainDS.ARecurringGiftDetail.Rows.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                            // set the donor key from the appropriate recurring gift
                            MainDS.ARecurringGift.DefaultView.RowFilter = String.Format("{0} = {1}",
                                                                                        ARecurringGiftTable.GetGiftTransactionNumberDBName(),
                                                                                        gdr.GiftTransactionNumber);

                            // there should be only one row
                            foreach (DataRowView drv in MainDS.ARecurringGift.DefaultView)
                            {
                                ARecurringGiftRow recurrGiftRow = (ARecurringGiftRow)drv.Row;
                                gdr.DonorKey         = recurrGiftRow.DonorKey;
                                PPartnerRow donorRow = (PPartnerRow)GiftDS.DonorPartners.Rows.Find(recurrGiftRow.DonorKey);
                                gdr.DonorName        = donorRow.PartnerShortName;
                                gdr.CurrencyCode     = MainDS.ARecurringGiftBatch[0].CurrencyCode;
                            }
                        }
                    }

                    // drop all unrelated gift rows, that don't have a detail for this child
                    for (int i = 0; i < MainDS.ARecurringGift.Count;)
                    {
                        ARecurringGiftRow gr = MainDS.ARecurringGift[0];
                        MainDS.ARecurringGiftDetail.DefaultView.RowFilter = String.Format("{0} = {1}",
                                                                                          ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                                          gr.GiftTransactionNumber);

                        if (MainDS.ARecurringGiftDetail.DefaultView.Count == 0)
                        {
                            MainDS.ARecurringGift.Rows.RemoveAt(i);
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            });

            bool isSponsoredChild = false;

            ASponsorshipStatus = "[N/A]";

            foreach (PPartnerTypeRow type in MainDS.PPartnerType.Rows)
            {
                if (type.TypeCode == "CHILDREN_HOME" || type.TypeCode == "HOME_BASED" || type.TypeCode == "BOARDING_SCHOOL" || type.TypeCode == "PREVIOUS_CHILD" || type.TypeCode == "CHILD_DIED")
                {
                    isSponsoredChild = true;
                }
                ASponsorshipStatus = type.TypeCode;
            }

            if (!isSponsoredChild)
            {
                return(new SponsorshipTDS());
            }

            return(MainDS);
        }
        private bool OnDeleteRowManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ACompletionMessage)
        {
            //TODO: Make this like deleton on GL Transactions form
            // e.g. pass copy to delete method on server...
            //GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy();
            //TempDS.Merge(FMainDS);

            bool DeletionSuccessful = false;

            ACompletionMessage = string.Empty;

            if (FBatchRow == null)
            {
                FBatchRow = GetRecurringBatchRow();
            }

            if (ARowToDelete == null)
            {
                return(false);
            }

            int  CurrentBatchNo   = ARowToDelete.BatchNumber;
            bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added);
            int  CurrentRowIndex  = GetSelectedRowIndex();

            TFrmRecurringGiftBatch FMyForm = (TFrmRecurringGiftBatch)this.ParentForm;

            GiftBatchTDS BackupMainDS = null;

            int    SelectedDetailNumber                 = ARowToDelete.DetailNumber;
            int    RecurringGiftToDeleteTransNo         = 0;
            string FilterAllRecurringGiftsOfBatch       = String.Empty;
            string FilterAllRecurringGiftDetailsOfBatch = String.Empty;

            int DetailRowCount = FGiftDetailView.Count;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                //Specify current action
                FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS;
                //Speeds up deletion of larger gift sets
                FMainDS.EnforceConstraints = false;
                // temporarily disable  New Donor Warning
                FMyForm.NewDonorWarning = false;

                //Backup the Dataset for reversion purposes
                BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false);

                //Don't run an inactive fields check on this batch
                FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(CurrentBatchNo);

                //Delete current row
                ARowToDelete.RejectChanges();

                if (!RowToDeleteIsNew)
                {
                    ShowDetails(ARowToDelete);
                }

                ARowToDelete.Delete();

                //If there existed (before the delete row above) more than one detail row, then no need to delete Recurring Gift header row
                if (DetailRowCount > 1)
                {
                    ACompletionMessage = Catalog.GetString("Recurring Gift Detail row deleted successfully!");

                    FGiftSelectedForDeletionFlag = false;

                    foreach (DataRowView rv in FGiftDetailView)
                    {
                        GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row;

                        if (row.DetailNumber > SelectedDetailNumber)
                        {
                            row.DetailNumber--;
                        }
                    }

                    FGift.LastDetailNumber--;
                }
                else
                {
                    ACompletionMessage = Catalog.GetString("Recurring Gift deleted successfully!");

                    RecurringGiftToDeleteTransNo = FGift.GiftTransactionNumber;

                    // Reduce all Recurring Gift Detail row Transaction numbers by 1 if they are greater then Recurring Gift to be deleted
                    FilterAllRecurringGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}",
                                                                         ARecurringGiftDetailTable.GetBatchNumberDBName(),
                                                                         FBatchNumber,
                                                                         ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                         RecurringGiftToDeleteTransNo);

                    DataView RecurringGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail);
                    RecurringGiftDetailView.RowFilter = FilterAllRecurringGiftDetailsOfBatch;
                    RecurringGiftDetailView.Sort      = String.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName());

                    foreach (DataRowView rv in RecurringGiftDetailView)
                    {
                        GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row;

                        row.GiftTransactionNumber--;
                    }

                    //Cannot delete the Recurring Gift row, just copy the data of rows above down by 1 row
                    // and then mark the top row for deletion
                    //In other words, bubble the Recurring Gift row to be deleted to the top
                    FilterAllRecurringGiftsOfBatch = String.Format("{0}={1} And {2}>={3}",
                                                                   ARecurringGiftTable.GetBatchNumberDBName(),
                                                                   FBatchNumber,
                                                                   ARecurringGiftTable.GetGiftTransactionNumberDBName(),
                                                                   RecurringGiftToDeleteTransNo);

                    DataView RecurringGiftView = new DataView(FMainDS.ARecurringGift);
                    RecurringGiftView.RowFilter = FilterAllRecurringGiftsOfBatch;
                    RecurringGiftView.Sort      = String.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName());

                    ARecurringGiftRow RecurringGiftRowToReceive  = null;
                    ARecurringGiftRow RecurringGiftRowToCopyDown = null;
                    ARecurringGiftRow RecurringGiftRowCurrent    = null;

                    int currentRecurringGiftTransNo = 0;

                    foreach (DataRowView gv in RecurringGiftView)
                    {
                        RecurringGiftRowCurrent = (ARecurringGiftRow)gv.Row;

                        currentRecurringGiftTransNo = RecurringGiftRowCurrent.GiftTransactionNumber;

                        if (currentRecurringGiftTransNo > RecurringGiftToDeleteTransNo)
                        {
                            RecurringGiftRowToCopyDown = RecurringGiftRowCurrent;

                            //Copy column values down
                            for (int j = 3; j < RecurringGiftRowToCopyDown.Table.Columns.Count; j++)
                            {
                                //Update all columns except the pk fields that remain the same
                                if (!RecurringGiftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text"))
                                {
                                    RecurringGiftRowToReceive[j] = RecurringGiftRowToCopyDown[j];
                                }
                            }
                        }

                        if (currentRecurringGiftTransNo == FBatchRow.LastGiftNumber)
                        {
                            //Mark last record for deletion
                            RecurringGiftRowCurrent.ChargeStatus = MFinanceConstants.MARKED_FOR_DELETION;
                        }

                        //Will always be previous row
                        RecurringGiftRowToReceive = RecurringGiftRowCurrent;
                    }

                    FPreviouslySelectedDetailRow = null;
                    FGiftSelectedForDeletionFlag = true;
                    FBatchRow.LastGiftNumber--;
                }

                //Save and check for inactive values and ex-workers and anonymous gifts
                //  in other unsaved Batches
                FPetraUtilsObject.SetChangedFlag();

                if (!FMyForm.SaveChangesManual(Logic.TExtraGiftBatchChecks.GiftBatchAction.DELETINGTRANS, false, false))
                {
                    FMyForm.GetBatchControl().UpdateRecurringBatchDictionary();

                    MessageBox.Show(Catalog.GetString("The gift detail has been deleted but the changes are not saved!"),
                                    Catalog.GetString("Deletion Warning"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    ACompletionMessage = string.Empty;

                    if (FGiftSelectedForDeletionFlag)
                    {
                        FGiftSelectedForDeletionFlag = false;
                        SetBatchLastGiftNumber();
                        UpdateControlsProtection();
                    }

                    UpdateTotals();

                    return(false);
                }

                //Clear current batch's gift data and reload from server
                RefreshRecurringBatchGiftData(FBatchNumber, true);

                DeletionSuccessful = true;
            }
            catch (Exception ex)
            {
                //Revert to previous state
                RevertDataSet(FMainDS, BackupMainDS, CurrentRowIndex);

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
            finally
            {
                FMyForm.NewDonorWarning         = true;
                FMainDS.EnforceConstraints      = true;
                FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.NONE;
                this.Cursor = Cursors.Default;
            }

            SetGiftDetailDefaultView();
            FFilterAndFindObject.ApplyFilter();
            UpdateRecordNumberDisplay();

            return(DeletionSuccessful);
        }
        private bool OnDeleteRowManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ACompletionMessage)
        {
            bool DeletionSuccessful = false;

            ACompletionMessage = string.Empty;

            if (ARowToDelete == null)
            {
                return(DeletionSuccessful);
            }

            bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added);

            if (!RowToDeleteIsNew)
            {
                try
                {
                    // temporarily disable  New Donor Warning
                    ((TFrmRecurringGiftBatch)this.ParentForm).NewDonorWarning = false;

                    //Return modified row to last saved state to avoid validation failures
                    ARowToDelete.RejectChanges();
                    ShowDetails(ARowToDelete);

                    if (!((TFrmRecurringGiftBatch)this.ParentForm).SaveChanges())
                    {
                        MessageBox.Show(Catalog.GetString("Error in trying to save prior to deleting current Gift detail!"),
                                        Catalog.GetString("Deletion Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);

                        return(DeletionSuccessful);
                    }
                }
                finally
                {
                    ((TFrmRecurringGiftBatch)this.ParentForm).NewDonorWarning = true;
                }
            }

            //Backup the Dataset for reversion purposes
            GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy();

            BackupMainDS.Merge(FMainDS);

            //To be used later....Pass copy to delete method.
            //RecurringGiftBatchTDS TempDS = (RecurringGiftBatchTDS)FMainDS.Copy();
            //TempDS.Merge(FMainDS);

            int    SelectedDetailNumber                 = ARowToDelete.DetailNumber;
            int    RecurringGiftToDeleteTransNo         = 0;
            string FilterAllRecurringGiftsOfBatch       = String.Empty;
            string FilterAllRecurringGiftDetailsOfBatch = String.Empty;

            int DetailRowCount = FGiftDetailView.Count;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                //Speeds up deletion of larger Recurring Gift sets
                FMainDS.EnforceConstraints = false;

                //Delete current detail row
                ARowToDelete.Delete();

                //If there existed (before the delete row above) more than one detail row, then no need to delete Recurring Gift header row
                if (DetailRowCount > 1)
                {
                    ACompletionMessage = Catalog.GetString("Recurring Gift Detail row deleted successfully!");

                    FGiftSelectedForDeletion = false;

                    foreach (DataRowView rv in FGiftDetailView)
                    {
                        GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row;

                        if (row.DetailNumber > SelectedDetailNumber)
                        {
                            row.DetailNumber--;
                        }
                    }

                    FGift.LastDetailNumber--;

                    FPetraUtilsObject.SetChangedFlag();
                }
                else
                {
                    ACompletionMessage = Catalog.GetString("Recurring Gift deleted successfully!");

                    RecurringGiftToDeleteTransNo = FGift.GiftTransactionNumber;

                    // Reduce all Recurring Gift Detail row Transaction numbers by 1 if they are greater then Recurring Gift to be deleted
                    FilterAllRecurringGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}",
                                                                         ARecurringGiftDetailTable.GetBatchNumberDBName(),
                                                                         FBatchNumber,
                                                                         ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(),
                                                                         RecurringGiftToDeleteTransNo);

                    DataView RecurringGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail);
                    RecurringGiftDetailView.RowFilter = FilterAllRecurringGiftDetailsOfBatch;
                    RecurringGiftDetailView.Sort      = String.Format("{0} ASC", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName());

                    foreach (DataRowView rv in RecurringGiftDetailView)
                    {
                        GiftBatchTDSARecurringGiftDetailRow row = (GiftBatchTDSARecurringGiftDetailRow)rv.Row;

                        row.GiftTransactionNumber--;
                    }

                    //Cannot delete the Recurring Gift row, just copy the data of rows above down by 1 row
                    // and then mark the top row for deletion
                    //In other words, bubble the Recurring Gift row to be deleted to the top
                    FilterAllRecurringGiftsOfBatch = String.Format("{0}={1} And {2}>={3}",
                                                                   ARecurringGiftTable.GetBatchNumberDBName(),
                                                                   FBatchNumber,
                                                                   ARecurringGiftTable.GetGiftTransactionNumberDBName(),
                                                                   RecurringGiftToDeleteTransNo);

                    DataView RecurringGiftView = new DataView(FMainDS.ARecurringGift);
                    RecurringGiftView.RowFilter = FilterAllRecurringGiftsOfBatch;
                    RecurringGiftView.Sort      = String.Format("{0} ASC", ARecurringGiftTable.GetGiftTransactionNumberDBName());

                    ARecurringGiftRow RecurringGiftRowToReceive  = null;
                    ARecurringGiftRow RecurringGiftRowToCopyDown = null;
                    ARecurringGiftRow RecurringGiftRowCurrent    = null;

                    int currentRecurringGiftTransNo = 0;

                    foreach (DataRowView gv in RecurringGiftView)
                    {
                        RecurringGiftRowCurrent = (ARecurringGiftRow)gv.Row;

                        currentRecurringGiftTransNo = RecurringGiftRowCurrent.GiftTransactionNumber;

                        if (currentRecurringGiftTransNo > RecurringGiftToDeleteTransNo)
                        {
                            RecurringGiftRowToCopyDown = RecurringGiftRowCurrent;

                            //Copy column values down
                            for (int j = 3; j < RecurringGiftRowToCopyDown.Table.Columns.Count; j++)
                            {
                                //Update all columns except the pk fields that remain the same
                                if (!RecurringGiftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text"))
                                {
                                    RecurringGiftRowToReceive[j] = RecurringGiftRowToCopyDown[j];
                                }
                            }
                        }

                        if (currentRecurringGiftTransNo == FBatchRow.LastGiftNumber)
                        {
                            //Mark last record for deletion
                            RecurringGiftRowCurrent.ChargeStatus = MFinanceConstants.MARKED_FOR_DELETION;
                        }

                        //Will always be previous row
                        RecurringGiftRowToReceive = RecurringGiftRowCurrent;
                    }

                    FPreviouslySelectedDetailRow = null;

                    FPetraUtilsObject.SetChangedFlag();

                    FGiftSelectedForDeletion = true;

                    FBatchRow.LastGiftNumber--;
                }

                //Try to save changes
                if (((TFrmRecurringGiftBatch)this.ParentForm).SaveChangesManual())
                {
                    //Clear current batch's Recurring Gift data and reload from server
                    RefreshCurrentRecurringBatchGiftData(FBatchNumber, true);
                }
                else
                {
                    throw new Exception("Unable to save after deleting a Recurring Gift!");
                }

                DeletionSuccessful = true;
            }
            catch (Exception ex)
            {
                //Revert to previous state
                RevertDataSet(FMainDS, BackupMainDS);

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
            finally
            {
                FMainDS.EnforceConstraints = true;
                SetGiftDetailDefaultView();
                FFilterAndFindObject.ApplyFilter();
                this.Cursor = Cursors.Default;
            }

            UpdateRecordNumberDisplay();

            return(DeletionSuccessful);
        }
        /// <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);
        }
Exemple #13
0
        /// <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));
            }
        }
        /// <summary>
        /// Creates a new Recurring Gift or Recurring Gift detail depending upon the parameter
        /// </summary>
        /// <param name="ACompletelyNewRecurringGift"></param>
        private void CreateANewRecurringGift(bool ACompletelyNewRecurringGift)
        {
            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 = FAutoSave && HasChanges && ((TFrmRecurringGiftBatch)ParentForm).SaveChangesManual();

            FCreatingNewGift = 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 || ((!FAutoSave || !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.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.MethodOfPaymentCode   = CurrentRecurringGiftRow.MethodOfPaymentCode;
                    newRow.MethodOfGivingCode    = CurrentRecurringGiftRow.MethodOfGivingCode;
                    newRow.DonorKey = CurrentRecurringGiftRow.DonorKey;

                    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;
                    }

                    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
                    TUC_RecurringGiftTransactions_Recipient.UpdateRecipientKeyText(0,
                                                                                   FPreviouslySelectedDetailRow,
                                                                                   cmbDetailMotivationGroupCode.GetSelectedString(),
                                                                                   cmbDetailMotivationDetailCode.GetSelectedString());
                    cmbKeyMinistries.Clear();
                    mniRecipientHistory.Enabled = false;
                }
            }
            finally
            {
                FCreatingNewGift = false;

                if (AutoSaveSuccessful)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Update the transaction method payment from outside
        /// </summary>
        public void UpdateMethodOfPayment()
        {
            Int32 LedgerNumber;
            Int32 BatchNumber;

            if (!((TFrmRecurringGiftBatch)this.ParentForm).GetBatchControl().FBatchLoaded)
            {
                return;
            }

            FBatchRow = GetRecurringBatchRow();

            if (FBatchRow == null)
            {
                FBatchRow = ((TFrmRecurringGiftBatch)this.ParentForm).GetBatchControl().GetSelectedDetailRow();
            }

            FBatchMethodOfPayment = ((TFrmRecurringGiftBatch)this.ParentForm).GetBatchControl().MethodOfPaymentCode;

            LedgerNumber = FBatchRow.LedgerNumber;
            BatchNumber  = FBatchRow.BatchNumber;

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

            if ((FLedgerNumber == LedgerNumber) && (FBatchNumber == BatchNumber))
            {
                //Rows already active in transaction tab. Need to set current row ac code below will not update selected row
                if (FPreviouslySelectedDetailRow != null)
                {
                    FPreviouslySelectedDetailRow.MethodOfPaymentCode = FBatchMethodOfPayment;
                    cmbDetailMethodOfPaymentCode.SetSelectedString(FBatchMethodOfPayment);
                }
            }

            //Update all transactions
            DataView GiftView = new DataView(FMainDS.ARecurringGift);

            GiftView.RowStateFilter = DataViewRowState.CurrentRows;
            GiftView.RowFilter      = String.Format("{0}={1}",
                                                    ARecurringGiftTable.GetBatchNumberDBName(),
                                                    BatchNumber);

            foreach (DataRowView drv in GiftView)
            {
                ARecurringGiftRow giftRow = (ARecurringGiftRow)drv.Row;
                giftRow.MethodOfPaymentCode = FBatchMethodOfPayment;
            }

            //Do same at detail level to update the grid
            DataView GiftDetailView = new DataView(FMainDS.ARecurringGiftDetail);

            GiftDetailView.RowStateFilter = DataViewRowState.CurrentRows;
            GiftDetailView.RowFilter      = String.Format("{0}={1}",
                                                          ARecurringGiftDetailTable.GetBatchNumberDBName(),
                                                          BatchNumber);

            foreach (DataRowView drv in GiftDetailView)
            {
                GiftBatchTDSARecurringGiftDetailRow giftDetailRow = (GiftBatchTDSARecurringGiftDetailRow)drv.Row;
                giftDetailRow.MethodOfPaymentCode = FBatchMethodOfPayment;
            }
        }
Exemple #16
0
        /// <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 bool PreDeleteManual(GiftBatchTDSARecurringGiftDetailRow ARowToDelete, ref string ADeletionQuestion)
        {
            bool allowDeletion = true;

            FGift = GetRecurringGiftRow(FPreviouslySelectedDetailRow.GiftTransactionNumber);
            FFilterAllDetailsOfGift = String.Format("{0}={1} and {2}={3}",
                ARecurringGiftDetailTable.GetBatchNumberDBName(),
                FPreviouslySelectedDetailRow.BatchNumber,
                ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(),
                FPreviouslySelectedDetailRow.GiftTransactionNumber);

            FGiftDetailView = new DataView(FMainDS.ARecurringGiftDetail);
            FGiftDetailView.RowFilter = FFilterAllDetailsOfGift;
            FGiftDetailView.Sort = ARecurringGiftDetailTable.GetDetailNumberDBName() + " ASC";
            String formattedDetailAmount = StringHelper.FormatUsingCurrencyCode(ARowToDelete.GiftAmount, GetCurrentRecurringBatchRow().CurrencyCode);

            if (FGiftDetailView.Count == 1)
            {
                ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete transaction {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 {0} from transaction {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("Recurring Gift no. {0} in Gift Batch no. {1} has no detail rows in the Gift Detail table!"),
                        ARowToDelete.GiftTransactionNumber,
                        ARowToDelete.BatchNumber);
                allowDeletion = false;
            }

            return allowDeletion;
        }
Exemple #18
0
        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);
            }
        }
        private void ShowDetailsForGift(ARecurringGiftRow ACurrentGiftRow)
        {
            //Set GiftRow controls
            txtDetailDonorKey.Text = ACurrentGiftRow.DonorKey.ToString();

            if (ACurrentGiftRow.IsMethodOfGivingCodeNull())
            {
                cmbDetailMethodOfGivingCode.SelectedIndex = -1;
            }
            else
            {
                cmbDetailMethodOfGivingCode.SetSelectedString(ACurrentGiftRow.MethodOfGivingCode);
            }

            if (ACurrentGiftRow.IsMethodOfPaymentCodeNull())
            {
                cmbDetailMethodOfPaymentCode.SelectedIndex = -1;
            }
            else
            {
                cmbDetailMethodOfPaymentCode.SetSelectedString(ACurrentGiftRow.MethodOfPaymentCode);
            }

            if (ACurrentGiftRow.IsReferenceNull())
            {
                txtDetailReference.Text = String.Empty;
            }
            else
            {
                txtDetailReference.Text = ACurrentGiftRow.Reference;
            }

            if (ACurrentGiftRow.IsReceiptLetterCodeNull())
            {
                cmbDetailReceiptLetterCode.SelectedIndex = -1;
            }
            else
            {
                cmbDetailReceiptLetterCode.SetSelectedString(ACurrentGiftRow.ReceiptLetterCode);
            }
        }
Exemple #20
0
        /// <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);
        }
        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);
        }