Created
July 25, 2013 10:46
Entrada extra de lotes,para el tutorial de programa de gestión desde 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit UEntLotExt; | |
interface | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
Dialogs, EditDefault, StdCtrls, ExtCtrls, Buttons, DB, DBCtrls; | |
type | |
TFEntLoteExt = class(TForm) | |
Panel1: TPanel; | |
Label38: TLabel; | |
EdLote: TEdit; | |
Label39: TLabel; | |
EdFecha: TEditDefault; | |
Label40: TLabel; | |
EdCantidad: TEdit; | |
Label41: TLabel; | |
EdFechaCaducidad: TEditDefault; | |
Label43: TLabel; | |
EdUsar: TEdit; | |
Label1: TLabel; | |
Label2: TLabel; | |
Label3: TLabel; | |
Label4: TLabel; | |
Label5: TLabel; | |
SB_Salir: TSpeedButton; | |
SBSalirPasarDatos: TSpeedButton; | |
EDCodigoArticulo: TEdit; | |
Label6: TLabel; | |
DSPRODUCTOS: TDataSource; | |
DSProductosStock: TDataSource; | |
procedure EdFechaEnter(Sender: TObject); | |
procedure EdFechaExit(Sender: TObject); | |
procedure EdCantidadExit(Sender: TObject); | |
procedure EdUsarExit(Sender: TObject); | |
procedure SBSalirPasarDatosClick(Sender: TObject); | |
procedure SB_SalirClick(Sender: TObject); | |
procedure FormKeyPress(Sender: TObject; var Key: Char); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
FEntLoteExt: TFEntLoteExt; | |
implementation | |
{$R *.dfm} | |
uses UDM, UExtPPAF; | |
procedure TFEntLoteExt.EdCantidadExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Salir de Cantidad ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
if EdCantidad.Text<>'' then | |
begin | |
try | |
StrToInt(EdCantidad.Text); //Para si no es un número provocar un fallo | |
EdUsar.Text:=EdCantidad.Text; | |
except | |
ShowMessage('El dato introducido no es una cantidad entera'); | |
EdCantidad.SetFocus; | |
end; | |
end; | |
end; | |
procedure TFEntLoteExt.EdUsarExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Nuevo lotes introducidos ]******* | |
//------------------------------------------------------------------------------ | |
var VarIControlError, VarICantIntr:Integer; | |
VarbEncontrado:Boolean; | |
begin | |
VarIControlError:=0; | |
VarbEncontrado:=False; | |
if EdUsar.Text='' then | |
begin | |
if EdCantidad.Text<>'' then | |
begin | |
EdUsar.Text:=EdCantidad.Text; | |
EdUsar.SetFocus; | |
end; | |
end else | |
if EdUsar.Text<>'' then | |
begin | |
Case MessageBox(0,pchar( '¿Desea que el núevo lote sea registrado, como entrada de la empresa?' +#13#10),pchar('Nuevo lote detectado'),4+32+0+4096) of | |
6:begin //Si | |
try | |
VarIControlError:=1; | |
VarICantIntr:=StrToInt(EdCantidad.Text); | |
//Productos LOTES | |
VarbEncontrado:=DSProductosStock.DataSet.Locate('CODIGOPRODUCTO;LOTE', VarArrayOf([EDCodigoArticulo.Text, EdLote.Text]), [LoCaseInsensitive, LoPartialKey]); | |
if not VarbEncontrado then DSProductosStock.DataSet.Insert | |
else DSProductosStock.DataSet.Edit; | |
DSProductosStock.DataSet.FieldByName('CODIGOPRODUCTO').Value:=EDCodigoArticulo.Text; | |
if EdCantidad.Text<>'' then | |
begin | |
DSProductosStock.DataSet.FieldByName('CANTIDADDEENTRADA').Value:=VarICantIntr; | |
if VarbEncontrado then DSProductosStock.DataSet.FieldByName('EXISTENCIAS').Value:=DSProductosStock.DataSet.FieldByName('EXISTENCIAS').Value+StrToInt(EdCantidad.Text) | |
else DSProductosStock.DataSet.FieldByName('EXISTENCIAS').Value:=VarICantIntr; | |
end else | |
begin | |
DSProductosStock.DataSet.FieldByName('CANTIDADDEENTRADA').Value:=0; | |
DSProductosStock.DataSet.FieldByName('EXISTENCIAS').Value:=0; | |
end; | |
if EdLote.Text<>'' then DSProductosStock.DataSet.FieldByName('LOTE').Value :=EdLote.Text | |
else DSProductosStock.DataSet.FieldByName('LOTE').Value := 'Lote no facilitado'; | |
DSProductosStock.DataSet.FieldByName('FECHAENTRADA').Value:=StrToDate(EdFecha.Text); | |
DSProductosStock.DataSet.Post; | |
except | |
ShowMessage('Se Ha producido un error'); | |
if DSProductosStock.DataSet.State in [dsEdit,dsInsert] then DSProductosStock.DataSet.Cancel; | |
if DSPRODUCTOS.DataSet.State in [dsEdit,dsInsert] then DSPRODUCTOS.DataSet.Cancel; | |
end; | |
End; | |
end; | |
if SBSalirPasarDatos.Enabled=False then SBSalirPasarDatos.Enabled:=True; | |
EdLote.SetFocus; | |
end; | |
end; | |
procedure TFEntLoteExt.EdFechaEnter(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ entrar en la fecha ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
EdFecha.Text:=DateToStr(Now); | |
end; | |
procedure TFEntLoteExt.EdFechaExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Salir de Fecha ]******* | |
//------------------------------------------------------------------------------ | |
begin | |
if EdFecha.Text<>'' then | |
begin | |
try | |
StrToDate(EdFecha.Text); | |
EdFechaCaducidad.Text:=DateToStr(EdFecha.MyDate+365); | |
except | |
ShowMessage('La fecha introducida no es valida'); | |
EdFecha.SetFocus; | |
end; | |
end; | |
end; | |
procedure TFEntLoteExt.FormKeyPress(Sender: TObject; var Key: Char); | |
//------------------------------------------------------------------------------ | |
//************************************************[ Al pulsar una tecla ]****** | |
// Al pulsar la tecla salta al foco del siguiente componente, si esta admitido | |
//------------------------------------------------------------------------------ | |
begin | |
if (Key = #13) then {Si se ha pulsado enter } | |
if (ActiveControl is TEdit) | |
or (ActiveControl is TDBEdit) | |
or (ActiveControl is TDBComboBox) then | |
begin | |
Key := #0; { anula la puulsación } | |
Perform(WM_NEXTDLGCTL, 0, 0); { mueve al próximo control } | |
end | |
end; | |
procedure TFEntLoteExt.SB_SalirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************************[ Salir ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FExtPPAF.SetFocus; | |
SBSalirPasarDatos.Enabled:=False; | |
Close; | |
end; | |
procedure TFEntLoteExt.SBSalirPasarDatosClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Salir y pasar datos ]**** | |
//------------------------------------------------------------------------------ | |
var I,VarICantidad,VarISuma,VarIUsar:Integer; | |
VarSCaduco,VarsLotes:string; | |
begin | |
VarSCaduco:=''; | |
VarsLotes:=''; | |
VarISuma:=0; | |
if (EdUsar.Text<>'') and (EdLote.Text<>'') then | |
begin | |
VarISuma:=VarISuma+StrToInt(EdUsar.Text); | |
if EdFechaCaducidad.Text<>'' then VarSCaduco:=VarSCaduco+' - ['+EdUsar.Text+'] ('+EdFechaCaducidad.Text+') - '; | |
if EdLote.Text<>'' then VarsLotes:=VarsLotes+' - ['+EdUsar.Text+'] ('+EdLote.Text+') - '; | |
end; | |
if VarISuma<>0 then FExtPPAF.dbnextCantidad.Field.Value:=FExtPPAF.dbnextCantidad.Field.Value+VarISuma; | |
if VarsLotes<>'' then FExtPPAF.NEDLotes.Text:=FExtPPAF.NEDLotes.Text+Copy(VarsLotes,0,(Length(VarsLotes)-3)); | |
if VarSCaduco<>'' then FExtPPAF.NEDVencimientos.Text:=FExtPPAF.NEDVencimientos.Text+Copy(VarSCaduco,0,(Length(VarSCaduco)-3)); | |
FExtPPAF.DBNEXTComision.SetFocus; | |
FExtPPAF.DBNExtCodigoArticuloChange(Sender); | |
FExtPPAF.DBNExtPrecioUnidadExit(Sender); | |
FExtPPAF.DBNExtDescuentoExit(Sender); | |
varExtppafTempo:=True; | |
varExtppaf:=5; | |
SBSalirPasarDatos.Enabled:=False; | |
Close; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment