|
Public Class OrderSubTotalShouldBeEqualToSumOfLineTotalsRule
Inherits ValidationRuleBase
Public Overrides ReadOnly Property RulePriority() As RulePriority
Get
Return RulePriority.High
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 New ValidationResult(Me.RuleName, ResultType.Undecided, "", "", "", Me.RulePriority)
Dim SumOfLineTotals As Decimal = 0
Dim drOrder As DTO.OrdersDataSet.OrderHeaderRow = CType(objectToValidate, DTO.OrdersDataSet.OrderHeaderRow)
For Each drOrderDetail As DTO.OrdersDataSet.OrderDetailRow In drOrder.GetChildRows("FK_OrderHeader_OrderDetail")
SumOfLineTotals += drOrderDetail.LineTotal
Next
If SumOfLineTotals = drOrder.SubTotal Then
result.ResultType = ResultType.Passed
Else
result.ResultType = ResultType.Failed
result.Message = String.Format("Sum of Line Totals was {0:C} Header SubTotal is {1:C}", SumOfLineTotals, drOrder.SubTotal)
result.ReferenceHint = "OrderHeaderID"
result.Reference = drOrder.OrderHeaderID.ToString
End If
results.Add(result)
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