//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "TAlarconBusc1.h"
#include "TAlarcon.h"
//---------------------------------------------------------------------
#pragma link "Grids"
#pragma resource "*.dfm"
TDlgBuscProd *DlgBuscProd;
//---------------------------------------------------------------------
__fastcall TDlgBuscProd::TDlgBuscProd(TComponent* AOwner)
	: TForm(AOwner)
{
}
//---------------------------------------------------------------------
void __fastcall TDlgBuscProd::ComboBox1Change(TObject *Sender)
{
  // Make the field we're locating in the leftmost field.
  Aplicacion -> TbBuscarCltProv->FieldByName(ComboBox1->Text)->Index = 0;
/*
  // In order to use FindNearest, we have to be indexed based on the field
  // we're doing the find in.  If we're using Locate, it doesn't matter what
  // the current index is, so we will set it to company, which is the default
  // in the Customer form.

  if (ComboBox1->Text == "CustNo")
*/
    Aplicacion -> TbBuscarCltProv->IndexName = "";

/*
  else
    DM2->CustLookup->IndexName = "ByCompany";
*/

  Edit1->SetFocus();
  Edit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TDlgBuscProd::Edit1Change(TObject *Sender)
{
  AnsiString BuscarEsto;

  BuscarEsto = Edit1->Text;

  { // Some non-indexed field.
    if ( //ComboBox1->Text != "Nombre del Producto"  &&
         BuscarEsto == "" )
        BuscarEsto = "0";

    Set<TLocateOption,0,1> flags;
    flags << loCaseInsensitive << loPartialKey;
    // Possibly apply the filter so we see only records matching this value.
    bool found;
    found = Aplicacion -> TbBuscarCltProv->Locate(ComboBox1->Text,
                                    BuscarEsto,
                                    flags);

    if ( found )
    {
      AnsiString BuscarCota;
      BuscarCota = BuscarEsto + "Z";

      Aplicacion -> TbBuscarCltProv->FilterOptions = Aplicacion -> TbBuscarCltProv->FilterOptions << foCaseInsensitive;

      Aplicacion -> TbBuscarCltProv->Filtered = true;
      Aplicacion -> TbBuscarCltProv->Filter = "([" + ComboBox1->Text + "] >= '" + BuscarEsto + "') AND [" + ComboBox1->Text + "] < '" + BuscarCota + "'";
    }
    else
      Aplicacion -> TbBuscarCltProv->Filtered = false;
  }

  Aplicacion -> TbBuscarCltProv->Refresh();

}
//---------------------------------------------------------------------------
void __fastcall TDlgBuscProd::DBGrid1DblClick(TObject *Sender)
{
  ModalResult = mrOk;
}
//---------------------------------------------------------------------------





