2009-08-27 17:53:40 +00:00
unit uViewDatosYSeleccionClienteContrato;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, StdCtrls, cxControls, cxContainer, cxEdit, cxLabel,
cxDBLabel, ExtCtrls, DB, uDADataTable, uBizContactos,
ComCtrls, ToolWin, ActnList, ImgList, PngImageList, cxTextEdit, cxDBEdit,
pngimage, JvExControls, JvComponent, JvButton, JvTransparentButton, Mask,
DBCtrls, uClientesController, dxLayoutControl, Buttons, uDAInterfaces,
cxMaskEdit, cxButtonEdit, uBizContratosCliente, uBizDireccionesContacto,
uDireccionesContactoController, Menus, cxLookAndFeelPainters, cxButtons,
cxMemo;
type
IViewDatosYSeleccionClienteContrato = interface( IViewBase)
[ '{18A4627C-9E15-404A-ACAC-6A41D729F89B}' ]
function GetContrato: IBizContratoCliente;
procedure SetContrato( const Value: IBizContratoCliente) ;
property Contrato: IBizContratoCliente read GetContrato write SetContrato;
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;
2009-11-24 18:11:03 +00:00
procedure ElegirDireccionParaContrato;
2009-08-27 17:53:40 +00:00
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
2009-11-24 18:11:03 +00:00
procedure RefrescarDireccion;
2009-08-27 17:53:40 +00:00
end ;
TfrViewDatosYSeleccionClienteContrato = class( TfrViewBase, IViewDatosYSeleccionClienteContrato)
dsCliente: TDADataSource;
ActionList1: TActionList;
actElegirContacto: TAction;
actAnadirContacto: TAction;
actVerContacto: TAction;
PngImageList: TPngImageList;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Item1: TdxLayoutItem;
edtlNombre: TcxDBTextEdit;
dxLayoutControl1Item2: TdxLayoutItem;
edtNIFCIF: TcxDBTextEdit;
2009-11-24 18:11:03 +00:00
bElegirCliente: TBitBtn;
2009-08-27 17:53:40 +00:00
dxLayoutControl1Item7: TdxLayoutItem;
2009-11-24 18:11:03 +00:00
bNuevoCliente: TBitBtn;
2009-08-27 17:53:40 +00:00
dxLayoutControl1Item8: TdxLayoutItem;
2009-11-24 18:11:03 +00:00
bVerFichaCliente: TBitBtn;
2009-08-27 17:53:40 +00:00
dxLayoutControl1Item9: TdxLayoutItem;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dsContrato: TDADataSource;
actElegirDireccion: TAction;
actElegirPersonaContacto: TAction;
dxLayoutControl1Item3: TdxLayoutItem;
edtPersonaContacto: TcxDBTextEdit;
dxLayoutControl1Item4: TdxLayoutItem;
edtDireccion: TcxMemo;
2009-11-24 18:11:03 +00:00
bElegirDireccion: TButton;
2009-08-27 17:53:40 +00:00
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Group3: TdxLayoutGroup;
dxLayoutControl1Item6: TdxLayoutItem;
2009-11-24 18:11:03 +00:00
bElegirPersonaContacto: TButton;
2009-08-27 17:53:40 +00:00
dxLayoutControl1Group5: TdxLayoutGroup;
2009-11-24 18:11:03 +00:00
dxLayoutControl1Item10: TdxLayoutItem;
edtTelefonos: TcxTextEdit;
dxLayoutControl1Item11: TdxLayoutItem;
edtReferencia: TcxDBTextEdit;
dxLayoutControl1Group6: TdxLayoutGroup;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Group7: TdxLayoutGroup;
2009-08-27 17:53:40 +00:00
procedure actElegirContactoExecute( Sender: TObject) ;
procedure actAnadirContactoExecute( Sender: TObject) ;
procedure actVerContactoUpdate( 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 ;
2009-11-24 18:11:03 +00:00
procedure EscribirTextoTelefonos;
2009-08-27 17:53:40 +00:00
protected
FClientesController : IClientesController;
FDireccionesController : IDireccionesContactoController;
FContrato : IBizContratoCliente;
FCliente : IBizCliente;
2009-11-24 18:11:03 +00:00
2009-08-27 17:53:40 +00:00
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 ;
function GetContrato: IBizContratoCliente;
procedure SetContrato( const Value: IBizContratoCliente) ;
procedure EscribirTextoDireccion;
public
constructor Create( AOwner: TComponent) ; override ;
destructor Destroy; override ;
procedure ElegirPersonaContacto;
2009-11-24 18:11:03 +00:00
procedure ElegirDireccionParaContrato;
2009-08-27 17:53:40 +00:00
procedure ElegirCliente;
procedure VerFichaCliente;
procedure AnadirNuevoCliente;
2009-11-24 18:11:03 +00:00
procedure RefrescarDireccion;
2009-08-27 17:53:40 +00:00
property Contrato: IBizContratoCliente read GetContrato write SetContrato;
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, uBizContactosPersonal, uDialogUtils;
procedure TfrViewDatosYSeleccionClienteContrato. actElegirContactoExecute( Sender: TObject) ;
begin
ElegirCliente;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actElegirDireccionExecute(
Sender: TObject) ;
begin
inherited ;
2009-11-24 18:11:03 +00:00
ElegirDireccionParaContrato;
RefrescarDireccion;
2009-08-27 17:53:40 +00:00
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actElegirDireccionUpdate(
Sender: TObject) ;
begin
inherited ;
2009-11-24 18:11:03 +00:00
( Sender as TAction) . Enabled : = Assigned( FCliente) and
Assigned( FCliente. Direcciones) and ( FCliente. Direcciones. Active)
and ( FCliente. Direcciones. RecordCount > 0 ) ;
2009-08-27 17:53:40 +00:00
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actElegirPersonaContactoExecute(
Sender: TObject) ;
begin
inherited ;
ElegirPersonaContacto;
2009-11-24 18:11:03 +00:00
RefrescarDireccion;
2009-08-27 17:53:40 +00:00
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actElegirPersonaContactoUpdate(
Sender: TObject) ;
begin
inherited ;
2009-11-24 18:11:03 +00:00
( Sender as TAction) . Enabled : = Assigned( FCliente) and
Assigned( FCliente. Personal) and ( FCliente. Personal. Active)
and ( FCliente. Personal. RecordCount > 0 ) ;
2009-08-27 17:53:40 +00:00
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actAnadirContactoExecute(
Sender: TObject) ;
begin
AnadirNuevoCliente;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actVerContactoExecute(
Sender: TObject) ;
begin
inherited ;
VerFichaCliente;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. actVerContactoUpdate( Sender: TObject) ;
begin
inherited ;
( Sender as TAction) . Enabled : = ( Length( edtlNombre. Text ) > 0 ) ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. AnadirNuevoCliente;
var
ACliente : IBizCliente;
begin
inherited ;
ACliente : = ( FClientesController. Nuevo as IBizCliente) ;
FClientesController. Ver( ACliente) ;
Self. Cliente : = ACliente;
end ;
constructor TfrViewDatosYSeleccionClienteContrato. Create( AOwner: TComponent) ;
begin
inherited ;
2009-11-24 18:11:03 +00:00
FMsgElegirCliente : = 'Elija el cliente al que se le realizar<61> el contrato.' ;
2009-08-27 17:53:40 +00:00
FClientesController : = TClientesController. Create;
FDireccionesController : = TDireccionesContactoController. Create;
edtlNombre. Enabled : = False ;
edtNIFCIF. Enabled : = False ;
edtDireccion. Enabled : = False ;
edtPersonaContacto. Enabled : = False ;
2009-11-24 18:11:03 +00:00
edtReferencia. Enabled : = False ;
edtTelefonos. Enabled : = False ;
2009-08-27 17:53:40 +00:00
end ;
destructor TfrViewDatosYSeleccionClienteContrato. Destroy;
begin
FClientesController : = NIL ;
FDireccionesController : = NIL ;
inherited ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. edtDireccionPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer ) ;
begin
inherited ;
2009-11-24 18:11:03 +00:00
ElegirDireccionParaContrato;
2009-08-27 17:53:40 +00:00
end ;
procedure TfrViewDatosYSeleccionClienteContrato. edtPersonaContactoPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer ) ;
begin
inherited ;
ElegirPersonaContacto;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. 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 ;
2009-11-24 18:11:03 +00:00
procedure TfrViewDatosYSeleccionClienteContrato. ElegirDireccionParaContrato;
2009-08-27 17:53:40 +00:00
var
ADireccion : IBizDireccionesContacto;
begin
2009-11-24 18:11:03 +00:00
if FCliente. Direcciones. RecordCount > 0 then
ADireccion : = FClientesController. ElegirDireccionEntrega( FCliente, 'El cliente dispone de varias direcciones. Seleccione la que quiere utilizar.' )
else begin
ADireccion : = FDireccionesController. Nuevo;
FDireccionesController. CopiarDireccionFiscal( FCliente, ADireccion) ;
end ;
2009-08-27 17:53:40 +00:00
if Assigned( ADireccion) then
begin
2009-11-24 18:11:03 +00:00
FContrato. Edit;
if ADireccion. IDIsNull then // Se ha elegido la direcci<63> n de raz<61> n social
2009-08-27 17:53:40 +00:00
begin
2009-11-24 18:11:03 +00:00
FContrato. ClearField( 'ID_DIRECCION' ) ;
2009-08-27 17:53:40 +00:00
FContrato. ClearField( 'IMPORTE_PORTE' ) ;
end
else begin
2009-11-24 18:11:03 +00:00
FContrato. ID_DIRECCION : = ADireccion. ID;
FContrato. IMPORTE_PORTE : = ADireccion. PORTE;
end ;
with FContrato do
begin
CALLE : = ADireccion. CALLE;
POBLACION : = ADireccion. POBLACION;
CODIGO_POSTAL : = ADireccion. CODIGO_POSTAL;
PROVINCIA : = ADireccion. PROVINCIA;
PERSONA_CONTACTO : = ADireccion. PERSONA_CONTACTO;
TELEFONO : = ADireccion. TELEFONO;
MOVIL : = ADireccion. MOVIL;
2009-08-27 17:53:40 +00:00
end ;
end ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. ElegirPersonaContacto;
var
APersona : IBizContactoPersonal;
begin
inherited ;
APersona : = FClientesController. ElegirPersonaContacto( FCliente. Personal, 'El cliente dispone de personas de contacto dadas de alta en su ficha. Seleccione la que quiere utilizar.' ) ;
2009-11-24 18:11:03 +00:00
try
if Assigned( APersona) then
begin
FContrato. Edit;
FContrato. PERSONA_CONTACTO : = APersona. NOMBRE;
end ;
finally
APersona : = NIL ;
2009-08-27 17:53:40 +00:00
end ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. EscribirTextoDireccion;
var
ACadena : String ;
begin
ACadena : = '' ;
2009-11-24 18:11:03 +00:00
if Assigned( FContrato) then
2009-08-27 17:53:40 +00:00
ACadena : = Format( '%s %s %s %s' ,
2009-11-24 18:11:03 +00:00
[ FContrato. CALLE, FContrato. POBLACION,
FContrato. CODIGO_POSTAL, FContrato. PROVINCIA] ) ;
2009-08-27 17:53:40 +00:00
edtDireccion. Text : = ACadena;
end ;
function TfrViewDatosYSeleccionClienteContrato. GetCliente: IBizCliente;
begin
Result : = FCliente;
end ;
function TfrViewDatosYSeleccionClienteContrato. GetID_Cliente: integer ;
begin
Result : = - 1 ;
if Assigned( FCliente) then
Result : = FCliente. ID;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. SetCliente( Value: IBizCliente) ;
2009-11-24 18:11:03 +00:00
var
ADireccion : IBizDireccionesContacto;
2009-08-27 17:53:40 +00:00
begin
2009-11-24 18:11:03 +00:00
ADireccion : = NIL ;
2009-08-27 17:53:40 +00:00
FCliente : = Value;
2009-11-24 18:11:03 +00:00
2009-08-27 17:53:40 +00:00
if Assigned( FCliente) then
begin
dsCliente. DataTable : = FCliente. DataTable;
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
//Solo podremos establecer persona de contacto si se ha asignado un cliente
if FCliente. ID > 0 then
edtPersonaContacto. Enabled : = True ;
2009-11-24 18:11:03 +00:00
ElegirDireccionParaContrato;
EscribirTextoDireccion;
EscribirTextoTelefonos;
2009-08-27 17:53:40 +00:00
end
else begin
dsCliente. DataTable : = NIL ;
FCliente : = NIL ;
edtPersonaContacto. Enabled : = False ;
end ;
if Assigned( FOnClienteChanged) then
FOnClienteChanged( Self) ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. SetID_Cliente( const Value: integer ) ;
begin
Self. Cliente : = IBizCliente( FClientesController. Buscar( Value) ) ;
end ;
function TfrViewDatosYSeleccionClienteContrato. GetOnClienteChanged: TNotifyEvent;
begin
Result : = FOnClienteChanged;
end ;
2009-11-24 18:11:03 +00:00
procedure TfrViewDatosYSeleccionClienteContrato. RefrescarDireccion;
begin
EscribirTextoDireccion;
EscribirTextoTelefonos;
end ;
2009-08-27 17:53:40 +00:00
function TfrViewDatosYSeleccionClienteContrato. GetContrato: IBizContratoCliente;
begin
Result : = FContrato;
end ;
2009-11-24 18:11:03 +00:00
procedure TfrViewDatosYSeleccionClienteContrato. EscribirTextoTelefonos;
var
ACadena : String ;
2009-08-27 17:53:40 +00:00
begin
2009-11-24 18:11:03 +00:00
ACadena : = '' ;
2009-09-10 16:51:20 +00:00
2009-11-24 18:11:03 +00:00
if not FContrato. TELEFONOIsNull then
ACadena : = FContrato. TELEFONO;
2009-09-10 16:51:20 +00:00
2009-11-24 18:11:03 +00:00
if not FContrato. MOVILIsNull then
begin
if ACadena < > '' then
ACadena : = ACadena + ' / ' ;
ACadena : = ACadena + FContrato. MOVIL;
2009-09-01 18:24:07 +00:00
end ;
2009-11-24 18:11:03 +00:00
edtTelefonos. Text : = ACadena;
2009-08-27 17:53:40 +00:00
end ;
2009-11-24 18:11:03 +00:00
2009-08-27 17:53:40 +00:00
procedure TfrViewDatosYSeleccionClienteContrato. SetOnClienteChanged(
const Value: TNotifyEvent) ;
begin
FOnClienteChanged : = Value;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. SetContrato(
const Value: IBizContratoCliente) ;
begin
FContrato : = Value;
if Assigned( FContrato) then
begin
dsContrato. DataTable : = FContrato. DataTable;
FCliente : = FContrato. Cliente;
dsCliente. DataTable : = FCliente. DataTable;
if not FCliente. DataTable. Active then
FCliente. DataTable. Active : = True ;
2009-11-24 18:11:03 +00:00
// <20> Hay cliente en el contrato?
2009-08-27 17:53:40 +00:00
if FCliente. ID > 0 then
2009-11-24 18:11:03 +00:00
begin
edtPersonaContacto. Enabled : = True ;
RefrescarDireccion;
end
else begin
edtPersonaContacto. Enabled : = False ;
edtDireccion. Lines. Clear;
edtTelefonos. Text : = '' ;
end ;
2009-08-27 17:53:40 +00:00
end
else begin
dsContrato. DataTable : = NIL ;
FCliente : = NIL ;
end ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. SetReadOnly( Value: Boolean ) ;
begin
inherited ;
if ( csLoading in Self. ComponentState) then
Exit;
actAnadirContacto. Enabled : = not ReadOnly ;
actElegirContacto. Enabled : = not ReadOnly ;
end ;
procedure TfrViewDatosYSeleccionClienteContrato. VerFichaCliente;
begin
if not Assigned( Cliente) then
2009-11-24 18:11:03 +00:00
ShowErrorMessage( 'No se ha indicado un cliente' , 'El contrato no tiene ning<6E> n cliente asociado a mostrar.' )
2009-08-27 17:53:40 +00:00
else begin
FClientesController. Ver( Cliente) ;
end ;
end ;
end .