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

namespace SigStock
{
    public class Customizer : MercatorUi.ICustomizers.ISigCreated
    {
        public void SigCreated(MercatorUi.Sig.Sig Sig)
        {
            Sig.BeforeSearch += new MercatorUi.Sig.SigClasses.BeforeSearchEventHandler(Sig_BeforeSearch);
        }

        // Laat toe om een opzoeking te doen op
        void Sig_BeforeSearch(object sender, MercatorUi.Sig.SigClasses.BeforeSearchEventArgs e)
        {
            if (e.Key.StartsWith(Api.Chr(20)) && (e.FormContext is MercatorUi.Forms.Billing.BillingForm))
                e.Key = e.Key.Substring(1);

            if (e.OriginalKey.Contains("+"))
            {
                string[] splits = e.OriginalKey.Split('+');
                string desiredWhereClause = "";
                bool first = true;
                foreach (string split in splits)
                {
                    if (!first)
                        desiredWhereClause += " and ";

                    desiredWhereClause += string.Format("(s_modele like '%{0}%')", split);
                    first = false;
                }
                e.DesiredWhereClause = desiredWhereClause;
            }
        }
    }
}