unit CajasFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, Wwdbigrd, Wwdbgrid, StdCtrls, Wwkeycb, ExtCtrls, Registry;

type
  TfmCaja = class(TForm)

    dbgCajas: TwwDBGrid;
    Button1: TButton;
    Button2: TButton;
    isEmpresa: TwwIncrementalSearch;
    Label1: TLabel;
    edtIdCadena: TEdit;
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    edtIdSucursal: TEdit;
    Label3: TLabel;
    edtUsuario: TEdit;
    Label4: TLabel;
    edtPassword: TEdit;
    procedure dbgCajasDblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure dbgCajasKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure dbgCajasKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    FBandera:Boolean;
    FCajeroId:Integer;
  end;

var
  fmCaja: TfmCaja;

implementation

uses Unit1;

{$R *.dfm}

procedure TfmCaja.Button1Click(Sender: TObject);
var lIdCadena, lIdSucursal, lUsuario, lPassword:String;
lCajaId:Integer;
begin
  lCajaId:=Form1.dsCajas.FieldByName('CAJA_ID').AsInteger;
  lIdCadena:=edtIdCadena.Text;
  lIdSucursal:=edtIdSucursal.Text;
  lUsuario:=edtUsuario.Text;
  lPassword:=edtPassword.Text;
  if (lIdCadena<>'') or (lIdSucursal<>'')  or (lUsuario<>'') or (lPassword<>'') or (lCajaId>0) then
  begin
    Form1.SetRegistryData(HKEY_LOCAL_MACHINE,'\Software\NGPlugOut\INTERFASECSO','CajaId',rdInteger,lCajaId);
    Form1.SetRegistryData(HKEY_LOCAL_MACHINE,'\Software\NGPlugOut\INTERFASECSO','IdCadena',rdString,lIdCadena);
    Form1.SetRegistryData(HKEY_LOCAL_MACHINE,'\Software\NGPlugOut\INTERFASECSO','IdSucursal',rdString,lIdSucursal);
    Form1.SetRegistryData(HKEY_LOCAL_MACHINE,'\Software\NGPlugOut\INTERFASECSO','Usuario',rdString,lUsuario);
    Form1.SetRegistryData(HKEY_LOCAL_MACHINE,'\Software\NGPlugOut\INTERFASECSO','Password',rdString, lPassword);
  end;

 Form1.FCajaId:=lCajaId;
 Form1.FIdCadena:=lIdCadena;
 Form1.FIdSucursal:=lIdSucursal;
 Form1.FUsuario:=lUsuario;
 Form1.FPassword:=lPassword;

 Form1.StatusBar1.Panels[2].Text := uppercase(Form1.dsCajas.FieldByName('NOMBRE').AsString);
 FBandera:=True;
 Close();
end;

procedure TfmCaja.Button2Click(Sender: TObject);
begin
 FBandera:=False;
 Close();
end;

procedure TfmCaja.dbgCajasDblClick(Sender: TObject);
begin
 Close();
end;

procedure TfmCaja.dbgCajasKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If key = vk_return then
  Begin
     Form1.FCajaId := Form1.dsCajas.FieldByName('CAJA_ID').AsInteger;
     Form1.StatusBar1.Panels[2].Text := uppercase(Form1.dsCajas.FieldByName('NOMBRE').AsString);
     FBandera:=True;
     Close();
  End;


end;

procedure TfmCaja.dbgCajasKeyPress(Sender: TObject; var Key: Char);
begin
  isEmpresa.Text := Key;
  isEmpresa.FindValue;
end;

procedure TfmCaja.FormShow(Sender: TObject);
begin
try
  FBandera:=False;
  edtIdCadena.Text:=Form1.GetRegistryData(HKEY_LOCAL_MACHINE,'\SOFTWARE\NGPlugOut\INTERFASECSO\','IdCadena');
  edtIdSucursal.Text:=Form1.GetRegistryData(HKEY_LOCAL_MACHINE,'\SOFTWARE\NGPlugOut\INTERFASECSO\','IdSucursal');
  edtUsuario.Text:=Form1.GetRegistryData(HKEY_LOCAL_MACHINE,'\SOFTWARE\NGPlugOut\INTERFASECSO\','Usuario');
  edtPassword.Text:=Form1.GetRegistryData(HKEY_LOCAL_MACHINE,'\SOFTWARE\NGPlugOut\INTERFASECSO\','Password');
except
begin

end;
end;
end;

end.
