git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@608 0c75b7a4-871f-7646-8a2f-f78d34cc349f
316 lines
9.3 KiB
ObjectPascal
316 lines
9.3 KiB
ObjectPascal
unit uViewDatosYSeleccionClienteBase;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, uViewBase, StdCtrls, cxControls, cxContainer, cxEdit, cxLabel,
|
|
cxDBLabel, ExtCtrls, DB, uDADataTable, uBizContactos, uClientesController,
|
|
uDAInterfaces, uBizDireccionesContacto,
|
|
uDireccionesContactoController, uBizContactosPersonal, ImgList, PngImageList,
|
|
ActnList, dxLayoutControl, Buttons;
|
|
|
|
type
|
|
IViewDatosYSeleccionClienteBase = interface(IViewBase)
|
|
['{EC1BAC23-95A7-469F-8E86-939C149C4528}']
|
|
function GetCliente: IBizCliente;
|
|
procedure SetCliente(Value: IBizCliente);
|
|
property Cliente: IBizCliente read GetCliente write SetCliente;
|
|
|
|
function GetID_Cliente: integer;
|
|
procedure SetID_Cliente(const Value: integer);
|
|
property ID_Cliente: integer read GetID_Cliente write SetID_Cliente;
|
|
|
|
function GetOnClienteChanged : TNotifyEvent;
|
|
procedure SetOnClienteChanged (const Value : TNotifyEvent);
|
|
property OnClienteChanged : TNotifyEvent read GetOnClienteChanged
|
|
write SetOnClienteChanged;
|
|
|
|
procedure ElegirPersonaContacto;
|
|
procedure ElegirDireccionCliente;
|
|
procedure ElegirCliente;
|
|
procedure VerFichaCliente;
|
|
procedure AnadirNuevoCliente;
|
|
end;
|
|
|
|
TfrViewDatosYSeleccionClienteBase = class(TfrViewBase, IViewDatosYSeleccionClienteBase)
|
|
dsCliente: TDADataSource;
|
|
ActionList1: TActionList;
|
|
actElegirContacto: TAction;
|
|
actAnadirContacto: TAction;
|
|
actVerContacto: TAction;
|
|
PngImageList: TPngImageList;
|
|
dxLayoutControl1Group_Root: TdxLayoutGroup;
|
|
dxLayoutControl1: TdxLayoutControl;
|
|
actElegirDireccion: TAction;
|
|
actElegirPersonaContacto: TAction;
|
|
Panel1: TPanel;
|
|
bElegirCliente: TBitBtn;
|
|
bNuevoCliente: TBitBtn;
|
|
bVerFicha: TBitBtn;
|
|
bvSeparador: TBevel;
|
|
procedure actElegirContactoExecute(Sender: TObject);
|
|
procedure actAnadirContactoExecute(Sender: TObject);
|
|
procedure edtPersonaContactoPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure edtDireccionPropertiesButtonClick(Sender: TObject;
|
|
AButtonIndex: Integer);
|
|
procedure actVerContactoExecute(Sender: TObject);
|
|
procedure actElegirDireccionUpdate(Sender: TObject);
|
|
procedure actElegirDireccionExecute(Sender: TObject);
|
|
procedure actElegirPersonaContactoExecute(Sender: TObject);
|
|
procedure actElegirPersonaContactoUpdate(Sender: TObject);
|
|
|
|
private
|
|
FOnClienteChanged : TNotifyEvent;
|
|
FMsgElegirCliente: String;
|
|
FMsgElegirDireccion: String;
|
|
FMsgElegirPersonaContacto: String;
|
|
protected
|
|
FClientesController : IClientesController;
|
|
FDireccionesController : IDireccionesContactoController;
|
|
|
|
FCliente : IBizCliente;
|
|
FDireccion : IBizDireccionesContacto;
|
|
FPersonaContacto : IBizContactoPersonal;
|
|
|
|
function GetCliente: IBizCliente; virtual;
|
|
procedure SetCliente(Value: IBizCliente); virtual;
|
|
function GetOnClienteChanged : TNotifyEvent;
|
|
procedure SetOnClienteChanged (const Value : TNotifyEvent);
|
|
procedure SetReadOnly(Value: Boolean); override;
|
|
function GetID_Cliente: integer; virtual;
|
|
procedure SetID_Cliente(const Value: integer); virtual;
|
|
|
|
procedure InicializarMensajes; virtual;
|
|
public
|
|
constructor Create(AOwner: TComponent); override;
|
|
destructor Destroy; override;
|
|
|
|
procedure ElegirPersonaContacto; virtual;
|
|
procedure ElegirDireccionCliente; virtual;
|
|
procedure ElegirCliente; virtual;
|
|
procedure VerFichaCliente; virtual;
|
|
procedure AnadirNuevoCliente; virtual;
|
|
|
|
property Cliente: IBizCliente read GetCliente write SetCliente;
|
|
property OnClienteChanged : TNotifyEvent read GetOnClienteChanged write SetOnClienteChanged;
|
|
property ID_Cliente: integer read GetID_Cliente write SetID_Cliente;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses
|
|
uDataModuleClientes, Math, uCustomView, uDialogUtils;
|
|
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actElegirContactoExecute(Sender: TObject);
|
|
begin
|
|
ElegirCliente;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actElegirDireccionExecute(
|
|
Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ElegirDireccionCliente;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actElegirDireccionUpdate(
|
|
Sender: TObject);
|
|
begin
|
|
inherited;
|
|
(Sender as TAction).Enabled := Assigned(FCliente.Direcciones) and
|
|
(FCliente.Direcciones.Active) and (FCliente.Direcciones.RecordCount > 0);
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actElegirPersonaContactoExecute(
|
|
Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ElegirPersonaContacto;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actElegirPersonaContactoUpdate(
|
|
Sender: TObject);
|
|
begin
|
|
inherited;
|
|
(Sender as TAction).Enabled := Assigned(FCliente.Personal) and
|
|
(FCliente.Personal.Active) and (FCliente.Personal.RecordCount > 0);
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actAnadirContactoExecute(
|
|
Sender: TObject);
|
|
begin
|
|
AnadirNuevoCliente;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.actVerContactoExecute(
|
|
Sender: TObject);
|
|
begin
|
|
inherited;
|
|
VerFichaCliente;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.AnadirNuevoCliente;
|
|
var
|
|
ACliente : IBizCliente;
|
|
begin
|
|
inherited;
|
|
ACliente := (FClientesController.Nuevo as IBizCliente);
|
|
FClientesController.Ver(ACliente);
|
|
Self.Cliente := ACliente;
|
|
end;
|
|
|
|
constructor TfrViewDatosYSeleccionClienteBase.Create(AOwner: TComponent);
|
|
begin
|
|
inherited;
|
|
|
|
FClientesController := TClientesController.Create;
|
|
FDireccionesController := TDireccionesContactoController.Create;
|
|
|
|
FPersonaContacto := NIL;
|
|
FDireccion := NIL;
|
|
FCliente := NIL;
|
|
end;
|
|
|
|
destructor TfrViewDatosYSeleccionClienteBase.Destroy;
|
|
begin
|
|
FPersonaContacto := NIL;
|
|
FDireccion := NIL;
|
|
FCliente := NIL;
|
|
|
|
FClientesController := NIL;
|
|
FDireccionesController := NIL;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.edtDireccionPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
inherited;
|
|
ElegirDireccionCliente;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.edtPersonaContactoPropertiesButtonClick(
|
|
Sender: TObject; AButtonIndex: Integer);
|
|
begin
|
|
inherited;
|
|
ElegirPersonaContacto;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.ElegirCliente;
|
|
var
|
|
ACliente : IBizCliente;
|
|
begin
|
|
inherited;
|
|
ACliente := (FClientesController.ElegirContacto(FClientesController.BuscarTodos, FMsgElegirCliente, False) as IBizCliente);
|
|
|
|
if Assigned(ACliente) then
|
|
Self.Cliente := ACliente;
|
|
ACliente := Nil;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.ElegirDireccionCliente;
|
|
var
|
|
ADireccion : IBizDireccionesContacto;
|
|
begin
|
|
inherited;
|
|
ADireccion := FClientesController.ElegirDireccionEntrega(FCliente, FMsgElegirDireccion);
|
|
|
|
if Assigned(ADireccion) then
|
|
FDireccion := ADireccion;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.ElegirPersonaContacto;
|
|
var
|
|
APersona : IBizContactoPersonal;
|
|
begin
|
|
inherited;
|
|
APersona := FClientesController.ElegirPersonaContacto(FCliente.Personal, FMsgElegirPersonaContacto);
|
|
if Assigned(APersona) then
|
|
FPersonaContacto := APersona;
|
|
end;
|
|
|
|
function TfrViewDatosYSeleccionClienteBase.GetCliente: IBizCliente;
|
|
begin
|
|
Result := FCliente;
|
|
end;
|
|
|
|
function TfrViewDatosYSeleccionClienteBase.GetID_Cliente: integer;
|
|
begin
|
|
Result := -1;
|
|
if Assigned(FCliente) then
|
|
Result := FCliente.ID;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.SetCliente(Value: IBizCliente);
|
|
begin
|
|
FCliente := Value;
|
|
if Assigned(FCliente) then
|
|
begin
|
|
dsCliente.DataTable := FCliente.DataTable;
|
|
|
|
if not FCliente.DataTable.Active then
|
|
FCliente.DataTable.Active := True;
|
|
end
|
|
else begin
|
|
dsCliente.DataTable := NIL;
|
|
FCliente := NIL;
|
|
FDireccion := NIL;
|
|
FPersonaContacto := NIL;
|
|
end;
|
|
|
|
if Assigned(FOnClienteChanged) then
|
|
FOnClienteChanged(Self);
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.SetID_Cliente(const Value: integer);
|
|
begin
|
|
Self.Cliente := IBizCliente(FClientesController.Buscar(Value));
|
|
end;
|
|
|
|
function TfrViewDatosYSeleccionClienteBase.GetOnClienteChanged: TNotifyEvent;
|
|
begin
|
|
Result := FOnClienteChanged;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.InicializarMensajes;
|
|
begin
|
|
FMsgElegirCliente := 'Elija el cliente que desea utilizar.';
|
|
FMsgElegirPersonaContacto := 'El cliente dispone de personas de contacto dadas de alta en su ficha. Seleccione la que quiere utilizar.';
|
|
FMsgElegirDireccion := 'El cliente dispone de direcciones de contacto dadas de alta en su ficha. Seleccione la que quiere utilizar.';
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.SetOnClienteChanged(
|
|
const Value: TNotifyEvent);
|
|
begin
|
|
FOnClienteChanged := Value;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.SetReadOnly(Value: Boolean);
|
|
begin
|
|
inherited;
|
|
|
|
if (csLoading in Self.ComponentState) then
|
|
Exit;
|
|
|
|
actAnadirContacto.Enabled := not ReadOnly;
|
|
actElegirContacto.Enabled := not ReadOnly;
|
|
actElegirDireccion.Enabled := not ReadOnly;
|
|
actElegirPersonaContacto.Enabled := not ReadOnly;
|
|
end;
|
|
|
|
procedure TfrViewDatosYSeleccionClienteBase.VerFichaCliente;
|
|
begin
|
|
if not Assigned(Cliente) then
|
|
ShowErrorMessage('No se ha indicado un cliente', '')
|
|
else begin
|
|
FClientesController.Ver(Cliente);
|
|
end;
|
|
end;
|
|
|
|
end.
|