unit uDataModuleCalendarios;

interface

uses {vcl:} SysUtils, Classes, DB, DBClient,
     {RemObjects:} uDAClientDataModule, uDADataTable, uDABINAdapter,
  uROServiceComponent, uRORemoteService, uROClient, uROBinMessage,
  uROWinInetHttpChannel, uDAScriptingProvider, uDACDSDataTable,
  uBizCitas;

type
  TdmCalendarios = class(TDAClientDataModule)
    DABINAdapter: TDABINAdapter;
    RORemoteService: TRORemoteService;
    tbl_Citas: TDACDSDataTable;
    ds_Citas: TDADataSource;
    tbl_Vendedores: TDACDSDataTable;
    ds_Vendedores: TDADataSource;
    procedure DAClientDataModuleCreate(Sender: TObject);
  private
  public
    function GetCodigo: Integer;
    function GetItems: IBizCitas;
    function GetMediciones: IBizCitas;
    function GetVendedores: IBizVendedores;
  end;

var
  dmCalendarios: TdmCalendarios;

implementation

{$R *.DFM}

uses
  Controls, Forms, uDAInterfaces, DataAbstract_Intf, FactuGES_Intf,
  uDataTableUtils, uROTypes, uEditorPreview, Variants,
  Dialogs, uDataModuleBase, uDBSelectionList,
  schCitasClient_Intf;


procedure TdmCalendarios.DAClientDataModuleCreate(Sender: TObject);
begin
  RORemoteService.Channel := dmBase.Channel;
  RORemoteService.Message := dmBase.Message;
end;

function TdmCalendarios.GetCodigo: Integer;
begin
  Result := (RORemoteService as IsrvCitas).GetCodigo('GEN_ID');
end;

function TdmCalendarios.GetItems: IBizCitas;
var
  dtCitas: TDACDSDataTable;
  ACursor: TCursor;
begin
  ACursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  try
    dtCitas := TDACDSDataTable.Create(NIL);
    CloneDataTable(tbl_Citas, dtCitas);
    dtCitas.BusinessRulesID := BIZ_CITAS;
    Result := (dtCitas as IBizCitas);
  finally
    Screen.Cursor := ACursor;
  end;
end;

function TdmCalendarios.GetMediciones: IBizCitas;
var
  dtCitas : IBizCitas;
begin
  dtCitas := GetItems;
  with dtCitas.DataTable.Where do
  begin
    if not Empty then
      AddOperator(opAND);
    OpenBraket;
    AddText('CITAS.' + fld_CITASTIPOTAREA  + ' = ''' + TextoTipoCita[Ord(tcMedicion)] + '''', False);
    CloseBraket;
  end;
  Result := dtCitas;
end;

function TdmCalendarios.GetVendedores: IBizVendedores;
var
  dtVendedores: TDACDSDataTable;
  ACursor: TCursor;
begin
  ACursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  try
    dtVendedores := TDACDSDataTable.Create(NIL);
    CloneDataTable(tbl_Vendedores, dtVendedores);
    dtVendedores.BusinessRulesID := BIZ_VENDEDORES;
    Result := (dtVendedores as IBizVendedores);
  finally
    Screen.Cursor := ACursor;
  end;
end;

initialization
  dmCalendarios := TdmCalendarios.Create(nil);

finalization
  FreeAndNil(dmCalendarios);

end.

