Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Business Rules
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Miscellaneous
Thread ID:
00825867
Message ID:
00826190
Views:
19
Thanks Kevin,

Okay, that makes sense. It's pretty much the way I do things now in Fox. I thought it might be more message-oriented. What are "Error-Provider style" broken rules as opposed to other styles of broken rules?

pamela

>Pamela,
>
>>I haven't actually used an mmBusinessRule yet, but the documentation discusses calling just before saving the data. I have had many situations where certain valid data is required in one control before the user can go on to the next control. (In VFP I call code from the Valid or LostFocus of a control.) I am not picturing how an individual rule is invoked from the user interface. I imagine that the control raises some sort of DataChanged event which is trapped by the bizobj. Can someone point me toward an example of how that would be done in MM?
>
>As Vic suggested at the end of his message, it's preferable to call a method on the business rule object rather than placing business rules in the UI. You can actually get a reference to the business rule object and call the method directly. For example, if you have a method on your rule object called "ValidateShipName" that returned a broken rule message, you could call it from the text box's Validating event handler like this:
>
>In C#:
>
>
>private void txtShipName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
>{
>	OrderRules BizRule = (OrderRules)this.oOrder.GetBusinessRuleObject();
>	string Message = BizRule.ValidateShipName(this.txtShipName.Text);
>	if (!mmString.Empty(Message))
>	{
>		MessageBox.Show(Message);
>		e.Cancel = true;
>	}
>}
>
>
>And in VB .NET:
>
>
>Private Sub txtShipName_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
>   Dim BizRule As OrderRules = CType(Me.oOrder.GetBusinessRuleObject(), OrderRules)
>   Dim Message As String = BizRule.ValidateShipName(Me.txtShipName.Text)
>   If Not mmString.Empty(Message) Then
>      MessageBox.Show(Message)
>      e.Cancel = True
>   End If
>End Sub
>
>
>Here's one extra tidbit...if your business rule objects are using "Error Provider" style broken rules, you need to perform an additional check in your rule object method to determine if the rule method was called directly, or via CheckRules. This can be determined by checking if the DataSet property is null:
>
>For example, in C#:
>
>
>public string ValidateShipName(string shipName)
>{
>	string message = null;
>
>	if (shipName == "")
>	{
>		message = "Must specify a ship name";
>		if (this.DataSet != null)
>		{
>			this.AddErrorProviderBrokenRule("ShipName",
>				message);
>		}
>	}
>	return message;
>}
>
>
>And in VB .NET:
>
>
>Public Function ValidateShipName(shipName As String) As String
>   Dim message As String = Nothing
>
>   If shipName = "" Then
>      message = "Must specify a ship name"
>      If Not (Me.DataSet Is Nothing) Then
>         Me.AddErrorProviderBrokenRule("ShipName", message)
>      End If
>   End If
>   Return message
>End Function
>
>
>I've made a change that will come out in the next version of MM .NET that won't require you to perform this additional check, but for now, you need to do it in methods that you are calling directly IF you are using the Error Provider-style broken rule messages.
>
>Regards,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform