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, cxCheckBox; 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; cxLista: TcxCheckBox; cxOtro: TcxCheckBox; cbLista: TcxDBLookupComboBox; dxLayoutGroup1: TdxLayoutGroup; dxLayoutControl1Item3: 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 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 LimpiarDireccionEntrega; 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 if cxLista.Checked then begin cbLista.Enabled := True; cbLista.DroppedDown := True; end else begin cbLista.Enabled := False; cbLista.Text := ''; if Assigned(FAlbaran) and (FAlbaran.ID_ALMACEN > 0) then begin FAlbaran.Edit; FAlbaran.ID_ALMACEN := 0; end; end; end; procedure TfrViewDireccionEntregaAlbaranProv.actOtroExecute(Sender: TObject); begin if cxOtro.Checked then begin if Assigned(FAlbaran) then FController.VerDireccionEntrega(FAlbaran); txtDireccion.Enabled := True; bModificar.Enabled := True; end else begin txtDireccion.Enabled := False; bModificar.Enabled := False; LimpiarDireccionEntrega; end; RefrescarDireccion; end; procedure TfrViewDireccionEntregaAlbaranProv.bModificarClick(Sender: TObject); begin inherited; actOtro.Execute; end; procedure TfrViewDireccionEntregaAlbaranProv.LimpiarDireccionEntrega; begin FController.LimpiarDireccion(FAlbaran); RefrescarDireccion; 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 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; end; end; procedure TfrViewDireccionEntregaAlbaranProv.SetAlbaranProveedor(const Value: IBizAlbaranProveedor); begin dsAlbaran.DataTable := nil; FAlbaran := Value; if Assigned(FAlbaran) then begin dsAlbaran.DataTable := FAlbaran.DataTable; { Para poder inicializar con el almacén por defecto en el caso de un albará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. } actLista.Checked := True; actOtro.Checked := True; 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 begin LimpiarDireccionEntrega; actOtro.Checked := False; end else begin if (FAlbaran.ID_ALMACEN <= 0) then actLista.Checked := False; if (Length(FAlbaran.CALLE) = 0) then actOtro.Checked := False; end; end; RefrescarDireccion; cxLista.Action := actLista; cxOtro.Action := actOtro; end; procedure TfrViewDireccionEntregaAlbaranProv.SetReadOnly(Value: Boolean); begin inherited; if ReadOnly then begin cxLista.Enabled := False; cxOtro.Enabled := False; end; end; procedure TfrViewDireccionEntregaAlbaranProv.txtDireccionDblClick(Sender: TObject); begin inherited; actOtro.Execute; end; end.