Environments_View


Creating the View

Add a Windows Form "Environments_View" to the Environments folder.
This will create a partial class that inherits from the System.Forms.Form class.
Display the Toolbox and add two buttons to this form.
Change button1 to have the name "btnOK" with caption "OK".
Change button2 to have the name "btnCancel" with caption "Cancel".
Display the code behind this form.


Add the following code to the MyForm_View.cs file.


Add an Enumeration above the partial class for all the different events.

public enum enEvents_Environments 
{
   WebReferencesAllComboBox_SelectedIndexChanged,
   DataGridView_EditingControlShowing,
   DataGridView_ComboBoxSelectedIndexChanged,
   Apply_Click,
   Cancel_Click
}

Add an Interface under the enumeration called "IMyForm_View".
This defines which members are required.

public interface IEnvironments_View 
{
   string Property_Caption { get; set; }

   System.Windows.Forms.ComboBox Property_WebReferencesAllComboBox { get; set; }
   System.Windows.Forms.DataGridView Property_DataGridView { get; set; }
   System.Windows.Forms.ComboBox Property_DataGridView_ComboBox { get; set; }
   System.Windows.Forms.DataGridViewRow Property_DataGridView_Row { get; set; }
}

Replace the Constructor with the following Partial Class declaration.

public partial class Environments_View : 
   System.Windows.Forms.Form,
   IEnvironments_View
{
   private Barclays.Research.Patterns.MVP.ChangeRequestEvents _changerequestedevents = null;
   private bool _fireEvents = false;

   public System.Windows.Forms.ComboBox Property_DataGridView_ComboBox { get; set; }
   public System.Windows.Forms.DataGridViewRow Property_DataGridView_Row { get; set; }

   //-----------------------------------------------------------------------
   public Environments_View(
      int Center_x,
      int Center_y)
   {
      try
      {
          InitializeComponent();
          this._changerequestedevents = new Barclays.Research.Patterns.MVP.ChangeRequestEvents(this);
          this._fireEvents = true;

          int windowCenter_x;
          int windowCenter_y;

          this._changerequestedevents = new Barclays.Research.Patterns.MVP.ChangeRequestEvents(this);
          this._fireEvents = true;

          windowCenter_x = Center_x - (int)this.Width / 2;
          windowCenter_y = Center_y - (int)this.Height / 2;

          if ((windowCenter_x > 0) && (windowCenter_y > 0))
          {
              this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
              this.Location = new System.Drawing.Point(windowCenter_x, windowCenter_y);
          }
       }
       catch (System.Exception ex)
       {
           BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
       }
    }

    //-----------------------------------------------------------------------
    public void RegisterChangeRequestListener<T>(string PropertyName,
        System.EventHandler<Barclays.Research.Patterns.MVP.PropertyChangeRequestEventArgs<T>> handler)
    {
        this._changerequestedevents.RegisterListener<T>(PropertyName, handler);
    }
    //-----------------------------------------------------------------------
    public void UnRegisterChangeRequestListener<T>(string PropertyName,
        System.EventHandler<Barclays.Research.Patterns.MVP.PropertyChangeRequestEventArgs<T>> handler)
    {
        this._changerequestedevents.UnRegisterListener<T>(PropertyName, handler);
    }
    //-----------------------------------------------------------------------
    public void FireChangeRequest(string PropertyName, string requestedValue)
    {
        if (this._changerequestedevents != null)
        {
            this._changerequestedevents.Fire(PropertyName, requestedValue);
        }
    }

Add the following properties

    public string Property_Caption 
    {
        get { return this.Text; }
        set { this.Text = value; }
    }
    //-----------------------------------------------------------------------
    public System.Windows.Forms.ComboBox Property_WebReferencesAllComboBox
    {
        get { return this.cboWebReferencesAll; }
        set { this.cboWebReferencesAll = value; }
    }
    //-----------------------------------------------------------------------
    public System.Windows.Forms.DataGridView Property_DataGridView
    {
        get { return this.dgvEnvironments; }
        set { this.dgvEnvironments = value; }
    }


    private void cboWebReferencesAll_SelectedIndexChanged(object sender, System.EventArgs e) 
    {
       try
       {
          if ((this._changerequestedevents != null) && (this._fireEvents == true))
          {
              this._changerequestedevents.Fire<string>(this.GetType().Name,
                  enEvents_Environments.WebReferencesAllComboBox_SelectedIndexChanged.ToString());
          }
       }
       catch (System.Exception ex)
       {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
       }
    }
    //-----------------------------------------------------------------------
    private void dgvEnvironments_EditingControlShowing(object sender, System.Windows.Forms.DataGridViewEditingControlShowingEventArgs e)
    {
       try
       {
          if ((this._changerequestedevents != null) && (this._fireEvents == true))
          {
             this.Property_DataGridView_ComboBox = e.Control as System.Windows.Forms.ComboBox;

             this._changerequestedevents.Fire<string>(this.GetType().Name,
                 enEvents_Environments.DataGridView_EditingControlShowing.ToString());
          }
       }
       catch (System.Exception ex)
       {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
       }
    }
    //-----------------------------------------------------------------------
    private void dgvEnvironments_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
    {
       try
       {
          if ((this._changerequestedevents != null) && (this._fireEvents == true))
          {
             this.Property_DataGridView_Row = this.Property_DataGridView.Rows[e.RowIndex];
          }
       }
       catch (System.Exception ex)
       {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
       }
    }
    //-----------------------------------------------------------------------
    private void btnCancel_Click(object sender, System.EventArgs e)
    {
        try
        {
           if ((this._changerequestedevents != null) && (this._fireEvents == true))
           {
               this._changerequestedevents.Fire<string>(this.GetType().Name,
                   enEvents_Environments.Cancel_Click.ToString());
           }
        }
        catch (System.Exception ex)
        {
           BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
        }
    }
    //-----------------------------------------------------------------------
    private void btnApply_Click(object sender, System.EventArgs e)
    {
       try
       {
          if ((this._changerequestedevents != null) && (this._fireEvents == true))
          {
             this._changerequestedevents.Fire<string>(this.GetType().Name,
                 enEvents_Environments.Apply_Click.ToString());
          }
       }
       catch (System.Exception ex)
       {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
       }
    }
}


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