/// <summary> /// /// This method will serialize a ProductGroup within a Product instance. /// /// </summary> /// <param name="poTmpPrdGroup">The target ProductGroup being serialized</param> /// <param name="poProductListBuilder">The buffer that is holding the written WONKA-XML message</param> /// <returns>None</returns> private void AppendProductGroup(WonkaPrdGroup poTmpPrdGroup, StringBuilder poProductListBuilder) { WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); if (poTmpPrdGroup.GetRowCount() > 0) { string sTmpAttrValue = null; foreach (WonkaPrdGroupDataRow TempDataRow in poTmpPrdGroup) { poProductListBuilder.Append("\n <" + poTmpPrdGroup.MasterGroup.GroupName + ">"); foreach (int nTmpAttrId in TempDataRow.Keys) { sTmpAttrValue = TempDataRow[nTmpAttrId]; if (!String.IsNullOrEmpty(sTmpAttrValue)) { WonkaRefAttr TempAttribute = WonkaRefEnv.GetAttributeByAttrId(nTmpAttrId); poProductListBuilder.Append("\n <" + TempAttribute.AttrName + ">"); poProductListBuilder.Append(WrapWithCData(sTmpAttrValue)); poProductListBuilder.Append("</" + TempAttribute.AttrName + ">"); } } poProductListBuilder.Append("\n </" + poTmpPrdGroup.MasterGroup.GroupName + ">"); } } }
/// <summary> /// /// If either the min and max values are set to be dynamic (i.e., subject to record values), /// this method will update the provided values for the min and max of this rule and use the /// appropriate target records to do so. /// /// <param name="poTransactionRecord">The incoming (i.e., transaction) record</param> /// <param name="poCurrentRecord">The old (i.e., current) record</param> /// <returns>None</returns> /// </summary> private void RefreshMinAndMax(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord) { string sTempAttrValue = null; if (!this.MinValueProps.IsLiteralValue) { int nAttrId = this.MinValueProps.AttributeInfo.AttrId; int nGroupId = this.MinValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MinValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } sTempAttrValue = TempProductGroup[0][nAttrId]; if (!String.IsNullOrEmpty(sTempAttrValue)) { this.MinValue = DateTime.ParseExact(sTempAttrValue, CONST_WONKA_DATETIME_FORMAT, null); } else { this.MinValue = DateTime.MinValue; } } if (!this.MaxValueProps.IsLiteralValue) { int nAttrId = this.MaxValueProps.AttributeInfo.AttrId; int nGroupId = this.MaxValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MaxValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } sTempAttrValue = TempProductGroup[0][nAttrId]; if (!String.IsNullOrEmpty(sTempAttrValue)) { this.MaxValue = DateTime.ParseExact(sTempAttrValue, CONST_WONKA_DATETIME_FORMAT, null); } else { this.MaxValue = DateTime.MaxValue; } } }
/// <summary> /// /// This method will apply the arithmetic 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); } TempProductGroup[0][nAttrId] = Convert.ToString(CalculateValue()); if (poErrorMessage != null) { poErrorMessage.Clear(); poErrorMessage.Append(GetVerboseError(TargetRecord)); } return(bResult); }
/// <summary> /// /// This method will refresh the assignment value if it's not literal (i.e., it's an Attribute on a record). /// /// <param name="poNewProduct">The incoming Product whose Attributes might be used to populate the Set</param> /// <param name="poOldProduct">The current Product whose Attributes might be used to populate the Set</param> /// <returns>Indicator of whether the assignment value was refreshed successfully</returns> /// </summary> private bool RefreshAssignValue(WonkaProduct poNewProduct, WonkaProduct poOldProduct) { bool bResult = true; int nAttrId = 0; int nGroupId = 0; if (!this.AssignValueProps.IsLiteralValue) { this.AssignValue = string.Empty; if (poNewProduct == null) { throw new Exception("ERROR! The new Product is null."); } if (poNewProduct == null) { throw new Exception("ERROR! The old Product is null."); } nAttrId = AssignValueProps.AttributeInfo.AttrId; nGroupId = AssignValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (AssignValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poNewProduct.GetProductGroup(nGroupId); } else { TempProductGroup = poOldProduct.GetProductGroup(nGroupId); } if (TempProductGroup.DataRowVector.Count > 0) { if ((TempProductGroup[0].Count > 0) && TempProductGroup[0].ContainsKey(nAttrId)) { this.AssignValue = TempProductGroup[0][nAttrId]; } } } return(bResult); }
/// <summary> /// /// If either the min and max values are set to be dynamic (i.e., subject to record values), /// this method will update the provided values for the min and max of this rule and use the /// appropriate target records to do so. /// /// NOTE: The code will only address the first row of a Group, in both the case of the old product and the new one. /// /// <param name="poTransactionRecord">The incoming (i.e., transaction) record</param> /// <param name="poCurrentRecord">The old (i.e., current) record</param> /// <returns>None</returns> /// </summary> private void RefreshMinAndMax(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord) { if (!this.MinValueProps.IsLiteralValue) { int nAttrId = this.MinValueProps.AttributeInfo.AttrId; int nGroupId = this.MinValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MinValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } this.MinValue = Convert.ToDouble(TempProductGroup[0][nAttrId]); } if (!this.MaxValueProps.IsLiteralValue) { int nAttrId = this.MaxValueProps.AttributeInfo.AttrId; int nGroupId = this.MaxValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MaxValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } this.MaxValue = Convert.ToDouble(TempProductGroup[0][nAttrId]); } }
/// <summary> /// /// This method will refresh the set of data if there are any mentioned Attributes. /// /// <param name="poNewProduct">The incoming Product whose Attributes might be used to populate the Set</param> /// <param name="poOldProduct">The current Product whose Attributes might be used to populate the Set</param> /// <param name="poDomainCache">Our domain cache that will be refreshed</param> /// <returns>Indicator of whether the set was refreshed successfully</returns> /// </summary> public bool RefreshCache(WonkaProduct poNewProduct, WonkaProduct poOldProduct, HashSet <string> poDomainCache) { bool bResult = true; int nAttrId = 0; int nGroupId = 0; WonkaBizRuleValueProps RuleValueProps = null; if (HasAttrIdTargets) { if (poNewProduct == null) { throw new Exception("ERROR! The new Product is null."); } if (poNewProduct == null) { throw new Exception("ERROR! The old Product is null."); } if (poDomainCache == null) { throw new Exception("ERROR! The provided Domain Cache is null."); } poDomainCache.Clear(); foreach (string sDomainValue in DomainValueProps.Keys) { RuleValueProps = DomainValueProps[sDomainValue]; if (RuleValueProps.IsLiteralValue) { poDomainCache.Add(sDomainValue); } else { nAttrId = RuleValueProps.AttributeInfo.AttrId; nGroupId = RuleValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (RuleValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poNewProduct.GetProductGroup(nGroupId); } else { TempProductGroup = poOldProduct.GetProductGroup(nGroupId); } foreach (WonkaPrdGroupDataRow TempDataRow in TempProductGroup) { if (TempDataRow.Keys.Contains(nAttrId)) { poDomainCache.Add(TempDataRow[nAttrId]); } } } } } return(bResult); }
/// <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); }
/// <summary> /// /// If either the min and max values are set to be dynamic (i.e., subject to record values), /// this method will update the provided values for the min and max of this rule and use the /// appropriate target records to do so. /// /// <param name="poTransactionRecord">The incoming (i.e., transaction) record</param> /// <param name="poCurrentRecord">The old (i.e., current) record</param> /// <returns>None</returns> /// </summary> private void RefreshMinAndMax(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord) { string sTempAttrValue = null; if (this.TodayIndicator) { DateTime DateTimeNow = DateTime.Now; if (this.AlmostOperator) { System.TimeSpan WindowSpan = new System.TimeSpan(1, 0, 0, 0); this.MinValue = DateTimeNow; this.MaxValue = DateTimeNow.Add(WindowSpan); } else { if (this.MinValue != DateTime.MinValue) { this.MinValue = DateTimeNow; } else { this.MaxValue = DateTimeNow; } } } else { if (!this.MinValueProps.IsLiteralValue) { int nAttrId = this.MinValueProps.AttributeInfo.AttrId; int nGroupId = this.MinValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MinValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } sTempAttrValue = TempProductGroup[0][nAttrId]; if (!string.IsNullOrEmpty(sTempAttrValue)) { this.MinValue = DateTime.ParseExact(sTempAttrValue, CONST_WONKA_DATETIME_FORMAT, null); } else { this.MinValue = DateTime.MinValue; } } if (!this.MaxValueProps.IsLiteralValue) { int nAttrId = this.MaxValueProps.AttributeInfo.AttrId; int nGroupId = this.MaxValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MaxValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } sTempAttrValue = TempProductGroup[0][nAttrId]; if (!string.IsNullOrEmpty(sTempAttrValue)) { this.MaxValue = DateTime.ParseExact(sTempAttrValue, CONST_WONKA_DATETIME_FORMAT, null); } else { this.MaxValue = DateTime.MaxValue; } } } }
/// <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; bool bAssignValue = true; int nAttrId = TargetAttribute.AttrId; int nGroupId = TargetAttribute.GroupId; WonkaProduct TargetRecord = null; WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); if (poTransactionRecord == null) { throw new Exception("ERROR! The new Product is null."); } if (poCurrentRecord == null) { throw new Exception("ERROR! The old Product is null."); } 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!"); } if (DefaultAssignment) { WonkaPrdGroup TempProductGroup = null; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } string sCurrentValue = string.Empty; if (TempProductGroup.GetRowCount() > 0) { if (TempProductGroup[0].ContainsKey(nAttrId)) { sCurrentValue = TempProductGroup[0][nAttrId]; } } if (!string.IsNullOrEmpty(sCurrentValue)) { bAssignValue = false; } } if (bAssignValue) { RefreshAssignValue(poTransactionRecord, poCurrentRecord); WonkaPrdGroup TempProductGroup = null; if (RecordOfInterest == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } TempProductGroup[0][nAttrId] = AssignValue; } return(bResult); }
/// <summary> /// /// If either the min and max values are set to be dynamic (i.e., subject to record values), /// this method will update the provided values for the min and max of this rule and use the /// appropriate target records to do so. /// /// NOTE: The code will only address the first row of a Group, in both the case of the old product and the new one. /// /// <param name="poTransactionRecord">The incoming (i.e., transaction) record</param> /// <param name="poCurrentRecord">The old (i.e., current) record</param> /// <returns>None</returns> /// </summary> private void RefreshMinAndMax(WonkaProduct poTransactionRecord, WonkaProduct poCurrentRecord) { if (this.BlockNumOperator) { if ((this.BlockNumDelegate != null) && (this.RulesHostEngine != null)) { string sCurrBlockNum = this.BlockNumDelegate.Invoke(this.RulesHostEngine, null); if (!String.IsNullOrEmpty(sCurrBlockNum)) { var HexNum = System.Numerics.BigInteger.Parse(sCurrBlockNum, System.Globalization.NumberStyles.HexNumber); double dVal = (double)HexNum; if (this.MinValue != Double.MinValue) { this.MinValue = dVal; } else { this.MaxValue = dVal; } } } } else { if (!this.MinValueProps.IsLiteralValue) { int nAttrId = this.MinValueProps.AttributeInfo.AttrId; int nGroupId = this.MinValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MinValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } this.MinValue = Convert.ToDouble(TempProductGroup[0][nAttrId]); } if (!this.MaxValueProps.IsLiteralValue) { int nAttrId = this.MaxValueProps.AttributeInfo.AttrId; int nGroupId = this.MaxValueProps.AttributeInfo.GroupId; WonkaPrdGroup TempProductGroup = null; if (this.MaxValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD) { TempProductGroup = poTransactionRecord.GetProductGroup(nGroupId); } else { TempProductGroup = poCurrentRecord.GetProductGroup(nGroupId); } this.MaxValue = Convert.ToDouble(TempProductGroup[0][nAttrId]); } } }