unit U_RPFun;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DBGrids, DB, cxDBData,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, ADODB, StrUtils, Midas,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxTimeEdit,
  cxTreeView, cxGrid, cxDBLookupComboBox, cxCalendar, cxCurrencyEdit,
  cxGridExportLink, ExtCtrls, Buttons, DBClient, RTComboBox, cxDropDownEdit,
  cxGridBandedTableView, cxGridDBBandedTableView, cxRichEdit, cxButtonEdit,
  IniFiles, WinSock, IdHTTP, dxcore, cxTextEdit, FireDAC.Comp.Client, cxCheckBox,
  Vcl.Clipbrd, cxMemo, dxLayoutControl;

function FromPrintFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

function FromShowFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

function FunPrintFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

function FromPrintRmf(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

function FunPrintRmf(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

//有窗体 根据配置文件选择报表
function FromPrintReport(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

//无窗体 根据配置文件选择报表
function FunPrintReport(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;

implementation

//无窗体
function FunPrintReport(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
var
  FileName, MReport: string;
  programIni: Tinifile;  //配置文件名
  JsonResult: PChar;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  MReport := programIni.ReadString('REPORTSET', 'reportType', '0');
  programIni.Free;

  if MReport = '0' then
  begin
    JsonResult := FunPrintFr3(App, DataBaseStr, JsonArgs);
  end
  else
  begin
    JsonResult := FunPrintRmf(App, DataBaseStr, JsonArgs);
  end;
  Result := JsonResult;
end;

function FromPrintReport(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
var
  FileName, MReport: string;
  programIni: Tinifile;  //配置文件名
  JsonResult: PChar;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  MReport := programIni.ReadString('REPORTSET', 'reportType', '0');
  programIni.Free;

  if MReport = '0' then
  begin
    JsonResult := FromPrintFr3(App, DataBaseStr, JsonArgs);
  end
  else
  begin
    JsonResult := FromPrintRmf(App, DataBaseStr, JsonArgs);
  end;
  Result := JsonResult;
end;

function FromPrintFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
type
  TMyFunc = function(App: Tapplication; FormID: integer; Title: PChar; DataBaseStr: PChar; JsonArgs: PChar): PChar; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  JsonResult: PChar;
begin
  Th := LoadLibrary('ReportPrint.dll');
  if Th > 0 then
  begin
    Tp := GetProcAddress(Th, 'GetDllForm');
    if Tp <> nil then
    begin
      Tf := TMyFunc(Tp);
      JsonResult := Tf(Application, 11, 'FR3报表', DataBaseStr, JsonArgs);
    end
    else
    begin
      JsonResult := '{"succsee":false,"message": "读取调用号异常"}';
    end;
  end
  else
  begin
    JsonResult := '{"succsee":false,"message": "找不到ReportPrint.dll"}';
  end;
  Result := JsonResult;
end;

function FromShowFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
type
  TMyFunc = function(App: Tapplication; FormID: integer; Title: PChar; DataBaseStr: PChar; JsonArgs: PChar): PChar; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  JsonResult: PChar;
begin
  Th := LoadLibrary('ReportPrint.dll');
  if Th > 0 then
  begin
    Tp := GetProcAddress(Th, 'GetDllForm');
    if Tp <> nil then
    begin
      Tf := TMyFunc(Tp);
      JsonResult := Tf(Application, 13, 'FR3报表', DataBaseStr, JsonArgs);
    end
    else
    begin
      JsonResult := '{"succsee":false,"message": "读取调用号异常"}';
    end;
  end
  else
  begin
    JsonResult := '{"succsee":false,"message": "找不到ReportPrint.dll"}';
  end;
  Result := JsonResult;
end;

function FunPrintFr3(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
type
  TMyFunc = function(App: Tapplication; FormID: integer; Title: PChar; DataBaseStr: PChar; JsonArgs: PChar): PChar; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  JsonResult: PChar;
begin
  Th := LoadLibrary('ReportPrint.dll');
  if Th > 0 then
  begin
    Tp := GetProcAddress(Th, 'GetDllForm');
    if Tp <> nil then
    begin
      Tf := TMyFunc(Tp);
      JsonResult := Tf(Application, 12, 'FR3报表', DataBaseStr, JsonArgs);
    end
    else
    begin
      JsonResult := '{"succsee":false,"message": "读取调用号异常"}';
    end;
  end
  else
  begin
    JsonResult := '{"succsee":false,"message": "找不到ReportPrint.dll"}';
  end;
  Result := JsonResult;
end;

function FromPrintRmf(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
type
  TMyFunc = function(App: Tapplication; FormID: integer; Title: PChar; DataBaseStr: PChar; JsonArgs: PChar): PChar; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  JsonResult: PChar;
begin
  Th := LoadLibrary('ReportPrint.dll');
  if Th > 0 then
  begin
    Tp := GetProcAddress(Th, 'GetDllForm');
    if Tp <> nil then
    begin
      Tf := TMyFunc(Tp);
      JsonResult := Tf(Application, 21, 'Rmf报表', DataBaseStr, JsonArgs);
    end
    else
    begin
      JsonResult := '{"succsee":false,"message": "读取调用号异常"}';
    end;
  end
  else
  begin
    JsonResult := '{"succsee":false,"message": "找不到ReportPrint.dll"}';
  end;
  Result := JsonResult;
end;

function FunPrintRmf(App: Tapplication; DataBaseStr: PChar; JsonArgs: PChar): PChar;
type
  TMyFunc = function(App: Tapplication; FormID: integer; Title: PChar; DataBaseStr: PChar; JsonArgs: PChar): PChar; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  JsonResult: PChar;
begin
  Th := LoadLibrary('ReportPrint.dll');
  if Th > 0 then
  begin
    Tp := GetProcAddress(Th, 'GetDllForm');
    if Tp <> nil then
    begin
      Tf := TMyFunc(Tp);
      JsonResult := Tf(Application, 22, 'Rmf报表', DataBaseStr, JsonArgs);
    end
    else
    begin
      JsonResult := '{"succsee":false,"message": "读取调用号异常"}';
    end;
  end
  else
  begin
    JsonResult := '{"succsee":false,"message": "找不到ReportPrint.dll"}';
  end;
  Result := JsonResult;
end;

end.

