unit uViewDireccionEntregaAlbaranCliente; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, uBizAlbaranesCliente, cxGraphics, dxLayoutControl, cxMemo, cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, StdCtrls, cxControls, DB, uDADataTable, ActnList, uAlbaranesClienteController, Buttons, cxDBEdit, uDAInterfaces; type IViewDireccionEntregaAlbaranCliente = interface(IViewBase) ['{C23A361A-98CA-450C-9F29-2DA7877601EE}'] function GetAlbaranCliente: IBizAlbaranCliente; procedure SetAlbaranCliente(const Value: IBizAlbaranCliente); property AlbaranCliente: IBizAlbaranCliente read GetAlbaranCliente write SetAlbaranCliente; end; TfrViewDireccionEntregaAlbaranCliente = class(TfrViewBase, IViewDireccionEntregaAlbaranCliente) dxLayoutControl1: TdxLayoutControl; dxLayoutGroup1: TdxLayoutGroup; dsAlbaran: TDADataSource; dsAlmacenes: TDADataSource; dxLayoutControl1Item1: TdxLayoutItem; eCalle: TcxDBTextEdit; dxLayoutControl1Item4: TdxLayoutItem; eCodigoPostal: TcxDBTextEdit; dxLayoutControl1Item5: TdxLayoutItem; eTlfTrabajo: TcxDBTextEdit; dxLayoutControl1Item6: TdxLayoutItem; ePersonaContacto: TcxDBTextEdit; dxLayoutControl1Group3: TdxLayoutGroup; dxLayoutControl1Group4: TdxLayoutGroup; dxLayoutControl1Item2: TdxLayoutItem; cbProvincia: TcxDBComboBox; dxLayoutControl1Group1: TdxLayoutGroup; dxLayoutControl1Item3: TdxLayoutItem; cbPoblacion: TcxDBComboBox; dxLayoutControl1Group2: TdxLayoutGroup; procedure cbListaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure cbProvinciaPropertiesInitPopup(Sender: TObject); procedure cbPoblacionPropertiesInitPopup(Sender: TObject); protected // FAlmacenesController : IAlmacenesController; // FAlmacenes: IBizAlmacen; FAlbaran : IBizAlbaranCliente; FController : IAlbaranesClienteController; FProvincias : TStringList; FIDProvincia : Integer; //Almacenará la provincia que hay seleccionada para no cargar las poblaciones si no es necesario FPoblaciones : TStringList; procedure CargarProvincias; procedure CargarPoblaciones; function GetAlbaranCliente: IBizAlbaranCliente; procedure SetAlbaranCliente(const Value: IBizAlbaranCliente); procedure RefrescarDireccion; public property AlbaranCliente: IBizAlbaranCliente read GetAlbaranCliente write SetAlbaranCliente; constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses uEditorRegistryUtils, uProvinciasPoblacionesController, uStringsUtils; procedure TfrViewDireccionEntregaAlbaranCliente.CargarPoblaciones; var i : integer; begin if (FIDProvincia <> StrToInt(FProvincias.Values[cbProvincia.Text])) then Begin FIDProvincia := StrToInt(FProvincias.Values[cbProvincia.Text]); with TProvinciasPoblacionesController.Create do try FPoblaciones := DarListaPoblaciones(FIDProvincia); with cbPoblacion.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to FPoblaciones.Count - 1 do Add(FPoblaciones.Names[i]); finally EndUpdate; end; end; finally Free; end; End; end; procedure TfrViewDireccionEntregaAlbaranCliente.CargarProvincias; var i : integer; begin with TProvinciasPoblacionesController.Create do try FProvincias := DarListaProvincias; with cbProvincia.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to FProvincias.Count - 1 do Add(FProvincias.Names[i]); finally EndUpdate; end; end; finally Free; end; end; procedure TfrViewDireccionEntregaAlbaranCliente.cbListaPropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); begin { if Assigned(FAlbaran) and (FAlbaran.ID_ALMACEN <> FAlmacenes.ID) 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 TfrViewDireccionEntregaAlbaranCliente.cbPoblacionPropertiesInitPopup( Sender: TObject); begin inherited; ShowHourglassCursor; try FreeANDNIL(FPoblaciones); if not Assigned(FProvincias) then CargarProvincias; if not EsCadenaVacia(cbProvincia.Text) and (FProvincias.IndexOfName(cbProvincia.Text) <> -1) then CargarPoblaciones finally HideHourglassCursor; end; end; procedure TfrViewDireccionEntregaAlbaranCliente.cbProvinciaPropertiesInitPopup( Sender: TObject); begin inherited; ShowHourglassCursor; try if not Assigned(FProvincias) then CargarProvincias; finally HideHourglassCursor; end; end; constructor TfrViewDireccionEntregaAlbaranCliente.Create(AOwner: TComponent); begin inherited; FIDProvincia := 0; FAlbaran := NIL; FProvincias := NIL; FPoblaciones := NIL; { FController := TAlbaranesClienteController.Create; FAlmacenesController := TAlmacenesController.Create; FAlmacenes := FAlmacenesController.BuscarTodos; FAlmacenes.DataTable.Active := True; dsAlmacenes.DataTable := FAlmacenes.DataTable;} end; destructor TfrViewDireccionEntregaAlbaranCliente.Destroy; begin { cbLista.Properties.OnValidate := Nil; FAlmacenesController := Nil; FAlmacenes := Nil; FController := NIL; } if Assigned(FProvincias) then FreeANDNIL(FProvincias); if Assigned(FPoblaciones) then FreeANDNIL(FPoblaciones); FAlbaran := NIL; inherited; end; function TfrViewDireccionEntregaAlbaranCliente.GetAlbaranCliente: IBizAlbaranCliente; begin Result := FAlbaran; end; procedure TfrViewDireccionEntregaAlbaranCliente.RefrescarDireccion; begin { memDireccion.Lines.Clear; if Assigned(FAlbaran) then begin memDireccion.Lines.Add(FAlbaran.CALLE); memDireccion.Lines.Add(FAlbaran.CODIGO_POSTAL + ' ' + FPedido.POBLACION); memDireccion.Lines.Add(FAlbaran.PROVINCIA); end;} end; procedure TfrViewDireccionEntregaAlbaranCliente.SetAlbaranCliente( const Value: IBizAlbaranCliente); begin FAlbaran := Value; if Assigned(FAlbaran) then dsAlbaran.DataTable := FAlbaran.DataTable else dsAlbaran.DataTable := NIL; { cbLista.Properties.OnValidate := NIL; dsAlbaran.DataTable := nil; FAlbaran := Value; if not FAlbaran.EsNuevo then RefrescarDireccion; // Esto al final para que no salten los eventos del cxComboBox dsAlbaran.DataTable := FAlbaran.DataTable; cbLista.Properties.OnValidate := cbListaPropertiesValidate;} end; end.