情况如下:
There are 4 controls, two drop downs, two date pickers and some validation rules. One is master drop down
Depending upon the value in master drop down, some validation rule will be applied on the two date pickers and the other drop down control.
This validation rules will trigger if user changes value in any of the four controls.
不可逆转的提供者必须置于所编辑的最后一次控制之下。
我想为每一项验证规则制定一种方法。 a. 组合总法:
Private void ValidateData(Control ctrl)
{
ClearAllErrors();
switch(value value in master dropdown)
case Value 1 : Rule1(ctrl)
case Value 2 : Rule2(ctrl)
....
}
类似做法的规则方法:
Private void Rule1(Control ctrl)
{
//Rule Logic
//Eg. Date in dropdown should between 5 days after the date in dropdown1
//and 3 days before the date in dropdown2.
//Set error provider on the control if rule breaks.
}
现在,在4项控制的任何一项经证实的事件上,我将通过这一控制,称之为瓦利定达(ValidateData)方法。
想法是保持该守则的可维持性。 这种方法能够以任何方式优化,或者有更好的办法处理这类验证。