Created
June 23, 2013 11:58
-
-
Save anonymous/5844768 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 ULotes; | |
{$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, IBCustomDataSet, IBQuery, StrUtils; | |
type | |
TFLotes = 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; | |
Timer1: TTimer; | |
Label1: TLabel; | |
Label2: TLabel; | |
Label3: TLabel; | |
Label4: TLabel; | |
Label5: TLabel; | |
Label6: TLabel; | |
Label8: TLabel; | |
DBNCodFabricable: TDBNewEditJL; | |
DBNCodEmpleado: TDBNewEditJL; | |
DBNLote: TDBNewEditJL; | |
DBNFecha: TDBNewEditJL; | |
DBNCaducidad: TDBNewEditJL; | |
DBNCantidad: TDBNewEditJL; | |
DBNMaestro: TDBNewEditJL; | |
DBICheckActivo: TDBIBCheckbox; | |
SPBCNuevaFP: TSpeedButtonBC; | |
SPBCBuscarFP: TSpeedButtonBC; | |
SpeedButtonBC1: TSpeedButtonBC; | |
SpeedButtonBC2: TSpeedButtonBC; | |
DBText1: TDBText; | |
DBText2: TDBText; | |
GroupBox1: TGroupBox; | |
Label7: TLabel; | |
IBQFABRICABLE: TIBQuery; | |
IBQEMPLEADOS: TIBQuery; | |
DSConfi: TDataSource; | |
DSIBQFABRICABLE: TDataSource; | |
DSIBQEMPLEADOS: TDataSource; | |
RGCaducos: TRadioGroup; | |
Label9: TLabel; | |
Label10: TLabel; | |
DBIBMemo1: TDBIBMemo; | |
IBQNotas: TIBQuery; | |
DSIBQNOTAS: TDataSource; | |
DSNotas: TDataSource; | |
PanelAux: TNewPanelDB; | |
SBCCambiarActivo: TSpeedButtonBC; | |
SBCLoteDerivado: TSpeedButtonBC; | |
GBImprimir: TGroupBoxJL; | |
SpeedButtonBC3: TSpeedButtonBC; | |
CBVistaPrevia: TCheckBox; | |
CBVerDialogo: TCheckBox; | |
BCerrarIMP: TButton; | |
IBQLotes: TIBQuery; | |
DSIBQLOTES: TDataSource; | |
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 SBCCambiarActivoClick(Sender: TObject); | |
Function SacarLote(Text:string;Modo:Integer):String; | |
procedure DBNCodFabricableChange(Sender: TObject); | |
procedure DBNCodEmpleadoChange(Sender: TObject); | |
procedure RGCaducosClick(Sender: TObject); | |
procedure SPBCNuevaFPClick(Sender: TObject); | |
procedure SPBCBuscarFPClick(Sender: TObject); | |
procedure SpeedButtonBC2Click(Sender: TObject); | |
procedure SpeedButtonBC1Click(Sender: TObject); | |
procedure DBNLoteChange(Sender: TObject); | |
procedure SBCLoteDerivadoClick(Sender: TObject); | |
procedure ActualizarEtiquetaUltimoLote; | |
procedure DBNCodEmpleadoExit(Sender: TObject); | |
procedure DBNFechaExit(Sender: TObject); | |
procedure DBNCantidadKeyPress(Sender: TObject; var Key: Char); | |
procedure FormShow(Sender: TObject); | |
procedure DBGNoEnableDrawColumnCell(Sender: TObject; const Rect: TRect; | |
DataCol: Integer; Column: TColumn; State: TGridDrawState); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
FLotes: TFLotes; | |
IBT:TIBTransaction; | |
implementation | |
{$R *.dfm} | |
uses UDM, UMENU, Fun, FUN_DBGRID, UFabricables,UEmpleados,UbusquedaFP,UNotas; | |
procedure TFLotes.ActualizarEtiquetaUltimoLote; | |
//------------------------------------------------------------------------------ | |
//******************************************[ ActualizarEtiquetaUltimoLote ]**** | |
//------------------------------------------------------------------------------ | |
var Year, Month, Day, Hour, Min, Sec, Msec: Word; | |
VarILargoCadena:Integer; | |
begin | |
DecodeDate(Now, Year, Month, Day); | |
if DM.IBDCONFI.FieldByName('USARSERIEYEAR').Value='S' then | |
begin //AnsiRightStr(IntToStr(Year), 2); //Estraemos sólo los 2 últimos digitos del año que usaremos de serial | |
Label7.Caption:= AnsiRightStr(IntToStr(Year), 2)+ceros(DM.IBDCONFI.FieldByName('NUMEROLOTE').Value,(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-2)); | |
end else | |
begin | |
VarILargoCadena:=Length(Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)); | |
Label7.Caption:=Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)+ceros(DM.IBDCONFI.FieldByName('NUMEROLOTE').Value,(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-VarILargoCadena)); | |
end; | |
end; | |
procedure TFLotes.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 TFLotes.BCerrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cerrar Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
BLimpiarClick(Sender); | |
GBBuscar.Visible:=False; | |
end; | |
procedure TFLotes.BCerrarIMPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cerrar Imrprimir ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBImprimir.Visible:=False; | |
end; | |
procedure TFLotes.BLimpiarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Limpia la busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
Ebusqueda.Text:=''; | |
BBuscarClick(Sender); | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFLotes.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 TFLotes.DBNCantidadKeyPress(Sender: TObject; var Key: Char); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ DBNCantidad KeyPress ]**** | |
// HE detectado varios fallos en el modo OnlyNumberDouble, por lo que lo hago de | |
//La siguiente manera hasta que lo corriga | |
//------------------------------------------------------------------------------ | |
function HaySeparador(const S:string):Boolean; | |
//------------------------------------------------------------------------------ | |
//**********************************************************[ HaySeparador ]**** | |
// Tanto la función como el código de este evento son del compañero Wilson | |
// bajado de http://www.delphiaccess.com/forum/general-8/como-hacer-para-que-un-edit-solo-acepte-numeros-de-tipo-float/ | |
//------------------------------------------------------------------------------ | |
var i,n :integer; | |
Separador : Char; | |
begin | |
n:= 0; | |
Result := False; | |
Separador := SysUtils.DecimalSeparator; | |
for I := 1 to Length(S) do | |
if S[i] = Separador then | |
n:= n+1; | |
Result := n >0; | |
end; | |
var Separador : Char; | |
begin | |
Separador := SysUtils.DecimalSeparator; | |
if (Key = Separador) and (Length(DBNCantidad.Text) = 0) then | |
begin | |
key := char(0); | |
showmessage('Caracter incorrecto'); | |
Exit; | |
end; | |
if (Key = Separador) and HaySeparador(DBNCantidad.Text) then | |
begin | |
key := char(0); | |
showmessage('Ya hay separador'); | |
Exit; | |
end; | |
if not (key in['0'..'9',Separador,#8]) then | |
begin | |
key := char(0); | |
showmessage('Caracter invalido'); | |
end; | |
end; | |
procedure TFLotes.DBNCodEmpleadoChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cambia el Empleado ]**** | |
// Para mostrar el nombre del Empleado | |
//------------------------------------------------------------------------------ | |
begin | |
if FLotes.Active then | |
begin | |
ActQuery(IBQEMPLEADOS,'SELECT * FROM EMPLEADOS WHERE (EMPLEADOS.CODIGO = '+QuotedStr(DBNCodEmpleado.Text)+')'); | |
end; | |
end; | |
procedure TFLotes.DBNCodEmpleadoExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Salir de Empleados ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
DBNCodEmpleadoChange(Sender); //Nos aseguramos de que paraezca el nombre | |
DBNFecha.SetFocus; //PAsamos el Foco ala Fecha | |
end; | |
procedure TFLotes.DBNCodFabricableChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************[ Cambia el Fabricable ]**** | |
// Para mostrar el nombre del fabricable | |
//------------------------------------------------------------------------------ | |
begin | |
if FLotes.Active then | |
begin | |
ActQuery(IBQFABRICABLE,'SELECT * FROM FABRICABLES WHERE (FABRICABLES.CODIGO = '+QuotedStr(DBNCodFabricable.Text)+')'); | |
end; | |
end; | |
procedure TFLotes.DBNFechaExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Salir de la Fecha ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
DBNCantidad.SetFocus; //Pasamos el Foco a La Cantidad | |
end; | |
procedure TFLotes.DBNLoteChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Cambia el Empleado ]**** | |
// Para mostrar el nombre del Empleado | |
//------------------------------------------------------------------------------ | |
begin | |
if FLotes.Active then | |
begin | |
ActQuery(IBQNotas,'SELECT * FROM NOTAS WHERE (NOTAS.NOMBREMODULO = '+QuotedStr('LOTES')+ | |
') AND (NOTAS.CODIGO = '+QuotedStr(DBNLote.Text)+ | |
') AND (NOTAS.DESCRIPCION = '+QuotedStr('CAMBIOS')+') '); | |
if IBQNotas.IsEmpty then DBIBMemo1.Lines.Clear; //Nos aseguramos que no queden testos que nos confundan | |
end; | |
end; | |
procedure TFLotes.EbusquedaChange(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************[ Mientras se escribe en busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
BBuscarClick(sender); | |
end; | |
procedure TFLotes.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; | |
PanelAux.ColorNotActive:=COLORPANELACT; | |
PanelAux.ActiveColor:=COLORPANELNOACT; | |
ActualizarEtiquetaUltimoLote; | |
// Mostramos los datos de los cuarres al verse y no solo al cambiar | |
DBIBMemo1.Lines.Clear; | |
DBNCodFabricableChange(SEnder); | |
DBNCodEmpleadoChange(Sender); | |
DBNLoteChange(Sender); | |
end; | |
procedure TFLotes.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(IBQFABRICABLE); | |
QuerryOC(IBQEMPLEADOS); | |
QuerryOC(IBQLotes); | |
QuerryOC(IBQNotas); | |
end; | |
procedure TFLotes.FormCreate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************[ Al Crearse el Fom ]****** | |
// Cosas que queremos que haga según se inicie el Form | |
//------------------------------------------------------------------------------ | |
begin | |
IBT:=DM.IBTransaction1; | |
{Cosas que queremos que haga según se inicie el Form} | |
end; | |
procedure TFLotes.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 TDBNewEditJL) | |
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 TFLotes.FormShow(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************************[ OnShow ]**** | |
// Mostramos los datos de los cuarres al verse y no solo al cambiar | |
//------------------------------------------------------------------------------ | |
begin | |
DBIBMemo1.Lines.Clear; | |
DBNCodFabricableChange(SEnder); | |
DBNCodEmpleadoChange(Sender); | |
DBNLoteChange(Sender); | |
end; | |
procedure TFLotes.RGCaducosClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************[ Calculos de la cadudidad ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
case RGCaducos.ItemIndex of | |
1:if DBNFecha.Text<>'' then DBNCaducidad.Text:=DateToStr((StrToDate(DBNFecha.Text)+183)); //6 Meses | |
2:if DBNFecha.Text<>'' then DBNCaducidad.Text:=DateToStr((StrToDate(DBNFecha.Text)+365)); //1 Año | |
3:if DBNFecha.Text<>'' then DBNCaducidad.Text:=DateToStr((StrToDate(DBNFecha.Text)+730)); //2 Años | |
end; | |
DBNCantidad.SetFocus; //Pasamos el Foco a La Cantidad | |
end; | |
function TFLotes.SacarLote(Text:string;Modo:Integer):String; | |
//------------------------------------------------------------------------------ | |
//*************************************************************[ SacarLote ]**** | |
// nos permite sacar la parte del númerador de la serie, se usa varias veces | |
//------------------------------------------------------------------------------ | |
var VarILargoSerie:Integer; | |
begin | |
case Modo of | |
0:begin | |
if DM.IBDCONFI.FieldByName('USARSERIEYEAR').Value='S' then | |
Result:=Copy(Text,3,DM.IBDCONFI.FieldByName('LARGOLOTE').AsInteger) | |
else | |
begin | |
VarILargoSerie:=Length(TRIM(DM.IBDCONFI.FieldByName('SERIE3').Value)); | |
Result:=Copy(Text,VarILargoSerie+1,DM.IBDCONFI.FieldByName('LARGOLOTE').AsInteger) | |
end; | |
end; | |
1:begin | |
Result:=Copy(Text,3,DM.IBDCONFI.FieldByName('LARGOLOTE').AsInteger); | |
end; | |
end; | |
end; | |
procedure TFLotes.SbBorrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Borrar el Actual Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin //Cambiar por el mensaje elegido | |
if (MessageBox(0, '¿Esta seguro de eliminar el registro actual?, Eliminar este registro afectara al resto del programa', //Aqui no se porque me manda la última comilla simple y la coma a la linea de abajo, por favor subir al final de la linea anterior | |
'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 TFLotes.SBBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Busqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBBuscar.Visible:=True; | |
Ebusqueda.SetFocus; | |
end; | |
procedure TFLotes.SBCancelarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cancelar Proceso]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Cancel; | |
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
end; | |
procedure TFLotes.SBConfirmarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Grabar datos ]****** | |
//------------------------------------------------------------------------------ | |
var VarBExiste:Boolean; | |
begin | |
try | |
VarBExiste:=False; | |
if (DBNCodFabricable.Text<>'') and (DBNCodEmpleado.Text<>'') and (DBNFecha.Text<>'') and (DBNCantidad.Text<>'') then | |
begin | |
if DsPrincipal.DataSet.State in [dsInsert] then | |
begin | |
ActQuery(IBQLotes,'select * from LOTES'); | |
if not DSIBQLOTES.DataSet.Locate('LOTE',DBNLote.Text,[loCaseInsensitive,loPartialKey]) then //Comprobar que no exista | |
begin //Grabamos el nuevo lote | |
DM.IBDCONFI.Edit; | |
DM.IBDCONFINUMEROLOTE.Value:=IntToStr(SoloInteger(SacarLote(DBNLote.Text,0))); //Para que nos devuelva sólo el n´ñumero sin la cerie ni los ceros | |
DM.IBDCONFI.post | |
end else VarBExiste:=True; | |
end; | |
if VarBExiste=false then | |
begin | |
DSPrincipal.DataSet.Post; | |
IBT.CommitRetaining; //Confirmamos el grabado de todos los cambios | |
ActualizarEtiquetaUltimoLote;// actualizamos la etiqueta con el último número de lote | |
end else ShowMessage('Este lote ya existe'); | |
end else ShowMessage('Debe dejar rellenos los campos, Código de Fabricable, Código de Empleado, Fecha y Cantidad'); | |
except | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ ULotes ] 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 | |
end; | |
end; | |
end; | |
procedure TFLotes.SBImprimirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Imprimir ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
GBImprimir.Visible:=True; | |
end; | |
procedure TFLotes.SBMas1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar un registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Next; | |
end; | |
procedure TFLotes.SBMasXClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*************************************************[ Avanzar x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value); | |
end; | |
procedure TFLotes.SBMenos1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Retroceder 1 registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Prior; | |
end; | |
procedure TFLotes.SBMenosxClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************[ Retroceder x Registros ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value); | |
end; | |
procedure TFLotes.SbModificarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Editar el actual registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.IsEmpty<>true then | |
begin | |
DSPrincipal.DataSet.Edit; | |
DBNCodEmpleado.SetFocus | |
end else ShowMessage('No hay tregistros disponibles para editar') | |
end; | |
procedure TFLotes.SbNuevoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Creamos un nuevo registro ]****** | |
//------------------------------------------------------------------------------ | |
var VarILargoCadena,year,VarIlote:Integer; | |
begin | |
DSPrincipal.DataSet.Insert; | |
year:=Ano(now); | |
VarIlote:=StrToInt(SacarLote(Label7.Caption,0))+1; | |
if DM.IBDCONFI.FieldByName('USARSERIEYEAR').Value='S' then | |
begin //AnsiRightStr(IntToStr(Year), 2); //Estraemos sólo los 2 últimos digitos del año que usaremos de serial | |
DBNLote.Text:= AnsiRightStr(IntToStr(Year), 2)+ceros(IntToStr(VarIlote),(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-2)); | |
end else | |
begin | |
VarILargoCadena:=Length(Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)); | |
DBNLote.Text:=Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)+ceros(IntToStr(VarIlote),(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-VarILargoCadena)); | |
end; | |
DBICheckActivo.Checked:=True; | |
DBNCodFabricable.SetFocus; | |
end; | |
procedure TFLotes.SBPrimeroClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al Primer Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.First; | |
end; | |
procedure TFLotes.SBUltimoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ Ir al último registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Last; | |
end; | |
procedure TFLotes.SB_SalirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Salir Del Form ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
FLotes.Close; | |
end; | |
procedure TFLotes.SPBCBuscarFPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Buscar fabricable ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSTabla:='FABRICABLES'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='LOTESF'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
procedure TFLotes.SPBCNuevaFPClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Nuevo Fabricable ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
Fabricables.Show; | |
Fabricables.SbNuevoClick(Sender); | |
end; | |
procedure TFLotes.SpeedButtonBC1Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Nuevo Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
FEmpleados.Show; | |
FEmpleados.SbNuevoClick(Sender); | |
end; | |
procedure TFLotes.SpeedButtonBC2Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************************[ Buscar Empleado ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSTabla:='EMPLEADOS'; //Pertenece al formularios UFbusquedaFP | |
VarSNomMod:='LOTESE'; //Desde que modulo lo llamamos | |
FbusquedaFP.Show; | |
end; | |
procedure TFLotes.SBCCambiarActivoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Cambiar Activo ]**** | |
//------------------------------------------------------------------------------ | |
var InputStr:string; | |
begin | |
try | |
DsPrincipal.DataSet.Edit; ///Editamos el registro para hacer el cambio | |
if DBICheckActivo.Checked then DsPrincipal.DataSet.FieldByName('ACTIVO').Value:='N' | |
else DsPrincipal.DataSet.FieldByName('ACTIVO').Value:='S'; | |
DsPrincipal.DataSet.Post; | |
Case Application.MessageBox(pchar( 'Crear una nota con los motivos y la fecha del cambio'), pchar('Crear nota del cambio'), 1+48+256) of | |
1:begin //Aceptar | |
InputStr:=''; | |
InputQuery('Motivo del cambio ','Especifique el motivo del cambio en '+Chr(39)+'ACTIVO'+Chr(39), InputStr); | |
if InputStr<>'' then | |
begin | |
if DSNotas.DataSet.Locate('NOMBREMODULO;CODIGO;DESCRIPCION',VarArrayOf(['LOTES',DBNLote.Text,'CAMBIOS']),[loCaseInsensitive,loPartialKey]) then | |
begin | |
DM.IBDNOTAS.Edit; | |
end else | |
begin | |
DM.IBDNOTAS.Insert; | |
DM.IBDNOTASNOMBREMODULO.Value:='LOTES'; | |
DM.IBDNOTASCODIGO.value:=DBNLote.Text; | |
DM.IBDNOTASDESCRIPCION.Value:='CAMBIOS'; | |
end; | |
DM.IBDNOTASNOTAS.Value:=DM.IBDNOTASNOTAS.Value+#13+#10+'Fecha: '+DateToStr(Now)+' Hora: '+TimeToStr(Now)+ ' Cambio realizado por '+Usuario+' Motivo del cambio: '+InputStr; | |
DM.IBDNOTAS.Post | |
end; | |
IBQNotas.Close; | |
IbqNotas.open; | |
end; | |
end; | |
IBT.CommitRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
except | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ ULotes ] Modulo:[ Cambiar Activo ]' + 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; | |
end; | |
end; | |
end; | |
procedure TFLotes.SBCLoteDerivadoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Creamos un Lote derivado ]****** | |
//------------------------------------------------------------------------------ | |
var VarILargoCadena,year,VarIlote:Integer; | |
VarSLoteMAestro:string; | |
begin | |
VarSLoteMAestro:=DBNLote.Text; | |
DSPrincipal.DataSet.Insert; | |
year:=Ano(now); | |
VarIlote:=StrToInt(SacarLote(Label7.Caption,0))+1; | |
if DM.IBDCONFI.FieldByName('USARSERIEYEAR').Value='S' then | |
begin //AnsiRightStr(IntToStr(Year), 2); //Estraemos sólo los 2 últimos digitos del año que usaremos de serial | |
DBNLote.Text:= AnsiRightStr(IntToStr(Year), 2)+ceros(IntToStr(VarIlote),(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-2)); | |
end else | |
begin | |
VarILargoCadena:=Length(Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)); | |
DBNLote.Text:=Trim(DM.IBDCONFI.FieldByName('SERIE3').Value)+ceros(IntToStr(VarIlote),(DM.IBDCONFI.FieldByName('LARGOLOTE').Value-VarILargoCadena)); | |
end; | |
DBICheckActivo.Checked:=True; | |
DBNMaestro.Text:=VarSLoteMAestro; //Cambia con respecto a SBNuevo, en que controlamos el lote maestro | |
DBNCodFabricable.SetFocus; | |
end; | |
procedure TFLotes.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; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment