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); procedure CustomViewShow(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 not FAlbaran.DataTable.ReadOnly then begin if Assigned(FAlbaran) and Assigned(FAlmacenes) then begin cbLista.EditText := FAlmacenes.NOMBRE; FAlbaran.Edit; FAlbaran.CALLE := FAlmacenes.CALLE; 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; end; procedure TfrViewDireccionEntregaAlbaranProv.cbListaPropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); begin if Assigned(FAlbaran) and Assigned(FAlmacenes) 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; procedure TfrViewDireccionEntregaAlbaranProv.CustomViewShow(Sender: TObject); begin inherited; if Assigned(FAlbaran) and not FAlbaran.ID_ALMACENIsNull then begin CambioDireccionAlmacen; end; 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; txtDireccion.Caption := txtDireccion.Caption + #13#10 + 'Persona contacto: ' + FAlbaran.PERSONA_CONTACTO; txtDireccion.Caption := txtDireccion.Caption + #13#10 + 'Teléfono: ' + FAlbaran.TELEFONO; if (actOtro.Checked) then begin txtDireccion.Enabled := True; bModificar.Enabled := True; cbLista.Enabled := False; cbLista.Text := ''; end else begin cbLista.Enabled := True; cbLista.DroppedDown := True; txtDireccion.Enabled := False; bModificar.Enabled := False; 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; if (FAlbaran.ID_ALMACEN < 1) then // CambioDireccionAlmacen else actLista.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.