Environments_Presenter


Creating the Presenter

Add a class called "Environments_Presenter" to the Environment folder.

public class Environments_Presenter : 
   MVP.BET_PassiveView<Forms.Environments_Model, Forms.Environments_View>
{
   public bool Property_FormCancelled { get; set; }

   public Environments_Presenter(Forms.Environments_Model myModel,
                                 Forms.Environments_View myView)
   {
      try
      {
         base.Initialize(myModel, myView);

         this.Property_FormCancelled = false;

         this.Method_DataGridView_Define(this.View.Property_DataGridView, true, false, false, false, System.Windows.Forms.ScrollBars.Vertical);
         this.Method_DataGridView_ColumnTextBoxAdd(this.View.Property_DataGridView, 0, "Service", 190);
         this.Method_DataGridView_ColumnComboBoxAdd(this.View.Property_DataGridView, 1, "Pointing At", 110);
         this.Method_DataGridView_ColumnTextBoxAdd(this.View.Property_DataGridView, 2, "URL", 420, true, "", true, "Window", true);

         this.View.Property_WebReferencesAllComboBox.Items.Add("PRODUCTION");
         this.View.Property_WebReferencesAllComboBox.Items.Add("TESTING");

         BET_WebService webservice;
         System.Windows.Forms.DataGridViewRow datagridviewrow;
         System.Windows.Forms.DataGridViewComboCellBoxCell datagridviewcomboboxcell;

         for (int icount = 0; icount < this.Model_Property_CoreObjects.Property_WebServicesHub.Property_ServicesList.Count; icount++)
         {
            webservice = this.Model.Property_CoreObjects.Property_WebServicesHub.Property_ServicesList[icount];
            webservice.Property_EnvironmentList.Sort();

            string[] environments = new string[webservice.Property_EnvironmentsList.Count];
            webservice.Property_EnvironmentList.CopyTo(environments);

            this.View.Property_DataGridView.Rows.Add();
            datagridviewrow = this.View.Property_DataGridView.Rows[this.View.Property_DataGridView.Rows.Count - 1];
            datagridviewrow.Cells[0].Value = webservice.Property_ServiceName;
            datagridviewcomboboxcell = datagridviewrow.Cells[1] as System.Windows.Forms.DataGridViewComboBoxCell;
            datagridviewcomboboxcell.Items.AddRange(environments);

            datagridviewrow.Cells[1].Value = webservice.Property_Environment.ToString();
            datagridviewrow.Cells[2].Value = webservice.Property_ServiceAddress.ToString();
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   protected override void SetViewState()
   {
   }
   //-----------------------------------------------------------------------
   protected override void WireEvents()
   {
      base._view.RegisterChangeRequestListener(this.View.GetType().Name,
         new System.EventHandler<MVP.PropertyChangeRequestEventArgs<string>(this.Method_OnEvent));
   }
   //-----------------------------------------------------------------------
   protected override void UnwireEvents()
   {
      base._view.UnRegisterChangeRequestListener(this.View.GetType().Name,
         new System.EventHandler<MVP.PropertyChangeRequestEventArgs<string>(this.Method_OnEvent));
   }
   //-----------------------------------------------------------------------
   private void Method_OnEvent(
      object Sender,
      MVP.PropertyChangeRequestEventArgs<string> Args)
   {
      try
      {
         string match = Args.RequestedValue.ToString();
         enEvents_Environments enumvalue = (enEvents_Environments)System.Enum.Parse(typeof(enEvents_Environments), match);

         switch (enumValue)
         {
            case enEvents_Environments.WebReferencesAllComboBox_SelectedIndexChanged:
               this.Method_Event_WebReferencesAllComboBox_SelectedIndexChanged(Sender, Args)
               break;

            case enEvents_Environments.DataGridView_EditingControlShowing:
               this.Method_Event_DataGridView_EditingControlShowing(Sender, Args)
               break;

            case enEvents_Environments.Apply_Click
               this.Method_Event_ApplyClick(Sender, Args)
               break;

            case enEvents_Environments.Cancel_Click
               this.Method_Event_CancelClick(Sender, Args)
               break;

            default:
               break;
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_Event_WebReferencesAllComboBox_SelectedIndexChanged(
      object Sender,
      System.EventArgs Args)
   {
      try
      {
         GlobalEnumerations.en_SERVICE_ENVIRON_TYPE enumEnvironment;
         string snewurl = "";
        
         for (int irowno = 0; irowno < this.View.Property_DataGridView.Rows.Count; irowno++)
         {
             this.View.Property_DataGridView.Rows[irowno].Cells[1].Value = this.View.Property_WebReferencesAllComboBox.Text;

             string senvironment = this.View.Property_DataGridView.Rows[irowno].Cells[1].Value.ToString()
             enumEnvironment = this.Model.Method_GetServiceEnvironment(senvironment);

             string surl = this.View.Property_DataGridView.Rows[irowno].Cells[0].Value.ToString().ToLower();
             snewurl = this.Model.Method_GetServiceURL(surl, enumEnvironment);
             this.View.Property_DataGridView.Rows[irowno].Cells[2].Value = snewurl;
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_Event_DataGridView_EditingControlShowing(
      object Sender,
      System.EventArgs Args)
   {
      try
      {
         System.Windows.Forms.ComboBox combobox

         if (this.View.Property_DataGridView.CurrentCell.ColumnIndex == 1)
         {
            combobox = this.View.Property_DataGridView_ComboBox;

            combobox.SelectionChangeCommitted -= Method_DataGridView_ComboBox_SelectedIndexChanged;
            combobox.SelectionChangeCommitted += Method_DataGridView_ComboBox_SelectedIndexChanged;
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   private void Method_DataGridView_ComboBox_SelectedIndexChanged(
      object Sender,
      System.EventArgs Args)
   {
      try
      {
         GlobalEnumerations.en_SERVICE_ENVIRON_TYPE enumEnvironment;
         string snewurl;

         this.View.Property_DataGridView_Row.Cells[1].Value = this.View.Property_DataGridView_ComboBox.Text;

         string senvironment = this.View.Property_DataGridView_Row.Cells[1].value.ToString();
         enumEnvironment = this.Model.Method_GetServiceEnvironment(senvironment);

         string surl = this.View.Property_DataGridView_Row.Cells[0].Value.ToString().ToLower()
         snewurl = this.Model.Method_GetServiceURL(surl, enumEnvironment);
         this.View.Property_DataGridView_Row.Cells[2].Value = snewurl;
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_Event_CancelClick(
      object Sender,
      System.EventArgs Args)
   {
      try
      {
         this.View.Dispose();
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_Event_ApplyClick(
      object Sender,
      System.EventArgs Args)
   {
      try
      {
         System.Collections.Generic.Dictionary<string, BET_ServiceInfo> oServiceInfo_Dict;
         oServiceInfo_Dict = new System.Collections.Generic.Dictionary<string, BET_ServiceInfo>();

         for (int irowno = 0; irowno < this.View.Property_DataGridView.Rows.Count; irowno++)
         {
            BET_ServiceInfo serviceinfo = new BET_ServiceInfo();
            serviceinfo.Property_ServiceName = this.View.Property_DataGridView_Row[irowno].Cells[0].value.ToString();

            BET_WebService webservice;
            webservice = this.Model.Property_CoreObjects.Property_WebServicesHub.Method_GetService(serviceinfo.Property_ServiceName);

            string senviroment = this.View.Property_DataGridView.Rows[irowno].Cells[1].Value.ToString();
            webservice.Property_Environment = this.Model.Method_GetServiceEnvironment(senvironment);
         }
         this.View.Dispose();
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_DataGridView_Define(
      System.Windows.Forms.DataGridView oDataGridView,
      bool bColumnHeadersVisible = true,
      bool bFullRowSelect = false,
      bool bMultiSelect = false,
      bool bShowCellToolTips = false,
      System.Windows.Forms.ScrollBars objScrollBars = System.Windows.Forms.ScrollBars.None)
   {
      try
      {
         oDataGridView.AllowUserToAddRows = false;
         oDataGridView.AllowUserToDeleteRows = false;
         oDataGridView.AllowUserToOrderColumns = false;
         oDataGridView.AllowUserToResizeColumns = false;
         oDataGridView.AllowUserToResizeRows = false;
         oDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.None;
         oDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
         oDataGridView.ColumnHeadersVisible = bColumnHeadersVisible;
         oDataGridView.MultiSelect = bMultiSelect;
         oDataGridView.RowHeadersVisible = false;

         if (bFullRowSelect == true)
         {
            oDataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            oDataGridView.ScrollBars = objScrollBars;
            oDataGridView.ShowCellToolTips = bShowCellToolTips;
            oDataGridView.ShowEditingIcon = false;
            oDataGridView.StandardTab = true;
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_DataGridView_ColumnTextBoxAdd(
      System.Windows.Forms.DataGridView oDataGridView,
      int iColumnDisplayIndex,
      string sColumnName,
      int iColumnWidth,
      bool bVisible = true,
      string sColumnHeaderText = "",
      bool bColumnReadOnly = true,
      string sBackgroundColor = "Window",
      bool bAutoFill = false,
      bool bSortedColumn = false,
      string sLeftOrRightAlign = "LEFT")
   {
      try
      {
         System.Windows.Forms.DataGridViewTextBoxColumn datagridviewtextboxcolumn;
         System.Windows.Forms.DataGridViewCell datagridviewcell;
         System.Windows.Forms.DataGridViewCellStyle datagridviewcellstyle;

         datagridviewcellstyle = new System.Windows.Forms.DataGridViewCellStyle();
         datagridviewcellstyle.NullValue = null;
         if (sBackgroundColor == "Control")
         {
            datagridviewcellstyle.BackColor = System.Drawing.Color.FromName("Control");
         }

         datagridviewcell = new System.Windows.Forms.DataGridViewTextBoxCell();
         datagridviewcell.Style = objdatagridviewcellstyle;

         datagridviewtextboxcolumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
         datagridviewtextboxcolumn.Name = sColumnName;
         if (sColumnHeaderText.Length == 0)
         {
            datagridviewtextboxcolumn.HeaderText = sColumnName;
         }
         if (sColumnHeaderText.Length > 0)
         {
            datagridviewtextboxcolumn.HeaderText = sColumnHeaderText;
         }
         datagridviewtextboxcolumn.DataPropertyName = sColumnName;
         datagridviewtextboxcolumn.DisplayIndex = iColumnDisplayIndex;
         datagridviewtextboxcolumn.ReadOnly = bColumnReadOnly;
         datagridviewtextboxcolumn.Visible = bVisible;
         datagridviewtextboxcolumn.CellTemplate = datagridviewcell;

         if (sLeftOrRightAlign == "RIGHT")
         {
            datagridviewtextboxcolumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            datagridviewtextboxcolumn.HeaderCell.Style.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            datagridviewtextboxcolumn.DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
         }
         if (bAutoFill == true)
         {
            datagridviewtextboxcolumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
         }

         datagridviewtextboxcolumn.Width = iColumnWidth;

         oDataGridView.Columns.Add(datagridviewtextboxcolumn);

         if (bSortedColumn == true)
         {
            oDataGridView.Sort(objDataGridView.Columns[oDataGridView.Columns.Count - 1],
                System.ComponentModel.ListSortDirection.Ascending);
         }
      }
      catch (System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
   //-----------------------------------------------------------------------
   public void Method_DataGridView_ColumnComboBoxAdd(
      System.Windows.Forms.DataGridView oDataGridView,
      int iColumnDisplayIndex,
      string sColumnName,
      int iColumnWidth,
      int iColumnMaxDropDownItems = 10)
   {
      try
      {
         System.Windows.Forms.DataGridViewComboBoxColumn datagridcomboboxcolumn;
         datagridcomboboxcolumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
         datagridcomboboxcolumn.Name = sColumnName;
         datagridcomboboxcolumn.Width = iColumnWidth;
         datagridcomboboxcolumn.DisplayIndex = iColumnDisplayIndex;
         datagridcomboboxcolumn.DropDownWidth = iColumnWidth;
         datagridcomboboxcolumn.MaxDropDownItems = iColumnMaxDropDownItems;
         datagridcomboboxcolumn.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
         oDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
         oDataGridView.Columns.Add(objdatagridcomboboxcolumn);
      }
      catch (System.Exception ex)
      {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }
}


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