Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA Enterprise SCADA

SampleFormPlugin

  • Last UpdatedJul 05, 2024
  • 3 minute read

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Windows.Forms;

using OASySDNA.Common;

using OASySDNA.ADE.ClientForms;

using OASySDNA.ADE.Controls;

namespace OASySDNA.ADE.SamplePlugIns

{

/// <summary>

/// Example form plug in.

/// </summary>

public class SampleFormPlugIn

{

ADEBaseEditForm editForm;

string args;

/// <summary>

/// Constuctor for the example form plug in.

/// This can be used for both TableEditFormPlugIns and RowEditFormPlugIns

/// </summary>

public SampleFormPlugIn()

{

}

/// <summary>

/// A simple plugin that displays the message.

/// This is useful for demoing plugins like CallPlugInOnPopupRowEdit.

/// For example: <RowEditFormPlugIn Name="CallPlugInOnPopupRowEdit" Args="Bit Pattern Input,ShowMessageBox,hello" />

/// </summary>

/// <param name="form">The form the plug in is called for.</param>

/// <param name="argStr">The string from the DBEdit file.</param>

public void ShowMessageBox(Form form, string argStr)

{

MessageBox.Show(argStr);

}

/// <summary>

/// A simple plugin to demonstrate the OverrideButtonEventRowEdit plugin.

/// For example: <RowEditFormPlugIn Name="OverrideButtonEventRowEdit" Args="historical,SampleButtonClick" />

/// </summary>

/// <param name="form">A row edit form</param>

/// <param name="argStr">the name of the button</param>

public void SampleButtonClickRowEdit(Form form, string argStr)

{

ADEEditFormButton btn = ADEBaseEditForm.FindControl(form.Controls, argStr, typeof(ADEEditFormButton)) as ADEEditFormButton;

if (btn == null)

{

DNALog.WriteLog(DNALog.LogLevel.Always, "SampleFormPlugin:SampleButtonClick: could not find button " + argStr);

ADEBaseEditForm.DumpControls(form.Controls, "");

return;

}

args = "Clicked the " + argStr + " button.";

btn.Click += new EventHandler(item_Click);

}

/// <summary>

/// Add a button to the tool bar.

/// </summary>

/// <param name="form">The form the plug in is called for.</param>

/// <param name="argStr">The string from the DBEdit file</param>

public void AddToolbarButton(Form form, string argStr)

{

DNALog.WriteLog(DNALog.LogLevel.Verbose, "SampleFormPlugin:AddToolbarButton " + argStr);

//MessageBox.Show("SampleFormPlugin::AddToolbarButton: ");

editForm = form as ADEBaseEditForm;

this.args = argStr;

// If you do not know the names of the controls, call this and look in the oasErrLog.log

//ADEBaseEditForm.DumpControls(form.Controls, "");

// Add a menu to the tool bar

ToolStrip toolBar = form.Controls["baseToolStrip"] as ToolStrip;

ToolStripItem item;

// Add a new function to the toolbar

item = toolBar.Items.Add("SampleFormPlugIn");

item.Click += new EventHandler(item_Click);

// If you want the plug-in to behave differently if brought up

// under different tree layouts (eg "LMS" or "RealTime") then

// find which one is checked.

/*

string viewMenu = FindADEViewMenu(form);

if (viewMenu != "")

MessageBox.Show("Form brought up from ADE->View->" + viewMenu + " menu checked");

*/

// This is an example on how to modify the data.

/*

TextBox txb = ADEBaseEditForm.FindControl(form.Controls, "name", typeof(TextBox)) as TextBox;

txb.Text = "Name2";

txb.DataBindings[0].WriteValue(); // Write value to the dataset.

*/

// Example on how to remove an event handler.

/*

ADETextBoxButton txbBtn = ADEBaseEditForm.FindControl(form.Controls, "name", typeof(ADETextBoxButton)) as ADETextBoxButton;

editForm.RemoveEventHandler(txbBtn.button, "button_Click", "Click");

*/

}

// Returns the DataTable for the control so you can modify the underlying data.

private DataTable GetDataTable(Control c)

{

Binding b = c.DataBindings[0];

BindingSource bs = b.DataSource as BindingSource;

DataSet dataSet = bs.DataSource as DataSet;

DataTable dt = dataSet.Tables[bs.DataMember];

return dt;

}

// Finds the Menu item that is checked under the ADE->View menu

// and returns the menu item's string (eg Main, RealTime, ACE

//

private string FindADEViewMenu(Form form)

{

ADEBaseEditForm f = form as ADEBaseEditForm;

if (f == null)

{

return "";

}

Form pf = f.callingForm;

if (pf == null)

{

return "";

}

MenuStrip ms = ADEBaseEditForm.FindControl(pf.Controls, "baseMenuStrip", typeof(MenuStrip)) as MenuStrip;

ToolStripMenuItem viewMenu = ms.Items["viewToolStripMenuItem"] as ToolStripMenuItem;

if (viewMenu == null)

{

return "";

}

for (int i = 2; i < viewMenu.DropDown.Items.Count; i++)

{

ToolStripMenuItem mi = viewMenu.DropDown.Items[i] as ToolStripMenuItem;

if (mi != null && mi.Checked)

{

return mi.Text;

}

return "";

}

private void item_Click(object sender, EventArgs e)

{

MessageBox.Show(args);

// Example on how to call the base edit form's event handler.

// editForm.CallEventHandler("CallCustomPopupMethodFromButton", sender, e);

}

}

}

Related Links