我正在Winform中实现MVP模式,我的问题是如何定义或实现模型?目前,我认为我什至没有!我有我的视图和演示者,但似乎所有的业务逻辑都在演示者中,而我的实体基本上是POCO或DTO。我要从演示者调用存储库,然后在其中填充实体,然后执行逻辑。我相信我正在努力实现被动MVP。
有人可以为我指出构建模型的正确方向,还是我使用正确,如果我有多个实体,则不需要模型吗?
接口
public interface IMaterialSearchView
{
MaterialGridDTO ReturnMaterial { get; set; }
int CurrentRowIndex { get; }
string FilterUnit { get; set; }
string FilterType { get; set; }
string FilterMaterial { get; set; }
string FilterGrade { get; set; }
string FilterDiameter { get; set; }
string FilterThickness { get; set; }
string FilterWidth { get; set; }
string FilterWallThickness { get; set; }
bool FilterTubing { get; set; }
bool FilterWithRadius { get; set; }
}
public interface IMaterialView : IMaterialSearchView
{
string ID { get; set; }
string Unit { get; set; }
string Type { get; set; }
string Material { get; set; }
string Grade { get; set; }
string MaterialName { get; set; }
string Barcode { get; set; }
string Description { get; set; }
string VendorLength { get; set; }
string VendorColor { get; set; }
string FormStatus { set; }
string Constant { get; set; }
string Diameter { get; set; }
string Thickness { get; set; }
string Width { get; set; }
string WallThickness { get; set; }
bool ReadOnlyDiameter { set; }
bool ReadOnlyThickness { set; }
bool ReadOnlyWidth { set; }
bool VisibleWallThickness { set; }
bool ReadOnlyMaterialName { set; }
bool EnableTubing { set; }
bool EnableWithRadius { set; }
Color FieldColor { get; set; }
bool WithRadius { get; set; }
bool Tubing { get; set; }
bool EnableRemove { set; }
object MaterialList { set; }
object TypeList { set; }
object GradeList { set; }
object MaterialFilterList { set; }
object TypeFilterList { set; }
object GradeFilterList { set; }
List<MaterialGridDTO> MaterialGrid { get; set; }
void InformUser(string message);
bool ExitForm(string message);
}
查看
private MaterialPresenter presenter;
public frmMaterial(OpenMode OpenMode)
{
InitializeComponent();
presenter = new MaterialPresenter(this);
if(OpenMode == OpenMode.SearchOnly) { splitMain.Panel1Collapsed = true; }
}
演示者
public class MaterialPresenter
{
private IMaterialView _view;
public MaterialPresenter(IMaterialView view)
{
_view = view;
}
我在演示者内部使用的实体(很多)之一
public class Materials
{
public string Barcode { get; set; }
public string FullName { get; set; }
public string Material { get; set; }
public string Type { get; set; }
public string Grade { get; set; }
public string Unit { get; set; }
public decimal Diameter { get; set; }
public decimal Thickness { get; set; }
public decimal Width { get; set; }
public decimal WallThickness { get; set; }
public decimal Constant { get; set; }
public bool Tubing { get; set; }
public bool WithRadius { get; set; }
public string Description { get; set; }
public decimal VendorLength { get; set; }
public string VendorColor { get; set; }
public string BarcodeInverse { get; set; }
public string Material_ID { get; set; }
}
我如何使用Entity的一些摘要。我所有的_view链接到界面定义的视图属性
private void FillMaterialList()
{
var materials = MaterialRepo.MaterialList();
_view.MaterialList = materials;
_view.MaterialFilterList = new BindingSource(materials, null);
}
public void OnApplyClick()
{
var material = FillMaterial();
try
{
var exist = MaterialRepo.ExistById(material.Material_ID);
if (exist)
{
MaterialRepo.Update(material);
_view.FormStatus = "Status: Update Successful.";
}
else
{
var id = MaterialRepo.Add(material);
_view.ID = id.ToString();
_view.FormStatus = "Status: Add Successful.";
}
var exit = _view.ExitForm("Material has been successfully Added/Updated \n\n Add/update another?");
if (exit)
{
var line = new MaterialGridDTO
{
Material_ID = _view.ID,
FullName = _view.MaterialName,
Unit = _view.Unit
};
_view.ReturnMaterial = line;
return;
}
}
catch (Exception ex)
{
_view.InformUser(ex.Message);
_view.FormStatus = "Status: Failed...";
}
}