MVP example

Here is an MVP example I created for a form. All forms in this little
tutorial project on EF was converted to use MVP.

http://www.vbforums.com/showthread.php?t=540421
The view to the form

using BLL.DTO;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DemoWindowsFormApp.Views
{
public interface IPayRollView : IView
{
List<DTOAuthor> DtoAuthors { get; set; }
ComboBox CbxAuthors { get; set; }
Label LblPayRollId { get; set; }
NumericUpDown NudSalary { get; set; }
}
}
The codebehind for PayrollView form that implements IPayRollView.
The thing that is different between this version of MVP is that I am
using events on the form instead of using events on the Interface that
you will see in the tutorial
The presenter.....

I am using everything you see in that tutorial. But the Service layer is
using a WCF Web service and the BLL and DAL sit behind the WCF service,
as opposed to the tutorial that has UI/Presenter/BLL/Service
Layer/DAL.architecture.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using BLL.DTO;
using DemoWindowsFormApp.Presenters;
using DemoWindowsFormApp.Views;
using Services;

namespace DemoWindowsFormApp
{
public partial class PayRollView : Form, IPayRollView
{
#region Members
private PayRollViewPresenter mPresenter;
#endregion
public PayRollView()
{
mPresenter = new PayRollViewPresenter(this,
TheService1.Instance);
InitializeComponent();
}
public List<DTOAuthor> DtoAuthors { get; set; }
public ComboBox CbxAuthors
{
get { return cbxAuthor; }
set { cbxAuthor = value; }
}
public Label LblPayRollId
{
get { return lblPayRollID; }
set { lblPayRollID = value; }
}
public NumericUpDown NudSalary
{
get { return nudSalary; }
set { nudSalary = value; }
}
private void PayRollView_Load(object sender, EventArgs e)
{
mPresenter.Load();
}
private void cbxAuthor_SelectedIndexChanged(object sender,
EventArgs e)
{
mPresenter.cbxAuthors_SelectedIndexChanged();
}
private void btnAdd_Click(object sender, EventArgs e)
{
mPresenter.btnAddClick();
}
private void btnUpdae_Click(object sender, EventArgs e)
{
mPresenter.btnUpdateClick();
}
private void btnDelete_Click(object sender, EventArgs e)
{
mPresenter.btnUpdateClick();
}
}
}

你可能感兴趣的:(example)