Tecsitel_FactuGES2/Source/Modulos/Pedidos a proveedor/Views/uEditorDireccionEntregaPedidoProveedor.pas

192 lines
5.3 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, dxSkinsCore, dxSkinBlue, dxSkinCaramel, dxSkinCoffee,
dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black,
dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
dxSkinOffice2007Silver, dxSkinSilver, dxSkinStardust, dxSkinsDefaultPainters,
dxSkinValentine, dxSkinXmas2008Blue, 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;
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;
AID : Integer;
begin
AID := StrToInt(FProvincias.Values[cbProvincia.Text]);
with TProvinciasPoblacionesController.Create do
try
FPoblaciones := DarListaPoblaciones(AID);
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;
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
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.