unit uBizInformes;

interface

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

const
  BIZ_CLIENT_INFORMES = 'Client.InformesBase';

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

  TBizInformes = class(TInformesDataTableRules, IBizInforme)
  protected
//    function GetVISTAValue: IROStrings; override;
//    procedure BeforePost(Sender: TDADataTable); override;
    procedure OnNewRecord(Sender: TDADataTable); override;
  public
  	function EsNuevo : Boolean;  
//    procedure Show; virtual; abstract;
//    procedure VerPropiedades;
//    function EsModificable : Boolean;
  end;

implementation

uses
  Windows;

{ TBizInformesVentasDataTableRules }

{
procedure TBizInformesDataTableRules.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 TBizInformesDataTableRules.EsModificable: Boolean;
begin
  Result := (MODIFICABLE = 'S');
end;

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

procedure TBizInformesDataTableRules.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;
}

{ TBizInformes }

function TBizInformes.EsNuevo: Boolean;
begin
  Result := (ID < 0);
end;

procedure TBizInformes.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  ID := GetRecNo; // -1, -2, -3...
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_INFORMES, TBizInformes);

end.
