C# Uniconta Page Events

Date: 2021-03-22

https://www.uniconta.com/developers-unipedia-global/develop-a-pageeventbase-plugin/

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

Or as a Event plugin script:

Menus > User-Plugin > Plugin-Type Event > Edit Script

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using Uniconta.API.Project;
using Uniconta.API.System;
using Uniconta.ClientTools.DataModel;
using Uniconta.Common;
using Uniconta.DataModel;

namespace Uniconta.API.Plugin {
    public class CustomPageEvents : PageEventsBase {
        public CustomPageEvents () : base () { }
        public override void Init (object page, CrudAPI api, UnicontaBaseEntity master) {
            base.Init (page, api, master);
        }
        public void Message (string message, string title) {
            var fn = this.GetType ().GetMethod ("ShowMessageBox");
            if (fn != null) fn.Invoke (this, new object[] { message, title });
        }
        public void ShowOrderConfirmation (DebtorOrderClient dbOrder, CompanyLayoutType doctype) {
            var assembly = Assembly.Load ("UnicontaPages");
            if (assembly == null) Message ("Assembly == null", "Error");
            var DebtorOrders = assembly.GetType ("UnicontaClient.Pages.DebtorOrders");
            if (DebtorOrders == null) Message ("DebtorOrders == null", "Error");
            var debtorOrdersPage = Activator.CreateInstance (DebtorOrders, new object[] { api });
            if (debtorOrdersPage == null) Message ("page == null", "Error");
            var fn = debtorOrdersPage.GetType ().GetMethod ("OrderConfirmation", BindingFlags.NonPublic | BindingFlags.Instance);
            if (fn == null) Message ("OrderConfirmation == null", "Error");
            if (fn != null) {
                fn.Invoke (debtorOrdersPage, new object[] { dbOrder, doctype });
            }
        }
        public override ErrorCodes OnUpdate (UnicontaBaseEntity record, UnicontaBaseEntity original) {
            if (record is DebtorOrderClient && original is DebtorOrderClient) {
                var c = (DebtorOrderClient) record;
                var o = (DebtorOrderClient) original;
                if (c.DeliveryDate != o.DeliveryDate) {
                    ShowOrderConfirmation (c, CompanyLayoutType.OrderConfirmation);
                }
            }
            return 0;
        }
		
		// public override ErrorCodes Validate (UnicontaBaseEntity record) { return 0; }
        // public override ErrorCodes OnInsert (UnicontaBaseEntity record) { return 0; }
        // public override ErrorCodes OnDelete (UnicontaBaseEntity record) { return 0; }
        // public override void Record_PropertyChanged (object sender, PropertyChangedEventArgs e) { }
        // public override bool OnMenuItemClicked (string ActionType, object sender) { return true; }
        // public override void PageClosing () { }
        // public override string CheckMandatoryFields (UnicontaBaseEntity record) { return null; }
        // public override void SetUserParm (string UserParm) { }
        // public override IEnumerable<PropValuePair> SearchFilter (IEnumerable<PropValuePair> appliedFilters) { return appliedFilters; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using Uniconta.API.System;
using Uniconta.Common;
using Uniconta.DataModel;
using Uniconta.ClientTools.DataModel;
using Uniconta.ClientTools.Page;

namespace Uniconta.API.Plugin {
    public class NumberSerieSetter  : PageEventsBase {
        public NumberSerieSetter() : base() {}
        public override void Init (object page, CrudAPI api, UnicontaBaseEntity master) {
            base.Init (page, api, master);
            //this.Message("Plugin: initialized " + master.GetType().FullName, "MyPlugin");
            SetCode((page as FormBasePage).ModifiedRow);
        }

        public void Message (string message, string title) {
            var fn = this.GetType().GetMethod("ShowMessageBox");
            if (fn != null) fn.Invoke (this, new object[] { message, title });
        }

        public void SetCode(UnicontaBaseEntity record) {
            if (record is WorkInstallationClient) {
                var c = (WorkInstallationClient)record;
                if (!string.IsNullOrWhiteSpace(c.Code)) return;
                
                var numberSerieAPI = new NumberSerieAPI(this.api);
                var numberSerie = ClientHelper.GetRefClient<NumberSerieClient>(this.api.CompanyId, typeof(NumberSerie), "ADRESSEN");
                var newNumber = numberSerieAPI.GetNewNumber("ADRESSEN");
                c.Code = numberSerie.Prefix + newNumber.Result.ToString();
            }
        }
		
        public override ErrorCodes OnInsert(UnicontaBaseEntity record) { return 0; }
        public override ErrorCodes OnUpdate(UnicontaBaseEntity record, UnicontaBaseEntity original) { return 0; }
        public override ErrorCodes OnDelete(UnicontaBaseEntity record) { return 0; }
        public override ErrorCodes Validate(UnicontaBaseEntity record) { return 0; }
        public override void Record_PropertyChanged(object sender, PropertyChangedEventArgs e) { }
        public override bool OnMenuItemClicked(string ActionType, object sender) { return true; }
        public override void PageClosing() { }
        public override string CheckMandatoryFields(UnicontaBaseEntity record) { return null; }
        public override void SetUserParm(string UserParm) {}
        public override IEnumerable<PropValuePair> SearchFilter(IEnumerable<PropValuePair> appliedFilters) { return appliedFilters; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Uniconta.API.System;
using Uniconta.Common;
using Uniconta.DataModel;
using Uniconta.ClientTools.DataModel;

namespace Uniconta.API.Plugin
{
    public AfleveradresNummering  : PageEventsBase
    {
        public AfleveradresNummering() : base() {}
        public override void Init(object page, CrudAPI api, UnicontaBaseEntity master) {}
        public override ErrorCodes Validate(UnicontaBaseEntity record) { return 0; }
		
        public override ErrorCodes OnInsert(UnicontaBaseEntity record) 
		{
			var c = (WorkInstallationClient)record;
			var numberSerieAPI = new NumberSerieAPI(this.api);
			var MyNumber = numberSerieAPI.GetNewNumber("BATCH");
			c.Number = MyNumber.Result.ToString();
			return 0; 
		}
		
        public override ErrorCodes OnUpdate(UnicontaBaseEntity record, UnicontaBaseEntity original) { return 0; }
        public override ErrorCodes OnDelete(UnicontaBaseEntity record) { return 0; }
        public override void Record_PropertyChanged(object sender, PropertyChangedEventArgs e) { }
        public override bool OnMenuItemClicked(string ActionType, object sender) { return true; }
        public override void PageClosing() {// this.ShowMessageBox("Page Closing", "Information"); }
        public override string CheckMandatoryFields(UnicontaBaseEntity record) { return null; }
        public override void SetUserParm(string UserParm) {}
        public override IEnumerable<PropValuePair> SearchFilter(IEnumerable<PropValuePair> appliedFilters) { return appliedFilters; }
    }
}
47350cookie-checkC# Uniconta Page Events