Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling Validation when leaving controls in web form
Message
De
09/09/2010 08:40:45
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
09/09/2010 08:31:42
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01479579
Message ID:
01480666
Vues:
50
Hi Frank,

VFP to dot net is a different way of thinking but I believe you are doing just fine. Keep going.
Tim

>OK, thanks. I'll try it that way. At times I feel like I am not conforming to the MM.NET way as what I think is pretty standard/simple (at least in my VFP framework) just doesn't work in MM.NET.
>
>Thanks again
>
>>Frank,
>>
>>The answer depends on if you will use the validation during the save as well. If so then I would do it the way I mentioned and I will paste in below. If this validation will not be used during the save ever, then I would just put this code in your business object and change the name to something other than Validate. Maybe VerifySumAssuredMaxMin() that way it isn't confused with the pre save validation. Just a thought.
>>
>>If you will use the Validation on save and I presume you would then I would do this.
>>
>>
>>In your business object
>>public string ValidateSumAssuredMaxMin(Guid? planPK, decimal? sumAssured)
>>{
>>       // Get the Plan for the specified PlanPK
>>	this.GetPlanByPlanPK((Guid)planPK);
>>
>>	// Call the validate method in the Rules object
>>	return this.Rules.ValidateSumAssuredMaxMin(this.Entity.MinSumAssured, this.Entity.MaxSumAssured, sumAssured);
>>
>>}
>>
>>
>>Then in your Rules and can still be called from the CheckRulesHook method before a save.
>>
>>public string ValidateSumAssuredMaxMin(decimal minSumAssured, decimal maxSumAssured, decimal sumAssured)
>>{
>>	string message = null;
>>
>>	if (minSumAssured > sumAssured || maxSumAssured < sumAssured)
>>	{
>>		message = "Rider Sum Assured must be between " + minSumAssured.ToString() +
>>			" and " + maxSumAssured.ToString();
>>
>>		this.AddErrorProviderBrokenRule("SumAssured", message);
>>	}
>>	return message;
>>
>>}
>>
>>
>>
>>>>Hi Frank,
>>>>
>>>>>Here's the code:
>>>>>
>>>>>
        public string ValidateSumAssuredMaxMin(Guid? planPK, decimal? sumAssured)
>>>>>        {
>>>>>            string message = null;
>>>>>                Plan oPlan = new Plan();
>>>>>                oPlan.GetPlanByPlanPK((Guid)planPK);
>>>>>                // check that the sum assured meets the min and max sum assured requirements
>>>>>                if (oPlan.Entity.MinSumAssured > (decimal)sumAssured
>>>>>                        || oPlan.Entity.MaxSumAssured < (decimal)sumAssured)
>>>>>                {
>>>>>                    message = "Rider Sum Assured must be between " + oPlan.Entity.MinSumAssured.ToString() + " and " + oPlan.Entity.MaxSumAssured.ToString();
>>>>>                    this.AddErrorProviderBrokenRule("SumAssured", message);
>>>>>                }
>>>>>            return message;
>>>>>        }
>>>>>
>>>>>This is called from a textbox that is in a grid displaying/editing the child business object.
>>>>
>>>>This is a bit of an odd answer, so bear with me. The business rules object is normally accessed via the business object and in this case you are accessing the rules object this way but then in the rules object you are creating a new business object. I did not trace through this to see what happens, but I would recommend a different approach. Maybe this.
>>>>
>>>>Put a method in your business object that you call instead of your rules object that can begin the validation process. What that method would do is GetPlanByPlanPK and then once the record is retrieved, let that method call the rules.ValidateSumAssuredMaxMin method. I would take the code out of the validate method which creates a business object and retrieves data.
>>>>
>>>>I hope that made sense, and let me know how that turns out.
>>>>Tim
>>>
>>>Tim,
>>>
>>>if I am doing something out of the ordinary I would prefer to do it the recommended way. So rather than trying it your suggested way, what would be the normal way to validate a field based on another field? In this case can I assume the Min and MaxSumassured are available without having to get them by creating a new BO?
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform