unit U_JwlStoreHelp;

interface

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

type
  TfrmJwlStoreHelp = class(TForm)
    DataSource1: TDataSource;
    Label1: TLabel;
    edttj: TEdit;
    ADOQueryHelp: TADOQuery;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    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
  frmJwlStoreHelp: TfrmJwlStoreHelp;

implementation
uses
  U_global;
{$R *.dfm}

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

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

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

  with ADOQueryHelp do
  begin
    close;
    sql.Clear;
    sql.Add('select A.whCode,A.whName from Gy_warehouse 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.whCode');
    open;
  end;
  
end;
procedure TfrmJwlStoreHelp.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
  begin
    if not ADOQueryHelp.IsEmpty then
      ModalResult:=1;
  end;
end;

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

end.
