unit U_WlHelp;

interface

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

type
  TfrmWlHelp = class(TForm)
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    ImageList24: TImageList;
    ToolBar1: TToolBar;
    Tok: TToolButton;
    ToolButton3: TToolButton;
    GroupBox1: TGroupBox;
    edttj: TEdit;
    Label1: TLabel;
    ADOQuery1MNumber: TStringField;
    ADOQuery1Mname: TWideStringField;
    ADOQuery1Model: TWideStringField;
    ADOQuery1CaiZhi: TWideStringField;
    ADOQuery1PurSortCode: TStringField;
    ADOQuery1InvSortcode: TStringField;
    ADOQuery1PrimaryUnit: TStringField;
    ADOQuery1PrimaryUnitName: TWideStringField;
    ADOQuery1PurUnit: TStringField;
    ADOQuery1PurUnitName: TWideStringField;
    ADOQuery1NowStorage: TBCDField;
    ADOQuery1HighStorage: TBCDField;
    ADOQuery1LowStorage: TBCDField;
    ADOQuery1SafeQuan: TBCDField;
    ADOQuery1Isbzqgl: TBooleanField;
    ADOQuery1Ispcgl: TBooleanField;
    Label2: TLabel;
    Edit1: TEdit;
    ADOConnection1: TADOConnection;
    cxGrid1: TcxGrid;
    cxGrid1Level1: TcxGridLevel;
    tv1: TcxGridDBTableView;
    tv1MNumber1: TcxGridDBColumn;
    tv1Mname1: TcxGridDBColumn;
    tv1Model1: TcxGridDBColumn;
    tv1CaiZhi1: TcxGridDBColumn;
    tv1PrimaryUnitName1: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure edttjChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure TokClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
  private

  public
    str_dylx:string;
    FStoreCode:string;
  end;

var
  frmWlHelp: TfrmWlHelp;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmWlHelp.FormShow(Sender: TObject);
begin
  try
    adoquery1.DisableControls ;
    with adoquery1 do
    begin
      close;
      sql.Clear;
      filtered:=false;
      sql.Add('select * from Gy_material ');
      //sql.Add('where StopFlag=''0''');
      sql.Add('where 1=1');
      if trim(FStoreCode)<>'' then
        sql.Add('and whcode='''+trim(FStoreCode)+'''');
      sql.Add('order by Mnumber');
      open;
    end;
  finally
    adoquery1.EnableControls ;
  end;
end;

procedure TfrmWlHelp.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;
/////////////////////////////////////////////////
  //Ìõ¼þ¹ýÂË
/////////////////////////////////////////////////
procedure TfrmWlHelp.edttjChange(Sender: TObject);
begin
  try
      ADOQuery1.DisableControls;
      if trim(edttj.Text)<>'' then
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
          filter:='mNumber like '+quotedStr('%'+trim(edttj.Text)+'%')+
                ' or mName like '+quotedStr(trim(edttj.Text)+'%');
          filtered:=true;
        end;
      end
      else
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
        end;
      end;
  finally
      ADOQuery1.EnableControls;
  end;

end;

procedure TfrmWlHelp.FormCreate(Sender: TObject);
begin
  cxgrid1.Align :=alClient;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;   
end;

procedure TfrmWlHelp.ToolButton3Click(Sender: TObject);
begin
  close;
end;

procedure TfrmWlHelp.TokClick(Sender: TObject);
begin
  if adoquery1.IsEmpty then
    ModalResult:=-1
  else
    modalResult:=1;
end;

procedure TfrmWlHelp.Edit1Change(Sender: TObject);
begin
  try
      ADOQuery1.DisableControls;
      if trim(edit1.Text)<>'' then
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
          filter:='model like '+quotedStr('%'+trim(edit1.Text)+'%');
          filtered:=true;
        end;
      end
      else
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
        end;

      end;
  finally
      ADOQuery1.EnableControls;
  end;
end;

procedure TfrmWlHelp.tv1DblClick(Sender: TObject);
begin
  modalResult:=1;
end;

end.
