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

Dans l'agenda du CRM, choisir une couleur par prospect

0000002696     -      05/02/2018

Le customizer montré ici explique comment intervenir par code sur la couleur attribuée aux éléments de l'agenda. Dans ce cas précis, la couleur pourra être définie dans la fiche du prospect. Si aucune couleur n'est définie dans la fiche prospect, ce sera celle du modèle d'action qui sera utilisée.

Le code ci-dessous montre comment permettre de fixer une couleur par défaut dans la fiche prospect.

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MercatorUi;
using System.Data;
using MercatorApi;

namespace SigXlead
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer
    {
        private DevComponents.DotNetBar.ColorPickerButton _colorPickerButton = null;
        private Control _controlColorPreview = null;    // Rectangle de preview de couleur
        private DataRow dr = null;
        
        public void FormLoadCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            dr = sigForm.DataSourceRow;
            // Création du control colorPicker
            _colorPickerButton = new DevComponents.DotNetBar.ColorPickerButton();
            _colorPickerButton.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
            _colorPickerButton.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
            _colorPickerButton.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
            _colorPickerButton.Location = new System.Drawing.Point(405, 11);
            _colorPickerButton.Size = new System.Drawing.Size(35, 20);
            _colorPickerButton.SelectedColorImageRectangle = new System.Drawing.Rectangle(2, 2, 12, 12);
            _colorPickerButton.SelectedColorChanged += new EventHandler(ColorPicker_SelectedColorChanged);
            if (sigForm.DataSourceRow["X_COLOR"].ToString() != "")
            {
                _controlColorPreview = sigForm.MovableControls["A098594442"];
                _colorPickerButton.SelectedColor = System.Drawing.ColorTranslator.FromHtml(sigForm.DataSourceRow["X_COLOR"].ToString());
                if (_controlColorPreview != null)
                    _controlColorPreview.BackColor = _colorPickerButton.SelectedColor;
            }
            // Ajout du colorPicker dans le control parent du champ X_NOM
            List<Control> l = sigForm.FindMovableControlsBySource("X_NOM");
            if (l.Count > 0)
                l[0].Parent.Controls.Add(_colorPickerButton);
        }        

        void ColorPicker_SelectedColorChanged(object sender, EventArgs e)
        {
            DevComponents.DotNetBar.ColorPickerButton colorPickerButton = (DevComponents.DotNetBar.ColorPickerButton)sender;
            if (_colorPickerButton != null && _colorPickerButton.SelectedColor.ToString() != "")
            {
                _controlColorPreview.BackColor = _colorPickerButton.SelectedColor;
                Api.SmartReplace(dr, "X_COLOR", ColorTranslator.ToHtml(colorPickerButton.SelectedColor));
            }
        }
    }
}

 

Ensuite, il faut ajouter du code dans le CRM afin de récupérer la couleur définie et l'appliquer au rendez-vous.

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

namespace Crm
{
    public class Customizer : MercatorUi.ICustomizers.IStringUpdater
    {

        public string StringUpdate(string ReqSql)
        {
            string id = Api.StrExtract(ReqSql, "<ID>", "</ID>");
            if (id.StartsWith("CRMCALENDAR"))
            {
                return ReqSql.Replace("as owner,ACTTEMPL.color",
                    "as owner, case "
                    + "when actions.MODULE = 'XLEAD' and actions.ID_SIG != '' and(select X_COLOR from xlead where xlead.X_ID = actions.ID_SIG) != '' "
                    + "then (select X_COLOR from xlead where xlead.X_ID = actions.ID_SIG) "
                    + "else ACTTEMPL.color end as COLOR");
            }
            else
                return ReqSql;
        }
    }
}