unit UDEVISESELECT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, Grids, DBGrids, ExtCtrls, Menus, Mask,
  ToolEdit, dxCore, dxButton;

type
  TFRMDEVISESELECT = class(TForm)
    Panel1: TPanel;
    GridClient: TDBGrid;
    Dsdevise: TDataSource;
    BtnOk: TBitBtn;
    Panel5: TPanel;
    eCode: TEdit;
    Label1: TLabel;
    PopupMenuGrid: TPopupMenu;
    Ajouter1: TMenuItem;
    Modifier1: TMenuItem;
    Supprimer1: TMenuItem;
    procedure FiltrerAffichage();
    procedure eCodeChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnOkClick(Sender: TObject);
    procedure GridClientKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BtnSupprimerClick(Sender: TObject);
    procedure eCodeKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FRMDEVISESELECT: TFRMDEVISESELECT;

implementation

{$R *.dfm}
uses UDATAPRIX;
procedure TFRMDEVISESELECT.FiltrerAffichage();
var asFiltre :String;
begin
asFiltre := '';
if(eCode.Text <> '') then
   asFiltre := 'upper(devise) LIKE ' + QuotedStr('%'+uppercase(eCode.Text) +'%');

DATAPRIX.devise.Close;
DATAPRIX.devise.SQL.Clear;
if asfiltre <>'' then
DATAPRIX.devise.SQL.Add('select * from devise where '+asFiltre)
else
DATAPRIX.devise.SQL.Add('select * from devise ');
DATAPRIX.devise.open;
end;

procedure TFRMDEVISESELECT.eCodeChange(Sender: TObject);
begin
FiltrerAffichage();
if(DATAPRIX.devise.RecordCount = 0)then
  ActiveControl := eCode;
end;

procedure TFRMDEVISESELECT.FormClose(Sender: TObject;
  var Action: TCloseAction);
  begin
Action := caFree;
end;

procedure TFRMDEVISESELECT.BtnOkClick(Sender: TObject);
begin
ModalResult := mrOk;
end;

procedure TFRMDEVISESELECT.GridClientKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if(Key in [VK_RETURN]) then
   BtnOkClick(Sender);
if((Key = VK_UP) and (GridClient.DataSource.DataSet.RecNo = 1)) then
  eCode.SetFocus;
end;

procedure TFRMDEVISESELECT.BtnSupprimerClick(Sender: TObject);
begin
if(Application.MessageBox('Voulez-vous supprimer la ligne en cours ?', 'Confirmation',MB_YESNO)= IDYES) then
   Dsdevise.DataSet.Delete;
end;

procedure TFRMDEVISESELECT.eCodeKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if(Key = VK_DOWN) then
    GridClient.SetFocus;
end;

procedure TFRMDEVISESELECT.FormShow(Sender: TObject);
begin
DATAPRIX.devise.Close;
DATAPRIX.devise.sql.clear;
DATAPRIX.devise.sql.Add('select * from devise order by devise');
DATAPRIX.devise.OPEN;
end;

end.
