Example #1
0
        /// <summary>
        ///
        /// This method will apply the assignment rule to either the transaction record or the current (i.e., database)
        /// record, using the other record as a reference.
        ///
        /// <param name="poTransactionRecord">The incoming record</param>
        /// <param name="poCurrentRecord">The current record (i.e., in the database)</param>
        /// <param name="poErrorMessage">The buffer that will contain an error message if the rule fails</param>
        /// <returns>Indicates whether or not the target product passed the rule successfully</returns>
        /// </summary>
        public override bool Execute(WonkaProduct poTransactionRecord,
                                     WonkaProduct poCurrentRecord,
                                     StringBuilder poErrorMessage)
        {
            bool bResult = false;

            WonkaProduct        TargetRecord = null;
            WonkaRefEnvironment WonkaRefEnv  = WonkaRefEnvironment.GetInstance();

            int nAttrId  = TargetAttribute.AttrId;
            int nGroupId = TargetAttribute.GroupId;

            if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD)
            {
                TargetRecord = poTransactionRecord;
            }
            else if (RecordOfInterest == TARGET_RECORD.TRID_OLD_RECORD)
            {
                TargetRecord = poCurrentRecord;
            }
            else
            {
                throw new Exception("ERROR!  The target record is none!");
            }

            string sTargetData =
                TargetRecord.GetPrimaryAttributeData(TargetAttribute.GroupId, TargetAttribute.AttrId);

            if (sTargetData == null)
            {
                sTargetData = string.Empty;
            }

            RefreshCache(poTransactionRecord, poCurrentRecord);

            WonkaPrdGroup TempProductGroup = null;

            if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD)
            {
                TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId);
            }
            else
            {
                TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId);
            }

            if ((CustomOpDelegate == null) && (CustomOpSource.CustomOpDelegate != null))
            {
                CustomOpDelegate = CustomOpSource.CustomOpDelegate;
            }

            if (CustomOpDelegate != null)
            {
                string[] CustomOpArgs = new string[4];

                for (int idx = 0; idx < 4; ++idx)
                {
                    if (idx < DomainCache.Count())
                    {
                        CustomOpArgs[idx] = DomainCache.ElementAt(idx);
                    }
                    else
                    {
                        CustomOpArgs[idx] = string.Empty;
                    }
                }

                string sCustomOpResult =
                    CustomOpDelegate(CustomOpArgs[0], CustomOpArgs[1], CustomOpArgs[2], CustomOpArgs[3]);

                // NOTE: If the result is empty, we consider the rule's invocation as a failure
                if (!String.IsNullOrEmpty(sCustomOpResult))
                {
                    TempProductGroup[0][nAttrId] = sCustomOpResult;
                    bResult = true;
                }

                if (poErrorMessage != null)
                {
                    poErrorMessage.Clear();
                    poErrorMessage.Append(GetVerboseError(TargetRecord));
                }
            }

            return(bResult);
        }