unit uViewDireccionEntregaAlbaranProv; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, uBizAlbaranesProveedor, cxGraphics, dxLayoutControl, cxMemo, cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, StdCtrls, cxControls, DB, uDADataTable, ActnList, uBizAlmacenes, uAlmacenesController, uAlbaranesProveedorController, Buttons, uDAInterfaces; type IViewDireccionEntregaAlbaranProv = interface(IViewBase) ['{20124A28-C343-4A70-8016-06DDF92C75E7}'] function GetAlbaranProveedor: IBizAlbaranProveedor; procedure SetAlbaranProveedor(const Value: IBizAlbaranProveedor); property AlbaranProveedor: IBizAlbaranProveedor read GetAlbaranProveedor write SetAlbaranProveedor; end; TfrViewDireccionEntregaAlbaranProv = class(TfrViewBase, IViewDireccionEntregaAlbaranProv) dxLayoutControl1: TdxLayoutControl; rdxDestino1: TRadioButton; rdxDestino2: TRadioButton; cbLista: TcxDBLookupComboBox; dxLayoutGroup1: TdxLayoutGroup; dxLayoutItem1: TdxLayoutItem; dxLayoutControl1Item3: TdxLayoutItem; dxLayoutControl1Item2: TdxLayoutItem; ActionList1: TActionList; actLista: TAction; actOtro: TAction; dsAlbaran: TDADataSource; dsAlmacenes: TDADataSource; dxLayoutControl1Item1: TdxLayoutItem; bModificar: TBitBtn; dxLayoutControl1Item4: TdxLayoutItem; txtDireccion: TStaticText; procedure actListaExecute(Sender: TObject); procedure actOtroExecute(Sender: TObject); procedure cbListaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure bModificarClick(Sender: TObject); procedure txtDireccionDblClick(Sender: TObject); protected FAlmacenesController : IAlmacenesController; FAlmacenes: IBizAlmacen; FAlbaran : IBizAlbaranProveedor; FController : IAlbaranesProveedorController; function GetAlbaranProveedor: IBizAlbaranProveedor; procedure SetAlbaranProveedor(const Value: IBizAlbaranProveedor); procedure CambioDireccionAlmacen; procedure RefrescarDireccion; procedure SetReadOnly(Value: Boolean); override; public property AlbaranProveedor: IBizAlbaranProveedor read GetAlbaranProveedor write SetAlbaranProveedor; constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses uEditorRegistryUtils, uCustomView; procedure TfrViewDireccionEntregaAlbaranProv.actListaExecute(Sender: TObject); begin actLista.Checked := True; RefrescarDireccion; end; procedure TfrViewDireccionEntregaAlbaranProv.actOtroExecute(Sender: TObject); begin actOtro.Checked := True; // memDireccion.Enabled := True; if Assigned(FAlbaran) then begin FController.VerDireccionEntrega(FAlbaran); if (FAlbaran.ID_ALMACEN > 0) then begin FAlbaran.Edit; FAlbaran.ID_ALMACEN := 0; end; end; RefrescarDireccion; end; procedure TfrViewDireccionEntregaAlbaranProv.bModificarClick(Sender: TObject); begin inherited; actOtro.Execute; end; procedure TfrViewDireccionEntregaAlbaranProv.CambioDireccionAlmacen; begin if Assigned(FAlbaran) and Assigned(FAlmacenes) then begin FAlbaran.Edit; FAlbaran.CALLE := FAlmacenes.CALLE; FAlbaran.POBLACION := FAlmacenes.POBLACION; FAlbaran.POBLACION := FAlmacenes.POBLACION; FAlbaran.PROVINCIA := FAlmacenes.PROVINCIA; FAlbaran.CODIGO_POSTAL := FAlmacenes.CODIGO_POSTAL; FAlbaran.PERSONA_CONTACTO := FAlmacenes.PERSONA_CONTACTO; FAlbaran.TELEFONO := FAlmacenes.TELEFONO; RefrescarDireccion; end; end; procedure TfrViewDireccionEntregaAlbaranProv.cbListaPropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); begin if Assigned(FAlbaran) and Assigned(FAlmacenes) and (FAlbaran.ID_ALMACEN <> FAlmacenes.ID) then CambioDireccionAlmacen; end; constructor TfrViewDireccionEntregaAlbaranProv.Create(AOwner: TComponent); begin inherited; FController := TAlbaranesProveedorController.Create; FAlmacenesController := TAlmacenesController.Create; FAlmacenes := FAlmacenesController.BuscarTodos; FAlmacenes.DataTable.Active := True; dsAlmacenes.DataTable := FAlmacenes.DataTable; end; destructor TfrViewDireccionEntregaAlbaranProv.Destroy; begin cbLista.Properties.OnValidate := Nil; FAlmacenesController := Nil; FAlmacenes := Nil; FController := NIL; inherited; end; function TfrViewDireccionEntregaAlbaranProv.GetAlbaranProveedor: IBizAlbaranProveedor; begin Result := FAlbaran; end; procedure TfrViewDireccionEntregaAlbaranProv.RefrescarDireccion; begin txtDireccion.Caption := ''; if Assigned(FAlbaran) then begin if (actOtro.Checked) then begin cbLista.Enabled := False; cbLista.Text := ''; txtDireccion.Enabled := True; txtDireccion.Caption := FAlbaran.CALLE; txtDireccion.Caption := txtDireccion.Caption + #13#10 + FAlbaran.CODIGO_POSTAL + ' ' + FAlbaran.POBLACION; txtDireccion.Caption := txtDireccion.Caption + #13#10 + FAlbaran.PROVINCIA; bModificar.Enabled := True; end else begin txtDireccion.Enabled := False; bModificar.Enabled := False; cbLista.Enabled := True; cbLista.DroppedDown := True; end; end; end; procedure TfrViewDireccionEntregaAlbaranProv.SetAlbaranProveedor(const Value: IBizAlbaranProveedor); begin cbLista.Properties.OnValidate := NIL; dsAlbaran.DataTable := nil; FAlbaran := Value; if Assigned(FAlbaran) then begin dsAlbaran.DataTable := FAlbaran.DataTable; cbLista.Properties.OnValidate := cbListaPropertiesValidate; { Para poder inicializar con el almacén por defecto en el caso de un almacén nuevo, antes hay que comprobar que la dirección alternativa está vacia porque puede ser que el albarán se haya generado automáticamente a partir de un pedido a proveedor con una dirección que no es un almacén. } if (FAlbaran.EsNuevo) and ((Length(FAlbaran.CALLE) = 0) and (Length(FAlbaran.CODIGO_POSTAL) = 0) and (Length(FAlbaran.POBLACION) = 0) and (Length(FAlbaran.PROVINCIA) = 0)) then CambioDireccionAlmacen else if (FAlbaran.ID_ALMACEN < 1) then actOtro.Checked := True; RefrescarDireccion; end; end; procedure TfrViewDireccionEntregaAlbaranProv.SetReadOnly(Value: Boolean); begin inherited; if ReadOnly then begin rdxDestino1.Enabled := False; rdxDestino2.Enabled := False; end; end; procedure TfrViewDireccionEntregaAlbaranProv.txtDireccionDblClick(Sender: TObject); begin inherited; actOtro.Execute; end; end.