From b0a0662564d65040839a04cadf04a484441adac3 Mon Sep 17 00:00:00 2001 From: "alexey.zablotskiy" Date: Fri, 4 Jul 2025 21:13:33 +0300 Subject: [PATCH] LMS2.6 --- baseconnection.pas | 13 ++++++++ connectionsdmunit.pas | 86 ++++++++++++++++++++++++++++++++++----------------- reportdmunit.lfm | 2 +- reportdmunit.pas | 20 +++++++----- 4 files changed, 85 insertions(+), 36 deletions(-) diff --git a/baseconnection.pas b/baseconnection.pas index 88548fd..f06b130 100644 --- a/baseconnection.pas +++ b/baseconnection.pas @@ -30,6 +30,7 @@ type nErrors: integer; fCheckConnect: boolean; procedure CleanDone; + function getCommand(index: integer): TCommand; public Host: string; port: integer; @@ -57,6 +58,7 @@ type function AddCommand(ACode: DWORD; iParam: QWORD; ACommandClass,ACommandName: string; Arguments: TStrings; intArgs: TParamArray; CmdData: TStream; out ID: string; out retCode:DWORD; out Errors: TStrings): boolean; function RunCommand(ACommand: TCommand): boolean; function FindCommand(IDCommand: string): TCommand; + function CommandCount: integer; procedure Idle; procedure SetIdle; procedure Execute; override; @@ -64,6 +66,7 @@ type class function newID: string; function calchash(data: TStream): string; property Journal: TStrings read fJournal; + property AllCommands[index: integer]: TCommand read getCommand; end; implementation @@ -219,6 +222,11 @@ begin result := nil; end; +function TBaseConnection.CommandCount: integer; +begin + result := Commands.Count; +end; + procedure TBaseConnection.Idle; var d: TDateTime; @@ -258,6 +266,11 @@ begin end; end; +function TBaseConnection.getCommand(index: integer): TCommand; +begin + result := (Commands.Objects[index] as TCommand); +end; + procedure TBaseConnection.Log(ALevel: TLogLevel; sender: TObject; msg: string); begin case ALevel of diff --git a/connectionsdmunit.pas b/connectionsdmunit.pas index 35bd048..64bbe21 100644 --- a/connectionsdmunit.pas +++ b/connectionsdmunit.pas @@ -259,9 +259,9 @@ begin begin result := true; rValues := TStringList.Create; - rvalues.Add('"help"'); - rvalues.Add('"version"'); - rValues.add('"reports"'); + rvalues.Add('{action:"help",params:[]}'); + rvalues.Add('{action:"version",params:[]}'); + rValues.add('{action:"reports",params:[]}'); rValues.add('{action:"arguments",params:["report"]}'); rValues.add('{action:"login",params:["user","password"]}'); rValues.add('{action:"logout",params:["connect"]}'); @@ -269,7 +269,7 @@ begin rValues.add('{action:"log",params:["connect"]}'); rValues.add('{action:"option_values",params:["connect","report","name"]}'); rValues.add('{action:"report",params:["connect","name"]}'); - rValues.add('{action:"status",params:["connect","operation"]}'); + rValues.add('{action:"status",params:["connect","operation?"]}'); rValues.add('{action:"result",params:["connect","operation"]}'); end; if ACommand='version' then @@ -368,32 +368,62 @@ begin if (ACommand='status') or (ACommand='result') then begin - cmdID := fields.Values['operation']; - cmd := con.FindCommand(cmdID); - if not assigned(cmd) then - begin - Answer := 'command not found'; - Code := ErrorCommand; - exit; - end; - if ACommand='status' then - begin - Answer := cmd.currentStage; - if assigned(cmd.Results) then - cmd.Results.AssignTo(Code,RetValue,Answer,rValues) - else + cmdID := fields.Values['operation']; + cmd := con.FindCommand(cmdID); + if (ACommand='result') and (cmdID='') then begin - rValues := TSTringList.Create; - for i := 0 to cmd.Journal.count-1 do - rValues.add('"'+TNIDBDM.StringAsJSON(cmd.Journal[i])+'"'); + Answer := 'operation not specified'; + Code := ErrorCommand; + exit; end; - code := cmd.Status; - if (code=StatusComplete) and assigned(cmd.Results.Data) then - RetValue:=cmd.Results.Data.Size - else - RetValue := 0; - result := true; - exit; + if (ACommand='result') and not assigned(cmd) then + begin + Answer := 'operation not found '+cmdID; + Code := ErrorCommand; + exit; + end; + if (cmdID<>'') and not assigned(cmd) then + begin + Answer := 'operation not found '+cmdID; + Code := ErrorCommand; + exit; + end; + if ACommand='status' then + begin + if not assigned(cmd) then + begin + RetValue:=con.CommandCount; + rValues := TStringList.Create; + {action:"help",params:[]} + rValues.Add('operations:['); + for i := 0 to RetValue-1 do + begin + cmd := con.AllCommands[i]; + Answer := cmd.currentStage; + code := cmd.Status; + rValues.Add(format('{id:"%s",name:"%s",status:%d,stage:"%s"},',[NIDBDM.StringAsJSON(cmd.CommandID),NIDBDM.StringAsJSON(cmd.CommandName),cmd.Status, NIDBDM.StringAsJSON(cmd.CurrentStage)])); + end; + rValues.Add('{id:"",name:"",status:-1,stage:""}]'); + end + else + begin + Answer := cmd.currentStage; + if assigned(cmd.Results) then + cmd.Results.AssignTo(Code,RetValue,Answer,rValues) + else + begin + rValues := TSTringList.Create; + for i := 0 to cmd.Journal.count-1 do + rValues.add('"'+TNIDBDM.StringAsJSON(cmd.Journal[i])+'"'); + end; + code := cmd.Status; + if (code=StatusComplete) and assigned(cmd.Results.Data) then + RetValue:=cmd.Results.Data.Size + else + RetValue := 0; + end; + result := true; + exit; end; if ACommand='result' then begin diff --git a/reportdmunit.lfm b/reportdmunit.lfm index 4a69773..ad31600 100644 --- a/reportdmunit.lfm +++ b/reportdmunit.lfm @@ -5,7 +5,7 @@ object ReportDM: TReportDM VerticalOffset = 317 Width = 330 object frxReport: TfrxReport - Version = '2023.3.3' + Version = '2024.1.0' DotMatrixReport = False EngineOptions.SilentMode = True EngineOptions.NewSilentMode = simSilent diff --git a/reportdmunit.pas b/reportdmunit.pas index ed09b9f..70d8c23 100644 --- a/reportdmunit.pas +++ b/reportdmunit.pas @@ -85,7 +85,7 @@ type procedure OnMasterRecord(Sender: TObject); function LoadReportTemplate(OnHash: TCalcHashProc): string; procedure SaveReportTemplate(hash: string;OnHash: TCalcHashProc); - procedure CopyReportVariables(AVariables, AParam: TxpMemParamManager); + procedure CopyReportVariables(AVariables, AParam: TxpMemParamManager; OnStage: TLogger); procedure LogExport(Sender: TObject); public RecordID: integer; @@ -620,12 +620,15 @@ begin end; -procedure TReportDM.CopyReportVariables(AVariables, AParam: TxpMemParamManager); +procedure TReportDM.CopyReportVariables(AVariables, AParam: TxpMemParamManager; + OnStage: TLogger); var i: integer; v: variant; begin - for I := Low(AVariables.Params) to High(AVariables.Params) do + if assigned(OnStage) then + OnStage(mtDebug,self,'Переменные отчета'); + for I := Low(AVariables.Params) to High(AVariables.Params) do begin if VarIsStr(AVariables.Params[i][1]) then v := maskFRSpecial(VarToStr(AVariables.Params[i][1])) @@ -682,7 +685,7 @@ begin OnStage(mtExtra,self,'загрузка шаблона'); oldHash := LoadReportTemplate(nil); - CopyReportVariables(AVariables,AParam); + CopyReportVariables(AVariables,AParam, OnStage); TxpFRFunctions.SetReport(NidbData,AVariables); if assigned(OnStage) then OnStage(mtExtra,self,'формирование отчета'); @@ -707,7 +710,7 @@ begin end; flt.OnBeforeExport:=@LogExport; flt.OnBeginExport:=@LogExport; - + flt.OpenAfterExport:=false; try if assigned(OnStage) then OnStage(mtExtra,self,'выгрузка'); @@ -718,11 +721,14 @@ begin flt.ShowProgress := false; try if not frxReport.Export(flt) then + begin NidbData.log(mtWarning,self,'ERROR EXPORT PDF'); - + OnStage(mtError,self,'Ошибка выгрузки в PDF'); + end; except on e: Exception do begin NidbData.logError(self,e,'frxReport.Export'); + OnStage(mtError,self,'Ошибка выгрузки в PDF '+e.message); raise; end; end; @@ -762,7 +768,7 @@ begin // Создаём источники данных CreateDBDataSet(ReportQueries); oldHash:=LoadReportTemplate(onHash); - CopyReportVariables(AVariables,AParam); + CopyReportVariables(AVariables,AParam,nil); TxpFRFunctions.SetReport(NidbData,AVariables); try