git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES/trunk@4 b68bf8ae-e977-074f-a058-3cfd71dd8f45
458 lines
12 KiB
ObjectPascal
458 lines
12 KiB
ObjectPascal
{
|
|
===============================================================================
|
|
Copyright (©) 2001. Rodax Software.
|
|
===============================================================================
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
|
|
bajo el que se suministra.
|
|
-----------------------------------------------------------------------------
|
|
Web: www.rodax-software.com
|
|
===============================================================================
|
|
Fecha primera versión: 13-05-2002
|
|
Versión actual: 1.0.0
|
|
Fecha versión actual: 13-05-2002
|
|
===============================================================================
|
|
Modificaciones:
|
|
|
|
Fecha Comentarios
|
|
---------------------------------------------------------------------------
|
|
===============================================================================
|
|
}
|
|
|
|
unit Instalador;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
|
StdCtrls, ExtCtrls, Db, IBCustomDataSet, Mask, DBCtrls, Buttons, ToolEdit,
|
|
IB, IBDatabase, RdxBarras, RdxBotones, RdxCampos, RdxMemo, RdxComboBox,
|
|
RdxCheckBox, RdxTitulos, RdxPaneles, Colores, Mensajes, Tipos,
|
|
RdxFrameInstaladores;
|
|
|
|
type
|
|
TfrInstalador = class(TRdxFrameInstaladores)
|
|
brDoble: TRdxBarraInferior;
|
|
brSimple: TRdxBarraInferior;
|
|
bAceptarSimple: TRdxBoton;
|
|
pnlDatos: TRdxPanel;
|
|
cDatos: TRdxCabecera;
|
|
eCodigo: TLabel;
|
|
eNombre: TLabel;
|
|
bAceptar: TRdxBoton;
|
|
bCancelar: TRdxBoton;
|
|
Nombre: TRdxDBEdit;
|
|
dsInstalador: TDataSource;
|
|
Codigo: TRdxDBEdit;
|
|
Titulo: TRdxPanelTituloOperacion;
|
|
Telefono: TRdxDBEdit;
|
|
eTelefono: TLabel;
|
|
procedure bSalirClick(Sender: TObject);
|
|
procedure bCancelarGuardarClick(Sender: TObject);
|
|
procedure CodigoExit(Sender: TObject);
|
|
procedure CodigoButtonClick(Sender: TObject);
|
|
procedure bAceptarClick(Sender: TObject);
|
|
protected
|
|
procedure activarModoAnadir; override;
|
|
procedure activarModoModificar; override;
|
|
procedure activarModoConsultar; override;
|
|
procedure activarModoEliminar; override;
|
|
function AnadirDatos : Boolean; override;
|
|
function ModificarDatos : Boolean; override;
|
|
function EliminarDatos : Boolean; override;
|
|
function CancelarAnadir : Boolean; override;
|
|
function CancelarModificar : Boolean; override;
|
|
function CancelarEliminar : Boolean; override;
|
|
procedure FreeContenido; override;
|
|
procedure BuscarInstalador; override;
|
|
function ComprobarDatos: Boolean; override;
|
|
public
|
|
constructor Create (AOwner : TComponent); override;
|
|
destructor Destroy; override;
|
|
published
|
|
property TablaInstaladores;
|
|
property CodigoInstalador;
|
|
end;
|
|
|
|
var
|
|
frInstalador: TfrInstalador;
|
|
|
|
implementation
|
|
|
|
{$R *.DFM}
|
|
uses
|
|
BaseDatos, TablaInstaladores, Instaladores, StrFunc,
|
|
Excepciones, IBErrorCodes, Configuracion, Literales;
|
|
|
|
constructor TfrInstalador.Create (AOwner : TComponent);
|
|
begin
|
|
inherited Create(AOwner);
|
|
Entidad := entInstalador;
|
|
ConfigurarFrame(Self, Self.Entidad);
|
|
|
|
BaseDatos := dmBaseDatos.BD;
|
|
Transaccion := dmBaseDatos.Transaccion;
|
|
TablaInstaladores := TIBDataSet.Create(Self);
|
|
dsInstalador.DataSet := TablaInstaladores;
|
|
with TablaInstaladores do
|
|
begin
|
|
Database := BaseDatos;
|
|
Transaction := Transaccion;
|
|
SelectSQL.Assign(dmTablaInstaladores.sqlConsultar);
|
|
InsertSQL.Assign(dmTablaInstaladores.sqlInsertar);
|
|
ModifySQL.Assign(dmTablaInstaladores.sqlModificar);
|
|
DeleteSQL.Assign(dmTablaInstaladores.sqlEliminar);
|
|
RefreshSQL.Assign(dmTablaInstaladores.sqlConsultar);
|
|
end;
|
|
end;
|
|
|
|
destructor TfrInstalador.Destroy;
|
|
begin
|
|
TablaInstaladores.Close;
|
|
TablaInstaladores.UnPrepare;
|
|
TablaInstaladores.Free;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfrInstalador.BuscarInstalador;
|
|
begin
|
|
if Transaccion = NIL then
|
|
exit;
|
|
|
|
try
|
|
TablaInstaladores.Close;
|
|
|
|
// Buscar la fila a tratar si es necesario
|
|
if not VarIsNull(CodigoInstalador) then
|
|
TablaInstaladores.Params.ByName('CODIGO').AsString := CodigoInstalador;
|
|
|
|
TablaInstaladores.Prepare;
|
|
TablaInstaladores.Open;
|
|
except
|
|
on E : EIBError do begin
|
|
VerMensaje(E.Message);
|
|
end;
|
|
on E : EDatabaseError do begin
|
|
VerMensaje(E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.FreeContenido;
|
|
begin
|
|
if (ContenidoModal is TRdxFrameInstaladores) then
|
|
begin
|
|
CodigoInstalador := (ContenidoModal as TRdxFrameInstaladores).CodigoInstalador;
|
|
ActivarModo;
|
|
end;
|
|
inherited FreeContenido;
|
|
end;
|
|
|
|
procedure TfrInstalador.CodigoExit(Sender: TObject);
|
|
begin
|
|
{ No tendria sentido comprobar si el codigo es correcto o no ya que no damos la
|
|
posibilidad de introducirmanualmente el codigo de instalador
|
|
|
|
if Modo <> Anadir then
|
|
exit;
|
|
if (Length(Codigo.Text) = 0) then
|
|
Codigo.Field.AsString := dmTablaInstaladores.darNuevoCodigo;
|
|
|
|
if (dmTablaInstaladores.validarCodigo(Codigo.Text)) then begin
|
|
Codigo.Field.asString := dmTablaInstaladores.formatearCodigo(Codigo.Text);
|
|
if (dmTablaInstaladores.existeInstalador(Codigo.Text)) then begin
|
|
VerMensajeFmt(msgInsCodInstRepetido, [Codigo.Text]);
|
|
Codigo.SetFocus;
|
|
end;
|
|
end
|
|
else begin
|
|
VerMensajeFmt(msgInsCodInstIncorrecto, [Codigo.Text]);
|
|
Codigo.SetFocus;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
function TfrInstalador.AnadirDatos : Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaInstaladores.Post;
|
|
TablaInstaladores.ApplyUpdates;
|
|
dmTablaInstaladores.incrementarCodigo;
|
|
FCodigoInstalador := TablaInstaladores.FieldByName('CODIGO').AsString;
|
|
Commit;
|
|
TablaInstaladores.CachedUpdates := False;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do begin
|
|
if E.IBErrorCode = isc_unique_key_violation then begin
|
|
VerMensajeFmt(msgInsCodInsRepetido, [Codigo.Field.AsString]);
|
|
TablaInstaladores.Edit;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrInstalador.ModificarDatos : Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaInstaladores.Post;
|
|
Commit;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrInstalador.EliminarDatos : Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaInstaladores.Delete;
|
|
Commit;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : VerMensajeFmt(msgInsBloqueado, [Codigo.Field.AsString]);
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TfrInstalador.activarModoAnadir;
|
|
begin
|
|
dsInstalador.AutoEdit := True;
|
|
Telefono.VerBoton := False;
|
|
try
|
|
TablaInstaladores.Close;
|
|
TablaInstaladores.CachedUpdates := True;
|
|
TablaInstaladores.Open;
|
|
TablaInstaladores.Insert;
|
|
Codigo.Field.asString := dmTablaInstaladores.darNuevoCodigo;
|
|
Visible := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.activarModoModificar;
|
|
begin
|
|
dsInstalador.AutoEdit := True;
|
|
Telefono.VerBoton := True;
|
|
try
|
|
TablaInstaladores.Open;
|
|
if TablaInstaladores.RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgInsNoExiste, [CodigoInstalador]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
TablaInstaladores.Edit;
|
|
TablaInstaladores.Post;
|
|
TablaInstaladores.Edit;
|
|
Visible := True;
|
|
except
|
|
on E : EIBError do
|
|
begin
|
|
case E.IBErrorCode of
|
|
isc_lock_conflict : begin
|
|
VerMensajeFmt(msgInsBloqueado, [CodigoInstalador]);
|
|
CancelarModificar;
|
|
CloseFrame;
|
|
Exit;
|
|
end
|
|
else
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.activarModoConsultar;
|
|
begin
|
|
dsInstalador.AutoEdit := False;
|
|
Telefono.VerBoton := True;
|
|
try
|
|
TablaInstaladores.Open;
|
|
if TablaInstaladores.RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgInsNoExiste, [CodigoInstalador]);
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
TablaInstaladores.Cancel;
|
|
Visible := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.activarModoEliminar;
|
|
begin
|
|
dsInstalador.AutoEdit := False;
|
|
Telefono.VerBoton := True;
|
|
try
|
|
TablaInstaladores.Open;
|
|
if TablaInstaladores.RecordCount = 0 then
|
|
begin
|
|
VerMensajeFmt(msgInsNoExiste, [CodigoInstalador]);
|
|
CancelarEliminar;
|
|
CloseFrame;
|
|
Exit;
|
|
end;
|
|
TablaInstaladores.Cancel;
|
|
Visible := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.CodigoButtonClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if (TratarCambios = IDCANCEL) then
|
|
exit;
|
|
{ Esto es porque en modo 'Modificar' hacemos un cambio y pulsamos
|
|
este botón se cierra la tabla y si en el frame hijo (el del grid) damos
|
|
a cancelar, FCodigoArticulo es NULL y da error al activar modo porque
|
|
no se inicializa los parámetros de la sql. Lo hace BuscarArticulo. }
|
|
if not TablaInstaladores.Active then
|
|
BuscarInstalador;
|
|
ContenidoModal := TfrInstaladores.Create(Self);
|
|
end;
|
|
|
|
procedure TfrInstalador.bAceptarClick(Sender: TObject);
|
|
begin
|
|
if (RealizarOperacion) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
function TfrInstalador.CancelarAnadir: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
TablaInstaladores.CancelUpdates;
|
|
RollBack;
|
|
TablaInstaladores.CachedUpdates := False;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrInstalador.CancelarEliminar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
function TfrInstalador.CancelarModificar: Boolean;
|
|
begin
|
|
Result := False;
|
|
try
|
|
RollBack;
|
|
TablaInstaladores.Close;
|
|
Result := True;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.bSalirClick(Sender: TObject);
|
|
begin
|
|
try
|
|
Rollback;
|
|
CloseFrame;
|
|
except
|
|
on E : EIBError do
|
|
TratarExcepcion(E);
|
|
on E : Exception do
|
|
TratarExcepcion(E);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrInstalador.bCancelarGuardarClick(Sender: TObject);
|
|
begin
|
|
if (TratarCambios = IDOK) then
|
|
CloseFrame;
|
|
end;
|
|
|
|
function TfrInstalador.ComprobarDatos: Boolean;
|
|
begin
|
|
Result := False;
|
|
|
|
if EsCadenaVacia(Nombre.Text) then
|
|
begin
|
|
VerMensaje(msgInsFaltaNombre);
|
|
Nombre.SetFocus;
|
|
Exit;
|
|
end;
|
|
|
|
{ No hay restricciones al eliminar un intalador si acaso si existiese en un
|
|
pedido, pero como no hay relacion en tablas sino que es copia de nombre y
|
|
apellidos y telefono en un campo persona de contacto de la tabla de pedidos,
|
|
no se tendrá en cuenta.
|
|
|
|
if Modo = Eliminar then
|
|
begin
|
|
if dmTablaInstaladores.existeInstaladorEnPedido(CodigoInstalador) then
|
|
begin
|
|
VerMensaje(msgExisteInstaladorEnPedido);
|
|
Exit;
|
|
end;
|
|
end;
|
|
}
|
|
|
|
Result := True;
|
|
end;
|
|
|
|
end.
|