|
Public Class OrderDetailLineTotalRule
Inherits ValidationRuleBase
Public Overrides ReadOnly Property RulePriority() As RulePriority
Get
Return RulePriority.Normal
End Get
End Property
Public Overrides Function Validate(ByVal objectToValidate As Object) As ValidationResultCollection
' This rule only checks a DTO.OrdersDataSets.OrderHeaderRow (an Order)
If Not TypeOf objectToValidate Is DTO.OrdersDataSet.OrderHeaderRow Then
Return Nothing
End If
Dim results As New ValidationResultCollection
Dim result As ValidationResult
Dim drOrder As DTO.OrdersDataSet.OrderHeaderRow = CType(objectToValidate, DTO.OrdersDataSet.OrderHeaderRow)
Dim lineTotal As Decimal
For Each drOD As DTO.OrdersDataSet.OrderDetailRow In drOrder.GetChildRows("FK_OrderHeader_OrderDetail")
lineTotal = drOD.OrderedQuantity * (drOD.UnitPrice - (drOD.UnitPrice * (drOD.UnitPriceDiscount / 100)))
If lineTotal <> drOD.LineTotal Then
result = New ValidationResult(Me.RuleName, ResultType.Passed, "", "", "", Me.RulePriority)
result.ResultType = ResultType.Failed
result.Message = String.Format("LineTotal {0:C} not equal to calculated line total {1:C}", drOD.LineTotal, lineTotal)
result.ReferenceHint = "OrderDetailD"
result.Reference = drOD.OrderDetailID.ToString
results.Add(result)
End If
Next
Return results
End Function
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here