unit U_kfSortHelp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, StdCtrls, ComCtrls, ToolWin, ExtCtrls;

type
  TfrmkfSortHelp = class(TForm)
    tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    tv1Column1: TcxGridDBColumn;
    tv1Column2: TcxGridDBColumn;
    DataSource1: TDataSource;
    ADOQueryHelp: TADOQuery;
    ToolBar2: TToolBar;
    TOk: TToolButton;
    ToolButton7: TToolButton;
    Panel1: TPanel;
    edttj: TEdit;
    Label1: TLabel;
    procedure ToolButton7Click(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure edttjChange(Sender: TObject);
  private
    procedure DoQuery();
  public
    { Public declarations }
  end;

var
  frmkfSortHelp: TfrmkfSortHelp;

implementation
uses
  U_adodbmd;
{$R *.dfm}

procedure TfrmkfSortHelp.ToolButton7Click(Sender: TObject);
begin
  close;
end;

procedure TfrmkfSortHelp.TOkClick(Sender: TObject);
begin
  if ADOQueryHelp.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmkfSortHelp.tv1DblClick(Sender: TObject);
begin
  tok.Click ;
end;

procedure TfrmkfSortHelp.FormCreate(Sender: TObject);
begin
   cxGrid1.Align :=alClient;
   DoQuery();
end;
///////////////////////////////////////////////////////
  //
////////////////////////////////////////////////////////
procedure TfrmkfSortHelp.DoQuery();
begin
  try
    adoqueryHelp.DisableControls ;
    with adoqueryHelp do
    begin
      close;
      sql.Clear;
      sql.Add('select kfsortCode as code,kfsortName as Name ');
      sql.Add('from kf_kfsort');
      sql.Add('where endflag=1 order by kfsortCode');
      open;
    end;
  finally
    adoqueryHelp.EnableControls ;
  end;
end;
procedure TfrmkfSortHelp.edttjChange(Sender: TObject);
var
  filterstr:string;
begin
  if trim(edttj.Text)<>'' then
  begin
    filterstr:='Code like '+quotedStr('%'+trim(edttj.Text)+'%')
               +' or Name like '+ quotedStr('%'+trim(edttj.Text)+'%');
  end;

  try
    adoqueryHelp.DisableControls ;
    with adoqueryHelp do
    begin
      filtered:=false;
      if trim(filterstr)<>'' then
      begin
        filter:=filterstr;
        filtered:=true;
      end;
    end
  finally
    adoqueryHelp.EnableControls;
  end;
end;

end.
