git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@1016 0c75b7a4-871f-7646-8a2f-f78d34cc349f
193 lines
5.2 KiB
ObjectPascal
193 lines
5.2 KiB
ObjectPascal
unit uEditorDireccionEntregaPedidoProveedor;
|
|
|
|
interface
|
|
|
|
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
|
|
Buttons, ExtCtrls, Mask, DBCtrls, DB, uDADataTable,
|
|
cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit,
|
|
uIEditorDireccionEntregaPedidoProveedor, uBizPedidosProveedor, uDAInterfaces,
|
|
cxGraphics, cxMaskEdit, cxDropDownEdit;
|
|
|
|
type
|
|
TfEditorDireccionEntregaPedidoProveedor = class(TForm, IEditorDireccionEntregaPedidoProveedor)
|
|
OKBtn: TButton;
|
|
CancelBtn: TButton;
|
|
Bevel1: TBevel;
|
|
eDireccion: TDBEdit;
|
|
eCodigoPostal: TDBEdit;
|
|
Label1: TLabel;
|
|
Label3: TLabel;
|
|
Label4: TLabel;
|
|
dsDireccion: TDADataSource;
|
|
cbProvincia: TcxDBComboBox;
|
|
Label2: TLabel;
|
|
cbPoblacion: TcxDBComboBox;
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure cbProvinciaPropertiesInitPopup(Sender: TObject);
|
|
procedure cbPoblacionPropertiesInitPopup(Sender: TObject);
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
private
|
|
pDireccion: String;
|
|
pPoblacion: String;
|
|
pProvincia: String;
|
|
FIDProvincia : Integer; //Almacenará la provincia que hay seleccionada para no cargar las poblaciones si no es necesario
|
|
pCodigoPostal: String;
|
|
FProvincias : TStringList;
|
|
FPoblaciones : TStringList;
|
|
FPedido : IBizPedidoProveedor;
|
|
procedure CargarProvincias;
|
|
procedure CargarPoblaciones;
|
|
function GetPedido: IBizPedidoProveedor;
|
|
procedure SetPedido(const Value: IBizPedidoProveedor);
|
|
public
|
|
property Pedido: IBizPedidoProveedor read GetPedido write SetPedido;
|
|
end;
|
|
|
|
implementation
|
|
{$R *.dfm}
|
|
|
|
uses
|
|
uProvinciasPoblacionesController, uStringsUtils;
|
|
|
|
{ TfEditorDireccionEntrega }
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.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 TfEditorDireccionEntregaPedidoProveedor.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 TfEditorDireccionEntregaPedidoProveedor.cbPoblacionPropertiesInitPopup(
|
|
Sender: TObject);
|
|
begin
|
|
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 TfEditorDireccionEntregaPedidoProveedor.cbProvinciaPropertiesInitPopup(
|
|
Sender: TObject);
|
|
begin
|
|
ShowHourglassCursor;
|
|
try
|
|
if not Assigned(FProvincias) then
|
|
CargarProvincias;
|
|
finally
|
|
HideHourglassCursor;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
begin
|
|
//En el caso de cancelar se recuperan los valores iniciales
|
|
if (Self.ModalResult <> mrOk) and (dsDireccion.DataTable.State in dsEditModes) then
|
|
begin
|
|
eDireccion.Field.Value := pDireccion;
|
|
cbPoblacion.DataBinding.Field.Value := pPoblacion;
|
|
cbProvincia.DataBinding.Field.Value := pProvincia;
|
|
eCodigoPostal.Field.Value := pCodigoPostal;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.FormCreate(Sender: TObject);
|
|
begin
|
|
FIDProvincia := 0;
|
|
FProvincias := NIL;
|
|
FPoblaciones := NIL;
|
|
end;
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.FormDestroy(Sender: TObject);
|
|
begin
|
|
if Assigned(FProvincias) then
|
|
FreeANDNIL(FProvincias);
|
|
|
|
if Assigned(FPoblaciones) then
|
|
FreeANDNIL(FPoblaciones);
|
|
end;
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.FormShow(Sender: TObject);
|
|
begin
|
|
//Guardamos los valores iniciales por si al final el usuario cancela
|
|
pDireccion := eDireccion.Text;
|
|
pPoblacion := cbPoblacion.Text;
|
|
pProvincia := cbProvincia.Text;
|
|
pCodigoPostal := eCodigoPostal.Text;
|
|
end;
|
|
|
|
function TfEditorDireccionEntregaPedidoProveedor.GetPedido: IBizPedidoProveedor;
|
|
begin
|
|
Result := FPedido;
|
|
end;
|
|
|
|
procedure TfEditorDireccionEntregaPedidoProveedor.SetPedido(
|
|
const Value: IBizPedidoProveedor);
|
|
begin
|
|
FPedido := Value;
|
|
if Assigned(FPedido) then
|
|
dsDireccion.DataTable := FPedido.DataTable
|
|
else
|
|
dsDireccion.DataTable := NIL;
|
|
end;
|
|
|
|
end.
|