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

namespace SigCli
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer,
                              MercatorUi.ICustomizers.IFormClosedCustomizer
    {

        public void FormLoadCustomize(System.Windows.Forms.Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.Contacts));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigGrids.Contacts contacts = (MercatorUi.Forms.Sig.SigGrids.Contacts)l[0];
                contacts.AssociatedPanelCreated += new MercatorUi.MovableControls.MovableGrid.AssociatedPanelCreatedHandler(contacts_AssociatedPanelCreated); //
            }
        }

        public void FormClosedCustomize(System.Windows.Forms.Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;

            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.Contacts));
            if (l.Count > 0)
            {
                MercatorUi.Forms.Sig.SigGrids.Contacts contacts = (MercatorUi.Forms.Sig.SigGrids.Contacts)l[0];
                contacts.AssociatedPanelCreated -= new MercatorUi.MovableControls.MovableGrid.AssociatedPanelCreatedHandler(contacts_AssociatedPanelCreated); //
            }
        }
        
        private void contacts_AssociatedPanelCreated(object sender, MercatorUi.MovableControls.MovableGrid.AssociatedPanelCreatedEventArgs e)
        {
            foreach (Control c in e.AssociatedPanel.Controls)
                if (c.Name == "buttonXDelete")
                {
                    c.Visible = false;
                    c.Enabled = false;
                }
        }
    }
}