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

namespace Main
{
    public class Customizer : MercatorUi.ICustomizers.IExec
    {
        public void Main(MercatorUi.ICustomizers.ExecAction Action)
        {
            if (Action == MercatorUi.ICustomizers.ExecAction.DossierOpen)
            {
                System.Windows.Forms.Form form = (System.Windows.Forms.Form)MercatorUi.Globals.StarterMainForm;
                form.FormClosing += new System.Windows.Forms.FormClosingEventHandler(formClosingEventHandler);
            }
            if (Action == MercatorUi.ICustomizers.ExecAction.DossierClose)
            {
                System.Windows.Forms.Form form = (System.Windows.Forms.Form)MercatorUi.Globals.StarterMainForm;
                form.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(formClosingEventHandler);
            }
        }

        void formClosingEventHandler(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            System.Windows.Forms.Form form = (System.Windows.Forms.Form)sender;
            if (Dialogs.AnswerYesNo("Voulez-vous vraiment fermer Mercator ?"))
                form.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(formClosingEventHandler);
            else
                e.Cancel = true;
        }
    }
}