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

namespace SigCli
{
    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.Actions actions = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigGrids.Actions>().FirstOrDefault();
            if (actions != null)
                actions.Grid.CellFormatted += Actions_CellFormatted;
        }

        public void FormClosedCustomize(Form form)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
            MercatorUi.Forms.Sig.SigGrids.Actions actions = sigForm.MovableControls.Values.OfType<MercatorUi.Forms.Sig.SigGrids.Actions>().FirstOrDefault();
            if (actions != null)
                actions.Grid.CellFormatted -= Actions_CellFormatted;
        }

        private void Actions_CellFormatted(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridView grid = (DataGridView)sender;
            if (Convert.ToDateTime(grid.Rows[e.RowIndex].Cells["date_done"].Value) > new DateTime(1900, 1, 1))
                e.CellStyle.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Italic, GraphicsUnit.Point, 0);
        }
    }
}