unit uViewProveedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewContacto, dxLayoutLookAndFeels, DB, uDADataTable,
  dxLayoutControl, cxMemo, cxDBEdit, cxContainer, cxEdit, cxTextEdit, cxControls,
  cxMaskEdit, cxSpinEdit, ImgList, PngImageList, ActnList, cxHyperLinkEdit,
  Buttons, PngSpeedButton, StdCtrls, cxCheckBox, cxGraphics, cxDropDownEdit,
  uGruposProveedorController, uDAInterfaces, uCustomView, uViewBase, uViewTienda,
  uViewObservaciones;

type
  IViewProveedor = interface(IViewContacto)
    ['{D251B289-767A-489A-A862-BE564C79EFE6}']
  end;

  TfrViewProveedor = class(TfrViewContacto, IViewProveedor)
    dxLayoutControlContactoItem22: TdxLayoutItem;
    cxDBCheckBox2: TcxDBCheckBox;
    dxLayoutControlContactoItem23: TdxLayoutItem;
    eCertificaciones: TcxDBTextEdit;
    dxLayoutControlContactoGroup14: TdxLayoutGroup;
    dxLayoutControlContactoItem20: TdxLayoutItem;
    cbGrupoProveedor: TcxDBComboBox;
    dxLayoutControlContactoItem21: TdxLayoutItem;
    eDescripcionProveedor: TcxDBTextEdit;
    dxLayoutControlContactoItem24: TdxLayoutItem;
    eCodigoAsignado: TcxDBTextEdit;
    dxLayoutControlContactoItem27: TdxLayoutItem;
    eNombreComercial: TcxDBTextEdit;
    procedure CustomViewCreate(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);
    procedure cbGrupoProveedorPropertiesInitPopup(Sender: TObject);
    procedure cbGrupoProveedorPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
  protected
    FGrupoController: IGruposProveedorController;
  public

  end;

implementation
{$R *.dfm}

uses
  uBizGruposProveedor, uBizContactos;


procedure TfrViewProveedor.cbGrupoProveedorPropertiesInitPopup(Sender: TObject);
begin
  inherited;
  with cbGrupoProveedor.Properties.Items do
  begin
    BeginUpdate;
    try
      Clear;
      AddStrings(FGrupoController.DarListaGruposProveedor);
    finally
      EndUpdate;
    end;
  end;
end;

procedure TfrViewProveedor.cbGrupoProveedorPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
var
  AGrupo : IBizGrupoProveedor;
begin
  inherited;
  with (Sender as TcxDBComboBox) do
  begin
    if (Length(DisplayValue) > 0) and (DisplayValue <> (Contacto as IBizProveedor).GRUPO_PROVEEDOR) then
      if Properties.LookupItems.IndexOf(DisplayValue) < 0 then
      begin
        Properties.LookupItems.BeginUpdate;
        AGrupo := FGrupoController.BuscarTodos;
        AGrupo.DataTable.Active := True;
        try
          FGrupoController.Anadir(AGrupo);
          AGrupo.DESCRIPCION := DisplayValue;
          FGrupoController.Guardar(AGrupo);
          Properties.LookupItems.Add(DisplayValue);
        finally
          Properties.LookupItems.EndUpdate;
          AGrupo := NIL;
        end;
      end;
  end;
end;

procedure TfrViewProveedor.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FGrupoController := TGruposProveedorController.Create;
end;

procedure TfrViewProveedor.CustomViewDestroy(Sender: TObject);
begin
  FGrupoController := Nil;
  inherited;
end;

end.
