Created
June 24, 2013 14:00
-
-
Save anonymous/5850255 to your computer and use it in GitHub Desktop.
Gestión 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 UEntradas; | |
{$R BOTONERA.RES} | |
interface | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, IBDatabase, | |
MMSystem, //Para la botonera | |
NewPanelDB, //Para usar el NEwPanelDB | |
SPBBC, //Para TSpeedButtonBC | |
Lapelpanel, //Para paneles con solapa | |
MyDbIbMemo, //Para DbiMemo | |
TDbIbchkbox, //Para campos boolean en Firebird | |
Mask, DbEditDefault, //PAra usar los DbeditDefault en vez de los Dbedit normal | |
DBCBEXT, //Para usar el DbCombobox Extendido | |
GroupboxJL, //Para usar el CgoupBox especial | |
Dialogs, ComCtrls, ExtCtrls, Grids, DBGrids, StdCtrls, Spin, Buttons, DB, DBCtrls, | |
DBneweditjl, Mneweditjl, IBCustomDataSet, IBQuery, StrUtils; | |
type | |
TFEntradas = class(TForm) | |
PanelBotonera: TNewPanelDB; | |
SBBarraStatus: TStatusBar; | |
Panel1: TPanel; | |
Panel2: TPanel; | |
PanelDatos: TNewPanelDB; | |
Panel3: TPanel; | |
DBGNoEnable: TDBGrid; | |
PanelConfirmar: TNewPanelDB; | |
DsPrincipal: TDataSource; | |
SBPrimero: TSpeedButtonBC; | |
SBMenosx: TSpeedButtonBC; | |
SBMenos1: TSpeedButtonBC; | |
SBMas1: TSpeedButtonBC; | |
SBMasX: TSpeedButtonBC; | |
SBUltimo: TSpeedButtonBC; | |
SbNuevo: TSpeedButtonBC; | |
SbModificar: TSpeedButtonBC; | |
SbBorrar: TSpeedButtonBC; | |
SB_Salir: TSpeedButtonBC; | |
SBBuscar: TSpeedButtonBC; | |
SBImprimir: TSpeedButtonBC; | |
SBConfirmar: TSpeedButtonBC; | |
SBCancelar: TSpeedButtonBC; | |
Label14: TLabel; | |
SEMobeByX: TSpinEdit; | |
GBBuscar: TGroupBoxJL; | |
Ebusqueda: TEdit; | |
BLimpiar: TButton; | |
BBuscar: TButton; | |
BCerrar: TButton; | |
GBImprimir: TGroupBoxJL; | |
CBVistaPrevia: TCheckBox; | |
CBVerDialogo: TCheckBox; | |
BCerrarIMP: TButton; | |
Timer1: TTimer; | |
Label1: TLabel; | |
Label2: TLabel; | |
Label3: TLabel; | |
Label4: TLabel; | |
Label5: TLabel; | |
Label6: TLabel; | |
DBNCodProd: TDBNewEditJL; | |
DBNLote: TDBNewEditJL; | |
DBNCodEmpleado: TDBNewEditJL; | |
DBNCaducidad: TDBNewEditJL; | |
DBNCantidad: TDBNewEditJL; | |
DBNFecha: TDBNewEditJL; | |
DBIBMemo1: TDBIBMemo; | |
SPBCNuevaFP: TSpeedButtonBC; | |
SPBCBuscarFP: TSpeedButtonBC; | |
DBText1: TDBText; | |
SpeedButtonBC1: TSpeedButtonBC; | |
SpeedButtonBC2: TSpeedButtonBC; | |
DBText2: TDBText; | |
SpeedButtonBC3: TSpeedButtonBC; | |
SpeedButtonBC4: TSpeedButtonBC; | |
DBText3: TDBText; | |
GBModificado: TGroupBox; | |
RDMotivos: TRadioGroup; | |
GBOtros: TGroupBox; | |
ENOtros: TMyNewEditJL; | |
IBQNotas: TIBQuery; | |
DSIBQNOTAS: TDataSource; | |
IBQFABRICABLE: TIBQuery; | |
DSIBQFABRICABLE: TDataSource; | |
IBQEMPLEADOS: TIBQuery; | |
DSIBQEMPLEADOS: TDataSource; | |
IBQLotes: TIBQuery; | |
DSIBQLOTES: TDataSource; | |
IBQARTICULO: TIBQuery; | |
DSIBQARTICULO: TDataSource; | |
DSNotas: TDataSource; | |
DSStock: TDataSource; | |
Memo1: TMemo; | |
procedure FormKeyPress(Sender: TObject; var Key: Char); | |
procedure SBPrimeroClick(Sender: TObject); | |
procedure SBMenosxClick(Sender: TObject); | |
procedure SBMenos1Click(Sender: TObject); | |
procedure SBMas1Click(Sender: TObject); | |
procedure SBMasXClick(Sender: TObject); | |
procedure SBUltimoClick(Sender: TObject); | |
procedure SbNuevoClick(Sender: TObject); | |
procedure SbModificarClick(Sender: TObject); | |
procedure SbBorrarClick(Sender: TObject); | |
procedure SBBuscarClick(Sender: TObject); | |
procedure BLimpiarClick(Sender: TObject); | |
procedure BBuscarClick(Sender: TObject); | |
procedure BCerrarClick(Sender: TObject); | |
procedure EbusquedaChange(Sender: TObject); | |
procedure SBImprimirClick(Sender: TObject); | |
procedure BCerrarIMPClick(Sender: TObject); | |
procedure SB_SalirClick(Sender: TObject); | |
procedure FormCreate(Sender: TObject); | |
procedure Timer1Timer(Sender: TObject); | |
procedure FormActivate(Sender: TObject); | |
procedure SBCancelarClick(Sender: TObject); | |
procedure SBConfirmarClick(Sender: TObject); | |
procedure FormClose(Sender: TObject; var Action: TCloseAction); | |
procedure SpeedButtonBC3Click(Sender: TObject); | |
procedure SpeedButtonBC4Click(Sender: TObject); | |
procedure SPBCNuevaFPClick(Sender: TObject); | |
procedure SpeedButtonBC1Click(Sender: TObject); | |
procedure SPBCBuscarFPClick(Sender: TObject); | |
procedure SpeedButtonBC2Click(Sender: TObject); | |
procedure DBNLoteChange(Sender: TObject); | |
procedure DBNCodProdChange(Sender: TObject); | |
procedure DBNCodEmpleadoChange(Sender: TObject); | |
procedure DBGNoEnableDrawColumnCell(Sender: TObject; const Rect: TRect; | |
DataCol: Integer; Column: TColumn; State: TGridDrawState); | |
procedure RDMotivosClick(Sender: TObject); | |
procedure VerNota; | |
procedure DSPrincipalDataChange(Sender: TObject; Field: TField); | |
procedure DBNCantidadKeyPress(Sender: TObject; var Key: Char); | |
procedure DBNLoteExit(Sender: TObject); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
FEntradas: TFEntradas; | |
VarICantidadAnterior:Integer; | |
//PAra registrar los cambios | |
VarSEntLote,VarSEntCodProd,VarSEntCodEmple:string; | |
VarIEntCantidad:Integer; | |
VarDEntFecha:TDate; | |
implementation | |
{$R *.dfm} | |
uses UMENU,UDM, Fun,FUN_DBGRID, ULotes,UArticulos,UEmpleados, UbusquedaFP; | |
procedure TFEntradas.BBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ Buscar ]****** | |
//------------------------------------------------------------------------------ | |
var Campo:string; | |
begin | |
Campo:='LOTE'; {Dato a rellenar por el progrmador con el nombre del campo en la busqueda} | |
DSPrincipal.DataSet.Locate(Campo,Ebusqueda.Text,[loCaseInsensitive,loPartialKey]); | |
end; | |
procedure TFEntradas.BCerrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cerrar Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
BLimpiarClick(Sender); | |
GBBuscar.Visible:=False; | |
end; | |
procedure TFEntradas.BCerrarIMPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cerrar Imrprimir ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBImprimir.Visible:=False; | |
end; | |
procedure TFEntradas.BLimpiarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Limpia la busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
Ebusqueda.Text:=''; | |
BBuscarClick(Sender); | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFEntradas.DBGNoEnableDrawColumnCell(Sender: TObject; | |
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ ZEbaro del Grid ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
Zebrado(DsPrincipal,DBGNoEnable, Rect, Column, State, COLOR1GRID,COLOR2GRID); | |
end; | |
procedure TFEntradas.DBNCantidadKeyPress(Sender: TObject; var Key: Char); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ DBNCantidad KeyPress ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if not (key in['0'..'9',#8]) then | |
begin | |
key := char(0); | |
showmessage('Caracter invalido'); | |
end; | |
end; | |
procedure TFEntradas.DBNCodEmpleadoChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cambia el Empleado ]**** | |
// Para mostrar el nombre del Empleado | |
//------------------------------------------------------------------------------ | |
begin | |
if FEntradas.Active then | |
begin //Posicionamos primero el lote y buscamos el producto fabricable | |
ActQuery(IBQEMPLEADOS,'SELECT * FROM EMPLEADOS WHERE (EMPLEADOS.CODIGO = '+QuotedStr(DBNCodEmpleado.Text)+')'); | |
end; | |
end; | |
procedure TFEntradas.DBNCodProdChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cambia el Producto ]**** | |
// Para mostrar el nombre del Artículo | |
//------------------------------------------------------------------------------ | |
begin | |
if FEntradas.Active then | |
begin //Posicionamos primero el lote y buscamos el producto fabricable | |
ActQuery(IBQARTICULO,'SELECT * FROM ARTICULOS WHERE (ARTICULOS.CODIGO = '+QuotedStr(DBNCodProd.Text)+')'); | |
end; | |
end; | |
procedure TFEntradas.DBNLoteChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*********************************************************[ Cambia el Lote]**** | |
// Para mostrar el nombre del fabricable según el lote | |
//------------------------------------------------------------------------------ | |
begin | |
if FEntradas.Active then | |
begin //Posicionamos primero el lote y buscamos el producto fabricable | |
if DBNLote.Text<>'' then | |
begin | |
ActQuery(IBQLotes,'SELECT * FROM LOTES WHERE (LOTES.LOTE = '+QuotedStr(DBNLote.Text)+')'); | |
ActQuery(IBQFABRICABLE,'SELECT * FROM FABRICABLES WHERE (FABRICABLES.CODIGO = '+QuotedStr(IBQLOTES.FieldByName('CODIGOPRODUCTOFABRICABLE').AsString)+')'); | |
if (DsPrincipal.DataSet.State in [dsEdit,dsInsert]) and | |
(Length(DBNLote.Text)=DM.IBDCONFILARGOLOTE.Value) then DBNCaducidad.Field.Value:=IBQLotes.FieldByName('CADUCIDAD').Value; | |
end; | |
end; | |
end; | |
procedure TFEntradas.DBNLoteExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ Salida del lote ]**** | |
//------------------------------------------------------------------------------ | |
var Year,VarILargoCadena:integer; | |
begin | |
YEar:=Ano(now); | |
if DBNLote.Text<>'' then //Controlamos que podamos meter el lote entero, o sólo los últimos digitos | |
begin | |
if DM.IBDCONFIUSARSERIEYEAR.AsString='S' then | |
begin | |
if Length(DBNLote.Text)<>DM.IBDCONFILARGOLOTE.value then DBNLote.Field.Value:= AnsiRightStr(IntToStr(Year), 2)+ceros(Trim(DBNLote.Text),(DM.IBDCONFILARGOLOTE.Value-2)); | |
end else | |
begin | |
if Length(DBNLote.Text)<>DM.IBDCONFILARGOLOTE.value then | |
begin | |
VarILargoCadena:=Length(Trim(DM.IBDCONFISERIE3.Value)); | |
DBNLote.Field.Value:=Trim(DM.IBDCONFISERIE3.Value)+ceros(Trim(DBNLote.Text),(DM.IBDCONFILARGOLOTE.Value-VarILargoCadena)); | |
end; | |
end; | |
DBNLoteChange(Sender); | |
end else ShowMessage('Debe introducir el número de lote'); | |
end; | |
procedure TFEntradas.DSPrincipalDataChange(Sender: TObject; Field: TField); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ DSPrincipa Change ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FEntradas.Active then | |
begin | |
if not (DsPrincipal.DataSet.State in [dsEdit,dsInsert]) then VerNota | |
else if (DsPrincipal.DataSet.State in [dsInsert]) then DBIBMemo1.Lines.Clear; | |
end; | |
end; | |
procedure TFEntradas.EbusquedaChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************[ Mientras se escribe en busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
BBuscarClick(sender); | |
end; | |
procedure TFEntradas.FormActivate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************[ Cuando se activa El form ]****** | |
// Lo que queremos que haga nuestro Form Cuando se Actiba | |
//------------------------------------------------------------------------------ | |
begin | |
//Carganmos las imagenes de los botones | |
SBPrimero.Glyph.Handle:=Loadbitmap(HInstance,'FIRST'); | |
SBMenosx.Glyph.Handle:=Loadbitmap(HInstance,'RETROCEDER'); | |
SBMenos1.Glyph.Handle:=Loadbitmap(HInstance,'PRIOR'); | |
SBMas1.Glyph.Handle:=Loadbitmap(HInstance,'NEXT'); | |
SBMasX.Glyph.Handle:=Loadbitmap(HInstance,'AVANZAR'); | |
SBUltimo.Glyph.Handle:=Loadbitmap(HInstance,'LAST'); | |
SbNuevo.Glyph.Handle:=Loadbitmap(HInstance,'NUEVO'); | |
SbModificar.Glyph.Handle:=Loadbitmap(HInstance,'EDIT'); | |
SbBorrar.Glyph.Handle:=Loadbitmap(HInstance,'BORRAR'); | |
SB_Salir.Glyph.Handle:=Loadbitmap(HInstance,'SALIR'); | |
SBBuscar.Glyph.Handle:=Loadbitmap(HInstance,'BUSCAR'); | |
SBImprimir.Glyph.Handle:=Loadbitmap(HInstance,'IMPRIMIR'); | |
SBConfirmar.Glyph.Handle:=Loadbitmap(HInstance,'CHECKROUND'); | |
SBCancelar.Glyph.Handle:=Loadbitmap(HInstance,'CANCEL'); | |
if Timer1.Enabled=false then Timer1.Enabled:=True; | |
//Ponemos el Juego de colores de mis NewPanelDB | |
PanelBotonera.ColorNotActive:=COLORPANELACT; | |
PanelBotonera.ActiveColor:=COLORPANELNOACT; | |
PanelDatos.ActiveColor:=COLORPANELACT; | |
PanelDatos.ColorNotActive:=COLORPANELNOACT; | |
PanelConfirmar.ActiveColor:=COLORPANELACT; | |
PanelConfirmar.ColorNotActive:=COLORPANELNOACT; | |
// Mostramos los datos de los cuarres al verse y no solo al cambiar | |
DBIBMemo1.Lines.Clear; | |
DBNLoteChange(SEnder); | |
DBNCodEmpleadoChange(Sender); | |
DBNCodProdChange(Sender); | |
VerNota; | |
end; | |
procedure TFEntradas.FormClose(Sender: TObject; var Action: TCloseAction); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Al Cerrarse El Form ]****** | |
// Cerramos todos los procesos para que no consuman memoria y posibles errores | |
//------------------------------------------------------------------------------ | |
begin | |
if Timer1.Enabled=true then Timer1.Enabled:=False; | |
QuerryOC(IBQNotas); | |
QuerryOC(IBQFABRICABLE); | |
QuerryOC(IBQEMPLEADOS); | |
QuerryOC(IBQLotes); | |
QuerryOC(IBQARTICULO); | |
end; | |
procedure TFEntradas.FormCreate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Al Crearse el Fom ]****** | |
// Cosas que queremos que haga según se inicie el Form | |
//------------------------------------------------------------------------------ | |
begin | |
{Cosas que queremos que haga según se inicie el Form} | |
end; | |
procedure TFEntradas.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 TFEntradas.RDMotivosClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Pulsamos en RDMotivos ]**** | |
//------------------------------------------------------------------------------ | |
begin //Si pulsamos en otros ponemos visible el enOtros, si no lo ocultamos | |
if RDMotivos.ItemIndex=5 then | |
begin | |
GBOtros.Visible:=true; | |
ENOtros.Text:=''; | |
ENOtros.SetFocus; | |
end else GBOtros.Visible:=False; | |
end; | |
procedure TFEntradas.SbBorrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Borrar el Actual Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin //Cambiar por el mensaje elegido | |
if (MessageBox(0, '¿Esta seguro de eliminar el registro actual?', | |
'Eliminar Registro', MB_ICONSTOP or MB_YESNO or MB_DEFBUTTON2) = ID_No) then abort | |
else begin | |
DSPrincipal.DataSet.Delete; | |
ShowMessage('El registro ha sido eliminado'); | |
IBT.CommitRetaining; | |
end; | |
end; | |
procedure TFEntradas.SBBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBBuscar.Visible:=True; | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFEntradas.SBCancelarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cancelar Proceso]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.State in [dsInsert,dsEdit] then DSPrincipal.DataSet.Cancel; | |
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
GBModificado.Visible:=False; | |
end; | |
procedure TFEntradas.SBConfirmarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Grabar datos ]****** | |
//------------------------------------------------------------------------------ | |
var VarBGrabar,VarBModificado:Boolean; | |
VarSCadenaTex:string; | |
VarICantidadAnt2,VarIExitenciasAnte:Integer; | |
begin | |
try | |
if (DBNLote.Text<>'') and (DBNCodProd.Text<>'') and (DBNCodEmpleado.Text<>'') and (DBNCantidad.Text<>'') and (DBNFecha.Text<>'') then | |
begin | |
VarBGrabar:=False; //PAra no grabar si no cumple las condiciones | |
if DsPrincipal.DataSet.State in [dsEdit] then //Si esta en edición | |
begin | |
case RDMotivos.ItemIndex of //Opcional crear una tabla de Partes y hacer un parte con el mótivo más detallado | |
0:begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='Error introducción'; | |
end; | |
1:begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='Error contabilización'; | |
end; | |
2:begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='Rotura'; | |
end; | |
3:begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='Uso Interno'; | |
end; | |
4:begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='Uso fabricación'; //Puede usarse para la creación de otro producto llamado también uso derivado | |
end; | |
5:begin | |
if ENOtros.Text<>'' then | |
begin | |
VarBGrabar:=True; | |
VarSCadenaTex:='OTROS [ '+ENOtros.Text+' ]'; | |
end else | |
begin | |
ShowMessage('Debe introducir un mótivo por el que modifica la entrada, para grabar'); | |
ENOtros.SetFocus; | |
end; | |
end; | |
end; | |
if VarBGrabar then | |
begin | |
Memo1.Lines.Clear; | |
Memo1.Lines.Add(#13+#10+'Fecha: '+DateToStr(Now)+' Hora: '+TimeToStr(Now)+ ' Cambio realizado por '+Usuario+' Motivo de la modificación : '+VarSCadenaTex); | |
if VarSEntLote<>DBNLote.Text then | |
begin | |
VarBModificado:=True; | |
Memo1.Lines.Add(#13+#10+'Ha cambia do el Lote [ '+VarSEntLote+' ] por el lote [ '+DBNLote.Text+' ]'); | |
end; | |
if VarSEntCodProd<>DBNCodProd.Text then | |
begin | |
VarBModificado:=True; | |
Memo1.Lines.Add(#13+#10+'Ha cambia do el código de porducto [ '+VarSEntCodProd+' ] por el código [ '+DBNCodProd.Text+' ]'); | |
end; | |
if VarSEntCodEmple<>DBNCodEmpleado.Text then | |
begin | |
VarBModificado:=True; | |
Memo1.Lines.Add(#13+#10+'Ha cambia do el código de empleado [ '+VarSEntCodEmple+' ] por el código [ '+DBNCodEmpleado.Text+' ]'); | |
end; | |
if IntToStr(VarIEntCantidad)<>DBNCantidad.Text then | |
begin | |
VarBModificado:=True; | |
Memo1.Lines.Add(#13+#10+'Ha cambia do la cantidad [ '+IntToStr(VarIEntCantidad)+' ] por la cantidad [ '+DBNCantidad.Text+' ]'); | |
end; | |
if DateToStr(VarDEntFecha)<>DBNFecha.Text then | |
begin | |
VarBModificado:=True; | |
Memo1.Lines.Add(#13+#10+'Ha cambia do la fecha [ '+DateToStr(VarDEntFecha)+' ] por la fecha [ '+DBNFecha.Text+' ]'); | |
end; | |
if VarBModificado then | |
begin | |
if DSNotas.DataSet.Locate('NOMBREMODULO;CODIGO;DESCRIPCION',VarArrayOf(['ENTRADAS',DsPrincipal.DataSet.FieldByName('ID').AsString,'MODIFICACION']),[loCaseInsensitive,loPartialKey]) then | |
begin | |
DM.IBDNOTAS.Edit; | |
end else | |
begin | |
DM.IBDNOTAS.Insert; | |
DM.IBDNOTASNOMBREMODULO.Value:='ENTRADAS'; | |
DM.IBDNOTASCODIGO.value:=DsPrincipal.DataSet.FieldByName('ID').AsString; | |
DM.IBDNOTASDESCRIPCION.Value:='MODIFICACION'; | |
end; | |
DM.IBDNOTASNOTAS.Value:=DM.IBDNOTASNOTAS.Value+Memo1.Lines.Text; | |
DM.IBDNOTAS.Post | |
end; | |
end; | |
end else VarBGrabar:=True; | |
if VarBGrabar then | |
begin | |
DsPrincipal.DataSet.Post; | |
if DSStock.DataSet.Locate('CODIGOPRODUCTO;LOTE',VarArrayOf([DBNCodProd.Text,DBNLote.Text]),[loCaseInsensitive,loPartialKey]) then | |
begin | |
VarICantidadAnt2:=DM.IBDSTOCKCANTIDADDEENTRADA.Value; | |
VarIExitenciasAnte:=DM.IBDSTOCKEXISTENCIAS.value; | |
DM.IBDSTOCK.edit; | |
//Si es igual no cambiamos ni cantidad ni existencias, en caso contrarioi tenemos que ver si hay que sumar o restar | |
if (VarICantidadAnterior-strtoint(DBNCantidad.Text))>0 then //Si las entradas son menores que antes nos da en positivo y restamos | |
begin | |
DM.IBDSTOCKEXISTENCIAS.Value:=VarICantidadAnt2-(VarICantidadAnterior-strtoint(DBNCantidad.Text)); | |
DM.IBDSTOCKCANTIDADDEENTRADA.Value:= VarIExitenciasAnte-(VarICantidadAnterior-strtoint(DBNCantidad.Text)); | |
end else | |
begin | |
if (VarICantidadAnterior-strtoint(DBNCantidad.Text))<0 then //Si las entradas son mayores que antes nos da en negativo y sumamos | |
begin | |
DM.IBDSTOCKEXISTENCIAS.Value:=VarICantidadAnt2+(strtoint(DBNCantidad.Text)-VarICantidadAnterior); | |
DM.IBDSTOCKCANTIDADDEENTRADA.Value:= VarIExitenciasAnte+(strtoint(DBNCantidad.Text)-VarICantidadAnterior); | |
end | |
end; | |
end else | |
begin //Si no encuentra | |
DM.IBDSTOCK.Insert; | |
DM.IBDSTOCKEXISTENCIAS.Value:=StrToInt(DBNCantidad.Text); | |
DM.IBDSTOCKCANTIDADDEENTRADA.Value:=StrToInt(DBNCantidad.Text); | |
DM.IBDSTOCKCADUCIDAD.value:=StrToDate(DBNCaducidad.Text); | |
end; | |
DM.IBDSTOCKLOTE.Value:=DBNLote.Text; | |
DM.IBDSTOCKFECHAENTRADA.Value:=StrToDate(DBNFecha.Text); | |
DM.IBDSTOCKACTIVO.Value:=DSIBQLOTES.DataSet.FieldByName('ACTIVO').Value; | |
DM.IBDSTOCKCODIGOPRODUCTO.Value:=DBNCodProd.Text; | |
DM.IBDSTOCK.Post; | |
IBT.CommitRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
GBModificado.Visible:=False; | |
end | |
end else ShowMessage('Todos los campos deben ser completados'); | |
except | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ UEntradas ] Modulo:[ Grabar ]' + Chr(13) + Chr(13) | |
+ 'Clase de error: ' + E.ClassName + Chr(13) + Chr(13) | |
+ 'Mensaje del error:' + E.Message+Chr(13) + Chr(13) | |
+ ' '+Chr(13) + Chr(13) | |
+ 'El proceso ha quedado interrumpido'); | |
if DsPrincipal.DataSet.State in [dsInsert,dsEdit] then DSPrincipal.DataSet.Cancel; | |
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
GBModificado.Visible:=False; | |
end; | |
end; | |
end; | |
procedure TFEntradas.SBImprimirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Imprimir ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBImprimir.Visible:=True; | |
end; | |
procedure TFEntradas.SBMas1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar un registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Next; | |
end; | |
procedure TFEntradas.SBMasXClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value); | |
end; | |
procedure TFEntradas.SBMenos1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Retroceder 1 registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Prior; | |
end; | |
procedure TFEntradas.SBMenosxClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************[ Retroceder x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value); | |
end; | |
procedure TFEntradas.SbModificarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Editar el actual registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.IsEmpty<>true then | |
begin | |
//Carganos las diferente variables | |
VarSEntLote:=DBNLote.Text; | |
VarSEntCodProd:=DBNCodProd.Text; | |
VarSEntCodEmple:=DBNCodEmpleado.Text; | |
VarIEntCantidad:=DBNCantidad.Field.Value; | |
VarDEntFecha:=DBNFecha.Field.Value; | |
VarICantidadAnterior:=StrToInt(DBNCantidad.Text); | |
DSPrincipal.DataSet.Edit; | |
GBModificado.Visible:=True; | |
RDMotivos.ItemIndex:=5; | |
GBOtros.Visible:=True; | |
ENOtros.Text:=''; | |
DBNLote.SetFocus; | |
end else ShowMessage('No hay tregistros disponibles para editar') | |
end; | |
procedure TFEntradas.SbNuevoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Creamos un nuevo registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Insert; | |
VarICantidadAnterior:=0; | |
DBNLote.SetFocus; | |
end; | |
procedure TFEntradas.SBPrimeroClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al Primer Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.First; | |
end; | |
procedure TFEntradas.SBUltimoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al último registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Last; | |
end; | |
procedure TFEntradas.SB_SalirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Salir Del Form ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
FEntradas.Close; | |
end; | |
procedure TFEntradas.SPBCBuscarFPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ Buscar Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSTabla:='LOTES'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='ENTRADASL'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
procedure TFEntradas.SPBCNuevaFPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//************************************************************[ Nuevo Lote ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FLotes.Show; | |
FLotes.SbNuevoClick(Sender); | |
end; | |
procedure TFEntradas.SpeedButtonBC1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Nuevo Artículo ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FArticulos.Show; | |
FArticulos.SbNuevoClick(Sender); | |
end; | |
procedure TFEntradas.SpeedButtonBC2Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ Buscar Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSTabla:='ARTICULOS'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='ENTRADASA'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
procedure TFEntradas.SpeedButtonBC3Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Nuevo Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FEmpleados.Show; | |
FEmpleados.SbNuevoClick(Sender); | |
end; | |
procedure TFEntradas.SpeedButtonBC4Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ Buscar Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSTabla:='EMPLEADOS'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='ENTRADASE'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
procedure TFEntradas.Timer1Timer(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ El evento del Timer ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
SBBarraStatus.Panels[2].Text:=TimeToStr(now); | |
if SBBarraStatus.Panels[1].Text<>DateToStr(Now) then SBBarraStatus.Panels[1].Text:=DateToStr(Now); | |
end; | |
procedure TFEntradas.VerNota; | |
//------------------------------------------------------------------------------ | |
//***************************************************************[ VerNota ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
if FEntradas.Active then | |
begin | |
if not (DsPrincipal.DataSet.State in [dsEdit,dsInsert]) then | |
begin | |
DBIBMemo1.Lines.Clear; | |
if DSNotas.DataSet.Locate('NOMBREMODULO;CODIGO;DESCRIPCION',VarArrayOf(['ENTRADAS',DsPrincipal.DataSet.FieldByName('ID').AsString,'MODIFICACION']),[loCaseInsensitive,loPartialKey]) then | |
begin | |
ActQuery(IBQNotas,'SELECT * FROM NOTAS WHERE (NOTAS.NOMBREMODULO = '+QuotedStr('ENTRADAS')+ | |
') AND(NOTAS.CODIGO = '+QuotedStr(DsPrincipal.DataSet.FieldByName('ID').AsString)+ | |
') AND(NOTAS.DESCRIPCION = '+QuotedStr('MODIFICACION')+')'); | |
if IBQNotas.IsEmpty then DBIBMemo1.Lines.Clear; //Nos aseguramos que no queden testos que nos confundan | |
end; | |
end else if (DsPrincipal.DataSet.State in [dsInsert]) then DBIBMemo1.Lines.Clear; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment