English 中文(简体)
c 结 论
原标题:c# Validation approach

情况如下:

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)方法。

想法是保持该守则的可维持性。 这种方法能够以任何方式优化,或者有更好的办法处理这类验证。

最佳回答

你的做法没有任何错误。

问题回答

Use a Validator Factory





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签