using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;
using MercatorDatabase;
using System.Windows.Forms;

namespace SigStock
{
    public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer
    {
        public void FormLoadCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            MercatorUi.Forms.Sig.SigGrids.Gam gamPrices = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigGrids.Gam>().FirstOrDefault(g => g.GridGameEnum == MercatorUi.Forms.Sig.SigGrids.GridGamEnum.Prices);
            if (gamPrices != null)
                gamPrices.AssociatedPanelCreated += gamPrices_AssociatedPanelCreated;
        }

        public void FormClosedCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            MercatorUi.Forms.Sig.SigGrids.Gam gamPrices = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigGrids.Gam>().FirstOrDefault(g => g.GridGameEnum == MercatorUi.Forms.Sig.SigGrids.GridGamEnum.Prices);
            if (gamPrices != null)
                gamPrices.AssociatedPanelCreated -= gamPrices_AssociatedPanelCreated;
        }

        void gamPrices_AssociatedPanelCreated(object sender, MercatorUi.MovableControls.MovableGrid.AssociatedPanelCreatedEventArgs e)
        {
            MercatorUi.Forms.Sig.SigGrids.GamBottomPanel gamPrices = (MercatorUi.Forms.Sig.SigGrids.GamBottomPanel)e.AssociatedPanel;

            DataTable dt = (DataTable)gamPrices.ComboBoxPrix.DataSource;
            foreach (DataRow dr in dt.Rows)
                dr["dec"] = 4;
        }
    }
}