PageEventBase plugin is a part of Uniconta Windows API. It can be found under Uniconta.WindowsAPI.PageEventBase.cs. For performing some work on inserting, updating, deleting, validating, on property change of a record on gridbase page, create a new plugin by extending PageEventBase.cs class and overriding virtual methods described in below code snippet.
//Summary // The abstract class PageEventsBase to be inherited for creating PageEventBase Plugin dll //Summary public abstract class PageEventsBase { public CrudAPI api; public UnicontaBaseEntity master; public object page; //summary // PageEventsBase constructor //summary public PageEventsBase() { } //summary // Variable _LastError //summary protected string _LastError; //summary // The GetLastError method to get last error //summary public string GetLastError { get { var s = _LastError; _LastError = null; return s; } } //summary // The Initialize method to set local variables //summary //Params object page :- to pass the page object //Params CrudAPI api :- to pass the api //Params UnicontaBaseEntity master :- to pass the master public void Initialize(object page, CrudAPI api, UnicontaBaseEntity master) { this.page = page; this.api = api; this.master = master; } //summary // Virtual method Init to initialize values //summary //Params object page :- to pass the page object //Params CrudAPI api :- to pass the api //Params UnicontaBaseEntity master :- to pass the master public virtual void Init(object page, CrudAPI api, UnicontaBaseEntity master) { this.page = page; this.api = api; this.master = master; } //summary // Virtual method Validate, when record is validated //summary //Params UnicontaBaseEntity record :- to pass the record public virtual ErrorCodes Validate(UnicontaBaseEntity record) { return 0; } //summary // Virtual method OnInsert, when record is inserted //summary //Params UnicontaBaseEntity record :- to pass the insterted record public virtual ErrorCodes OnInsert(UnicontaBaseEntity record) { return 0; } //summary // Virtual method OnUpdate, when record is updated //summary //Params UnicontaBaseEntity record :- to pass the updated record //Params UnicontaBaseEntity original :- to pass the original record public virtual ErrorCodes OnUpdate(UnicontaBaseEntity record, UnicontaBaseEntity original) { return 0; } //summary // Virtual method OnDelete, when record is deleted //summary //Params UnicontaBaseEntity record :- to pass the deleted record public virtual ErrorCodes OnDelete(UnicontaBaseEntity record) { return 0; } //summary // Virtual SelectedRowChanged, when selected row of grid is changed //summary public virtual void SelectedRowChanged(SelectedItemChangedArgs e) { } //summary // Virtual event Record_PropertyChanged, when property value is changed //summary public virtual void Record_PropertyChanged(object sender, PropertyChangedEventArgs e) { } //summary // Virtual method OnMenuClickedClicked, when local menu is clicked //summary //Params string ActionType :- to pass the local ribbon menu action type string [Obsolete("Use OnMenuItemClicked function instead. It will be removed in future versions")] public virtual bool OnMenuClickedClicked(string ActionType) { return true; } //summary // Virtual method OnMenuItemClicked, when local menu is clicked //summary //Params string ActionType :- to pass the local ribbon menu action type string //Params object sender :- to pass the local menu ribbon item public virtual bool OnMenuItemClicked(string ActionType, object sender) { return true; } //summary // Virtual method OnMenuItemClicked, when local menu is clicked //summary //Params string ActionType :- to pass the local ribbon menu action type string //Params object sender :- to pass the local menu ribbon item public virtual bool OnMenuItemClicked(string ActionType, object sender, object args) { return true; } //summary // Virtual method PageClosing, when page is closed //summary public virtual void PageClosing() { } //summary // Virtual method CheckMandatoryFields, when madatory fields are validated //summary //Params UnicontaBaseEntity record :- to pass the record public virtual string CheckMandatoryFields(UnicontaBaseEntity record) { return null; } //summary // Trace method, for opening trace window //summary //Params string msg :- to pass message for tracing public void Trace(string msg) { var traceFunction = this.page?.GetType().GetMethod("Trace"); traceFunction?.Invoke(this.page, new object[] { msg }); } //summary // ShowMessageBox method, for showing messagebox //summary //Params string msg :- to pass message //Params string caption :- to pass caption //Returns MessageBoxResult; public MessageBoxResult ShowMessageBox(string msg, string caption) { return MessageBox.Show(msg, caption, MessageBoxButton.OK); } }
Handling menu events
Menu events can be handled on the basis of ActionType
For example: To restrict adding or deleting row on certain conditions, user can handle onMenuItemClicked event like this:
public override bool OnMenuItemClicked(string ActionType, object sender, object arguments) { if (ActionType == "PreAddRow" || ActionType == "PreDeleteRow") return false; return true; }
Installing a PageEventsBase plugin
- Similarly to other plugins, put the .dll file into the C:\Uniconta\PluginPath folder.
- Go to Tools-> Menus-> User Plugin, then add UserPlugin, specify the name of the plugin, select control name on which plugin will work, select PageEventBasePlugin by clicking on ‘+’ button if it is a partner plugin, otherwise just type in the name of the .dll file. Specify the class name inheriting PageEventBase class. Lastly, choose type of plugin to Event