Le customizer montré ici explique comment intervenir par code sur la création d'éléments (rendez-vous) du calendrier du CRM. Cette programmation exploite l'évènement AddingAppointment de CrmCalendarForm. L'eventArgs de cet événement contient 2 propriétés :
- CrmAppointment Appointment : qui correspond à l'objet qui va être ajouté dans le calendrier
- DataRow DrAction : qui contient l'enregistrement complet de la table ACTIONS pour le rendez-vous qui se crée.
Le code ci-dessous montre comment fixer la valeur du sujet et de la note de ce rendez-vous.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MercatorApi;
using MercatorUi;
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.AddingAppointment += CrmCalendarForm_AddingAppointment;
crmCalendarForm.FormClosed += CrmCalendarForm_FormClosed;
}
}
private void CrmCalendarForm_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
MercatorUi.Forms.Action.CrmCalendarForm crmCalendarForm = (MercatorUi.Forms.Action.CrmCalendarForm)sender;
crmCalendarForm.AddingAppointment -= CrmCalendarForm_AddingAppointment;
crmCalendarForm.FormClosed -= CrmCalendarForm_FormClosed;
}
private void CrmCalendarForm_AddingAppointment(object sender, MercatorUi.Forms.Action.CrmCalendarForm.AddingAppointmentEventArgs e)
{
e.Appointment.Subject = string.Format("{0} - {1}", e.DrAction["objet"], e.DrAction["sig_nom"]);
e.Appointment.Description = e.DrAction["note"].ToString() + "\r\n------------------\r\n" + e.DrAction["lib"].ToString();
}
}
}