unit uMedicacionReportController;

interface

uses
  Classes, SysUtils, uDADataTable, uControllerBase, uIDataModuleMedicacionReport,
  uPacientesController, uMedicacionesController, uDetallesMedicacionController,
  uBizMedicaciones, uIntegerListUtils;

type
  IMedicacionReportController = interface(IControllerBase)
  ['{9DD34D7A-C396-4DBF-9A16-C060DE111AA8}']
    procedure Preview(const AListaID : TIntegerList);
    procedure Print(const AListaID : TIntegerList);
    procedure EtiquetasPreview(const AID : integer; Const withRefCliente: Boolean);
    procedure EtiquetasPrint(const AID : integer; Const withRefCliente: Boolean);
  end;

  TMedicacionReportController = class(TControllerBase, IMedicacionReportController)
  private
    FDataModule : IDataModuleMedicacionReport;
    function CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;

  public
    constructor Create; override;
    destructor Destroy; override;

    procedure Preview(const AListaID : TIntegerList);
    procedure Print(const AListaID : TIntegerList);
    procedure EtiquetasPreview(const AID : integer; const withRefCliente: Boolean);
    procedure EtiquetasPrint(const AID : integer; const withRefCliente: Boolean);
  end;


implementation

uses
  uROTypes, uEditorRegistryUtils, uIEditorMedicacionesPreview,
  uEditorPreview, uDataModuleMedicaciones, uEditorBase, cxControls,
  uStringsUtils, uSistemaFunc, uFactuGES_App;

{ TMedicacionReportController }

constructor TMedicacionReportController.Create;
begin
  inherited;
  FDataModule := TDataModuleMedicacion.Create(Nil);
end;

function TMedicacionReportController.CreateEditor(const AName: String;
  const IID: TGUID; out Intf): Boolean;
begin
  Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
end;


destructor TMedicacionReportController.Destroy;
begin
  FDataModule := NIL;
  inherited;
end;

procedure TMedicacionReportController.EtiquetasPreview(const AID: integer; const withRefCliente: Boolean);
var
  AStream: Binary;
  AEditor : IEditorMedicacionesPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetEtiquetas(AID, withRefCliente);
    try
      CreateEditor('EditorMedicacionesPreview', IEditorMedicacionesPreview, AEditor);
      if Assigned(AEditor) then
        try
          AEditor.LoadFromStream(AStream);
          AEditor.Preview;
        finally
          AEditor.Release;
        end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;
end;

procedure TMedicacionReportController.EtiquetasPrint(const AID: integer; const withRefCliente: Boolean);
var
  AStream: Binary;
  AEditor : IEditorMedicacionesPreview;
begin
  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetEtiquetas(AID, withRefCliente);
    try
      CreateEditor('EditorMedicacionesPreview', IEditorMedicacionesPreview, AEditor);
      if Assigned(AEditor) then
        try
          AEditor.LoadFromStream(AStream);
          AEditor.Print;
        finally
          AEditor.Release;
        end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;
end;

procedure TMedicacionReportController.Preview(const AListaID : TIntegerList);
var
  AStream: Binary;
  AEditor : IEditorMedicacionesPreview;
begin
{  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetEtiquetas(AListaID);
    try
      CreateEditor('EditorMedicacionPreview', IEditorMedicacionPreview, AEditor);
      if Assigned(AEditor) then
      begin
        try
          AEditor.Controller := Self;
          AEditor.ListaID := AListaID;
          AEditor.Title := 'Albarán - ' + AppFactuGES.EmpresaActiva.NOMBRE;
          AEditor.LoadFromStream(AStream);
          AEditor.Preview;
        finally
          AEditor.Release;
        end;
      end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;  }
end;

procedure TMedicacionReportController.Print(const AListaID : TIntegerList);
var
  AStream: Binary;
  AEditor : IEditorMedicacionesPreview;
begin
{  AEditor := NIL;

  ShowHourglassCursor;
  try
    AStream := FDataModule.GetRptAlbaranes(AListaID);
    try
      CreateEditor('EditorMedicacionPreview', IEditorMedicacionPreview, AEditor);
      if Assigned(AEditor) then
      begin
        try
          AEditor.Controller := Self;
          AEditor.ListaID := AListaID;
          AEditor.Title := 'Albarán - ' + AppFactuGES.EmpresaActiva.NOMBRE;
          AEditor.LoadFromStream(AStream);
          AEditor.Print;
        finally
          AEditor.Release;
        end;
      end;
    finally
      FreeAndNil(AStream);
      AEditor := Nil;
    end;
  finally
    HideHourglassCursor;
  end;  }
end;

end.
