In de CRM-calender een afspraak toevoegen via het context menu

0000002798     -      16-02-2018

Met de hier geïllustreerde customizer kan u snel een nieuwe actie toevoegen aan de CRM-kalender (afspraak). Het biedt de mogelijkheid om de invoer van het actie-model en het informatiebestand (klant, prospect,...) dat aan deze actie moet worden gekoppeld te omzeilen. In de code hieronder zijn er 2 parameters ingesteld als constanten. Het zal eenvoudig zijn om aan te passen voor ander gebruik.

Het is absoluut noodzakelijk om ervoor te zorgen dat het gehanteerde actie-model compatibel is met de kalender. (type_pim=2)

Als u voor het openen van een context-menu een bereik van uren selecteert in de kalender, zal men rekening houden met deze periode om het begin en einde van de actie in te stellen.

De code is als volgt:

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;
using DevComponents.DotNetBar;

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

        public void Main(MercatorUi.ICustomizers.ExecAction Action)
        {
            if (Action == MercatorUi.ICustomizers.ExecAction.DossierOpen)
            {
                Globals.Main.BaseFormCreating += new MercatorUi.Main.BaseFormCreatingEventHandler(Main_BaseFormCreating);
            }
            else if (Action == MercatorUi.ICustomizers.ExecAction.DossierClose)
            {
                Globals.Main.BaseFormCreating -= new MercatorUi.Main.BaseFormCreatingEventHandler(Main_BaseFormCreating);
            }
        }

        void Main_BaseFormCreating(object sender, MercatorUi.Main.BaseFormCreatingEventArgs e)
        {
            if (e.Form is MercatorUi.Forms.Action.CrmCalendarForm)
            {
                MercatorUi.Forms.Action.CrmCalendarForm crmCalendarForm = (MercatorUi.Forms.Action.CrmCalendarForm)e.Form;
                crmCalendarForm.ShowingContextMenu += crmCalendarForm_ShowingContextMenu;
                crmCalendarForm.Disposed += crmCalendarForm_Disposed;
            }
        }

        void crmCalendarForm_Disposed(object sender, EventArgs e)
        {
            MercatorUi.Forms.Action.CrmCalendarForm crmCalendarForm = (MercatorUi.Forms.Action.CrmCalendarForm)sender;
            crmCalendarForm.ShowingContextMenu -= crmCalendarForm_ShowingContextMenu;
            crmCalendarForm.Disposed -= crmCalendarForm_Disposed;
        }

        void crmCalendarForm_ShowingContextMenu(object sender, MercatorUi.Forms.Action.CrmCalendarForm.ShowingContextMenuEventArgs e)
        {
            MercatorUi.Forms.Action.CrmCalendarForm crmCalendarForm = (MercatorUi.Forms.Action.CrmCalendarForm)sender;

            ButtonItem addCustomActionItem = new ButtonItem();
            addCustomActionItem.Text = "Ajouter Action Custom";
            addCustomActionItem.Name = "addCustomActionItem";
            addCustomActionItem.Tag = crmCalendarForm;
            addCustomActionItem.Click += AddCustomActionItem_Click;
            addCustomActionItem.Disposed += addCustomActionItem_Disposed;
            e.ContextMenuItems.Add(addCustomActionItem);
        }

        private void addCustomActionItem_Disposed(object sender, EventArgs e)
        {
            ButtonItem addCustomActionItem = (ButtonItem)sender;
            addCustomActionItem.Disposed -= addCustomActionItem_Disposed;
            addCustomActionItem.Click -= AddCustomActionItem_Click;
        }

        private const string idActTempl = ".A-85FA695"; // ID van ACTTEMPL. Opgelet: TYPE_PIM moet 2 als waarde hebben voor dit actie-model (compatible kalender)
        private const string IdCli = "INEO1     "; // de klant moet bestaan

        private void AddCustomActionItem_Click(object sender, EventArgs e)
        {
            ButtonItem addCustomActionItem = (ButtonItem)sender;
            MercatorUi.Forms.Action.CrmCalendarForm crmCalendarForm = (MercatorUi.Forms.Action.CrmCalendarForm)addCustomActionItem.Tag;
            DateTime startDate = crmCalendarForm.CalendarView.DateSelectionStart.GetValueOrDefault();
            DateTime endDate = crmCalendarForm.CalendarView.DateSelectionEnd.GetValueOrDefault();
            MercatorUi.Engine.Crm.ActionEngine actionEngine = MercatorUi.Engine.Crm.ActionEngine.InitNew(MercatorUi.Sig._SigEnum.CLI, IdCli, idActTempl);
            if (actionEngine.DataSet == null)
                return;
            actionEngine.ActionsRecord.MOMENT_1 = startDate;
            actionEngine.ActionsRecord.MOMENT_2 = endDate;
            actionEngine.CalendarOwnerKey = crmCalendarForm.CalendarView.SelectedOwner;
            MercatorUi.Forms.Action.ActionForm actionFormNew = new MercatorUi.Forms.Action.ActionForm(idActTempl.Substring(1), MercatorUi.Forms.Action.ActionClasses.ActionFormMode.Normal, actionEngine, null);
            actionFormNew.Show(Globals.iw);
        }
    }
}