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.Gescom.GescomAllowancesFootersForm)
            {
                MercatorUi.Forms.Gescom.GescomAllowancesFootersForm gescomAllowancesFootersForm = (MercatorUi.Forms.Gescom.GescomAllowancesFootersForm)e.Form;
                gescomAllowancesFootersForm.AddingBaremePied += gescomAllowancesFootersForm_AddingBaremePied;
                gescomAllowancesFootersForm.FormClosed += gescomAllowancesFootersForm_FormClosed;
            }
        }

        void gescomAllowancesFootersForm_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
        {
            MercatorUi.Forms.Gescom.GescomAllowancesFootersForm gescomAllowancesFootersForm = (MercatorUi.Forms.Gescom.GescomAllowancesFootersForm)sender;
            gescomAllowancesFootersForm.AddingBaremePied -= gescomAllowancesFootersForm_AddingBaremePied;
            gescomAllowancesFootersForm.FormClosed -= gescomAllowancesFootersForm_FormClosed;
        }

        // l'event AddingBaremePied est appelé lors de l'ajout de chaque ligne dans la liste
        void gescomAllowancesFootersForm_AddingBaremePied(object sender, MercatorUi.Forms.Gescom.GescomAllowancesFootersForm.AddingBaremePiedEventArgs e)
        {
            e.ListViewItem.Text += " "
                + Convert.ToDateTime(e.DataRow["debut"]).ToShortDateString()
                + "-"
                + Convert.ToDateTime(e.DataRow["fin"]).ToShortDateString();
        }

    }
}