logs
This commit is contained in:
parent
6f83f16929
commit
2b6d2c161b
@ -38,6 +38,8 @@ type
|
|||||||
UserID: integer;
|
UserID: integer;
|
||||||
LastAccess: TDateTime;
|
LastAccess: TDateTime;
|
||||||
procedure Log(ALevel:TLogLevel;sender: TObject; msg: string);
|
procedure Log(ALevel:TLogLevel;sender: TObject; msg: string);
|
||||||
|
procedure LogError(Sender: TObject; e: Exception; Command: string);
|
||||||
|
|
||||||
property Created: TDateTime read fCreated;
|
property Created: TDateTime read fCreated;
|
||||||
property LastReceive: TDateTime read fCommandReceived;
|
property LastReceive: TDateTime read fCommandReceived;
|
||||||
property LastComplete: TDateTime read fCommandCompleted;
|
property LastComplete: TDateTime read fCommandCompleted;
|
||||||
@ -130,7 +132,15 @@ begin
|
|||||||
begin
|
begin
|
||||||
cmd := cc.Create(self.newID, self.Processor,ACommandName,fLogger,User,UserID);
|
cmd := cc.Create(self.newID, self.Processor,ACommandName,fLogger,User,UserID);
|
||||||
cmd.AccessTime:=NOW();
|
cmd.AccessTime:=NOW();
|
||||||
|
try
|
||||||
result := cmd.ParseCommand(ACode,iParam,ACommandName,Arguments,intArgs,CmdData, Errors);
|
result := cmd.ParseCommand(ACode,iParam,ACommandName,Arguments,intArgs,CmdData, Errors);
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(self,e,format('ParseCommand(%s,%s)',[ACommandClass, ACommandName]));
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if result then
|
if result then
|
||||||
begin
|
begin
|
||||||
Commands.AddObject(ACommandName,cmd);
|
Commands.AddObject(ACommandName,cmd);
|
||||||
@ -152,13 +162,27 @@ begin
|
|||||||
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
inc(nErrors);
|
inc(nErrors);
|
||||||
|
result := false;
|
||||||
|
ID := format('Неизвестная команда %s(%s)',[ACommandClass, ACommandName]);
|
||||||
|
log(mtWarning,self,ID);
|
||||||
|
retCode := ErrorCommand;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBaseConnection.RunCommand(ACommand: TCommand): boolean;
|
function TBaseConnection.RunCommand(ACommand: TCommand): boolean;
|
||||||
begin
|
begin
|
||||||
|
log(mtDebug,self,format('Запуск на исполнение %s_%s %s',[ACommand.CommandName,ACommand.CommandSubClass, ACommand.CommandID]));
|
||||||
|
try
|
||||||
ACommand.doRun();
|
ACommand.doRun();
|
||||||
log(mtDebug,Self,'complete '+ACommand.CommandID);
|
log(mtDebug,Self,'Завершена '+ACommand.CommandID);
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(self,e,format('Command %s',[ACommand.CommandID]));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
fCommandCompleted:=Now();
|
fCommandCompleted:=Now();
|
||||||
inc(nCommandReady);
|
inc(nCommandReady);
|
||||||
end;
|
end;
|
||||||
@ -229,6 +253,12 @@ begin
|
|||||||
flogger(ALevel,sender,msg);
|
flogger(ALevel,sender,msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBaseConnection.LogError(Sender: TObject; e: Exception;
|
||||||
|
Command: string);
|
||||||
|
begin
|
||||||
|
log(mtError,Sender,format('%s вызвала ошибку %s(%s) ',[Command, e.classname,e.message]));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBaseConnection.Execute;
|
procedure TBaseConnection.Execute;
|
||||||
var
|
var
|
||||||
cmd: TCommand;
|
cmd: TCommand;
|
||||||
@ -239,7 +269,6 @@ begin
|
|||||||
while Commands.Count>0 do
|
while Commands.Count>0 do
|
||||||
begin
|
begin
|
||||||
cmd := Commands.Objects[0] as TCommand;
|
cmd := Commands.Objects[0] as TCommand;
|
||||||
log(mtDebug,self,format('run(%s) %s %s ',[cmd.CommandID,cmd.CommandName, cmd.CommandSubClass]));
|
|
||||||
try
|
try
|
||||||
RunCommand(cmd);
|
RunCommand(cmd);
|
||||||
finally
|
finally
|
||||||
@ -260,15 +289,32 @@ function TBaseConnection.ProcessOptionValues(ReportName, ParamName: string;
|
|||||||
var
|
var
|
||||||
c: TCommand;
|
c: TCommand;
|
||||||
tmp: TStrings;
|
tmp: TStrings;
|
||||||
|
cc: TCommandClass;
|
||||||
begin
|
begin
|
||||||
with TCommandCollection.Find('report',Reportname).Create('', self.Processor,ReportName,fLogger,User,UserID) do
|
cc := TCommandCollection.Find('report',Reportname);
|
||||||
try
|
if assigned(cc) then
|
||||||
ParseCommand(0,0,ReportName,ParamValues,[],nil,tmp);
|
try
|
||||||
if assigned(tmp) then FreeAndNil(tmp);
|
with cc.Create('', self.Processor,ReportName,fLogger,User,UserID) do
|
||||||
result := ProcessOptionValues(ParamName,answer,RetValue,OptionValues);
|
try
|
||||||
finally
|
ParseCommand(0,0,ReportName,ParamValues,[],nil,tmp);
|
||||||
free
|
if assigned(tmp) then FreeAndNil(tmp);
|
||||||
end;
|
result := ProcessOptionValues(ParamName,answer,RetValue,OptionValues);
|
||||||
|
finally
|
||||||
|
free
|
||||||
|
end;
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(self,e,format('ProcessOptionValues(report=%s,param=%s)',[ReportName,ParamName]));
|
||||||
|
result := false;
|
||||||
|
Answer := e.Message;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
|
answer := 'Отчет не найден '+ReportName;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TBaseConnection.newID: string;
|
class function TBaseConnection.newID: string;
|
||||||
|
@ -6,7 +6,6 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, DaemonApp, ConnectionsDmUnit,eventlog;
|
Classes, SysUtils, DaemonApp, ConnectionsDmUnit,eventlog;
|
||||||
|
|
||||||
type
|
type
|
||||||
TLMSReportCGI=class;
|
TLMSReportCGI=class;
|
||||||
{ TDaemonThread }
|
{ TDaemonThread }
|
||||||
@ -18,6 +17,7 @@ type
|
|||||||
procedure Execute;override;
|
procedure Execute;override;
|
||||||
function sleepMin(n: integer): boolean;
|
function sleepMin(n: integer): boolean;
|
||||||
constructor Create(AOwner: TLMSReportCGI);
|
constructor Create(AOwner: TLMSReportCGI);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLMSReportCGI }
|
{ TLMSReportCGI }
|
||||||
@ -38,7 +38,7 @@ var
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
LazLogger;
|
LazLogger, extTypes;
|
||||||
procedure RegisterDaemon;
|
procedure RegisterDaemon;
|
||||||
begin
|
begin
|
||||||
RegisterDaemonClass(TLMSReportCGI)
|
RegisterDaemonClass(TLMSReportCGI)
|
||||||
@ -70,14 +70,14 @@ end;
|
|||||||
|
|
||||||
procedure TLMSReportCGI.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);
|
procedure TLMSReportCGI.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);
|
||||||
begin
|
begin
|
||||||
logger.Info('Запуск сервиса');
|
logger.Info('Запуск сервиса '+version);
|
||||||
workThread.Start;
|
workThread.Start;
|
||||||
OK := true;
|
OK := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLMSReportCGI.DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);
|
procedure TLMSReportCGI.DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);
|
||||||
begin
|
begin
|
||||||
debugln('Останов сервиса');
|
logger.Info('Останов сервиса '+version);
|
||||||
workThread.Terminate;
|
workThread.Terminate;
|
||||||
workThread.WaitFor;
|
workThread.WaitFor;
|
||||||
end;
|
end;
|
||||||
@ -86,7 +86,6 @@ end;
|
|||||||
|
|
||||||
procedure TDaemonThread.Execute;
|
procedure TDaemonThread.Execute;
|
||||||
begin
|
begin
|
||||||
flogger.debug('TDaemonThread.Execute');
|
|
||||||
fData := TConnectionsDM.CreateWithLog(fLogger);
|
fData := TConnectionsDM.CreateWithLog(fLogger);
|
||||||
try
|
try
|
||||||
fData.Start;
|
fData.Start;
|
||||||
@ -99,7 +98,6 @@ begin
|
|||||||
finally
|
finally
|
||||||
fData.free;
|
fData.free;
|
||||||
end;
|
end;
|
||||||
flogger.debug('TDaemonThread.Execute.complete');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDaemonThread.sleepMin(n: integer): boolean;
|
function TDaemonThread.sleepMin(n: integer): boolean;
|
||||||
|
@ -127,7 +127,7 @@ var
|
|||||||
vs: string;
|
vs: string;
|
||||||
vi: integer;
|
vi: integer;
|
||||||
begin
|
begin
|
||||||
log(mtDebug,'FillVars');
|
try
|
||||||
script := format('insert into tmp_report_variables(name,value_string,var_type) values(''UserName'',%s,0); ',[TNIDBDM.StringAsSQL(UserName)]);
|
script := format('insert into tmp_report_variables(name,value_string,var_type) values(''UserName'',%s,0); ',[TNIDBDM.StringAsSQL(UserName)]);
|
||||||
ASQL := format(Q_varlist,[ReportID,0]);
|
ASQL := format(Q_varlist,[ReportID,0]);
|
||||||
with Processor.GetData(ASQL) do
|
with Processor.GetData(ASQL) do
|
||||||
@ -155,7 +155,6 @@ begin
|
|||||||
try
|
try
|
||||||
while not eof do
|
while not eof do
|
||||||
begin
|
begin
|
||||||
log(mtDebug, FieldByName('name').asString);
|
|
||||||
q := FieldByName('query').AsString;
|
q := FieldByName('query').AsString;
|
||||||
UpdateCodeWithArguments(q);
|
UpdateCodeWithArguments(q);
|
||||||
try
|
try
|
||||||
@ -171,8 +170,17 @@ begin
|
|||||||
finally
|
finally
|
||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
if script<>'' then
|
if script<>'' then
|
||||||
Processor.ExecuteSQL(script);
|
Processor.ExecuteSQL(script);
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(e,'FillVars');
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TReportCommand.OnFillVariables(AVariables: TxpMemParamManager);
|
procedure TReportCommand.OnFillVariables(AVariables: TxpMemParamManager);
|
||||||
@ -246,7 +254,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
fResult := TCommandData.Create(0,fileData.size,ReportTitle+'.pdf',['type=application/pdf'],[],fileData);
|
fResult := TCommandData.Create(0,fileData.size,ReportTitle+'.pdf',['type=application/pdf'],[],fileData);
|
||||||
fileData.Seek(0,soFromBeginning);
|
fileData.Seek(0,soFromBeginning);
|
||||||
(fileData as TMemoryStream).SaveToFile(Extractfilepath(paramstr(0))+'out/report.pdf');
|
{$IFDEF DEBUG} (fileData as TMemoryStream).SaveToFile(format('%sout/%s_%s.pdf',[ Extractfilepath(paramstr(0)),self.CommandID,ReportTitle])); {$ENDIF}
|
||||||
fileData.Seek(0,soFromBeginning);
|
fileData.Seek(0,soFromBeginning);
|
||||||
result := true;
|
result := true;
|
||||||
finally
|
finally
|
||||||
|
@ -51,6 +51,7 @@ type
|
|||||||
function ParseCommand(ACode: DWORD; iParam: QWORD; ACommand: string; Args: TStrings; intArgs: TParamArray; CmdData: TStream; out Errors: TStrings): boolean;
|
function ParseCommand(ACode: DWORD; iParam: QWORD; ACommand: string; Args: TStrings; intArgs: TParamArray; CmdData: TStream; out Errors: TStrings): boolean;
|
||||||
function ParseArguments(Args: TStrings; out Errors: TStrings): boolean; virtual; abstract;
|
function ParseArguments(Args: TStrings; out Errors: TStrings): boolean; virtual; abstract;
|
||||||
procedure Log(ALevel:TLogLevel; msg: string);
|
procedure Log(ALevel:TLogLevel; msg: string);
|
||||||
|
procedure logError(e:Exception; Command: string);
|
||||||
function ProcessOptionValues(ParamName: string; out Answer: string; out RetValue: QWORD; out OptionValues: TStrings): boolean; virtual; abstract;
|
function ProcessOptionValues(ParamName: string; out Answer: string; out RetValue: QWORD; out OptionValues: TStrings): boolean; virtual; abstract;
|
||||||
end;
|
end;
|
||||||
TCommandClass=class of TCommand;
|
TCommandClass=class of TCommand;
|
||||||
@ -166,6 +167,7 @@ begin
|
|||||||
Results.Free;
|
Results.Free;
|
||||||
fResult := TCommandData.Create(ErrorInternal,0,e.ClassName,[e.Message],[],nil);
|
fResult := TCommandData.Create(ErrorInternal,0,e.ClassName,[e.Message],[],nil);
|
||||||
Results.Name:=e.Message;
|
Results.Name:=e.Message;
|
||||||
|
logError(e,'doRun');
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -190,6 +192,11 @@ begin
|
|||||||
fLogger(ALevel,self, self.CommandID+#09+msg)
|
fLogger(ALevel,self, self.CommandID+#09+msg)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCommand.logError(e: Exception; Command: string);
|
||||||
|
begin
|
||||||
|
log(mtError,format('%s вызвала ошибку %s(%s)',[Command,e.classname,e.Message]));
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
TCommandCollection.Init;
|
TCommandCollection.Init;
|
||||||
finalization
|
finalization
|
||||||
|
0
commit_info.sh
Normal file → Executable file
0
commit_info.sh
Normal file → Executable file
@ -53,6 +53,7 @@ type
|
|||||||
property DataBase: string read fDataBase;
|
property DataBase: string read fDataBase;
|
||||||
property Logger: TEventLog read fLogger write fLogger;
|
property Logger: TEventLog read fLogger write fLogger;
|
||||||
procedure Log(ALevel: TLogLevel; Sender: TObject; msg: string);
|
procedure Log(ALevel: TLogLevel; Sender: TObject; msg: string);
|
||||||
|
procedure LogError(Sender: TObject; e: Exception; Command: string);
|
||||||
procedure InitBaseCon;
|
procedure InitBaseCon;
|
||||||
procedure Start;
|
procedure Start;
|
||||||
procedure Stop;
|
procedure Stop;
|
||||||
@ -130,7 +131,7 @@ begin
|
|||||||
result.Host:=DataHost;
|
result.Host:=DataHost;
|
||||||
result.port:=DataPort;
|
result.port:=DataPort;
|
||||||
result.DataBase:=DataBase;
|
result.DataBase:=DataBase;
|
||||||
log(mtDebug, self, 'New '+result.ConnectionID);
|
log(mtDebug, self, 'Новое соединение с БД '+result.ConnectionID);
|
||||||
result.Init;
|
result.Init;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
@ -143,7 +144,7 @@ begin
|
|||||||
for i := conList.Count-1 downto 0 do
|
for i := conList.Count-1 downto 0 do
|
||||||
if TBaseConnection(conlist[i])=con then
|
if TBaseConnection(conlist[i])=con then
|
||||||
begin
|
begin
|
||||||
log(mtDebug,self,'terminate '+con.ConnectionID);
|
log(mtDebug,self,'Закрытие соединения '+con.ConnectionID);
|
||||||
TBaseConnection(conlist[i]).terminate;
|
TBaseConnection(conlist[i]).terminate;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -157,7 +158,7 @@ begin
|
|||||||
for i := conList.Count-1 downto 0 do
|
for i := conList.Count-1 downto 0 do
|
||||||
if TBaseConnection(conlist[i]).ConnectionID=ID then
|
if TBaseConnection(conlist[i]).ConnectionID=ID then
|
||||||
begin
|
begin
|
||||||
log(mtDebug,self,'terminate '+ID);
|
log(mtDebug,self,'Закрытие соединения '+ID);
|
||||||
TBaseConnection(conlist[i]).terminate;
|
TBaseConnection(conlist[i]).terminate;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -169,7 +170,7 @@ var
|
|||||||
i: integer;
|
i: integer;
|
||||||
con: TBaseConnection;
|
con: TBaseConnection;
|
||||||
begin
|
begin
|
||||||
log(mtDebug, self,'ClearConnections');
|
log(mtExtra, self,'ClearConnections');
|
||||||
for i := 0 to conList.Count-1 do
|
for i := 0 to conList.Count-1 do
|
||||||
begin
|
begin
|
||||||
con := TBaseConnection(conlist[i]);
|
con := TBaseConnection(conlist[i]);
|
||||||
@ -185,13 +186,13 @@ var
|
|||||||
i: integer;
|
i: integer;
|
||||||
con: TBaseConnection;
|
con: TBaseConnection;
|
||||||
begin
|
begin
|
||||||
log(mtDebug,self,'ClearTerminated');
|
log(mtExtra,self,'ClearTerminated');
|
||||||
for i := conlist.Count-1 downto 0 do
|
for i := conlist.Count-1 downto 0 do
|
||||||
begin
|
begin
|
||||||
con := TBaseConnection(conlist[i]);
|
con := TBaseConnection(conlist[i]);
|
||||||
if con.Finished then
|
if con.Finished then
|
||||||
begin
|
begin
|
||||||
log(mtDebug, self,'Destroy terminated '+con.ConnectionID);
|
log(mtDebug, self,'Закрытие по таймауту '+con.ConnectionID);
|
||||||
con.free;
|
con.free;
|
||||||
conlist.delete(i);
|
conlist.delete(i);
|
||||||
end;
|
end;
|
||||||
@ -215,7 +216,7 @@ var
|
|||||||
cmd: TCommand;
|
cmd: TCommand;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
log(mtInfo, Self,'Process Request '+ACommand);
|
log(mtDebug, Self,'Обработка запроса '+ACommand);
|
||||||
ClearTerminated;
|
ClearTerminated;
|
||||||
result := false;
|
result := false;
|
||||||
RetValue := 0;
|
RetValue := 0;
|
||||||
@ -356,11 +357,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
if cmd.Status=StatusComplete then
|
if cmd.Status=StatusComplete then
|
||||||
begin
|
begin
|
||||||
log(mtDebug,self,'result ready');
|
|
||||||
cmd.Results.AssignTo(Code,RetValue,Answer,rValues,iValues,ByteData);
|
cmd.Results.AssignTo(Code,RetValue,Answer,rValues,iValues,ByteData);
|
||||||
cmd.Done;
|
cmd.Done;
|
||||||
result := true;
|
result := true;
|
||||||
log(mtDebug,self,'result ready ok ');
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -378,7 +377,7 @@ begin
|
|||||||
result := false;
|
result := false;
|
||||||
Answer := e.message;
|
Answer := e.message;
|
||||||
Code := ErrorInternal;
|
Code := ErrorInternal;
|
||||||
log(mtError,self,format('ProcessRequest () -> %s(%s)',[e.ClassName,e.Message]));
|
LogError(self,e, format('ProcessRequest(%s)',[ACommand]));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -394,6 +393,7 @@ procedure TConnectionsDM.FillTemplates(RepList: TStrings);
|
|||||||
var
|
var
|
||||||
asql: string;
|
asql: string;
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
asql :=
|
asql :=
|
||||||
'select r.xp_rpt_id,r.name, c.cgi_name from xp_report r '+
|
'select r.xp_rpt_id,r.name, c.cgi_name from xp_report r '+
|
||||||
' join xp_report_cgi c on c.xp_rpt_id=r.xp_rpt_id '+
|
' join xp_report_cgi c on c.xp_rpt_id=r.xp_rpt_id '+
|
||||||
@ -408,6 +408,13 @@ begin
|
|||||||
finally
|
finally
|
||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
logError(Self,e,format('FillTemplates',[]));
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
function TConnectionsDM.CalcHash(Data: TStream): string;
|
function TConnectionsDM.CalcHash(Data: TStream): string;
|
||||||
var
|
var
|
||||||
@ -455,7 +462,15 @@ function TConnectionsDM.ProcessLogin(UserName, UserPassword: string; out UserID
|
|||||||
var
|
var
|
||||||
ASQL: string;
|
ASQL: string;
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
Result := MainCon.CheckUser(UserName,UserPassword,UserID);
|
Result := MainCon.CheckUser(UserName,UserPassword,UserID);
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
logError(Self,e,format('ProcessLogin(user=%s)',[UserName]));
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConnectionsDM.ProcessArguments(ReportName: string; out
|
function TConnectionsDM.ProcessArguments(ReportName: string; out
|
||||||
@ -465,6 +480,7 @@ var
|
|||||||
begin
|
begin
|
||||||
result := false;
|
result := false;
|
||||||
rValues := TStringList.Create;
|
rValues := TStringList.Create;
|
||||||
|
try
|
||||||
ASQL := format(
|
ASQL := format(
|
||||||
'select r.xp_rpt_id,r.name as reportname,p.name as paramname, '+
|
'select r.xp_rpt_id,r.name as reportname,p.name as paramname, '+
|
||||||
'case p.type '+
|
'case p.type '+
|
||||||
@ -508,12 +524,20 @@ begin
|
|||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
logError(Self,e,format('ProcessArguments(report=%s)',[ReportName]));
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConnectionsDM.ProcessReports(out rValues: TStrings): boolean;
|
function TConnectionsDM.ProcessReports(out rValues: TStrings): boolean;
|
||||||
var
|
var
|
||||||
ASQL: string;
|
ASQL: string;
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
rValues := TStringList.Create;
|
rValues := TStringList.Create;
|
||||||
ASQL :=
|
ASQL :=
|
||||||
'select c.cgi_name,r.name as rep_name '+
|
'select c.cgi_name,r.name as rep_name '+
|
||||||
@ -531,6 +555,13 @@ begin
|
|||||||
finally
|
finally
|
||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(self,e,format('ProcessReports',[]));
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
result := true;
|
result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -542,6 +573,7 @@ var
|
|||||||
code: string;
|
code: string;
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
ASQL := format(
|
ASQL := format(
|
||||||
'select source from xp_report_params p '+
|
'select source from xp_report_params p '+
|
||||||
' join xp_report_cgi c on c.xp_rpt_id=p.xp_rpt_id '+
|
' join xp_report_cgi c on c.xp_rpt_id=p.xp_rpt_id '+
|
||||||
@ -570,6 +602,13 @@ begin
|
|||||||
free;
|
free;
|
||||||
end;
|
end;
|
||||||
result := true;
|
result := true;
|
||||||
|
|
||||||
|
except on e: Exception do
|
||||||
|
begin
|
||||||
|
LogError(self,e,format('ProcessOptionValues(report=%s,param=%s)',[ReportName,ParamName]));
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -586,10 +625,10 @@ begin
|
|||||||
fDataBase:= ini.ReadString('DATA','database','');
|
fDataBase:= ini.ReadString('DATA','database','');
|
||||||
fServicePort := ini.ReadInteger('PARAMS','port',6543);
|
fServicePort := ini.ReadInteger('PARAMS','port',6543);
|
||||||
fTimeOut:=ini.ReadInteger('PARAMS','timeout',CONNECT_TIMEOUT);
|
fTimeOut:=ini.ReadInteger('PARAMS','timeout',CONNECT_TIMEOUT);
|
||||||
log(mtInfo,self,format('server %s:%d/%s',[fDataHost,fDataPort,fDataBase]));
|
|
||||||
finally
|
finally
|
||||||
ini.free;
|
ini.free;
|
||||||
end;
|
end;
|
||||||
|
log(mtInfo,self,format('База данных %s:%d/%s Порт для соединения %d',[fDataHost,fDataPort,fDataBase,fServicePort]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TConnectionsDM.Log(ALevel: TLogLevel; Sender: TObject; msg: string);
|
procedure TConnectionsDM.Log(ALevel: TLogLevel; Sender: TObject; msg: string);
|
||||||
@ -617,6 +656,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TConnectionsDM.LogError(Sender: TObject; e: Exception; Command: string
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
log(mtError,Sender,format('%s вызвала ошибку %s(%s) ',[Command, e.classname,e.message]));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TConnectionsDM.InitBaseCon;
|
procedure TConnectionsDM.InitBaseCon;
|
||||||
begin
|
begin
|
||||||
MainCon.connection.RemoteHost:=DataHost;
|
MainCon.connection.RemoteHost:=DataHost;
|
||||||
|
@ -7,7 +7,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, LNet, syncobjs;
|
Classes, SysUtils, LNet, syncobjs;
|
||||||
const
|
const
|
||||||
version='0.0.0.1';
|
version='0.0.1.2';
|
||||||
cmdRequest=1;
|
cmdRequest=1;
|
||||||
cmdAnswer=2;
|
cmdAnswer=2;
|
||||||
cmdError=3;
|
cmdError=3;
|
||||||
|
@ -5,11 +5,11 @@ object ReportDM: TReportDM
|
|||||||
VerticalOffset = 317
|
VerticalOffset = 317
|
||||||
Width = 330
|
Width = 330
|
||||||
object frxReport: TfrxReport
|
object frxReport: TfrxReport
|
||||||
Version = '2023.3.3'
|
Version = '2023.3.0'
|
||||||
DotMatrixReport = False
|
DotMatrixReport = False
|
||||||
EngineOptions.SilentMode = True
|
EngineOptions.SilentMode = True
|
||||||
EngineOptions.NewSilentMode = simSilent
|
EngineOptions.NewSilentMode = simSilent
|
||||||
IniFile = '\Software\Fast Reports'
|
IniFile = 'tmp/fr6.ini'
|
||||||
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick, pbCopy, pbSelection]
|
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick, pbCopy, pbSelection]
|
||||||
PreviewOptions.Zoom = 1
|
PreviewOptions.Zoom = 1
|
||||||
PrintOptions.Printer = 'Default'
|
PrintOptions.Printer = 'Default'
|
||||||
|
@ -194,7 +194,6 @@ end;
|
|||||||
|
|
||||||
procedure TReportDM.frxReportEndDoc(Sender: TObject);
|
procedure TReportDM.frxReportEndDoc(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,Sender,'TReportDM.frxReportEndDoc');;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TReportDM.CreateDBDataSet(Query: TReportQuery; EditReport: Boolean);
|
procedure TReportDM.CreateDBDataSet(Query: TReportQuery; EditReport: Boolean);
|
||||||
@ -364,7 +363,6 @@ procedure TReportDM.frxReportPreview(Sender: TObject);
|
|||||||
var
|
var
|
||||||
Report: TfrxReport;
|
Report: TfrxReport;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,Sender,'TReportDM.frxReportPreview');;
|
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -374,7 +372,6 @@ var
|
|||||||
q: TReportquery;
|
q: TReportquery;
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'LoadQueries');
|
|
||||||
SQL := format(
|
SQL := format(
|
||||||
'select q.xp_rpt_q_id,qp.xp_rpt_q_id as ParentID,q.Link_field, '+
|
'select q.xp_rpt_q_id,qp.xp_rpt_q_id as ParentID,q.Link_field, '+
|
||||||
' q.Name,'+
|
' q.Name,'+
|
||||||
@ -405,12 +402,10 @@ begin
|
|||||||
for i := ReportQueries.QueryCount-1 downto 0 do
|
for i := ReportQueries.QueryCount-1 downto 0 do
|
||||||
if ReportQueries.Queries[i].ParentID>0 then
|
if ReportQueries.Queries[i].ParentID>0 then
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'LoadQueries.'+ReportQueries.Queries[i].Name);
|
|
||||||
q := ReportQueries.Find(ReportQueries.Queries[i].ParentID);
|
q := ReportQueries.Find(ReportQueries.Queries[i].ParentID);
|
||||||
if assigned(q) then
|
if assigned(q) then
|
||||||
q.AddQuery(ReportQueries.Queries[i]);
|
q.AddQuery(ReportQueries.Queries[i]);
|
||||||
end;
|
end;
|
||||||
NidbData.log(mtDebug,self,'LoadQueries-OK');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TReportDM.LoadDefaultVariables(AVariables: TxpMemParamManager);
|
procedure TReportDM.LoadDefaultVariables(AVariables: TxpMemParamManager);
|
||||||
@ -421,7 +416,6 @@ var
|
|||||||
OptionName,
|
OptionName,
|
||||||
OptionValue: String;
|
OptionValue: String;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'LoadDefaultVariables');
|
|
||||||
|
|
||||||
SQL := 'select name,value from options where name in (''GOU_Name'',''Dep_Name'')';
|
SQL := 'select name,value from options where name in (''GOU_Name'',''Dep_Name'')';
|
||||||
with NidbData.GetData(sql) do
|
with NidbData.GetData(sql) do
|
||||||
@ -490,7 +484,6 @@ procedure TReportDM.LoadVariables(AVariables, AParam: TxpMemParamManager);
|
|||||||
var
|
var
|
||||||
sql: string;
|
sql: string;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'LoadVariables');
|
|
||||||
sql := 'select name,value_string, value_int from tmp_report_variables where var_type=0';
|
sql := 'select name,value_string, value_int from tmp_report_variables where var_type=0';
|
||||||
with NidbData.GetData(sql) do
|
with NidbData.GetData(sql) do
|
||||||
try
|
try
|
||||||
@ -525,7 +518,6 @@ begin
|
|||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
NidbData.log(mtDebug,self,'LoadVariables-OK');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TReportDM.OnMasterRecord(Sender: TObject);
|
procedure TReportDM.OnMasterRecord(Sender: TObject);
|
||||||
@ -570,7 +562,6 @@ var
|
|||||||
BlobStream : TStream;
|
BlobStream : TStream;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'ExportReport.TemplateArh');
|
|
||||||
ReportStream := TMemoryStream.Create;
|
ReportStream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
with NidbData.GetData(format('select TemplateArh from xp_report where xp_rpt_id=%d',[RecordID])) do
|
with NidbData.GetData(format('select TemplateArh from xp_report where xp_rpt_id=%d',[RecordID])) do
|
||||||
@ -614,7 +605,6 @@ var
|
|||||||
ASQL: string;
|
ASQL: string;
|
||||||
newhash: string;
|
newhash: string;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'ExportReport.TemplateArh');
|
|
||||||
ReportStream := TMemoryStream.Create;
|
ReportStream := TMemoryStream.Create;
|
||||||
BlobStream := TMemoryStream.Create;
|
BlobStream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
@ -637,7 +627,6 @@ var
|
|||||||
i: integer;
|
i: integer;
|
||||||
v: variant;
|
v: variant;
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,self,'CopyReportVariables');
|
|
||||||
for I := Low(AVariables.Params) to High(AVariables.Params) do
|
for I := Low(AVariables.Params) to High(AVariables.Params) do
|
||||||
begin
|
begin
|
||||||
if VarIsStr(AVariables.Params[i][1]) then
|
if VarIsStr(AVariables.Params[i][1]) then
|
||||||
@ -659,7 +648,6 @@ end;
|
|||||||
|
|
||||||
procedure TReportDM.LogExport(Sender: TObject);
|
procedure TReportDM.LogExport(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
NidbData.log(mtDebug,Sender,'export-started');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -675,7 +663,6 @@ var
|
|||||||
begin
|
begin
|
||||||
fOnVars:=OnVars;
|
fOnVars:=OnVars;
|
||||||
frxReport.EngineOptions.EnableThreadSafe:=true;
|
frxReport.EngineOptions.EnableThreadSafe:=true;
|
||||||
NidbData.log(mtDebug,self,'ExportReport');
|
|
||||||
ReportQueries := TReportQuery.Create;
|
ReportQueries := TReportQuery.Create;
|
||||||
AVariables := TxpMemParamManager.Create;
|
AVariables := TxpMemParamManager.Create;
|
||||||
AParam := TxpMemParamManager.Create;
|
AParam := TxpMemParamManager.Create;
|
||||||
@ -706,7 +693,7 @@ begin
|
|||||||
try
|
try
|
||||||
frxReport.PrepareReport(False);
|
frxReport.PrepareReport(False);
|
||||||
frxReport.OnPreview := @frxReportPreview;
|
frxReport.OnPreview := @frxReportPreview;
|
||||||
frxReport.SaveToFile(Extractfilepath(paramstr(0))+'out/report.fr3');
|
{$IFDEF DEBUG} frxReport.SaveToFile(Extractfilepath(paramstr(0))+'out/report.fr3'); {$ENDIF}
|
||||||
except on e: Exception do
|
except on e: Exception do
|
||||||
begin
|
begin
|
||||||
NidbData.logError(self,e,'frxReport.PrepareReport');
|
NidbData.logError(self,e,'frxReport.PrepareReport');
|
||||||
@ -751,7 +738,6 @@ begin
|
|||||||
AVariables.Free;
|
AVariables.Free;
|
||||||
AParam.Free;
|
AParam.Free;
|
||||||
end;
|
end;
|
||||||
NidbData.log(mtDebug,self,'Report complete');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TReportDM.EditReport(OnVars: TVariableFillProc; OnHash: TCalcHashProc
|
procedure TReportDM.EditReport(OnVars: TVariableFillProc; OnHash: TCalcHashProc
|
||||||
@ -765,7 +751,6 @@ var
|
|||||||
begin
|
begin
|
||||||
fOnVars:=OnVars;
|
fOnVars:=OnVars;
|
||||||
frxReport.EngineOptions.EnableThreadSafe:=true;
|
frxReport.EngineOptions.EnableThreadSafe:=true;
|
||||||
NidbData.log(mtDebug,self,'EditReport');
|
|
||||||
ReportQueries := TReportQuery.Create;
|
ReportQueries := TReportQuery.Create;
|
||||||
AVariables := TxpMemParamManager.Create;
|
AVariables := TxpMemParamManager.Create;
|
||||||
AParam := TxpMemParamManager.Create;
|
AParam := TxpMemParamManager.Create;
|
||||||
@ -798,7 +783,6 @@ begin
|
|||||||
AVariables.Free;
|
AVariables.Free;
|
||||||
AParam.Free;
|
AParam.Free;
|
||||||
end;
|
end;
|
||||||
NidbData.log(mtDebug,self,'Report complete');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user