MyForm_Presenter


Creating the Presenter

Add a class called "MyForm_Presenter" to the MyForm folder.
Make the following changes to this class.
Change the constructor

public class MyForm_Presenter : 
   MVP.BET_PassiveView<MyForm_Model, MyForm_View>
{
   public bool Property_FormCancelled { get; set; }
   
   //-----------------------------------------------------------------------
   public MyForm_Presenter(MyForm_Model model, MyForm_View view)
   {
          bool showform;

          base.Initialize(model, view);
          showform = model.Method_Initialize();

          this.View.Property_Checkbox = this.Model.Property_Checkbox;
          this.Property_FormCancelled = false;
   
          if (showform == false)
          {
              this.View.Method_Close();
          }
   }
}

Add the following Helper methods

protected override void Method_WireEvents() 
{
   base.View.Method_RegisterChangeRequestListener(
        this.View.GetType().Name,
        new System.EventHandler<MVP.BET_EventArgs<string>>
           (this.Method_OnEvent));
}
//-----------------------------------------------------------------------
protected override void Method_UnwireEvents()
{
   base.View.Method_UnRegisterChangeRequestListener(
        this.View.GetType().Name,
        new System.EventHandler<MVP.BET_EventArgs<string>>
            (this.Method_OnEvent));
}
//-----------------------------------------------------------------------
private void Method_OnEvent(
   object Sender,
   MVP.BET_EventArgs<string> args)
{
       string match = args.RequestedValue.ToString();
       enEvents_MyForm enumValue =
           (enEvents_MyForm)System.Enum.Parse(typeof(enEvents_MyForm), match);

       switch (enumValue)
       {
           case enEvents_MyForm.OK_Click:
               this.Method_Event_OKClick(Sender, args);
               break;

           case enEvents_MyForm.Cancel_Click:
               this.Method_Event_CancelClick(Sender, args);
               break;

           default:
               break;
       }
}
//-----------------------------------------------------------------------
public void Method_Event_CancelClick(object sender, System.EventArgs e)
{
       this.View.Method_Close();
       this.Dispose();
}
//-----------------------------------------------------------------------
public void Method_Event_OKClick(object sender, System.EventArgs e)
{
       this.Model.Property_Checkbox = this.View.Property_Checkbox;
       this.View.Method_Close();
       this.Dispose();
}

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext