unit U_MaterialSortHelp;

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
  TfrmMaterialSortHelp = 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
  frmMaterialSortHelp: TfrmMaterialSortHelp;

implementation
uses
  U_adodbmd;
{$R *.dfm}

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

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

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

procedure TfrmMaterialSortHelp.FormCreate(Sender: TObject);
begin
   cxGrid1.Align :=alClient;
   DoQuery();
end;
///////////////////////////////////////////////////////
  //
////////////////////////////////////////////////////////
procedure TfrmMaterialSortHelp.DoQuery();
begin
  try
    adoqueryHelp.DisableControls ;
    with adoqueryHelp do
    begin
      close;
      sql.Clear;
      sql.Add('select sortCode as code,sortName as Name ');
      sql.Add('from SX_SXsort');
      sql.Add('where endflag=1 order by sortCode');
      open;
    end;
  finally
    adoqueryHelp.EnableControls ;
  end;
end;
procedure TfrmMaterialSortHelp.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.
