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

347 lines
10 KiB
ObjectPascal

unit uViewDireccionEntregaPedidoProv;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uViewBase, uBizPedidosProveedor, cxGraphics, dxLayoutControl, cxMemo,
cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit,
cxDBLookupEdit, cxDBLookupComboBox, StdCtrls, cxControls, DB, uDADataTable,
ActnList, uBizAlmacenes, uAlmacenesController, uPedidosProveedorController,
Buttons, uDAInterfaces, uBizObras, uObrasController, cxButtonEdit, cxDBEdit,
ExtCtrls, cxLabel, cxDBLabel;
type
IViewDireccionEntregaPedidoProv = interface(IViewBase)
['{7467855C-066F-4A60-B88F-2837C8050B1E}']
function GetPedidoProveedor: IBizPedidoProveedor;
procedure SetPedidoProveedor(const Value: IBizPedidoProveedor);
property PedidoProveedor: IBizPedidoProveedor read GetPedidoProveedor write SetPedidoProveedor;
end;
TfrViewDireccionEntregaPedidoProv = class(TfrViewBase, IViewDireccionEntregaPedidoProv)
dxLayoutControl1: TdxLayoutControl;
rdxDestino1: TRadioButton;
rdxDestino2: TRadioButton;
cbListaAlmacenes: TcxDBLookupComboBox;
dxLayoutGroup1: TdxLayoutGroup;
dxLayoutItem1: TdxLayoutItem;
dxLayoutControl1Item3: TdxLayoutItem;
dxLayoutControl1Item2: TdxLayoutItem;
ActionList1: TActionList;
actListaAlmacenes: TAction;
actOtro: TAction;
dsPedido: TDADataSource;
dsAlmacenes: TDADataSource;
dxLayoutControl1Item1: TdxLayoutItem;
bModificar: TBitBtn;
txtDireccion: TStaticText;
dxLayoutControl1Item5: TdxLayoutItem;
dxLayoutControl1Item4: TdxLayoutItem;
RadioButton1: TRadioButton;
dsObras: TDADataSource;
actListaObras: TAction;
Bevel1: TBevel;
dxLayoutControl1Item8: TdxLayoutItem;
edtEntregarA: TcxDBButtonEdit;
dxLayoutControl1Item7: TdxLayoutItem;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dxLayoutControl1Group3: TdxLayoutGroup;
lblNombreObra: TcxDBLabel;
dxLayoutControl1Item9: TdxLayoutItem;
procedure actListaAlmacenesExecute(Sender: TObject);
procedure actOtroExecute(Sender: TObject);
procedure cbListaAlmacenesPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
procedure bModificarClick(Sender: TObject);
procedure txtDireccionDblClick(Sender: TObject);
procedure actListaObrasExecute(Sender: TObject);
procedure edtEntregarAPropertiesButtonClick(Sender: TObject;
AButtonIndex: Integer);
procedure dsPedidoDataChange(Sender: TObject; Field: TField);
protected
FAlmacenesController : IAlmacenesController;
FAlmacenes: IBizAlmacen;
FObrasController : IObrasController;
FObra: IBizObra;
FPedido : IBizPedidoProveedor;
FController : IPedidosProveedorController;
function GetPedidoProveedor: IBizPedidoProveedor;
procedure SetPedidoProveedor(const Value: IBizPedidoProveedor);
procedure CambioDireccionAlmacen;
procedure RefrescarControles;
procedure SetReadOnly(Value: Boolean); override;
procedure RecuperarObra;
public
property PedidoProveedor: IBizPedidoProveedor read GetPedidoProveedor write SetPedidoProveedor;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PrepararObra;
procedure CambioDireccionObra;
end;
implementation
{$R *.dfm}
uses
uEditorRegistryUtils, uCustomView, uEditorElegirPersonaContactoPedido, uBizInventario;
procedure TfrViewDireccionEntregaPedidoProv.actListaAlmacenesExecute(Sender: TObject);
begin
actListaAlmacenes.Checked := True;
RefrescarControles;
end;
procedure TfrViewDireccionEntregaPedidoProv.actListaObrasExecute(
Sender: TObject);
begin
actListaObras.Checked := True;
RefrescarControles;
CambioDireccionObra;
end;
procedure TfrViewDireccionEntregaPedidoProv.actOtroExecute(Sender: TObject);
begin
actOtro.Checked := True;
if Assigned(FPedido) then
begin
FController.VerDireccionEntrega(FPedido);
if (FPedido.ID_ALMACEN > 0) then
begin
FPedido.Edit;
FPedido.ID_ALMACEN := 0;
end;
end;
RefrescarControles;
end;
procedure TfrViewDireccionEntregaPedidoProv.bModificarClick(Sender: TObject);
begin
inherited;
actOtro.Execute;
end;
procedure TfrViewDireccionEntregaPedidoProv.CambioDireccionAlmacen;
begin
if Assigned(FPedido) and Assigned(FAlmacenes) then
begin
FPedido.Edit;
FPedido.CALLE := FAlmacenes.CALLE;
FPedido.POBLACION := FAlmacenes.POBLACION;
FPedido.POBLACION := FAlmacenes.POBLACION;
FPedido.PROVINCIA := FAlmacenes.PROVINCIA;
FPedido.CODIGO_POSTAL := FAlmacenes.CODIGO_POSTAL;
RefrescarControles;
end;
end;
procedure TfrViewDireccionEntregaPedidoProv.CambioDireccionObra;
begin
if Assigned(FPedido) and Assigned(FObra) then
begin
FPedido.Edit;
FPedido.CALLE := FObra.CALLE;
FPedido.POBLACION := FObra.POBLACION;
FPedido.POBLACION := FObra.POBLACION;
FPedido.PROVINCIA := FObra.PROVINCIA;
FPedido.CODIGO_POSTAL := FObra.CODIGO_POSTAL;
RefrescarControles;
end;
end;
procedure TfrViewDireccionEntregaPedidoProv.cbListaAlmacenesPropertiesValidate(
Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
var Error: Boolean);
begin
if Assigned(FPedido) and Assigned(FAlmacenes) and (FPedido.ID_ALMACEN <> FAlmacenes.ID) then
CambioDireccionAlmacen;
end;
constructor TfrViewDireccionEntregaPedidoProv.Create(AOwner: TComponent);
begin
inherited;
FController := TPedidosProveedorController.Create;
FAlmacenesController := TAlmacenesController.Create;
FAlmacenes := FAlmacenesController.BuscarTodos;
FAlmacenes.DataTable.Active := True;
dsAlmacenes.DataTable := FAlmacenes.DataTable;
FObrasController := TObrasController.Create;
FObra := NIL;
end;
destructor TfrViewDireccionEntregaPedidoProv.Destroy;
begin
//cbListaObras.Properties.OnValidate := Nil;
cbListaAlmacenes.Properties.OnValidate := Nil;
FAlmacenesController := Nil;
FAlmacenes := Nil;
FObrasController := Nil;
FObra := NIL;
FController := NIL;
inherited;
end;
procedure TfrViewDireccionEntregaPedidoProv.dsPedidoDataChange(Sender: TObject;
Field: TField);
begin
inherited;
if Assigned(Field) and (Field.FieldName = 'ID_OBRA') then
begin
PrepararObra;
if actListaObras.Enabled then
begin
if not Assigned(FObra) then
RecuperarObra;
CambioDireccionObra
end
else
FObra := NIL;
end;
end;
procedure TfrViewDireccionEntregaPedidoProv.edtEntregarAPropertiesButtonClick(
Sender: TObject; AButtonIndex: Integer);
var
AID_Subcontrata : Integer;
APersonaContacto : String;
begin
inherited;
AID_Subcontrata := -1;
if not FPedido.ID_OBRAIsNull then
begin
RecuperarObra;
if FObrasController.LocalizarEjecucionActiva(FObra.Ejecuciones) then
begin
if not FObra.Ejecuciones.ID_SUBCONTRATAIsNull then
AID_Subcontrata := FObra.Ejecuciones.ID_SUBCONTRATA;
end;
end;
APersonaContacto := FPedido.PERSONA_CONTACTO;
if ElegirPersonaContactoPedido(AID_Subcontrata, APersonaContacto) then
begin
FPedido.Edit;
FPedido.PERSONA_CONTACTO := APersonaContacto;
end;
end;
function TfrViewDireccionEntregaPedidoProv.GetPedidoProveedor: IBizPedidoProveedor;
begin
Result := FPedido;
end;
procedure TfrViewDireccionEntregaPedidoProv.RecuperarObra;
begin
if Assigned(FObra) and (FObra.ID = FPedido.ID_OBRA) then
Exit; // No hace falta volver a recuperarla
FObra := FObrasController.Buscar(FPedido.ID_OBRA);
FObra.Open;
end;
procedure TfrViewDireccionEntregaPedidoProv.RefrescarControles;
begin
txtDireccion.Caption := '';
if Assigned(FPedido) then
begin
if (actOtro.Checked) then
begin
cbListaAlmacenes.Enabled := False;
cbListaAlmacenes.Text := '';
txtDireccion.Enabled := True;
txtDireccion.Caption := FPedido.CALLE;
txtDireccion.Caption := txtDireccion.Caption + #13#10 + FPedido.CODIGO_POSTAL + ' ' + FPedido.POBLACION;
txtDireccion.Caption := txtDireccion.Caption + #13#10 + FPedido.PROVINCIA;
bModificar.Enabled := True;
end
else if (actListaAlmacenes.Checked) then
begin
txtDireccion.Enabled := False;
cbListaAlmacenes.Enabled := True;
cbListaAlmacenes.DroppedDown := True;
bModificar.Enabled := False;
end
else begin
bModificar.Enabled := False;
txtDireccion.Enabled := False;
cbListaAlmacenes.Enabled := False;
cbListaAlmacenes.Text := '';
end;
end;
end;
procedure TfrViewDireccionEntregaPedidoProv.PrepararObra;
begin
if Assigned(FPedido) and FPedido.Active then
if FPedido.ID_OBRAIsNull then
begin
actListaObras.Enabled := False;
if actListaObras.Checked then
actListaAlmacenes.Execute;
end
else
actListaObras.Enabled := True;
end;
procedure TfrViewDireccionEntregaPedidoProv.SetPedidoProveedor(
const Value: IBizPedidoProveedor);
begin
cbListaAlmacenes.Properties.OnValidate := NIL;
dsPedido.DataTable := nil;
FPedido := Value;
dsPedido.DataTable := FPedido.DataTable;
cbListaAlmacenes.Properties.OnValidate := cbListaAlmacenesPropertiesValidate;
if (FPedido.EsNuevo) then
CambioDireccionAlmacen
else begin
if (FPedido.ID_ALMACEN > 0) then
if FPedido.TIPO_ALMACEN = CTE_INV_ALMACEN then
actListaAlmacenes.Checked := True
else begin
actListaObras.Checked := True
end
else
actOtro.Checked := True;
end;
PrepararObra;
RefrescarControles;
end;
procedure TfrViewDireccionEntregaPedidoProv.SetReadOnly(Value: Boolean);
begin
inherited;
if (csLoading in Self.ComponentState) then
Exit;
rdxDestino1.Enabled := not ReadOnly;
rdxDestino2.Enabled := not ReadOnly;
RadioButton1.Enabled := not ReadOnly;
end;
procedure TfrViewDireccionEntregaPedidoProv.txtDireccionDblClick(
Sender: TObject);
begin
inherited;
actOtro.Execute;
end;
end.