Een kleur kiezen per prospect in de CRM-agenda

0000002696     -      05-02-2018

De customizer hieronder legt uit hoe je door middel van code de kleur kan wijzigen van elementen uit de agenda. In dit geval kan de kleur gedefinieerd worden in de prospectfiche. Indien er geen enkele kleur gedefinieerd is in de prospectfiche, zal de kleur uit het actiemodel gebruikt worden.

De code hieronder toont hoe je de standaardkleur in een prospectfiche instelt.

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;    // Rechthoek met een preview van de kleur
        private DataRow dr = null;
        
        public void FormLoadCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            dr = sigForm.DataSourceRow;
            // Creatie van de 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;
            }
            // Toevoegen van de colorPicker aan de parent-control van het veld 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));
            }
        }
    }
}

 

Vervolgens moet men deze code toevoegen aan de CRM om de gedefinieerde kleur op te halen en toe te passen op de afspraak.

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;
        }
    }
}