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

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

        private System.Drawing.Image imgZoom = MercatorUi._Divers.ImageFromResource("_catch");

        public void FormLoadCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
            MercatorUi.Forms.Sig.SigGrids.UserDefined userDefinedGrid = (MercatorUi.Forms.Sig.SigGrids.UserDefined)sigForm.MovableControls["9739737CA0"];
            userDefinedGrid.Grid.StandardColumnsCreated += new MercatorUi.GridPro.StandardColumnsCreatedHandler(userDefinedGrid_StandardColumnsCreated);
            userDefinedGrid.Grid.CellSuperClick += new MercatorUi.GridPro.CellSuperClickHandler(GridBrouillons_CellSuperClick);
        }

        public void FormClosedCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
            MercatorUi.Forms.Sig.SigGrids.UserDefined userDefinedGrid = (MercatorUi.Forms.Sig.SigGrids.UserDefined)sigForm.MovableControls["9739737CA0"];
            userDefinedGrid.Grid.StandardColumnsCreated -= new MercatorUi.GridPro.StandardColumnsCreatedHandler(userDefinedGrid_StandardColumnsCreated);
            userDefinedGrid.Grid.CellSuperClick -= new MercatorUi.GridPro.CellSuperClickHandler(GridBrouillons_CellSuperClick);
        }

        void userDefinedGrid_StandardColumnsCreated(object sender, EventArgs e)
        {
            MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
            grid.Columns[0].Visible = false; // masquer la colonne TYPE
            grid.Columns[1].Visible = false; // masquer la colonne ID
            grid.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; // colonne PIECE
            ((MercatorUi.GridPro.DataGridViewDoubleTextBoxColumn)grid.Columns[3]).DisplayFormat = "#########";
            MercatorUi.GridPro.DataGridViewHidableButtonXColumn colButtonZoom = new MercatorUi.GridPro.DataGridViewHidableButtonXColumn();
            colButtonZoom.Name = "zoom";
            colButtonZoom.HeaderText = "";
            colButtonZoom.Image = imgZoom;
            colButtonZoom.Width = 34;
            grid.Columns.Add(colButtonZoom);
        }

        void GridBrouillons_CellSuperClick(object sender, DataGridViewCellEventArgs e)
        {
            MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
            MercatorUi.Forms.Sig.SigGrids.UserDefined userDefined = (MercatorUi.Forms.Sig.SigGrids.UserDefined)grid.Parent;
            if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0) && (grid.Columns[e.ColumnIndex].Name == "zoom"))
                MercatorUi.Globals.Main.ShowBillingExisting("V", Convert.ToInt32(grid.Rows[e.RowIndex].Cells[0].Value), grid.Rows[e.RowIndex].Cells[1].Value.ToString(), grid.Rows[e.RowIndex].Cells[2].Value.ToString(), Convert.ToInt64(grid.Rows[e.RowIndex].Cells[3].Value));
        }

    }
}