unit FOPCIONESCODBARRAS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, Buttons,dateutils;

type
  TOPCIONESCODBARRAS = class(TForm)
    Label5: TLabel;
    Edit3: TEdit;
    LVarios: TLabel;
    Luno: TLabel;
    Lnum: TLabel;
    bACEPTAR: TButton;
    bCancelar: TButton;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure bACEPTARClick(Sender: TObject);
    procedure bCancelarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Valor :string;
    Cantidad : string;
  end;

var
  OPCIONESCODBARRAS: TOPCIONESCODBARRAS;

implementation

uses UDMGS, menu;

{$R *.dfm}




procedure TOPCIONESCODBARRAS.FormKeyPress(Sender: TObject; var Key: Char);
begin
    if ActiveControl=nil then
    begin
        Perform(WM_NextDLGCtl, 0, 0);
        key:=#0;
    end;

    if (key = #13) and not (activecontrol is tbutton) then
    begin
        Perform(WM_NextDLGCtl, 0, 0);
        key:=#0;
    end;
end;

procedure TOPCIONESCODBARRAS.FormShow(Sender: TObject);
begin
  lnum.Caption := cantidad;
  edit3.Text := cantidad;
  if (strtoint(cantidad)>1) then
  begin
    lvarios.Visible := true;
    luno.visible := false;
  end
  else
  begin
    lvarios.Visible := false;
    luno.visible := true;
  end;
  edit3.SetFocus;
end;


procedure TOPCIONESCODBARRAS.FormCreate(Sender: TObject);
begin
//vvv
end;
procedure TOPCIONESCODBARRAS.bACEPTARClick(Sender: TObject);
var aux:integer;
begin
  aux := 0;
  try
     aux :=  strtoint(edit3.Text);
     if ((aux > strtoint(cantidad))  or (aux<0)) then
     begin
        showmessage('La cantidad debe estar entre 0 y '+cantidad);
        edit3.SetFocus;
        edit3.Text := cantidad;
     end
     else
        self.modalresult := mrok;
  except
     showmessage ('El valor no es válido');
     edit3.Text := cantidad;
     edit3.SetFocus;
  end;
  valor := edit3.Text;
end;
procedure TOPCIONESCODBARRAS.bCancelarClick(Sender: TObject);
begin
 self.modalresult := mrcancel;
 valor := '0';
end;

end.
