using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;

// <ReferenceInclude>"CustomClassLibrary.dll"</ReferenceInclude>


namespace Main
{
    public class Customizer : MercatorUi.ICustomizers.IInitReport
    {

        private static bool customFunctionsAdded = false; // static : zie commentaar beneden (De geregistreerde objecten zijn statisch)

        public void InitReport(object report) // Het echte report type is FastReport.Report
        {
            FastReport.Report fastReport = (FastReport.Report)report;
            if (!Api.StringArrayContains(fastReport.ReferencedAssemblies, "CustomClassLibrary.dll"))
                fastReport.ReferencedAssemblies = Api.StringArrayAdd(fastReport.ReferencedAssemblies, "CustomClassLibrary.dll");
            if (!customFunctionsAdded) // De geregistreerde objecten zijn statisch -> daarom moet deze code maar 1x uitgevoerd worden per instance van Mercator.
            {
                Type custom = typeof(CustomClassLibrary.Custom);
                FastReport.Utils.RegisteredObjects.AddFunctionCategory("Custom", "Custom");
                //de methode MyMethod1 biedt 2 mogelijkheden: men moet dus de types specifiëren
                FastReport.Utils.RegisteredObjects.AddFunction(custom.GetMethod("MyMethod1", new Type[2] { typeof(int), typeof(int) }), "Custom");
                FastReport.Utils.RegisteredObjects.AddFunction(custom.GetMethod("MyMethod1", new Type[3] { typeof(int), typeof(int), typeof(int) }), "Custom");
                // MyMethod2 biedt maar 1 mogelijkheid-> type moet men dus niet specifiëren
                FastReport.Utils.RegisteredObjects.AddFunction(custom.GetMethod("MyMethod2"), "Custom");
                customFunctionsAdded = true;
            }
        }

    }
}