unit uBizControlesBase;

interface

uses
  Classes, DB, SysUtils, uROClasses, uDADataTable, schControlesClient_Intf;

type
  IBizControlBase = interface(IListaControlesPorCategoria)
  ['{203A654A-16DF-404B-ACD4-CCCA796091C6}']
    procedure Show;
    procedure VerPropiedades;
    function EsModificable : Boolean;
  end;

  TBizControlBaseDataTableRules = class(TListaControlesPorCategoriaDataTableRules, IBizControlBase)
  protected
    function GetVISTAValue: IROStrings; override;
    procedure BeforePost(Sender: TDADataTable); override;
  public
    procedure Show; virtual; abstract;
    procedure VerPropiedades;
    function EsModificable : Boolean;    
  end;

implementation

uses
  Windows, Dialogs, uDACDSDataTable, uDataModuleBase,
  uEditorUtils, Variants, uFormPropiedadesControl, Forms, Controls;

{ TBizInformesVentasDataTableRules }

procedure TBizControlBaseDataTableRules.BeforePost(
  Sender: TDADataTable);
begin
  inherited;
  if Length(CATEGORIA) = 0 then
    raise Exception.Create('Categorķa no asignada');

  if Length(NOMBRE) = 0 then
    VerPropiedades;
end;

function TBizControlBaseDataTableRules.EsModificable: Boolean;
begin
  Result := (MODIFICABLE = 'S');
end;

function TBizControlBaseDataTableRules.GetVISTAValue: IROStrings;
begin
  Result := NewROStrings();
  Result.Add(DataTable.Fields[idx_ListaControlesPorCategoriaVISTA].AsString);
end;

procedure TBizControlBaseDataTableRules.VerPropiedades;
begin
  with TfrPropiedadesControl.Create(NIL) do
  try
    Nombre := Self.NOMBRE;
    Descripcion := Self.DESCRIPCION;
    Modificable := Self.EsModificable;
    Icono := Self.ICONO;
    if (ShowModal = mrOK) then
    begin
      DataTable.Edit;
      Self.NOMBRE := Nombre;
      Self.DESCRIPCION := Descripcion;
      Self.ICONO := Icono;
      if Modificable then
        Self.MODIFICABLE := 'S'
      else
        Self.MODIFICABLE := 'N';
    end;
  finally
    Free;
  end;
end;

end.
