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

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

        public void FormLoadCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.Actions));
            if (l.Count == 0)
                return;
            MercatorUi.Forms.Sig.SigGrids.Actions actions = (MercatorUi.Forms.Sig.SigGrids.Actions)l[0];
            actions.Grid.CellFormatted += new DataGridViewCellFormattingEventHandler(actions_CellFormatted);
        }

        public void FormClosedCustomize(Form WindowsForm)
        {
            MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)WindowsForm;
            List<Control> l = sigForm.FindMovableControlsByType(typeof(MercatorUi.Forms.Sig.SigGrids.Actions));
            if (l.Count == 0)
                return;
            MercatorUi.Forms.Sig.SigGrids.Actions actions = (MercatorUi.Forms.Sig.SigGrids.Actions)l[0];
            actions.Grid.CellFormatted -= new DataGridViewCellFormattingEventHandler(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 System.Drawing.Font("Microsoft Sans Serif", 8.25F, FontStyle.Italic, GraphicsUnit.Point, ((byte)(0)));
        }
    }
}