Esempio n. 1
0
        private void ShowDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            if (ARow == null)
            {
                return;
            }

            // DateEffective and FieldKey cannot be changed once saved
            if (ARow.RowState == DataRowState.Added)
            {
                dtpDetailDateEffective.Enabled = true;
                txtDetailFieldKey.Enabled      = true;
            }
            else
            {
                dtpDetailDateEffective.Enabled = false;
                txtDetailFieldKey.Enabled      = false;
            }

            if (ARow.DateEffective == ARow.DateExpires)
            {
                btnDeactivate.Enabled = false;
            }
            else
            {
                btnDeactivate.Enabled = true;
            }
        }
Esempio n. 2
0
        public static bool ActiveGiftDestination(long AFromPartnerKey,
                                                 long AToPartnerKey,
                                                 TPartnerClass APartnerClass,
                                                 out bool AFromGiftDestinationNeedsEnded,
                                                 out bool AToGiftDestinationNeedsEnded)
        {
            bool ReturnValue = true;
            bool FromGiftDestinationNeedsEnded = false;
            bool ToGiftDestinationNeedsEnded   = false;
            PPartnerGiftDestinationRow FromGiftDestinationRowNeedsEnded = null;
            PPartnerGiftDestinationRow ToGiftDestinationRowNeedsEnded   = null;
            PPartnerGiftDestinationRow ActiveRow = null;

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                           ref Transaction,
                                                           delegate
            {
                // if partners are Person's then find their family keys
                if (APartnerClass == TPartnerClass.PERSON)
                {
                    AFromPartnerKey = ((PPersonRow)PPersonAccess.LoadByPrimaryKey(AFromPartnerKey, Transaction).Rows[0]).FamilyKey;
                    AToPartnerKey   = ((PPersonRow)PPersonAccess.LoadByPrimaryKey(AToPartnerKey, Transaction).Rows[0]).FamilyKey;
                }

                // check for an active gift destination for the 'From' partner
                PPartnerGiftDestinationTable GiftDestinations = PPartnerGiftDestinationAccess.LoadViaPPartner(AFromPartnerKey, Transaction);
                ActiveRow = GetActiveGiftDestination(GiftDestinations);

                // return if no active record has been found
                if (ActiveRow == null)
                {
                    ReturnValue = false;
                }
                else
                {
                    // check for clash with the 'To' partner
                    PPartnerGiftDestinationTable ToGiftDestinations = PPartnerGiftDestinationAccess.LoadViaPPartner(AToPartnerKey, Transaction);
                    CheckGiftDestinationClashes(ToGiftDestinations, ActiveRow, out FromGiftDestinationRowNeedsEnded,
                                                out ToGiftDestinationRowNeedsEnded);

                    if (FromGiftDestinationRowNeedsEnded != null)
                    {
                        FromGiftDestinationNeedsEnded = true;
                    }

                    if (ToGiftDestinationRowNeedsEnded != null)
                    {
                        ToGiftDestinationNeedsEnded = true;
                    }
                }
            });

            AFromGiftDestinationNeedsEnded = FromGiftDestinationNeedsEnded;
            AToGiftDestinationNeedsEnded   = ToGiftDestinationNeedsEnded;

            return(ReturnValue);
        }
Esempio n. 3
0
        public static bool ActiveGiftDestination(long AFromPartnerKey,
                                                 long AToPartnerKey,
                                                 TPartnerClass APartnerClass,
                                                 out bool AFromGiftDestinationNeedsEnded,
                                                 out bool AToGiftDestinationNeedsEnded)
        {
            AFromGiftDestinationNeedsEnded = false;
            AToGiftDestinationNeedsEnded   = false;
            PPartnerGiftDestinationRow FromGiftDestinationRowNeedsEnded = null;
            PPartnerGiftDestinationRow ToGiftDestinationRowNeedsEnded   = null;
            PPartnerGiftDestinationRow ActiveRow   = null;
            TDBTransaction             Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                // if partners are Person's then find their family keys
                if (APartnerClass == TPartnerClass.PERSON)
                {
                    AFromPartnerKey = ((PPersonRow)PPersonAccess.LoadByPrimaryKey(AFromPartnerKey, Transaction).Rows[0]).FamilyKey;
                    AToPartnerKey   = ((PPersonRow)PPersonAccess.LoadByPrimaryKey(AToPartnerKey, Transaction).Rows[0]).FamilyKey;
                }

                // check for an active gift destination for the 'From' partner
                PPartnerGiftDestinationTable GiftDestinations = PPartnerGiftDestinationAccess.LoadViaPPartner(AFromPartnerKey, Transaction);
                ActiveRow = GetActiveGiftDestination(GiftDestinations);

                // return if no active record has been found
                if (ActiveRow == null)
                {
                    return(false);
                }

                // check for clash with the 'To' partner
                PPartnerGiftDestinationTable ToGiftDestinations = PPartnerGiftDestinationAccess.LoadViaPPartner(AToPartnerKey, Transaction);
                CheckGiftDestinationClashes(ToGiftDestinations, ActiveRow, out FromGiftDestinationRowNeedsEnded, out ToGiftDestinationRowNeedsEnded);

                if (FromGiftDestinationRowNeedsEnded != null)
                {
                    AFromGiftDestinationNeedsEnded = true;
                }

                if (ToGiftDestinationRowNeedsEnded != null)
                {
                    AToGiftDestinationNeedsEnded = true;
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                TLogging.LogAtLevel(7, "TMergePartnersWebConnector.GetPartnerBankingDetails: rollback own transaction.");
            }

            return(true);
        }
        private void ValidateDataDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedPartnerValidation_Partner.ValidateGiftDestinationRowManual(this, ARow, ref VerificationResultCollection,
                                                                              FPetraUtilsObject.ValidationControlsDict);

            // add VerificationResults from validating on all data (FPetraUtilsObject_DataSaved)
            VerificationResultCollection.AddCollection(FVerificationResultCollection);
            FVerificationResultCollection = null;
        }
Esempio n. 5
0
        private void UpdateGiftDestinationForSingleCommitment(PmStaffDataRow AEligibleCommitmentRow)
        {
            List <PPartnerGiftDestinationRow> ActiveGiftDestinationsWhichCanBeEnded = new List <PPartnerGiftDestinationRow>();
            PPartnerGiftDestinationRow        GiftDestinationWhichCanBeModified     = null;
            PPartnerGiftDestinationRow        GiftDestinationWhichCanBeDeactivated  = null;
            DataRowState   RowState = DataRowState.Unchanged;
            PmStaffDataRow OriginalCommitmentRow = null;

            // get the rowstate of EligibleCommitmentRow
            DataRow TempRow = FIndividualDataDS.PmStaffData.Rows.Find(new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key });

            if (TempRow != null)
            {
                RowState = TempRow.RowState;
            }
            else
            {
                RowState = DataRowState.Deleted;
            }

            // If gift destination records already exist for this partner's family...
            if ((FInspectDS.PPartnerGiftDestination != null) && (FInspectDS.PPartnerGiftDestination.Rows.Count > 0))
            {
                // Get the original record (before it was edited)
                if ((RowState == DataRowState.Modified) || (RowState == DataRowState.Deleted))
                {
                    OriginalCommitmentRow = (PmStaffDataRow)FOriginalCommitments.Rows.Find(
                        new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key });
                }

                // for a modified row... only changes to recieving field, start data and end date can update the Gift Destination
                if ((RowState == DataRowState.Modified) &&
                    (OriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField) &&
                    (OriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) &&
                    (OriginalCommitmentRow.EndOfCommitment == AEligibleCommitmentRow.EndOfCommitment))
                {
                    return;
                }
                else
                {
                    CompareCommitmentToGiftDestinations(RowState, AEligibleCommitmentRow, OriginalCommitmentRow,
                                                        ref GiftDestinationWhichCanBeModified, ref GiftDestinationWhichCanBeDeactivated, ref ActiveGiftDestinationsWhichCanBeEnded);
                }
            }

            DealWithPotentialGiftDestinationUpdates(RowState, AEligibleCommitmentRow, GiftDestinationWhichCanBeModified,
                                                    GiftDestinationWhichCanBeDeactivated, ActiveGiftDestinationsWhichCanBeEnded);
        }
Esempio n. 6
0
        private void ValidateDataDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedPartnerValidation_Partner.ValidateGiftDestinationRowManual(this, ARow, ref VerificationResultCollection,
                                                                              FPetraUtilsObject.ValidationControlsDict);

            if (VerificationResultCollection.HasCriticalErrors) // If something went wrong - allow the user to fix it!
            {
                dtpDetailDateEffective.Enabled = true;
                txtDetailFieldKey.Enabled      = true;
            }

            // add VerificationResults from validating on all data (FPetraUtilsObject_DataSaved)
            VerificationResultCollection.AddCollection(FVerificationResultCollection);
            FVerificationResultCollection = null;
        }
Esempio n. 7
0
        private void NewRowManual(ref PPartnerGiftDestinationRow ANewRow)
        {
            // create a key that is at least one more that all the (unsaved) records in the grid AND all the records in the database
            int Max = 0;

            foreach (PPartnerGiftDestinationRow Row in FMainDS.PPartnerGiftDestination.Rows)
            {
                if ((Row.RowState != DataRowState.Deleted) && (Row.Key >= Max))
                {
                    Max = Row.Key + 1;
                }
            }

            ANewRow.Key        = Math.Max(Max, TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination());
            ANewRow.PartnerKey = FPartnerKey;
            ANewRow.FieldKey   = 0;
            ANewRow["Order"]   = DateTime.MaxValue;
        }
Esempio n. 8
0
        public static void CheckGiftDestinationClashes(PPartnerGiftDestinationTable AToPartnersGiftDestinations,
                                                       PPartnerGiftDestinationRow AFromActiveRow,
                                                       out PPartnerGiftDestinationRow AFromGiftDestinationNeedsEnded,
                                                       out PPartnerGiftDestinationRow AToGiftDestinationNeedsEnded)
        {
            AFromGiftDestinationNeedsEnded = null;
            AToGiftDestinationNeedsEnded   = null;

            foreach (PPartnerGiftDestinationRow Row in AToPartnersGiftDestinations.Rows)
            {
                if ((Row.DateEffective != Row.DateExpires) &&
                    (Row.DateEffective >= AFromActiveRow.DateEffective) && (Row.DateEffective > DateTime.Today) &&
                    (AFromActiveRow.IsDateExpiresNull() || (Row.DateEffective <= AFromActiveRow.DateExpires)))
                {
                    AFromGiftDestinationNeedsEnded = Row;
                }
                else if ((Row.DateEffective != Row.DateExpires) &&
                         (Row.DateEffective < AFromActiveRow.DateEffective) &&
                         (Row.IsDateExpiresNull() || (Row.DateExpires >= AFromActiveRow.DateEffective)))
                {
                    AToGiftDestinationNeedsEnded = Row;
                }
            }
        }
Esempio n. 9
0
        /// Iterate through each gift destination and compare with commitment record.
        /// Determine if gift destination can be updated and how.
        private void CompareCommitmentToGiftDestinations(DataRowState ARowState,
                                                         PmStaffDataRow AEligibleCommitmentRow,
                                                         PmStaffDataRow AOriginalCommitmentRow,
                                                         ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified,
                                                         ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated,
                                                         ref List <PPartnerGiftDestinationRow> AActiveGiftDestinationsWhichCanBeEnded)
        {
            bool Repeat = true;

            while (Repeat)
            {
                Repeat = false;

                foreach (PPartnerGiftDestinationRow CurrentRow in FInspectDS.PPartnerGiftDestination.Rows)
                {
                    // if two records are the same
                    if ((AOriginalCommitmentRow != null) &&
                        (AOriginalCommitmentRow.ReceivingField == CurrentRow.FieldKey) &&
                        (AOriginalCommitmentRow.StartOfCommitment == CurrentRow.DateEffective) &&
                        (AOriginalCommitmentRow.EndOfCommitment == CurrentRow.DateExpires) &&
                        (CurrentRow.DateEffective != CurrentRow.DateExpires))
                    {
                        if ((ARowState == DataRowState.Modified) &&
                            (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) &&
                            (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField))
                        {
                            // if the field and start date have not been changed then we can update the Gift Destination
                            AGiftDestinationWhichCanBeModified = CurrentRow;
                            continue;
                        }
                        else if (ARowState == DataRowState.Deleted)
                        {
                            AGiftDestinationWhichCanBeDeactivated = CurrentRow;
                            return;
                        }
                    }
                    else if (ARowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    else if (CurrentRow.DateEffective == CurrentRow.DateExpires)
                    {
                        // ignore inactive Gift Destination
                        continue;
                    }

                    if ((AEligibleCommitmentRow.IsEndOfCommitmentNull() &&
                         (CurrentRow.IsDateExpiresNull() || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment))) ||
                        !AEligibleCommitmentRow.IsEndOfCommitmentNull() &&
                        ((CurrentRow.IsDateExpiresNull() && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) ||
                         (!CurrentRow.IsDateExpiresNull() &&
                          (((CurrentRow.DateEffective >= AEligibleCommitmentRow.StartOfCommitment) &&
                            (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) ||
                           (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment) &&
                           (CurrentRow.DateExpires <= AEligibleCommitmentRow.EndOfCommitment)))))
                    {
                        AActiveGiftDestinationsWhichCanBeEnded.Add(CurrentRow);
                    }
                }
            }
        }
Esempio n. 10
0
        /// Ask the user if they want to update the Gift Destination and then make the changes
        private void DealWithPotentialGiftDestinationUpdates(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow,
                                                             PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified,
                                                             PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, List <PPartnerGiftDestinationRow> AActiveGiftDestinationsWhichCanBeEnded)
        {
            string        UnitName = "";
            string        ActiveGiftDestinations = "";
            string        EndOfCommitment;
            bool          CreateNewGiftDestination = false;
            TPartnerClass PartnerClass;

            // set end date to display to user in messagebox
            if (AEligibleCommitmentRow.IsEndOfCommitmentNull())
            {
                EndOfCommitment = "'Open Ended'";
            }
            else
            {
                EndOfCommitment = AEligibleCommitmentRow.EndOfCommitment.Value.ToShortDateString();
            }

            // get the receiving fields short name
            TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(AEligibleCommitmentRow.ReceivingField,
                                                                                     out UnitName,
                                                                                     out PartnerClass);
            UnitName = UnitName + " (" + AEligibleCommitmentRow.ReceivingField + ")";

            // if existing active Gift Destination/s can be ended in order to add a Gift Destination for new commitment
            if (AActiveGiftDestinationsWhichCanBeEnded.Count > 0)
            {
                string Message = "";

                // get gift destination field's short name
                foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded)
                {
                    string ActiveGiftDestinationName = "";

                    TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(
                        Row.FieldKey, out ActiveGiftDestinationName, out PartnerClass);

                    // add conjunctions
                    if (AActiveGiftDestinationsWhichCanBeEnded.Count > 1)
                    {
                        if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) == AActiveGiftDestinationsWhichCanBeEnded.Count - 1)
                        {
                            ActiveGiftDestinations += " and ";
                        }
                        else if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) < AActiveGiftDestinationsWhichCanBeEnded.Count - 1)
                        {
                            ActiveGiftDestinations += ", ";
                        }
                    }

                    ActiveGiftDestinations += "'" + ActiveGiftDestinationName + "' (" + Row.FieldKey + ")";
                }

                // two different messages depending on number of gift destinations that need to be closed
                if (AActiveGiftDestinationsWhichCanBeEnded.Count == 1)
                {
                    Message = Catalog.GetString(string.Format(
                                                    "This Person's Family has an existing Gift Destination record to the field {0} that is active during the period {1} to {2}."
                                                    +
                                                    "{3}Would you like to shorten or deactivate this Gift Destination and make this new Commitment to " +
                                                    "the field '{4}' the active Gift Destination for this period?",
                                                    ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment,
                                                    "\n\n", UnitName));
                }
                else
                {
                    Message = Catalog.GetString(string.Format(
                                                    "This Person's Family has existing Gift Destination records to the fields {0} that are active during the period {1} to {2}."
                                                    +
                                                    "{3}Would you like to shorten or deactivate these Gift Destinations and make this new Commitment to " +
                                                    "the field '{4}' the active Gift Destination for this period?",
                                                    ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment,
                                                    "\n\n", UnitName));
                }

                // offer to end Gift Destination/s and use new commitment instead
                if (MessageBox.Show(Message,
                                    Catalog.GetString("Update Gift Destination"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    CreateNewGiftDestination = true;

                    foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded)
                    {
                        if (Row.DateEffective >= AEligibleCommitmentRow.StartOfCommitment)
                        {
                            // deactivate future gift destinations
                            Row.DateExpires = Row.DateEffective;
                        }
                        else
                        {
                            // shorten older gift destinations
                            if (Row.DateEffective != AEligibleCommitmentRow.StartOfCommitment)
                            {
                                Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment.AddDays(-1);
                            }
                            else
                            {
                                Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment;
                            }
                        }
                    }
                }
            }
            // if an existing gift destination can be updated from a modified commitment
            else if (AGiftDestinationWhichCanBeModified != null)
            {
                // offer to modify this Gift Destination
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                                          "This Person's Family has an existing Gift Destination record which matches a modified commitment." +
                                                          "{0}Would you like to update the Gift Destination record to the field '{1}' " +
                                                          "for the period {2} to {3}?",
                                                          "\n\n", UnitName,
                                                          AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)),
                                    Catalog.GetString("Update Gift Destination"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    AGiftDestinationWhichCanBeModified.DateExpires = AEligibleCommitmentRow.EndOfCommitment;
                }
            }
            // if an existing gift destination can be made inactive because of a deleted commitment
            else if (AGiftDestinationWhichCanBeDeactivated != null)
            {
                // offer to deactivate this Gift Destination
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                                          "This Person's Family has an existing Gift Destination record which matches a deleted commitment.{0}" +
                                                          "Would you like to deactivate the Gift Destination record to the field '{1}'" +
                                                          "for the period {2} to {3}?",
                                                          "\n\n", UnitName,
                                                          AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)),
                                    Catalog.GetString("Update Gift Destination"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    AGiftDestinationWhichCanBeDeactivated.DateExpires = AGiftDestinationWhichCanBeDeactivated.DateEffective;
                }
            }
            // if there is no active Gift Destination during dates of new commitment
            else if (ARowState != DataRowState.Deleted)
            {
                // offer to create new Gift Destination using new commitment
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                                          "This Person's Family does not have an active Gift Destination during the period " +
                                                          "{0} to {1}.{2}Would you like to make this new Commitment to the field " +
                                                          "'{3}' the active Gift Destination for this period?",
                                                          AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n",
                                                          UnitName)),
                                    Catalog.GetString("Update Gift Destination"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    CreateNewGiftDestination = true;
                }
            }

            /* create a brand new Gift Destination */

            if (CreateNewGiftDestination)
            {
                if (FInspectDS.PPartnerGiftDestination == null)
                {
                    FInspectDS.Merge(new PPartnerGiftDestinationTable());
                }

                // create new Gift Destination
                PPartnerGiftDestinationRow NewRow = FInspectDS.PPartnerGiftDestination.NewRowTyped(true);
                NewRow.Key           = TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination() + FNewRecords;
                NewRow.PartnerKey    = ((PPersonRow)FInspectDS.PPerson.Rows[0]).FamilyKey;
                NewRow.FieldKey      = AEligibleCommitmentRow.ReceivingField;
                NewRow.DateEffective = AEligibleCommitmentRow.StartOfCommitment;
                NewRow.DateExpires   = AEligibleCommitmentRow.EndOfCommitment;
                FInspectDS.PPartnerGiftDestination.Rows.Add(NewRow);

                FNewRecords++;
            }
        }
        private void ValidateDataDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedPartnerValidation_Partner.ValidateGiftDestinationRowManual(this, ARow, ref VerificationResultCollection,
                FPetraUtilsObject.ValidationControlsDict);

            if (VerificationResultCollection.HasCriticalErrors) // If something went wrong - allow the user to fix it!
            {
                dtpDetailDateEffective.Enabled = true;
                txtDetailFieldKey.Enabled = true;
            }

            // add VerificationResults from validating on all data (FPetraUtilsObject_DataSaved)
            VerificationResultCollection.AddCollection(FVerificationResultCollection);
            FVerificationResultCollection = null;
        }
        private void ValidateDataDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedPartnerValidation_Partner.ValidateGiftDestinationRowManual(this, ARow, ref VerificationResultCollection,
                FPetraUtilsObject.ValidationControlsDict);

            // add VerificationResults from validating on all data (FPetraUtilsObject_DataSaved)
            VerificationResultCollection.AddCollection(FVerificationResultCollection);
            FVerificationResultCollection = null;
        }
        private void ShowDetailsManual(PPartnerGiftDestinationRow ARow)
        {
            if (ARow == null)
            {
                return;
            }

            // DateEffective and FieldKey cannot be changed once saved
            if (ARow.RowState == DataRowState.Added)
            {
                dtpDetailDateEffective.Enabled = true;
                txtDetailFieldKey.Enabled = true;
            }
            else
            {
                dtpDetailDateEffective.Enabled = false;
                txtDetailFieldKey.Enabled = false;
            }

            if (ARow.DateEffective == ARow.DateExpires)
            {
                btnDeactivate.Enabled = false;
            }
            else
            {
                btnDeactivate.Enabled = true;
            }
        }
 private void GetDetailDataFromControlsManual(PPartnerGiftDestinationRow ARow)
 {
     // updates the custom field to display field name in the grid
     ARow["FieldName"] = txtDetailFieldKey.LabelText;
 }
        private void NewRowManual(ref PPartnerGiftDestinationRow ANewRow)
        {
            // create a key that is at least one more that all the (unsaved) records in the grid AND all the records in the database
            int Max = 0;

            foreach (PPartnerGiftDestinationRow Row in FMainDS.PPartnerGiftDestination.Rows)
            {
                if ((Row.RowState != DataRowState.Deleted) && (Row.Key >= Max))
                {
                    Max = Row.Key + 1;
                }
            }

            ANewRow.Key = Math.Max(Max, TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination());
            ANewRow.PartnerKey = FPartnerKey;
            ANewRow.FieldKey = 0;
            ANewRow["Order"] = DateTime.MaxValue;
        }
Esempio n. 16
0
 private void GetDetailDataFromControlsManual(PPartnerGiftDestinationRow ARow)
 {
     // updates the custom field to display field name in the grid
     ARow["FieldName"] = txtDetailFieldKey.LabelText;
 }
Esempio n. 17
0
        private static void GenerateCommitmentRecord(
            XmlNode ACurrentNode,
            PFamilyRow AFamilyRow,
            PartnerEditTDS AMainDS,
            PersonnelTDS APersonnelDS,
            DataTable AFieldKeys)
        {
            DataView FamilyView = new DataView(AMainDS.PPerson);

            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort      = PPersonTable.GetFamilyIdDBName();
            PPersonRow firstPerson = (PPersonRow)FamilyView[0].Row;

            int FieldID =
                Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "fieldCommitment")) % AFieldKeys.Rows.Count;
            long FieldPartnerKey = Convert.ToInt64(AFieldKeys.Rows[FieldID].ItemArray[0]);

            PPartnerGiftDestinationRow giftDestination = AMainDS.PPartnerGiftDestination.NewRowTyped();

            if (NextKeyForGiftDestination == -1)
            {
                NextKeyForGiftDestination = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination();
            }
            else
            {
                NextKeyForGiftDestination++;
            }

            giftDestination.Key           = NextKeyForGiftDestination;
            giftDestination.FieldKey      = FieldPartnerKey;
            giftDestination.PartnerKey    = AFamilyRow.PartnerKey;
            giftDestination.PartnerClass  = MPartnerConstants.PARTNERCLASS_FAMILY;
            giftDestination.DateEffective = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));

            PmStaffDataRow staffData = APersonnelDS.PmStaffData.NewRowTyped();

            staffData.SiteKey        = DomainManager.GSiteKey;
            staffData.Key            = (APersonnelDS.PmStaffData.Count + 1) * -1;
            staffData.PartnerKey     = firstPerson.PartnerKey;
            staffData.ReceivingField = FieldPartnerKey;

            // TODO: could add foreign nationals
            staffData.HomeOffice        = DomainManager.GSiteKey;
            staffData.OfficeRecruitedBy = DomainManager.GSiteKey;

            staffData.StartOfCommitment = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));
            int LengthCommitment = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "lengthCommitment"));

            staffData.StatusCode = "LONG-TERMER";

            if (LengthCommitment > 0)
            {
                string LengthCommitmentUnit = TXMLParser.GetAttribute(ACurrentNode, "lengthCommitmentUnit");

                if (LengthCommitmentUnit == "week")
                {
                    staffData.StatusCode      = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddDays(7 * LengthCommitment);
                }
                else if (LengthCommitmentUnit == "month")
                {
                    staffData.StatusCode      = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddMonths(LengthCommitment);
                }
                else if (LengthCommitmentUnit == "year")
                {
                    if (LengthCommitment < 3)
                    {
                        staffData.StatusCode = "WORKER";
                    }

                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddYears(LengthCommitment);
                }
            }

            APersonnelDS.PmStaffData.Rows.Add(staffData);

            giftDestination.DateExpires = staffData.EndOfCommitment;

            if (AMainDS.PPartnerGiftDestination == null)
            {
                AMainDS.PPartnerGiftDestination.Merge(new PPartnerGiftDestinationTable());
            }

            AMainDS.PPartnerGiftDestination.Rows.Add(giftDestination);

            // TODO depending on start and end date of commitment, set EX-WORKER or no special type yet at all
            string SpecialType = MPartnerConstants.PARTNERTYPE_WORKER;

            if (!staffData.IsEndOfCommitmentNull() && (staffData.EndOfCommitment < DateTime.Today))
            {
                SpecialType = MPartnerConstants.PARTNERTYPE_EX_WORKER;
            }

            if (SpecialType != string.Empty)
            {
                // create special type for family partner
                PPartnerTypeRow PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped();
                PartnerTypeRow.PartnerKey = AFamilyRow.PartnerKey;
                PartnerTypeRow.TypeCode   = SpecialType;
                AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);

                // set special type WORKER for the parents
                for (int countPerson = 0; countPerson < FamilyView.Count && countPerson < 2; countPerson++)
                {
                    PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row;

                    // create special type for the person partners
                    PartnerTypeRow            = AMainDS.PPartnerType.NewRowTyped();
                    PartnerTypeRow.PartnerKey = personRow.PartnerKey;
                    PartnerTypeRow.TypeCode   = SpecialType;
                    AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);
                }
            }
        }
        /// Iterate through each gift destination and compare with commitment record.
        /// Determine if gift destination can be updated and how.
        private void CompareCommitmentToGiftDestinations(DataRowState ARowState,
            PmStaffDataRow AEligibleCommitmentRow,
            PmStaffDataRow AOriginalCommitmentRow,
            ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified,
            ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated,
            ref List <PPartnerGiftDestinationRow>AActiveGiftDestinationsWhichCanBeEnded)
        {
            // only changes to recieving field, start data and end date can update the Gift Destination
            if ((ARowState == DataRowState.Modified)
                && (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField)
                && (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment)
                && (AOriginalCommitmentRow.EndOfCommitment == AEligibleCommitmentRow.EndOfCommitment))
            {
                return;
            }

            bool Repeat = true;

            while (Repeat)
            {
                Repeat = false;

                foreach (PPartnerGiftDestinationRow CurrentRow in FInspectDS.PPartnerGiftDestination.Rows)
                {
                    // if two records are the same
                    if ((AOriginalCommitmentRow != null)
                        && (AOriginalCommitmentRow.ReceivingField == CurrentRow.FieldKey)
                        && (AOriginalCommitmentRow.StartOfCommitment == CurrentRow.DateEffective)
                        && (AOriginalCommitmentRow.EndOfCommitment == CurrentRow.DateExpires)
                        && (CurrentRow.DateEffective != CurrentRow.DateExpires))
                    {
                        if ((ARowState == DataRowState.Modified)
                            && (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment)
                            && (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField))
                        {
                            // if the field and start date have not been changed then we can update the Gift Destination
                            AGiftDestinationWhichCanBeModified = CurrentRow;
                            continue;
                        }
                        else if (ARowState == DataRowState.Deleted)
                        {
                            AGiftDestinationWhichCanBeDeactivated = CurrentRow;
                            return;
                        }
                    }
                    else if (ARowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    else if (CurrentRow.DateEffective == CurrentRow.DateExpires)
                    {
                        // ignore inactive Gift Destination
                        continue;
                    }

                    if ((AEligibleCommitmentRow.IsEndOfCommitmentNull()
                         && (CurrentRow.IsDateExpiresNull() || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment)))
                        || !AEligibleCommitmentRow.IsEndOfCommitmentNull()
                        && ((CurrentRow.IsDateExpiresNull() && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment))
                            || (!CurrentRow.IsDateExpiresNull()
                                && (((CurrentRow.DateEffective >= AEligibleCommitmentRow.StartOfCommitment)
                                     && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment))
                                    || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment)
                                    && (CurrentRow.DateExpires <= AEligibleCommitmentRow.EndOfCommitment)))))
                    {
                        AActiveGiftDestinationsWhichCanBeEnded.Add(CurrentRow);
                    }
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Validates a Gift Destination record
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        /// <returns>void</returns>
        public static void ValidateGiftDestinationRowManual(object AContext, PPartnerGiftDestinationRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;

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

            // 'Field Key' must be a Partner associated with a Cost Centre
            DataColumn ValidationColumn = ARow.Table.Columns[PPartnerGiftDestinationTable.ColumnFieldKeyId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (!TSharedPartnerValidationHelper.PartnerIsLinkedToCC(ARow.FieldKey))
                {
                    VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn,
                        String.Format(
                            Catalog.GetString("Gift Destination ({0}) must be a Partner linked to a Cost Centre."),
                            ARow.FieldKey),
                        Catalog.GetString("Partner Validation"),
                        PetraErrorCodes.ERR_PARTNER_MUST_BE_CC,
                        ValidationControlsData.ValidationControl,
                        TResultSeverity.Resv_Critical);
                }

                // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to
                // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different
                // ResultText!
                AVerificationResultCollection.Remove(ValidationColumn);
                AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
            }

            // Date Effective must not be after Date Expired (it can be equal)
            ValidationColumn = ARow.Table.Columns[PPartnerGiftDestinationTable.ColumnDateEffectiveId];

            if (ARow.DateEffective > ARow.DateExpires)
            {
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALID_DATES)),
                    ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }
        /// Ask the user if they want to update the Gift Destination and then make the changes
        private void DealWithPotentialGiftDestinationUpdates(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow,
            PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified,
            PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, List <PPartnerGiftDestinationRow>AActiveGiftDestinationsWhichCanBeEnded)
        {
            string UnitName = "";
            string ActiveGiftDestinations = "";
            string EndOfCommitment;
            bool CreateNewGiftDestination = false;
            TPartnerClass PartnerClass;

            // set end date to display to user in messagebox
            if (AEligibleCommitmentRow.IsEndOfCommitmentNull())
            {
                EndOfCommitment = "'Open Ended'";
            }
            else
            {
                EndOfCommitment = AEligibleCommitmentRow.EndOfCommitment.Value.ToShortDateString();
            }

            // get the receiving fields short name
            TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(AEligibleCommitmentRow.ReceivingField,
                out UnitName,
                out PartnerClass);
            UnitName = UnitName + " (" + AEligibleCommitmentRow.ReceivingField + ")";

            // if existing active Gift Destination/s can be ended in order to add a Gift Destination for new commitment
            if (AActiveGiftDestinationsWhichCanBeEnded.Count > 0)
            {
                string Message = "";

                // get gift destination field's short name
                foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded)
                {
                    string ActiveGiftDestinationName = "";

                    TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(
                        Row.FieldKey, out ActiveGiftDestinationName, out PartnerClass);

                    // add conjunctions
                    if (AActiveGiftDestinationsWhichCanBeEnded.Count > 1)
                    {
                        if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) == AActiveGiftDestinationsWhichCanBeEnded.Count - 1)
                        {
                            ActiveGiftDestinations += " and ";
                        }
                        else if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) < AActiveGiftDestinationsWhichCanBeEnded.Count - 1)
                        {
                            ActiveGiftDestinations += ", ";
                        }
                    }

                    ActiveGiftDestinations += "'" + ActiveGiftDestinationName + "' (" + Row.FieldKey + ")";
                }

                // two different messages depending on number of gift destinations that need to be closed
                if (AActiveGiftDestinationsWhichCanBeEnded.Count == 1)
                {
                    Message = Catalog.GetString(string.Format(
                            "This Person's Family has an existing Gift Destination record to the field {0} that is active during the period {1} to {2}."
                            +
                            "{3}Would you like to shorten or deactivate this Gift Destination and make this new Commitment to " +
                            "the field '{4}' the active Gift Destination for this period?",
                            ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment,
                            "\n\n", UnitName));
                }
                else
                {
                    Message = Catalog.GetString(string.Format(
                            "This Person's Family has existing Gift Destination records to the fields {0} that are active during the period {1} to {2}."
                            +
                            "{3}Would you like to shorten or deactivate these Gift Destinations and make this new Commitment to " +
                            "the field '{4}' the active Gift Destination for this period?",
                            ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment,
                            "\n\n", UnitName));
                }

                // offer to end Gift Destination/s and use new commitment instead
                if (MessageBox.Show(Message,
                        Catalog.GetString("Update Gift Destination"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    CreateNewGiftDestination = true;

                    foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded)
                    {
                        if (Row.DateEffective >= AEligibleCommitmentRow.StartOfCommitment)
                        {
                            // deactivate future gift destinations
                            Row.DateExpires = Row.DateEffective;
                        }
                        else
                        {
                            // shorten older gift destinations
                            if (Row.DateEffective != AEligibleCommitmentRow.StartOfCommitment)
                            {
                                Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment.AddDays(-1);
                            }
                            else
                            {
                                Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment;
                            }
                        }
                    }
                }
            }
            // if an existing gift destination can be updated from a modified commitment
            else if (AGiftDestinationWhichCanBeModified != null)
            {
                // offer to modify this Gift Destination
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                "This Person's Family has an existing Gift Destination record which matches a modified commitment." +
                                "{0}Would you like to update the Gift Destination record to the field '{1}' " +
                                "for the period {2} to {3}?",
                                "\n\n", UnitName,
                                AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)),
                        Catalog.GetString("Update Gift Destination"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    AGiftDestinationWhichCanBeModified.DateExpires = AEligibleCommitmentRow.EndOfCommitment;
                }
            }
            // if an existing gift destination can be made inactive because of a deleted commitment
            else if (AGiftDestinationWhichCanBeDeactivated != null)
            {
                // offer to deactivate this Gift Destination
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                "This Person's Family has an existing Gift Destination record which matches a deleted commitment.{0}" +
                                "Would you like to deactivate the Gift Destination record to the field '{1}'" +
                                "for the period {2} to {3}?",
                                "\n\n", UnitName,
                                AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)),
                        Catalog.GetString("Update Gift Destination"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    AGiftDestinationWhichCanBeDeactivated.DateExpires = AGiftDestinationWhichCanBeDeactivated.DateEffective;
                }
            }
            // if there is no active Gift Destination during dates of new commitment
            else if (ARowState != DataRowState.Deleted)
            {
                // offer to create new Gift Destination using new commitment
                if (MessageBox.Show(Catalog.GetString(string.Format(
                                "This Person's Family does not have an active Gift Destination during the period " +
                                "{0} to {1}.{2}Would you like to make this new Commitment to the field " +
                                "'{3}' the active Gift Destination for this period?",
                                AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n",
                                UnitName)),
                        Catalog.GetString("Update Gift Destination"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    CreateNewGiftDestination = true;
                }
            }

            /* create a brand new Gift Destination */

            if (CreateNewGiftDestination)
            {
                if (FInspectDS.PPartnerGiftDestination == null)
                {
                    FInspectDS.Merge(new PPartnerGiftDestinationTable());
                }

                // create new Gift Destination
                PPartnerGiftDestinationRow NewRow = FInspectDS.PPartnerGiftDestination.NewRowTyped(true);
                NewRow.Key = TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination() + FNewRecords;
                NewRow.PartnerKey = ((PPersonRow)FInspectDS.PPerson.Rows[0]).FamilyKey;
                NewRow.FieldKey = AEligibleCommitmentRow.ReceivingField;
                NewRow.DateEffective = AEligibleCommitmentRow.StartOfCommitment;
                NewRow.DateExpires = AEligibleCommitmentRow.EndOfCommitment;
                FInspectDS.PPartnerGiftDestination.Rows.Add(NewRow);

                FNewRecords++;
            }
        }
Esempio n. 21
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());
        }
Esempio n. 22
0
        public static void CheckGiftDestinationClashes(PPartnerGiftDestinationTable AToPartnersGiftDestinations,
            PPartnerGiftDestinationRow AFromActiveRow,
            out PPartnerGiftDestinationRow AFromGiftDestinationNeedsEnded,
            out PPartnerGiftDestinationRow AToGiftDestinationNeedsEnded)
        {
            AFromGiftDestinationNeedsEnded = null;
            AToGiftDestinationNeedsEnded = null;

            foreach (PPartnerGiftDestinationRow Row in AToPartnersGiftDestinations.Rows)
            {
                if ((Row.DateEffective != Row.DateExpires)
                    && (Row.DateEffective >= AFromActiveRow.DateEffective) && (Row.DateEffective > DateTime.Today)
                    && (AFromActiveRow.IsDateExpiresNull() || (Row.DateEffective <= AFromActiveRow.DateExpires)))
                {
                    AFromGiftDestinationNeedsEnded = Row;
                }
                else if ((Row.DateEffective != Row.DateExpires)
                         && (Row.DateEffective < AFromActiveRow.DateEffective)
                         && (Row.IsDateExpiresNull() || (Row.DateExpires >= AFromActiveRow.DateEffective)))
                {
                    AToGiftDestinationNeedsEnded = Row;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Validates a Gift Destination record
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        /// <returns>void</returns>
        public static void ValidateGiftDestinationRowManual(object AContext, PPartnerGiftDestinationRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult;

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

            // 'Field Key' must be a Partner of Class 'UNIT' and must not be 0
            ValidationColumn = ARow.Table.Columns[PPartnerGiftDestinationTable.ColumnFieldKeyId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = IsValidUNITPartner(
                    ARow.FieldKey, false, THelper.NiceValueDescription(
                        ValidationControlsData.ValidationControlLabel) + " must be set correctly.",
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to
                // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different
                // ResultText!
                AVerificationResultCollection.Remove(ValidationColumn);
                AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
            }

            // Date Effective must not be after Date Expired (it can be equal)
            ValidationColumn = ARow.Table.Columns[PPartnerGiftDestinationTable.ColumnDateEffectiveId];

            if (ARow.DateEffective > ARow.DateExpires)
            {
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALID_DATES)),
                    ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }