LMS-2_ReportAPI/fr_utils.pas
2025-07-03 10:18:37 +03:00

91 lines
3.3 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit fr_utils;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, Classes, fs_iinterpreter, xpMemParamManagerUnit, frxClass, cgiDM;
type
{ TxpFRFunctions }
TxpFRFunctions = class(TfsRTTIModule)
private
class var fData: TNIDBDM;
class var fVars: TxpMemParamManager;
function CallMethod(Instance: TObject; AClassType: TClass; const AMethodName: String; var Params: Variant): Variant;
function _(const szMsgId: string): string;
public
constructor Create(AScript: TfsScript); override;
class procedure SetReport(Adata: TNIDBDM; AVariables: TxpMemParamManager);
end;
implementation
uses
//gnugettext,
numberinwords;
function TxpFRFunctions._(const szMsgId: string): string;
begin
Result := szMsgId;
if Assigned(fData) then
begin
result := fData.QueryValue(format('select interpretation from xp_vocabulary where term=%s',[TNidbDM.StringAsSQL(szMsgId)]),szMsgId);
end;
end;
constructor TxpFRFunctions.Create(AScript: TfsScript);
begin
inherited Create(AScript);
with AScript do
begin
AddMethod('function _(str:string):string', @CallMethod, 'LMS функции', 'Функция _()');
AddMethod('function Log(str:string):integer', @CallMethod, 'LMS функции', 'Функция LOG()');
AddMethod('function Variable(str:string):string', @CallMethod, 'LMS функции', 'Функция Variable()');
AddMethod('function AnsiLowerCase(str:string):string', @CallMethod, 'LMS функции', 'Функция AnsiLowerCase()');
AddMethod('function ЧислоСловами(number:integer;gender:integer;declension:integer):string', @CallMethod, 'LMS функции', 'Функция ЧислоСловами(число, род (0=М,1=Ж,2=С), падеж (0=И,5=П))');
AddMethod('function НомерСловами(number:integer;gender:integer;declension:integer):string', @CallMethod, 'LMS функции', 'Функция НомерСловами(число, род (0=М,1=Ж,2=С), падеж (0=И,5=П))');
AddMethod('function Нагрузка(reqname: string; paramNumber: integer):string', @CallMethod, 'LMS функции', 'Функция Нагрузка(параметр нагрузки, номер поля (1=не менее,2=не более))');
AddMethod('procedure Логотип(ControlName: string; ImageName: string)',@CallMethod,'LMS функции','Отображение логотипа');
end;
end;
class procedure TxpFRFunctions.SetReport(Adata: TNIDBDM;
AVariables: TxpMemParamManager);
begin
fData := AData;
fVars := AVariables;
end;
function TxpFRFunctions.CallMethod(Instance: TObject; AClassType: TClass;
const AMethodName: String; var Params: Variant): Variant;
begin
if AMethodName = '_' then Result := _(Params[0])
else
if AnsiSameText(AMethodName,'Log') then begin
result := true;
end
else
if AnsiSameText(AMethodName,'Variable') then
begin
if fVars<>nil then
Result := fVars[(Params[0])]
else
Result := '';
end
else
if AnsiSameText(AMethodName, 'AnsiLowerCase') then Result := AnsiLowerCase(Params[0])
else
if AnsiSameText(AMethodName, 'ЧислоСловами') then Result := number999(Params[0],Params[1],Params[2])
else
if AnsiSameText(AMethodName, 'НомерСловами') then Result := number999_ord(Params[0],Params[1],Params[2])
end;
initialization
fsRTTIModules.Add(TxpFRFunctions);
end.