unit U_DyeStoreHelp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, ExtCtrls;

type
  TfrmDyeStoreHelp = class(TForm)
    DataSource1: TDataSource;
    Label1: TLabel;
    edttj: TEdit;
    ADOQueryHelp: TADOQuery;
    DBGrid1: TDBGrid;
    ADOConnection1: TADOConnection;
    procedure FormShow(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure edttjChange(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    procedure DoQuery();
  public
    fRightCtr:Boolean;
  end;

var
  frmDyeStoreHelp: TfrmDyeStoreHelp;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmDyeStoreHelp.FormShow(Sender: TObject);
begin
  DoQuery();
  dbgrid1.SetFocus;
end;

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

procedure TfrmDyeStoreHelp.edttjChange(Sender: TObject);
begin
  DoQuery();
end;
procedure TfrmDyeStoreHelp.DoQuery();
var
  whereStr:string;
begin
  if trim(edttj.text)<>'' then
    whereStr:='and (A.DSCode like '+quotedStr('%'+trim(edttj.text)+'%')
              +' or DSName like '+quotedStr('%'+trim(edttj.text)+'%')+')';

  with ADOQueryHelp do
  begin
    close;
    sql.Clear;
    sql.Add('select A.DSCode,A.DSName from  XC_DyeStore A');
    {if fRightCtr then
    sql.Add('inner join gy_whLimit B on A.whcode=B.whCode and B.czyBm='+quotedStr(gUserId));}
    sql.Add('where valid=1');
    sql.Add(whereStr);
    sql.Add(' order by A.DSCode');
    open;
  end;
  
end;
procedure TfrmDyeStoreHelp.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
  begin
    if not ADOQueryHelp.IsEmpty then
      ModalResult:=1;
  end;
end;

procedure TfrmDyeStoreHelp.FormCreate(Sender: TObject);
begin
  fRightCtr:=true;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;  
end;

end.
