unit U_foreigncurrencyHelp;

interface

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

type
  TfrmforeigncurrencyHelp = class(TForm)
    ToolBar1: TToolBar;
    TBOk: TToolButton;
    TBClose: TToolButton;
    ImageList24: TImageList;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    edttj: TEdit;
    cxGrid1: TcxGrid;
    tv1: TcxGridDBTableView;
    tv1Code: TcxGridDBColumn;
    tv1Name: TcxGridDBColumn;
    tv1AccRate: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ADOQueryHelp: TADOQuery;
    procedure TBOkClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure edttjChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmforeigncurrencyHelp: TfrmforeigncurrencyHelp;

implementation
uses
  U_global;

{$R *.dfm}

procedure TfrmforeigncurrencyHelp.TBOkClick(Sender: TObject);
begin
  if ADOQueryHelp.IsEmpty then
    ModalResult:=-1
  else
    modalResult:=1;
end;

procedure TfrmforeigncurrencyHelp.TBCloseClick(Sender: TObject);
begin
  ModalResult:=-1;
end;

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

procedure TfrmforeigncurrencyHelp.edttjChange(Sender: TObject);
begin
  try
    ADOQueryHelp.DisableControls;
    if trim(edttj.Text)<>'' then
    begin
      with ADOQueryHelp do
      begin
        filtered:=false;
        filter:='code like '+quotedStr('%'+trim(edttj.Text)+'%')+
              ' or name like '+quotedStr(trim(edttj.Text)+'%');
        filtered:=true;
      end;
    end
    else
    begin
      with ADOQueryHelp do
      begin
        filtered:=false;
      end;
    end;
  finally
    ADOQueryHelp.EnableControls;
  end;
end;

procedure TfrmforeigncurrencyHelp.FormShow(Sender: TObject);
begin
  try
    ADOQueryHelp.DisableControls ;
    with ADOQueryHelp do
    begin
      Filtered:=False;
      close;
      sql.Clear;
      sql.Add('select foreigncurrCode Code,foreigncurrName Name, ');
      sql.Add('AccRate from GY_foreigncurrency order by Code');
      open;
    end;
  finally
    ADOQueryHelp.EnableControls ;
  end;
end;

procedure TfrmforeigncurrencyHelp.tv1DblClick(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
