Vous consultez une page technique concernant le logiciel de gestion Mercator. Celle-ci contient des informations spécifiques destinées aux professionnels de Mercator. Souhaitez-vous être redirigés vers des informations plus générales ?


   Ne plus poser cette question

Ajouter une colonne dans l'objet ActionTree d'un signalétique

0000002620     -      29/03/2016

Le paramétrage effectué ici montre comment ajouter une colonne (actions.contact) dans l'objet ActionTree du signalétique clients. S'agissant d'une vue en arbre, le processus est quelque peu différent par rapport à l'ajout d'une colonne dans une DataGridView.

Dans un premier temps, le customizer SigCli va implémenter l'interface MercatorUi.ICustomizers.IStringUpdater, qui va permettre de modifier 2 requêtes SQL :

  • la requête permettant de lister les noeuds parents. Elle est reconnue par un id = SIG_ACTIONSTREE_PARENTS_CLI
  • la requête permettant de lister les noeuds enfants d'un parent. Elle est reconnue par un id = SIG_ACTIONSTREE_CHILDS_CLI

(Dans ces ID, CLI doit être remplacé par le signalétique concerné).

Dans un second temps, il faut souscrire à l'évènement AddingNode défini dans la classe MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl. Pour atteindre l'instance de cette classe, il faut utiliser l'arborescence suivante : MercatorUi.Forms.Sig.SigObjects.ActionsTree défini en tant qu'objet dans la SigForm, contient le MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl, lui-même contenant un contrôle Tree

Lors de l'ajout de chaque noeud dans le Tree, l'évènement AddingNode est levé dans l'ActionsTreeControl. L'eventArgs permet notamment de connaître :

  • e.Node : le noeud qui vient d'être ajouté
  • e.Node.Dr : la DataRow associée à ce noeud
  • e.NodeType : le type Parent ou Enfant
Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MercatorUi;
using MercatorApi;
using System.Data;


namespace SigCli
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer,
                              MercatorUi.ICustomizers.IStringUpdater
    {
        string MercatorUi.ICustomizers.IStringUpdater.StringUpdate(string StringToModify)
        {
            string id = Api.StrExtract(StringToModify, "/*<ID>", "</ID>*/");
            if (id == "SIG_ACTIONSTREE_PARENTS_CLI") // requête pour le niveau "parent"
            {
                StringToModify = StringToModify.Replace("actions.users,", "actions.users,actions.contact,");
            }
            else if (id == "SIG_ACTIONSTREE_CHILDS_CLI") // requête pour le niveau "enfant"
            {
                StringToModify = StringToModify.Replace("actions.users,", "actions.users,actions.contact,");
            }
            return StringToModify;
        }

        public void FormLoadCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
                actionTree.ActionsTreeControl.AddingNode += new MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventHandler(ActionsTreeControl_AddingNode);
            }
        }

        public void FormClosedCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigObjects.ActionsTree));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigObjects.ActionsTree actionTree = (MercatorUi.Forms.Sig.SigObjects.ActionsTree)l[0];
                actionTree.ActionsTreeControl.AddingNode -= new MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventHandler(ActionsTreeControl_AddingNode);
            }
        }

        void ActionsTreeControl_AddingNode(object sender, MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.AddingNodeEventArgs e)
        {
            MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl actionsTreeControl = (MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl)sender;
            if (actionsTreeControl.Tree.Columns.Count == 7) // 7 = le nombre de colonnes en standard - ce code ne sera exécuté qu'une seule fois -> on ajoute la colonne dans la collection Columns du Tree
            {
                DevComponents.AdvTree.ColumnHeader colContact = new DevComponents.AdvTree.ColumnHeader(_Divers.Iif_langue(Globals.Langue, "Contact", "Contactpersoon", "Contact"));
                colContact.SortingEnabled = false;
                colContact.Width.Absolute = 200;
                actionsTreeControl.Tree.Columns.Add(colContact);
            }
            _Divers.AddCellsToNode(e.Node, 1); // comme on a ajouté une colonne, il faut ajouter une Cell à chaque noeud
            e.Node.Cells[7].Text = e.Node.Dr["contact"].ToString();
            if (e.NodeType == MercatorUi.Forms.Sig.SigClasses.ActionsTreeControl.NodeEnum.Parent)
                e.Node.Cells[7].Text = "Parent=" + e.Node.Dr["contact"].ToString();
            else
                e.Node.Cells[7].Text = "Enfant=" + e.Node.Dr["contact"].ToString();
        }
    }
}