Windowsフォームアプリケーションでユーザー入力を検証しようとしています(MVPデザインパターンを使用)。これはMVPを使用した最初のプロジェクトであるため、ユーザー入力検証コードをどこにどのように配置するかが明確ではありません。具体的には、ProductNameとProductPriceの2つのテキストボックスコントロールを含むProductsフォームがあります。
以下は、私のProductForm、IProductView、ProductPresenterのコードです。
IProductView.cs
public interface IProductView
{
string ProductName { get; set; }
int ProductPrice { get; set; }
event EventHandler<EventArgs> Save;
}
frmProduct.cs
public partial class frmProduct : Form,IProductView
{
ProductPresenter pPresenter;
public frmProduct()
{
InitializeComponent();
pPresenter = new ProductPresenter(this);
}
public new string ProductName
{
get
{
return txtName.Text;
}
}
public int ProductPrice
{
get
{
return Convert.ToInt32(txtPrice.Text);
}
}
public event EventHandler<EventArgs> Save;
}
ProductPresenter.cs
public class ProductPresenter
{
private IProductView pView;
public ProductPresenter(IProductView View)
{
this.pView = View;
this.Initialize();
}
private void Initialize()
{
this.pView.Save += new EventHandler<EventArgs>(pView_Save);
void pView_Save(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
ErrorProvider(EP)コントロールを使用したい+多くのフォームでEPコントロールを使用するので、EPコードを何らかのメソッドに入れてコントロールを渡すことで、ほとんどのコードを再利用できればと思います。メッセージ。この検証コードはどこに置くべきですか?
よろしく、