Po hlavnich upravach sdileni sponeni a uvolnovani connection poolu

This commit is contained in:
2026-04-13 12:20:09 +02:00
parent a62b608cfd
commit 1258a27a4e
16 changed files with 2006 additions and 1324 deletions

Binary file not shown.

View File

@ -133,7 +133,7 @@ IF (@genDokladMat=1) OR (@genDokladFin=1)
IF (@@FETCH_STATUS<>0) BREAK IF (@@FETCH_STATUS<>0) BREAK
SET @cnt = (SELECT COUNT(d.ID) FROM dbo.TabDokladyZbozi d JOIN dbo.TabDokladyZbozi_EXT de ON (de.ID=d.ID) WHERE d.IDSklad=@cilovySklad AND d.RadaDokladu=@radaDokl SET @cnt = (SELECT COUNT(d.ID) FROM dbo.TabDokladyZbozi d JOIN dbo.TabDokladyZbozi_EXT de ON (de.ID=d.ID) WHERE d.IDSklad=@cilovySklad AND d.RadaDokladu=@radaDokl
AND CAST(d.DatPorizeni AS DATE)=IIF(@material=0, CAST(@datumDokladuMat AS DATE), CAST(@datumDokladuFin AS DATE)) AND s.BlokovaniEditoru IS NULL AND CAST(d.DatPorizeni AS DATE)=IIF(@material=0, CAST(@datumDokladuMat AS DATE), CAST(@datumDokladuFin AS DATE)) AND d.BlokovaniEditoru IS NULL
AND d.DruhPohybuZbo=@druhPohybuZbo AND d.Realizovano=0 AND de._Vyroba_ObjednavkaMat_Typ=(@material+1) AND d.DruhPohybuZbo=@druhPohybuZbo AND d.Realizovano=0 AND de._Vyroba_ObjednavkaMat_Typ=(@material+1)
) )
IF (@cnt<=1) IF (@cnt<=1)

View File

@ -794,6 +794,7 @@ uses
var lQry: TFDQuery; var lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
lSQL, where, errMsg: string; lSQL, where, errMsg: string;
lokIDcka: TList<integer>;
cnt, rNo, idVPr: integer; cnt, rNo, idVPr: integer;
typPrikazu: integer; typPrikazu: integer;
operace, material, spustene: boolean; operace, material, spustene: boolean;
@ -804,11 +805,12 @@ uses
p: TVyrobniPrikaz; p: TVyrobniPrikaz;
vpSvr: TVyrobniPrikazService; vpSvr: TVyrobniPrikazService;
locParams: TDictionary<string, string>; locParams: TDictionary<string, string>;
lokIDcko: TObject;
begin begin
cisOper:= ''; cisOper:= '';
locParams:= TDictionary<string, string>.Create; locParams:= TDictionary<string, string>.Create;
try
operace:= false; operace:= false;
if (params.ContainsKey('operace')) then if (params.ContainsKey('operace')) then
@ -1027,7 +1029,7 @@ uses
if (params.ContainsKey('doDatum')) then if (params.ContainsKey('doDatum')) then
if (params.Items['doDatum']<>'') then if (params.Items['doDatum']<>'') then
odDatum:= params.Items['doDatum']; doDatum:= params.Items['doDatum'];
if (doDatum<>'') then if (doDatum<>'') then
begin begin
if (Length(doDatum)=8) then if (Length(doDatum)=8) then
@ -1066,51 +1068,85 @@ uses
vpSvr := TVyrobniPrikazService.Create (self.FDM); vpSvr := TVyrobniPrikazService.Create (self.FDM);
try
sqlConnX := TFDConnection.Create (nil); sqlConnX := TFDConnection.Create (nil);
try
sqlConnX.ConnectionDefName := sqlPoolName; sqlConnX.ConnectionDefName := sqlPoolName;
sqlConnX.Open;
lokIDcka := TList<Integer>.Create;
try
lQry := TFDQuery.Create (nil); lQry := TFDQuery.Create (nil);
try try
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
lQry.FetchOptions.Mode := fmAll; lQry.FetchOptions.Mode := fmAll;
lQry.Open (lSQL); lQry.Open (lSQL);
cnt := lQry.RecordCount; cnt := lQry.RecordCount;
vpList:= TObjectList<TVyrobniPrikaz>.Create;
try if not lQry.Active then
if not(lQry.Active) then
lQry.Open (lSQL); lQry.Open (lSQL);
lQry.First; lQry.First;
rNo := 1; rNo := 1;
try
while (rNo <= cnt) do while (rNo <= cnt) do
begin begin
lQry.RecNo := rNo; lQry.RecNo := rNo;
idVPr := lQry.FieldByName('ID').AsInteger; idVPr := lQry.FieldByName('ID').AsInteger;
p:= vpSvr.GetByID (idVPr, locParams); lokIDcka.Add (idVPr);
vpList.Add(p); if not lQry.Active then
if not(lQry.Active) then lQry.Open (lSQL);
lQry.Open;
Inc(rNo); Inc(rNo);
end; end;
result:= vpList;
except on E:Exception do except
on E: Exception do
begin begin
errMsg:= e.Message; {$IF CompilerVersion >= 37.0} // Delphi 13+
raise EServiceException.Create('Chyba načítání naskenované položky/položek dokladu: ' + E.Message); raise EServiceException.Create ('Chyba načítání naskenované položky/položek dokladu') from E;
end; {$ELSE}
end; raise EServiceException.Create ('Chyba načítání naskenované položky/položek dokladu: ' + E.Message) at ExceptAddr;
finally {$ENDIF}
begin
vpSvr.Free;
FreeAndNil(lQry);
end; end;
end; end;
locParams.Free; finally
sqlConnX.Close; lQry.Free;
end;
vpList := TObjectList<TVyrobniPrikaz>.Create;
try
for idVPr in lokIDcka do
begin
p := vpSvr.GetByID (idVPr, locParams, sqlConnX);
vpList.Add (p);
end;
result := vpList;
vpList := nil; // zabrani uvolneni v finally
finally
vpList.Free;
end;
finally
lokIDcka.Free;
end;
finally
sqlConnX.Free; sqlConnX.Free;
end; end;
finally
vpSvr.Free;
end;
finally
locParams.Free;
end;
end;

View File

@ -55,7 +55,7 @@
var lSQL, errMsg, url, outData, fName, loopCasTyp: string; var lSQL, errMsg, url, outData, fName, loopCasTyp: string;
lLoop, idDigiFile, cnt, idx: Integer; lLoop, idDigiFile, cnt, idx: Integer;
lLoopMax, koefProCas: integer; lLoopMax, koefProCas: integer;
logRunCnt: integer; logRunCnt, intTemp: integer;
Msg: TMsg; Msg: TMsg;
firstRun, inProg, inDL: boolean; firstRun, inProg, inDL: boolean;
lQry: TFDQuery; lQry: TFDQuery;
@ -95,13 +95,15 @@
attrIdx:= attribs.IndexOf('zapisObjMatExpPrIntMins'); attrIdx:= attribs.IndexOf('zapisObjMatExpPrIntMins');
if (attrIdx>-1) then if (attrIdx>-1) then
if (attribs.Get(attrIdx).NodeValue<>null) then if TryStrToInt(VarToStr(attribs.Get(attrIdx).NodeValue), intTemp) then
lLoopMax:= attribs.Get(attrIdx).NodeValue; lLoopMax:= intTemp;
end; // n1 = config end; // n1 = config
end; // specCfgXML.DocumentElement<>nil end; // specCfgXML.DocumentElement<>nil
end; // not specCfgXML.IsEmptyDoc end; // not specCfgXML.IsEmptyDoc
end; // FileExists(cfgFile) end; // FileExists(cfgFile)
except except
on E: Exception do
datMod.LogInfo (Quick.Logger.etError, 'Chyba cteni konfigu THeoRTNZapisObjMatThread: ' + E.Message);
end; end;
finally finally
begin begin
@ -125,16 +127,7 @@
liDueTime.QuadPart := -1*_Second; liDueTime.QuadPart := -1*_Second;
sqlConnX:= TFDConnection.Create (nil); while not(Terminated) and FRunning do
sqlConnX.Params.SetStrings (datMod.sqlConnParams);
lSQL:= 'DECLARE @errMsg NVARCHAR(500)=N''''' + CRLF +'IF OBJECT_ID(N''dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew'', N''P'') IS NOT NULL' + CRLF
+ ' EXEC dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew @errMsg OUT' + CRLF + 'SELECT @errMsg AS ErrMsg';
lQry:= TFDQuery.Create(nil);
try
lQry.Connection:= sqlConnX;
while not(Terminated) or not(FRunning) do
begin begin
if (HDCDZApiService<>nil) then if (HDCDZApiService<>nil) then
if (HDCDZApiService.Terminated) then if (HDCDZApiService.Terminated) then
@ -147,6 +140,14 @@
if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu
begin begin
sqlConnX := TFDConnection.Create (nil);
try
sqlConnX.Params.SetStrings (datMod.sqlConnParams);
lQry := TFDQuery.Create(nil);
try
lQry.Connection := sqlConnX;
idDigiFile:= 0; idDigiFile:= 0;
firstRun:= false; firstRun:= false;
@ -165,6 +166,10 @@
if (sqlConnX.Connected) then if (sqlConnX.Connected) then
begin begin
inProg:= true; inProg:= true;
lSQL:= 'DECLARE @errMsg NVARCHAR(500)=N''''' + CRLF +'IF OBJECT_ID(N''dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew'', N''P'') IS NOT NULL' + CRLF
+ ' EXEC dbo.ep_Vyroba_GenObjednavkuMatDoVyrobyNew @errMsg OUT' + CRLF + 'SELECT @errMsg AS ErrMsg';
lQry.Open(lSQL); lQry.Open(lSQL);
if (lQry.RecordCount>0) then if (lQry.RecordCount>0) then
begin begin
@ -178,10 +183,10 @@
{$ENDIF} {$ENDIF}
end; end;
end; end;
lQry.Close;
inProg:= false; inProg:= false;
end; // sql Connected end; // sql Connected
end; end; // 1=1
end; end;
except on E:Exception do except on E:Exception do
@ -197,14 +202,22 @@
end; end;
end; end;
end; end;
finally
lQry.Free;
end;
finally
sqlConnX.Free;
end;
lLoop:= 0; lLoop:= 0;
if (logRunCnt<5) then if (logRunCnt<5) then
Inc (logRunCnt); Inc (logRunCnt);
end; end; // if lLoop=lLoopMax...
Inc (lLoop); Inc (lLoop);
if (FTimer<>0) then if (FTimer<>0) then
SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false); SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false);
repeat repeat
@ -212,20 +225,10 @@
until lBusy = WAIT_OBJECT_0; until lBusy = WAIT_OBJECT_0;
// Sleep (998); // Sleep (998);
end; end; // while not(Terminated) and FRunning
finally
end;
if (lQry<>nil) then if (FTimer<>0) then
begin CloseHandle (FTimer);
lQry.Close;
FreeAndNil (lQry);
end;
if (sqlConnX<>nil) then
begin
sqlConnX.Close;
FreeAndNil (sqlConnX);
end;
end; // 1=1 end; // 1=1

Binary file not shown.

View File

@ -13,9 +13,7 @@ uses
Winapi.Windows, Winapi.Windows,
System.Classes, System.Classes,
{$IFDEF DEBUG}
Web.WebReq, Web.WebReq,
{$ENDIF}
MVCFramework.Middleware.Swagger, MVCFramework.Middleware.Swagger,
MVCFramework.Swagger.Commons, MVCFramework.Swagger.Commons,

View File

@ -5,7 +5,7 @@
<FrameworkType>VCL</FrameworkType> <FrameworkType>VCL</FrameworkType>
<MainSource>hdcDZApi.dpr</MainSource> <MainSource>hdcDZApi.dpr</MainSource>
<Base>True</Base> <Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config> <Config Condition="'$(Config)'==''">Release</Config>
<Platform Condition="'$(Platform)'==''">Win64</Platform> <Platform Condition="'$(Platform)'==''">Win64</Platform>
<TargetedPlatforms>2</TargetedPlatforms> <TargetedPlatforms>2</TargetedPlatforms>
<AppType>Application</AppType> <AppType>Application</AppType>
@ -131,9 +131,9 @@
<DCC_ImageBase>700000</DCC_ImageBase> <DCC_ImageBase>700000</DCC_ImageBase>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo> <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_MajorVer>3</VerInfo_MajorVer> <VerInfo_MajorVer>3</VerInfo_MajorVer>
<VerInfo_Release>2025</VerInfo_Release> <VerInfo_Release>2026</VerInfo_Release>
<VerInfo_Build>1205</VerInfo_Build> <VerInfo_Build>412</VerInfo_Build>
<VerInfo_Keys>CompanyName=HD Consulting s.r.o. Strakonice;FileDescription=HDC x Pro Holding DataZone komunikator (API);FileVersion=3.0.2025.1205;InternalName=;LegalCopyright=(c) 2022-25 HD Consulting s.r.o. / Tomas Buzin;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=XE12.3.1;LastCompiledTime=2025.12.05 12:42:18</VerInfo_Keys> <VerInfo_Keys>CompanyName=HD Consulting s.r.o. Strakonice;FileDescription=HDC x Pro Holding DataZone komunikator (API);FileVersion=3.0.2026.412;InternalName=;LegalCopyright=(c) 2022-25 HD Consulting s.r.o. / Tomas Buzin;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=XE12.3.1;LastCompiledTime=2026.04.12 16:03:18</VerInfo_Keys>
<Icon_MainIcon>api2-5.ico</Icon_MainIcon> <Icon_MainIcon>api2-5.ico</Icon_MainIcon>
<DCC_MapFile>3</DCC_MapFile> <DCC_MapFile>3</DCC_MapFile>
<DCC_DebugInformation>2</DCC_DebugInformation> <DCC_DebugInformation>2</DCC_DebugInformation>
@ -251,7 +251,7 @@
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\SVGIconImageList290.bpl">Ethea SVGIconImageList VCL components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\SVGIconImageList290.bpl">Ethea SVGIconImageList VCL components</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\EssentialsDR290.bpl">TurboPack Essentials Delphi Runtime package</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\EssentialsDR290.bpl">TurboPack Essentials Delphi Runtime package</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\PngComponentsD290.bpl">Png Components for Delphi</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\PngComponentsD290.bpl">Png Components for Delphi</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dmvcframeworkRT120.bpl">DMVCFramework - CopyRight (2010-2024) Daniele Teti and the DMVCFramework Team</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dmvcframeworkRT120.bpl">DMVCFramework - CopyRight (2010-2025) Daniele Teti and the DMVCFramework Team</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvAppFrmDesign290.bpl">JVCL Application and Form Components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvAppFrmDesign290.bpl">JVCL Application and Form Components</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvBandsDesign290.bpl">JVCL Band Objects</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvBandsDesign290.bpl">JVCL Band Objects</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvCmpDesign290.bpl">JVCL Non-Visual Components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\JvCmpDesign290.bpl">JVCL Non-Visual Components</Excluded_Packages>
@ -282,6 +282,7 @@
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dclunidac290.bpl">Devart Universal Data Access Components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dclunidac290.bpl">Devart Universal Data Access Components</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dclSVGIconImageListFMX290.bpl">Ethea SVGIconImageList FMX components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dclSVGIconImageListFMX290.bpl">Ethea SVGIconImageList FMX components</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dcldxIconLibraryRS29.bpl">Express Cross Platform Library Icon Library by Developer Express Inc.</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\dcldxIconLibraryRS29.bpl">Express Cross Platform Library Icon Library by Developer Express Inc.</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\ColorButton.bpl">(untitled)</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\VirtualTreesDD290.bpl">File C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\VirtualTreesDD290.bpl not found</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\VirtualTreesDD290.bpl">File C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\VirtualTreesDD290.bpl not found</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\Vyvoj12_0.bpl">Helios Orange Components</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\Vyvoj12_0.bpl">Helios Orange Components</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\LockBox3DR290.bpl">TurboPack LockBox 3 Delphi runtime package</Excluded_Packages> <Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\23.0\Bpl\LockBox3DR290.bpl">TurboPack LockBox 3 Delphi runtime package</Excluded_Packages>

Binary file not shown.

View File

@ -246,7 +246,7 @@ uses
try try
Render(ObjectDict().Add('data', GetStavSkladuService.GetByParams(params))); // viz uSvc_ObehZbozi.pas Render(ObjectDict().Add('data', GetStavSkladuService.GetByParams(params, FDM.sqlConn))); // viz uSvc_ObehZbozi.pas
except except
{$IFDEF NORENDER400} {$IFDEF NORENDER400}
RenderStatusMessage (200); RenderStatusMessage (200);
@ -343,7 +343,7 @@ uses
try try
Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params))); // viz uSvc_ObehZbozi.pas Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params, FDM.sqlConn))); // viz uSvc_ObehZbozi.pas
except except
{$IFDEF NORENDER400} {$IFDEF NORENDER400}
RenderStatusMessage (200); RenderStatusMessage (200);
@ -410,7 +410,7 @@ uses
begin begin
params.Add('id', iId.ToString); params.Add('id', iId.ToString);
try try
Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params))); // viz uSvc_ObehZbozi.pas Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params, FDM.sqlConn))); // viz uSvc_ObehZbozi.pas
except except
{$IFDEF NORENDER400} {$IFDEF NORENDER400}
RenderStatusMessage (200); RenderStatusMessage (200);
@ -550,7 +550,7 @@ uses
params.Add('iddoklad', iIdDoklad.ToString); params.Add('iddoklad', iIdDoklad.ToString);
try try
Render(ObjectDict().Add('data', GetPolozkaOZService.GetByParams(params))); // viz uSvc_ObehZbozi.pas Render(ObjectDict().Add('data', GetPolozkaOZService.GetByParams(params, FDM.sqlConn))); // viz uSvc_ObehZbozi.pas
except except
{$IFDEF NORENDER400} {$IFDEF NORENDER400}
RenderStatusMessage (200); RenderStatusMessage (200);

View File

@ -854,7 +854,7 @@ uses
try try
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params))); Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -886,7 +886,7 @@ uses
params.Add('id', iId.ToString); params.Add('id', iId.ToString);
try try
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params))); Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -974,7 +974,7 @@ uses
if (iId>0) then if (iId>0) then
begin begin
try try
Render(ObjectDict().Add('data', GetVyrobaEvidenceOperaciService.GetByID (iId))); Render(ObjectDict().Add('data', GetVyrobaEvidenceOperaciService.GetByID (iId, nil, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1040,7 +1040,7 @@ uses
params.Add('id', iId.ToString); params.Add('id', iId.ToString);
try try
Render(ObjectDict().Add('data', GetTPVCisKoopService.GetByParams (params))); Render(ObjectDict().Add('data', GetTPVCisKoopService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1122,7 +1122,7 @@ uses
params.Add('spustene', '1'); params.Add('spustene', '1');
try try
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params) )); Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params, FDM.sqlConn) ));
except on E:Exception do except on E:Exception do
begin begin
RenderStatusMessage (200); RenderStatusMessage (200);
@ -1161,7 +1161,7 @@ uses
params.Add('jenId', '1'); params.Add('jenId', '1');
try try
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params))); Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
end; end;
@ -1204,7 +1204,7 @@ uses
try try
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByID (iId, params))); Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByID (iId, params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1330,7 +1330,7 @@ uses
try try
Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params))); Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1420,7 +1420,7 @@ uses
mnReq:= 0; mnReq:= 0;
try try
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetKusovnik (idVPr, mnReq, jenPlatne, 0))); Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetKusovnik (idVPr, mnReq, jenPlatne, 0, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1477,7 +1477,7 @@ uses
params.Add('stavPrikazu', iStav.ToString); params.Add('stavPrikazu', iStav.ToString);
try try
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params))); Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1570,7 +1570,7 @@ uses
try try
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params))); Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1680,7 +1680,7 @@ uses
try try
Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByParams (p))); // viz uSvc_Vyroba.pas Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByParams (p, FDM.sqlConn))); // viz uSvc_Vyroba.pas
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1721,7 +1721,7 @@ uses
params.Add ('kontrolnipostupy', '1'); params.Add ('kontrolnipostupy', '1');
try try
Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByID (iid, params))); Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByID (iid, params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1840,7 +1840,7 @@ uses
try try
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByParams(params))); Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByParams(params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -1876,7 +1876,7 @@ uses
bPol:= (p=1); bPol:= (p=1);
try try
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByID(iId, bPol))); Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByID(iId, bPol, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -2100,7 +2100,7 @@ uses
params.Add('dilec', idDilce.ToString); params.Add('dilec', idDilce.ToString);
try try
Render(ObjectDict().Add('data', GetTPVOperaceDilceService.GetByParams (params))); Render(ObjectDict().Add('data', GetTPVOperaceDilceService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
end; end;
@ -2176,7 +2176,7 @@ uses
params.Add('id', iId.ToString); params.Add('id', iId.ToString);
try try
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params))); Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
except except
RenderStatusMessage (200); RenderStatusMessage (200);
{ {
@ -2382,7 +2382,7 @@ uses
params.Add ('id', iId.ToString); params.Add ('id', iId.ToString);
try try
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByID (iId, params))); Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByID (iId, params, FDM.sqlConn)));
except except
// RenderStatusMessage (200); // RenderStatusMessage (200);
{ {
@ -2424,7 +2424,7 @@ uses
{$ENDIF} {$ENDIF}
try try
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByParams (params))); Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByParams (params, FDM.sqlConn)));
except except
// RenderStatusMessage (200); // RenderStatusMessage (200);
{ {

View File

@ -9,7 +9,7 @@ uses
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.UI, FireDAC.Phys.MSSQLDef, Data.DB, FireDAC.Comp.Client, FireDAC.Comp.UI, FireDAC.Phys.MSSQLDef,
FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL, FireDAC.Stan.Param, FireDAC.DatS,
FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Stan.Consts, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Stan.Consts,
Winapi.ActiveX, Winapi.ActiveX, System.RegularExpressions,
MVCFramework.Logger, MVCFramework.Logger,
Quick.Logger, Quick.Threads, Quick.Logger.Provider.Files; Quick.Logger, Quick.Threads, Quick.Logger.Provider.Files;
@ -44,6 +44,7 @@ type
function SQLRecordExists (sqlText: string): Boolean; function SQLRecordExists (sqlText: string): Boolean;
function SQLColumnExists (const tabName: string; const colName: string): Boolean; function SQLColumnExists (const tabName: string; const colName: string): Boolean;
function SQLIDsToString (const tabName: string=''; where: string=''): string; function SQLIDsToString (const tabName: string=''; where: string=''): string;
function SQLIsSafe (const S: string): boolean;
function SQLGetString (sqlCmd: string=''; sqlConnLoc: TFDConnection=nil): string; function SQLGetString (sqlCmd: string=''; sqlConnLoc: TFDConnection=nil): string;
function StreamToString (const M: TStream): string; function StreamToString (const M: TStream): string;
@ -57,6 +58,8 @@ type
var var
datMod: TdatMod; datMod: TdatMod;
ConnDef: IFDStanConnectionDef; ConnDef: IFDStanConnectionDef;
ConnInit: Boolean = false;
ConnInitLock: TObject;
implementation implementation
@ -156,90 +159,13 @@ uses System.StrUtils, Data.Win.ADODB,
dbConnOleDB:= false; dbConnOleDB:= false;
{
drvList:= TStringList.Create;
try
GetProviderNames(drvList);
{$IFDEF DEBUG}
{
if (drvList.Count>0) then
begin
Writeln(CRLF+'Registrovane drivery:');
for idx:=0 to drvList.Count-1 do
Writeln(drvList.Strings[idx]);
end;
Writeln('');
{$ENDIF}
{
if (drvList.IndexOf('MSOLEDBSQL') >= 0) then
mamOleDb:= true;
if (drvList.IndexOf('MSOLEDBSQL19') >= 0) then
dbEncConn:= true;
if not(mamOleDb) or (odbc) then
begin
mamOleDb:= false;
idx:= -1;
if (drvList.Find('ODBC Driver 17', idx)) then
drvName2:= drvList.Strings[idx];
if (drvList.Find('ODBC Driver 18', idx)) then
begin
drvName2:= drvList.Strings[idx];
dbEncConn:= true;
end;
if (drvList.Find('ODBC Driver 19', idx)) then
begin
drvName2:= drvList.Strings[idx];
dbEncConn:= true;
end;
end;
sqlMSSQLDrv.ODBCDriver:= drvName2;
if (drvName.Contains('ODBC')) then
drvName:= 'ODBC';
// sqlMSSQLDrv.DriverID:= drvName;
dbConnOleDB:= mamOleDb;
{$IFDEF DEBUG}
{ Writeln('Vybrany driver: ' + sqlMSSQLDrv.ODBCDriver);
{$ENDIF}
{
finally
drvList.Free;
end;
}
if not(sqlConn.Connected) and (dbServer<>'') and (dbName<>'') then if not(sqlConn.Connected) and (dbServer<>'') and (dbName<>'') then
begin begin
try try
sqlConnParams:= TStringList.Create;
sqlConnParams.Clear;
oPars:= TStringList.Create; oPars:= TStringList.Create;
try try
// sqlConn.Params.Clear; // oPars.Add(S_FD_ConnParam_Common_DriverID + '=MSSQL'); // je definovan v AddConnectionDef
// sqlConn.DriverName:= drvName;
// sqlConn.Params.Add(S_FD_ConnParam_Common_DriverID + '=' + drvName);
sqlConnParams.Add(S_FD_ConnParam_Common_DriverID + '=MSSQL');
sqlConnParams.Add(S_FD_ConnParam_Common_Server + '=' + dbServer);
sqlConnParams.Add(S_FD_ConnParam_Common_Port + '=' + dbPort.ToString);
sqlConnParams.Add(S_FD_ConnParam_Common_Database + '=' + dbName);
sqlConnParams.Add(S_FD_ConnParam_Common_UserName + '=' + dbUser);
sqlConnParams.Add(S_FD_ConnParam_Common_Password + '=' + dbPwd);
sqlConnParams.Add(S_FD_ConnParam_Common_OSAuthent + '=No');
sqlConnParams.Add(S_FD_ConnParam_Common_MetaDefSchema + '=dbo');
sqlConnParams.Add(S_FD_ConnParam_Common_LoginTimeout + '=15');
sqlConnParams.Add(S_FD_ConnParam_MSSQL_MARS + '=Yes');
// sqlConnParams.Add(S_FD_ConnParam_Common_Pooled + '=True');
// sqlConnParams.Add(S_FD_ConnParam_Common_Pool_MaximumItems + '=100');
sqlConnParams.Add(S_FD_ConnParam_Common_ExtendedMetadata + '=True');
sqlConnParams.Add(S_FD_ConnParam_Common_ApplicationName + '=hdcdzAPIsvc2');
sqlConnParams.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=TrustServerCertificate=yes');
oPars.Add(S_FD_ConnParam_Common_DriverID + '=MSSQL');
oPars.Add(S_FD_ConnParam_Common_Server + '=' + dbServer); oPars.Add(S_FD_ConnParam_Common_Server + '=' + dbServer);
oPars.Add(S_FD_ConnParam_Common_Port + '=' + dbPort.ToString); oPars.Add(S_FD_ConnParam_Common_Port + '=' + dbPort.ToString);
oPars.Add(S_FD_ConnParam_Common_Database + '=' + dbName); oPars.Add(S_FD_ConnParam_Common_Database + '=' + dbName);
@ -249,42 +175,58 @@ uses System.StrUtils, Data.Win.ADODB,
oPars.Add(S_FD_ConnParam_Common_MetaDefSchema + '=dbo'); oPars.Add(S_FD_ConnParam_Common_MetaDefSchema + '=dbo');
oPars.Add(S_FD_ConnParam_Common_LoginTimeout + '=15'); oPars.Add(S_FD_ConnParam_Common_LoginTimeout + '=15');
oPars.Add(S_FD_ConnParam_MSSQL_MARS + '=Yes'); oPars.Add(S_FD_ConnParam_MSSQL_MARS + '=Yes');
oPars.Add(S_FD_ConnParam_Common_ExtendedMetadata + '=True'); oPars.Add(S_FD_ConnParam_Common_ExtendedMetadata + '=False'); // True jen pri pouziti AutoGenerate SQL / CachedUpdates / UpdateObject
oPars.Add(S_FD_ConnParam_Common_ApplicationName + '=hdcdzAPIsvc'); oPars.Add(S_FD_ConnParam_Common_ApplicationName + '=hdcdzAPIsvc');
oPars.Add(S_FD_ConnParam_Common_Pooled + '=True'); oPars.Add(S_FD_ConnParam_Common_Pooled + '=True');
oPars.Add(S_FD_ConnParam_Common_Pool_MaximumItems + '=100'); oPars.Add(S_FD_ConnParam_Common_Pool_MaximumItems + '=300');
oPars.Add(S_FD_ConnParam_Common_Pool_ExpireTimeout + '=30000'); // FireDAC v intervalu 30 sekund testuje platnost spojeni, jestli to SQL server neukoncil
oPars.Add(S_FD_ConnParam_Common_Pool_CleanupTimeout + '=90000'); // FireDAC v intervalu 90 sekund cisti nepouzivana spojeni
oPars.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=TrustServerCertificate=yes'); oPars.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=TrustServerCertificate=yes');
// oPars.Add('CommandTimeout=120');
if (dbEncConn) then
oPars.Add(S_FD_ConnParam_MSSQL_Encrypt + '=Yes');
if (FDManager.FindConnection(sqlPoolName)=nil) then if not(ConnInit) then
begin begin
FDManager.AddConnectionDef (sqlPoolName, 'MSSQL', oPars, true); TMonitor.Enter(ConnInitLock);
if (FDManager.State<>dmsInactive) then try
Sleep(0); if not(ConnInit) then
end; begin
if (FDManager.ConnectionDefs.FindConnectionDef(sqlPoolName) = nil) then
FDManager.AddConnectionDef(sqlPoolName, 'MSSQL', oPars);
if (FDManager.State = dmsInactive) then
FDManager.Open; FDManager.Open;
ConnInit := True;
end;
finally
TMonitor.Exit (ConnInitLock);
end;
end;
// sqlConn.Params.SetStrings(oPars); // sqlConn.Params.SetStrings(oPars);
sqlConn.ConnectionDefName:= sqlPoolName; sqlConn.ConnectionDefName:= sqlPoolName;
sqlQry1.ConnectionName:= sqlConn.ConnectionDefName; sqlQry1.Connection:= sqlConn;
sqlQry2.ConnectionName:= sqlConn.ConnectionDefName; sqlQry2.Connection:= sqlConn;
sqlQry3.ConnectionName:= sqlConn.ConnectionDefName; sqlQry3.Connection:= sqlConn;
sqlQry10.ConnectionName:= sqlConn.ConnectionDefName; sqlQry10.Connection:= sqlConn;
sqlQry11.ConnectionName:= sqlConn.ConnectionDefName; sqlQry11.Connection:= sqlConn;
// if (dbConnOleDB) then // if (dbConnOleDB) then
// sqlMSSQLDrv.ODBCDriver:= ''; // sqlMSSQLDrv.ODBCDriver:= '';
connStr:= '';
if (dbEncConn) then if (dbEncConn) then
begin begin
if (dbConnOleDB) then if (dbConnOleDB) then
connStr:= 'Encrypt=True;TrustServerCertificate=True;UseEncryptionForData=True' connStr:= ';Encrypt=True;TrustServerCertificate=True;UseEncryptionForData=True'
else else
connStr:= 'Encrypt=yes;TrustServerCertificate=yes;Encrypt=yes'; connStr:= ';Encrypt=yes;TrustServerCertificate=yes;Encrypt=yes';
// sqlConn.Params.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=' + connStr); // sqlConn.Params.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=' + connStr);
end; end;
connStr:= FDManager.ConnectionDefs.ConnectionDefByName(sqlPoolName).Params.Text + connStr;
connStr:= sqlConn.Params.DelimitedText;
sqlConn.Open; sqlConn.Open;
sqlConn.ExecSQL('SET LOCK_TIMEOUT 60000'); // čekej max 60 sekund na lock, ne nekonecne jako je default (-1)
except on E:Exception do except on E:Exception do
begin begin
result:= E.Message; result:= E.Message;
@ -294,7 +236,7 @@ uses System.StrUtils, Data.Win.ADODB,
end; end;
end; // try end; // try
finally finally
if (oPars<>nil) then // sqlConnParams.Free;
oPars.Free; oPars.Free;
end; // try end; // try
end; end;
@ -458,6 +400,24 @@ uses System.StrUtils, Data.Win.ADODB,
function TdatMod.SQLIsSafe (const S: string): boolean;
var UpperS: string;
begin
result:= TRegEx.IsMatch (S, '^[A-Za-z0-9_ \(\)=<>!\.,]+$', [roIgnoreCase]);
if not result then
Exit;
UpperS := UpperCase(S);
// zakázaná klíčová slova
if TRegEx.IsMatch(UpperS, '\b(SELECT|INSERT|UPDATE|DELETE|DROP|EXEC|UNION)\b') then
Exit (False);
result := True;
end;
function TdatMod.SQLIDsToString (const tabName: string = ''; where: string = ''): string; function TdatMod.SQLIDsToString (const tabName: string = ''; where: string = ''): string;
var lSQL, s, t: string; var lSQL, s, t: string;
c: boolean; c: boolean;
@ -491,15 +451,23 @@ uses System.StrUtils, Data.Win.ADODB,
begin begin
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
try try
result := '';
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
where:= where.Replace(';', '').Replace('--', '').Trim; // sanitace podminky where:= where.Replace(';', '').Replace('--', '').Trim; // sanitace podminky
lSQL:= 'SELECT STRING_AGG(ID,'','') AS IDs FROM ' + t + IfThen(where<>'', ' WHERE ' + where, ''); lSQL:= 'SELECT STRING_AGG(ID,'','') AS IDs FROM ' + t + IfThen(where<>'', ' WHERE ' + where, '');
if not(SQLIsSafe(where)) then
lSQL:= '';
if (lSQL<>'') then
begin
try try
lQry.Open (lSQL); lQry.Open (lSQL);
result := lQry.FieldByName('IDs').AsString; result := lQry.FieldByName('IDs').AsString;
except on E:Exception do except on E:Exception do
result := ''; result := '';
end; end;
end;
finally finally
lQry.Free; lQry.Free;
end; end;
@ -608,10 +576,12 @@ uses System.StrUtils, Data.Win.ADODB,
initialization initialization
ConnInitLock := TObject.Create;
// CoInitialize(nil); // CoInitialize(nil);
finalization finalization
ConnInitLock.Free;
// CoUninitialize; // CoUninitialize;
end. end.

View File

@ -6,6 +6,9 @@ interface
uses uses
System.Generics.Collections, System.Generics.Collections,
System.SysUtils, System.SysUtils,
FireDAC.Stan.Option,
FireDAC.Comp.Client,
FireDAC.Stan.Param,
JsonDataObjects, JsonDataObjects,
uSvc_Base, uSvc_Base,
uCommons, uCommons,
@ -36,7 +39,7 @@ type
TKmenZboziService = class(TServiceBase) TKmenZboziService = class(TServiceBase)
public public
function GetAll: TObjectList<TKmenZbozi>; virtual; function GetAll: TObjectList<TKmenZbozi>; virtual;
function GetByID (const AID: Integer; params: TDictionary<string, string>=nil): TKmenZbozi; virtual; function GetByID (const AID: Integer; params: TDictionary<string, string>=nil; AConn: TFDConnection = nil): TKmenZbozi; virtual;
function GetByParams (params: TDictionary<string, string>): TObjectList<TKmenZbozi>; virtual; function GetByParams (params: TDictionary<string, string>): TObjectList<TKmenZbozi>; virtual;
function GetMeta: TJSONObject; virtual; function GetMeta: TJSONObject; virtual;
function GetPrepocetMJ (idKmen: integer): TObjectList<TPrepocetMJ>; virtual; function GetPrepocetMJ (idKmen: integer): TObjectList<TPrepocetMJ>; virtual;
@ -49,9 +52,6 @@ implementation
uses uses
System.StrUtils, System.StrUtils,
System.Variants, System.Variants,
FireDAC.Stan.Option,
FireDAC.Comp.Client,
FireDAC.Stan.Param,
Quick.Logger, Quick.Logger,
MVCFramework.Commons, MVCFramework.Commons,
MVCFramework.FireDAC.Utils, MVCFramework.FireDAC.Utils,
@ -211,6 +211,7 @@ uses
sqlConnX:= TFDConnection.Create (nil); sqlConnX:= TFDConnection.Create (nil);
sqlConnX.ConnectionDefName:= sqlPoolName; sqlConnX.ConnectionDefName:= sqlPoolName;
lSQL:= 'SELECT ' + sqlSelKmen + ' FROM ' + tblKZ + ' ORDER BY ID'; lSQL:= 'SELECT ' + sqlSelKmen + ' FROM ' + tblKZ + ' ORDER BY ID';
lQry:= TFDQuery.Create (nil); lQry:= TFDQuery.Create (nil);
@ -220,10 +221,9 @@ uses
lQry.Open (lSQL); lQry.Open (lSQL);
result:= lQry.AsObjectList<TKmenZbozi>; result:= lQry.AsObjectList<TKmenZbozi>;
finally finally
lQry.Free;
end; end;
lQry.Free;
sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end; end;
@ -231,18 +231,25 @@ uses
function TKmenZboziService.GetByID (const AID: Integer; params: TDictionary<string, string>=nil): TKmenZbozi; function TKmenZboziService.GetByID (const AID: Integer; params: TDictionary<string, string>=nil; AConn: TFDConnection = nil): TKmenZbozi;
{$IFDEF CUSTOM_CTRL_Rootvin} {$IFDEF CUSTOM_CTRL_Rootvin}
const rtnASOLTrideni = '_ASOL_IdentifTrideni'; const rtnASOLTrideni = '_ASOL_IdentifTrideni';
{$ENDIF} {$ENDIF}
var lSQL, extInfoStr: string; var lSQL, extInfoStr: string;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
lokalniConnection: boolean;
begin begin
result := nil; result := nil;
lokalniConnection:= (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create (nil); sqlConnX:= TFDConnection.Create (nil);
sqlConnX.ConnectionDefName:= sqlPoolName; sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX:= AConn;
extInfoStr:= ''; extInfoStr:= '';
if (SQLTableExists ('dbo', tblKZe)) then if (SQLTableExists ('dbo', tblKZe)) then
@ -288,10 +295,10 @@ uses
raise EServiceException.Create ('Chyba nacitani kmenove karty: ' + E.Message); raise EServiceException.Create ('Chyba nacitani kmenove karty: ' + E.Message);
end; end;
finally finally
lQry.Free;
end; end;
lQry.Free; if (lokalniConnection) then
sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end; end;

View File

@ -7,6 +7,9 @@ interface
uses uses
System.Generics.Collections, System.Generics.Collections,
System.SysUtils, System.SysUtils,
FireDAC.Stan.Option,
FireDAC.Comp.Client,
FireDAC.Stan.Param,
JsonDataObjects, JsonDataObjects,
uSvc_Base, uSvc_Base,
uCommons, uCommons,
@ -40,7 +43,7 @@ type
TSerioveCisloPohybOZService = class(TServiceBase) TSerioveCisloPohybOZService = class(TServiceBase)
public public
function GetMeta: TJSONObject; virtual; function GetMeta: TJSONObject; virtual;
function GetByParams (params: TDictionary<string, string>): TObjectList<TSerioveCisloPohybOZ>; virtual; function GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TSerioveCisloPohybOZ>; virtual;
end; end;
@ -48,15 +51,15 @@ type
TStavSkladuService = class(TServiceBase) TStavSkladuService = class(TServiceBase)
public public
function GetMeta: TJSONObject; virtual; function GetMeta: TJSONObject; virtual;
function GetByParams (params: TDictionary<string, string>): TObjectList<TStavSkladu>; virtual; function GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TStavSkladu>; virtual;
end; end;
TDokladOZService = class(TServiceBase) TDokladOZService = class(TServiceBase)
public public
function GetByID (const AID: integer; sdServer: boolean=false; params: TDictionary<string, string>=nil): TDokladOZ; virtual;
function GetMeta: TJSONObject; virtual; function GetMeta: TJSONObject; virtual;
function GetByParams (params: TDictionary<string, string>): TObjectList<TDokladOZ>; virtual; function GetByID (const AID: integer; sdServer: boolean=false; params: TDictionary<string, string>=nil; AConn: TFDConnection = nil): TDokladOZ; virtual;
function GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TDokladOZ>; virtual;
function GetDruhyDokladu (druhpohybu: string): TObjectList<TDruhDokZbo>; virtual; function GetDruhyDokladu (druhpohybu: string): TObjectList<TDruhDokZbo>; virtual;
end; end;
@ -64,8 +67,8 @@ type
TPolozkaOZService = class(TServiceBase) TPolozkaOZService = class(TServiceBase)
public public
function GetMeta: TJSONObject; virtual; function GetMeta: TJSONObject; virtual;
function GetByID (const AID: integer; sdServer: boolean=false): TPohybOZ; virtual; function GetByID (const AID: integer; sdServer: boolean=false; AConn: TFDConnection = nil): TPohybOZ; virtual;
function GetByParams (params: TDictionary<string, string>): TObjectList<TPohybOZ>; virtual; function GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TPohybOZ>; virtual;
end; end;
@ -76,9 +79,6 @@ implementation
uses uses
System.StrUtils, System.StrUtils,
System.DateUtils, System.DateUtils,
FireDAC.Stan.Option,
FireDAC.Comp.Client,
FireDAC.Stan.Param,
MVCFramework.FireDAC.Utils, MVCFramework.FireDAC.Utils,
MVCFramework.DataSet.Utils, MVCFramework.DataSet.Utils,
MVCFramework.Serializer.Commons; MVCFramework.Serializer.Commons;
@ -90,15 +90,26 @@ uses
{ TStavSkladuService } { TStavSkladuService }
function TStavSkladuService.GetByParams (params: TDictionary<string, string>): TObjectList<TStavSkladu>; function TStavSkladuService.GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TStavSkladu>;
var lSQL, where, odDatum, doDatum, strTemp: string; var lSQL, where, odDatum, doDatum, strTemp: string;
datOd, datDo: TDateTime; datOd, datDo: TDateTime;
id: integer; id: integer;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
lokalniConnection: boolean;
begin begin
result:= nil; result:= nil;
lokalniConnection := (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX := AConn;
lSQL:= 'SELECT ' + GetTabCols('dbo', tblSS) + ' FROM ' + tblSS; lSQL:= 'SELECT ' + GetTabCols('dbo', tblSS) + ' FROM ' + tblSS;
where:= ''; where:= '';
@ -129,14 +140,14 @@ uses
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
try try
sqlConnX.Connected := true;
lQry.Connection:= sqlConnX; lQry.Connection:= sqlConnX;
try try
lQry.Open(lSQL); lQry.Open(lSQL);
result:= lQry.AsObjectList<TStavSkladu>; result:= lQry.AsObjectList<TStavSkladu>;
lQry.Close;
except on E:Exception do except on E:Exception do
raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message); raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message);
end; end;
@ -144,9 +155,11 @@ uses
lQry.Free; lQry.Free;
end; end;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end;
end; end;
@ -245,21 +258,33 @@ uses
function TDokladOZService.GetByParams (params: TDictionary<string, string>): TObjectList<TDokladOZ>; function TDokladOZService.GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TDokladOZ>;
var lSQL, lSQLmin, where, odDatum, doDatum, sklad, strTemp: string; var lSQL, lSQLmin, where, odDatum, doDatum, sklad, strTemp: string;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
datOd, datDo: TDateTime; datOd, datDo: TDateTime;
id, iDZ, idPrikaz, cnt, rNo: integer; id, iDZ, idPrikaz, cnt, rNo: integer;
jenSeznam, polozky, minimum: Boolean; jenSeznam, polozky, minimum: Boolean;
d: TDokladOZ; resList: TObjectList<TDokladOZ>;
dList: TObjectList<TDokladOZ>; resObj: TDokladOZ;
noDatum, snZSDServeru: boolean; noDatum, snZSDServeru: boolean;
radyD, sklady, dpz: string; radyD, sklady, dpz: string;
p: TDictionary<string, string>; p: TDictionary<string, string>;
lokalniConnection: boolean;
lokIDcka: TList<integer>;
begin begin
result:= nil; result:= nil;
lokalniConnection := (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX := AConn;
p:= TDictionary<string, string>.Create; p:= TDictionary<string, string>.Create;
radyD:= ''; radyD:= '';
dpz:= ''; dpz:= '';
@ -421,20 +446,19 @@ uses
end; end;
{$ENDIF} {$ENDIF}
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
try try
sqlConnX.Connected := true;
lQry.FetchOptions.Mode := fmAll; lQry.FetchOptions.Mode := fmAll;
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
lQry.Open (lSQL); lQry.Open (lSQL);
cnt := lQry.RecordCount; cnt := lQry.RecordCount;
if (cnt>0) then if (cnt>0) then
begin begin
lQry.Close;
lokIDcka:= TList<integer>.Create;
try try
d:= TDokladOZ.Create;
dList:= TObjectList<TDokladOZ>.Create;
try try
rNo:= 1; rNo:= 1;
lQry.First; lQry.First;
@ -442,45 +466,72 @@ uses
begin begin
lQry.RecNo:= rNo; lQry.RecNo:= rNo;
iDZ:= lQry.FieldByName('ID').AsInteger; iDZ:= lQry.FieldByName('ID').AsInteger;
d:= self.GetByID (iDZ, snZSDServeru, p); lokIDcka.Add (iDZ);
dList.Add(d);
if not(lQry.Active) then if not(lQry.Active) then
lQry.Open; lQry.Open;
Inc(rNo); Inc(rNo);
end; end;
result:= dList; // FDM.sqlQry1.AsObjectList<TDokladOZ>; lQry.Close;
except on E:Exception do except on E:Exception do
raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message); raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message);
end; end;
// FreeAndNil(dList); // FreeAndNil(dList);
resList:= TObjectList<TDokladOZ>.Create;
try
for iDZ in lokIDcka do
begin
resObj:= self.GetByID (iDZ, snZSDServeru, p, sqlConnX);
resList.Add (resObj);
end;
result:= resList;
resList:= nil;
finally finally
resList.Free;
end;
finally
lokIDcka.Free;
end; end;
end end
else else
raise EServiceException.Create('Vybran<61>m podm<64>nk<6E>m neodpov<6F>d<EFBFBD> <20><>dn<64> doklad'); raise EServiceException.Create('Vybran<61>m podm<64>nk<6E>m neodpov<6F>d<EFBFBD> <20><>dn<64> doklad');
finally finally
lQry.Close;
FreeAndNil(lQry);
end;
p.Free; p.Free;
lQry.Close;
lQry.Free;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end; end;
end;
end;
function TDokladOZService.GetByID (const AID: Integer; sdServer: boolean=false; params: TDictionary<string, string>=nil): TDokladOZ; function TDokladOZService.GetByID (const AID: Integer; sdServer: boolean=false; params: TDictionary<string, string>=nil; AConn: TFDConnection = nil): TDokladOZ;
var lSQL, extInfoStr, errMsg: string; var lSQL, extInfoStr, errMsg: string;
minimumDat, polozky: boolean; minimumDat, polozky: boolean;
p: TDictionary<string, string>; p: TDictionary<string, string>;
ps: TPolozkaOZService; ps: TPolozkaOZService;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
lokalniConnection: boolean;
begin begin
result := nil; result := nil;
lokalniConnection := (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX:= AConn;
extInfoStr:= ''; extInfoStr:= '';
if (SQLTableExists ('dbo', tblDZe)) then if (SQLTableExists ('dbo', tblDZe)) then
begin begin
@ -491,6 +542,7 @@ uses
lQry.Open(lSQL, [AID]); lQry.Open(lSQL, [AID]);
if (lQry.RecordCount>0) then if (lQry.RecordCount>0) then
extInfoStr:= lQry.AsJSONObject; extInfoStr:= lQry.AsJSONObject;
lQry.Close;
finally finally
lQry.Free; lQry.Free;
end; end;
@ -532,11 +584,9 @@ uses
lSQL:= lSQL + ' FROM ' + tblDZ + ' WHERE ID=:ID'; lSQL:= lSQL + ' FROM ' + tblDZ + ' WHERE ID=:ID';
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
try try
sqlConnX.Connected := true;
lQry.FetchOptions.Mode:= fmAll; lQry.FetchOptions.Mode:= fmAll;
lQry.Connection:= sqlConnX; lQry.Connection:= sqlConnX;
lQry.Open(lSQL, [AID]); lQry.Open(lSQL, [AID]);
@ -554,11 +604,14 @@ uses
finally finally
p.Free; p.Free;
ps.Free; ps.Free;
FreeAndNil(lQry); lQry.Close;
end; lQry.Free;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end;
end;
end; end;
@ -589,19 +642,28 @@ uses
{ TPolozkaOZService } { TPolozkaOZService }
function TPolozkaOZService.GetByParams (params: TDictionary<string, string>): TObjectList<TPohybOZ>; function TPolozkaOZService.GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TPohybOZ>;
var lSQL, where: string; var lSQL, where: string;
id, AID, cnt, rNo: integer; id, AID, cnt, rNo: integer;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
pList: TObjectList<TPohybOZ>; resList: TObjectList<TPohybOZ>;
p: TPohybOZ; resObj: TPohybOZ;
sdServer: boolean; sdServer: boolean;
lokalniConnection: boolean;
lokIDcka: TList<integer>;
begin begin
result:= nil; result:= nil;
p:= TPohybOZ.Create; lokalniConnection := (AConn = nil);
// pList:= TObjectList<TPohybOZ>.Create; if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX := AConn;
lSQL:= 'SELECT ' + GetTabCols('dbo', tblPZ, '', false) + ' FROM ' + tblPZ; lSQL:= 'SELECT ' + GetTabCols('dbo', tblPZ, '', false) + ' FROM ' + tblPZ;
@ -634,16 +696,14 @@ uses
// lSQL:= lSQL.Replace('TabPohybyZbozi.', 'main.'); // lSQL:= lSQL.Replace('TabPohybyZbozi.', 'main.');
sqlConnX:= TFDConnection.Create(nil); sqlConnX.Connected := true;
sqlConnX.ConnectionDefName:= sqlPoolName;
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
try try
lQry.FetchOptions.Mode := fmAll; lQry.FetchOptions.Mode := fmAll;
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
lQry.Open (lSQL); lQry.Open (lSQL);
cnt := lQry.RecordCount; cnt := lQry.RecordCount;
pList:= TObjectList<TPohybOZ>.Create; lokIDcka := TList<integer>.Create;
try try
lQry.First; lQry.First;
rNo := 1; rNo := 1;
@ -651,31 +711,46 @@ uses
begin begin
lQry.RecNo := rNo; lQry.RecNo := rNo;
AID := lQry.FieldByName('ID').AsInteger; AID := lQry.FieldByName('ID').AsInteger;
p:= self.GetByID (AID, sdServer); lokIDcka.Add (AID);
pList.Add(p);
if not(lQry.Active) then if not(lQry.Active) then
lQry.Open; lQry.Open;
Inc (rNo); Inc (rNo);
end; end;
result:= pList;
except on E:Exception do except on E:Exception do
raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> polo<6C>ky/polo<6C>ek dokladu: ' + E.Message); raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> polo<6C>ky/polo<6C>ek dokladu: ' + E.Message);
end; end;
// pList.Free; // pList.Free;
resList := TObjectList<TPohybOZ>.Create;
try
for AID in lokIDcka do
begin
resObj := self.GetByID (AID, sdServer, sqlConnX);
resList.Add (resObj);
end;
result := resList;
resList := nil;
finally finally
resList.Free;
end;
finally
lokIDcka.Free;
lQry.Close; lQry.Close;
FreeAndNil (lQry); FreeAndNil (lQry);
end; end;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end;
end; end;
function TPolozkaOZService.GetByID (const AID: Integer; sdServer: boolean=false): TPohybOZ; function TPolozkaOZService.GetByID (const AID: Integer; sdServer: boolean=false; AConn: TFDConnection = nil): TPohybOZ;
var lSQL, lSQL2, sz, rDokl, dpz, skl, sTemp: string; var lSQL, lSQL2, sz, rDokl, dpz, skl, sTemp: string;
p: TDictionary<string, string>; p: TDictionary<string, string>;
pds: TSerioveCisloPohybOZService; pds: TSerioveCisloPohybOZService;
@ -684,6 +759,8 @@ uses
lQry, lQry2: TFDQuery; lQry, lQry2: TFDQuery;
sqlConnX, sqlConnX2: TFDConnection; sqlConnX, sqlConnX2: TFDConnection;
extInfoStr: string; extInfoStr: string;
lokalniConnection: boolean;
lokIDcka: TList<integer>;
{$IFDEF CUSTOM_CTRL_Rootvin} {$IFDEF CUSTOM_CTRL_Rootvin}
silo: string; silo: string;
siloInt, idMzdy: integer; siloInt, idMzdy: integer;
@ -691,12 +768,21 @@ uses
begin begin
result:= nil; result:= nil;
lokalniConnection := (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
end
else
sqlConnX := AConn;
{$IFDEF CUSTOM_CTRL_Rootvin} {$IFDEF CUSTOM_CTRL_Rootvin}
silo:= ''; silo:= '';
{$ENDIF} {$ENDIF}
sqlConnX:= TFDConnection.Create(nil); sqlConnX.Connected := true;
sqlConnX.ConnectionDefName:= sqlPoolName;
lQry:= TFDQuery.Create(nil); lQry:= TFDQuery.Create(nil);
lQry.FetchOptions.Mode:= fmAll; lQry.FetchOptions.Mode:= fmAll;
lQry.Connection:= sqlConnX; lQry.Connection:= sqlConnX;
@ -791,14 +877,19 @@ uses
end; end;
{$ENDIF} {$ENDIF}
if (lokalniConnection) then
begin
sqlConnX2 := TFDConnection.Create(nil); sqlConnX2 := TFDConnection.Create(nil);
sqlConnX2.ConnectionDefName := sqlPoolName;
end
else
sqlConnX2 := AConn;
sqlConnX2.Connected := true;
lQry2 := TFDQuery.Create (nil); lQry2 := TFDQuery.Create (nil);
try try
sqlConnX2.ConnectionDefName:= sqlPoolName;
lQry2.Connection:= sqlConnX2; lQry2.Connection:= sqlConnX2;
@ -880,13 +971,16 @@ uses
finally finally
lQry2.Free; lQry2.Free;
if (lokalniConnection) then
begin
sqlConnX2.Close; sqlConnX2.Close;
sqlConnX2.Free; sqlConnX2.Free;
end; end;
end;
if (extInfoStr<>'') then if (extInfoStr<>'') then
result.ExtInfo:= ExtInfoStr; result.ExtInfo:= ExtInfoStr;
result.SerialNums:= pds.GetByParams (p); result.SerialNums:= pds.GetByParams (p, sqlConnX);
if (u>0) then if (u>0) then
begin begin
Result.Umisteni:= us.GetByID (u); Result.Umisteni:= us.GetByID (u);
@ -905,15 +999,18 @@ uses
else else
raise EServiceException.Create('Polo<6C>ka dokladu ob<6F>hu zbo<62><6F> s ID ' + AID.ToString + ' nebyla nalezena.'); raise EServiceException.Create('Polo<6C>ka dokladu ob<6F>hu zbo<62><6F> s ID ' + AID.ToString + ' nebyla nalezena.');
finally finally
lokIDcka.Free;
p.Free; p.Free;
pds.Free; pds.Free;
lQry.Close; lQry.Close;
FreeAndNil (lQry); FreeAndNil (lQry);
end; end;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end;
end; end;
@ -1030,6 +1127,7 @@ uses
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
lQry.Open (lSQL); lQry.Open (lSQL);
Result := lQry.MetadataAsJSONObject(); Result := lQry.MetadataAsJSONObject();
lQry.Close;
finally finally
lQry.Free; lQry.Free;
end; end;
@ -1043,16 +1141,28 @@ uses
function TSerioveCisloPohybOZService.GetByParams (params: TDictionary<string, string>): TObjectList<TSerioveCisloPohybOZ>; function TSerioveCisloPohybOZService.GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TSerioveCisloPohybOZ>;
var lSQL, lSQL2, where: string; var lSQL, lSQL2, where: string;
lQry: TFDQuery; lQry: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
id, idPZ: integer; id, idPZ: integer;
s: TSerioveCisloPohybOZ; s: TSerioveCisloPohybOZ;
sdServer: boolean; sdServer: boolean;
lokalniConnection: boolean;
lokIDcka: TList<integer>;
begin begin
result:= nil; result:= nil;
lokalniConnection := (AConn = nil);
if (lokalniConnection) then
begin
sqlConnX := TFDConnection.Create(nil);
sqlConnX.ConnectionDefName := sqlPoolName;
end
else
sqlConnX := AConn;
lSQL := 'SELECT ' + GetTabCols('', tblVyrCP, 'main') + IfThen(selSpecVyrCP<>'', ', ' + selSpecVyrCP.Replace('#', ''), '') lSQL := 'SELECT ' + GetTabCols('', tblVyrCP, 'main') + IfThen(selSpecVyrCP<>'', ', ' + selSpecVyrCP.Replace('#', ''), '')
+ ', 0 AS ZdrojSD, 0 AS IDDokladGSD FROM ' + tblVyrCP + ' main'; + ', 0 AS ZdrojSD, 0 AS IDDokladGSD FROM ' + tblVyrCP + ' main';
where := ''; where := '';
@ -1086,12 +1196,8 @@ uses
if (selSpecVyrCP='') then if (selSpecVyrCP='') then
lSQL := lSQL.Replace('main.', ''); lSQL := lSQL.Replace('main.', '');
sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName;
lQry := TFDQuery.Create(nil); lQry := TFDQuery.Create(nil);
{$IF DEFINED(CUSTOM_CTRL_Rootvin) or DEFINED(CUSTOM_CTRL_GatemaSD)} {$IF DEFINED(CUSTOM_CTRL_Rootvin) or DEFINED(CUSTOM_CTRL_GatemaSD)}
// test zda polozky pochazi z SD serveru // test zda polozky pochazi z SD serveru
if (idPZ>0) or (sdServer) then if (idPZ>0) or (sdServer) then
@ -1112,19 +1218,22 @@ uses
end; end;
{$ENDIF} {$ENDIF}
try try
sqlConnX.Connected:= true;
lQry.FetchOptions.Mode := fmAll; lQry.FetchOptions.Mode := fmAll;
lQry.Connection := sqlConnX; lQry.Connection := sqlConnX;
lQry.Open (lSQL); lQry.Open (lSQL);
result := lQry.AsObjectList<TSerioveCisloPohybOZ>; result := lQry.AsObjectList<TSerioveCisloPohybOZ>;
lQry.Close;
finally finally
lQry.Free; lQry.Free;
end; end;
if (lokalniConnection) then
begin
sqlConnX.Close; sqlConnX.Close;
sqlConnX.Free; sqlConnX.Free;
end;
end; end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -451,7 +451,7 @@ uses
logRun: Int64; logRun: Int64;
Msg: TMsg; Msg: TMsg;
mamTabPrijataData, firstRun, inProg, canCont: boolean; mamTabPrijataData, firstRun, inProg, canCont: boolean;
lQry, lQry2: TFDQuery; lQry, lQry2, lQry3: TFDQuery;
sqlConnX: TFDConnection; sqlConnX: TFDConnection;
begin begin
lLoop:= 0; lLoop:= 0;
@ -507,20 +507,25 @@ uses
{$ENDIF} {$ENDIF}
begin begin
sqlConnX:= TFDConnection.Create(nil); // sqlConnX:= TFDConnection.Create(nil);
sqlConnX.ConnectionDefName:= sqlPoolName; // sqlConnX.ConnectionDefName:= sqlPoolName;
sqlConnX.Open; // sqlConnX.Open;
if (sqlConnX.Connected) then if (1=1) then // (sqlConnX.Connected)
begin begin
lSQL := 'SELECT d.ID FROM ' + tblPrijataJsonData + ' d WITH(NOLOCK) WHERE d.Blokovano=0 AND d.DatZpracovani IS NULL'; lSQL := 'SELECT d.ID FROM ' + tblPrijataJsonData + ' d WITH(NOLOCK) WHERE d.Blokovano=0 AND d.DatZpracovani IS NULL';
lSQL:= lSQL + ' AND ISNULL(d.PosledniChyba,N'''')=N'''''; lSQL := lSQL + ' AND ISNULL(d.PosledniChyba,N'''')=N'''' AND d.Nezpracovat=0';
lSQL := lSQL + ' AND d.Blokovano=0 '; // AND ISNULL( (SELECT COUNT(ID) FROM dbo._hdc_ph_Log WHERE LogText=N''Zpracovani API json'' AND IntValue=d.ID), 0)<4'; lSQL := lSQL + ' AND d.Blokovano=0 '; // AND ISNULL( (SELECT COUNT(ID) FROM dbo._hdc_ph_Log WHERE LogText=N''Zpracovani API json'' AND IntValue=d.ID), 0)<4';
lSQL := lSQL + ' ORDER BY d.ID'; lSQL := lSQL + ' ORDER BY d.ID';
lQry := TFDQuery.Create(nil); lQry := TFDQuery.Create(nil);
lQry2:= TFDQuery.Create(nil);
// lQry2.Connection:= sqlConnX;
try try
lQry.Connection:= sqlConnX; // lQry.Connection:= sqlConnX;
lQry.ConnectionName := sqlPoolName;
lQry2.ConnectionName := sqlPoolName;
lQry.Open(lSQL); lQry.Open(lSQL);
lQry.First; lQry.First;
@ -531,25 +536,20 @@ uses
idTask := lQry.FieldByName('ID').asInteger; idTask := lQry.FieldByName('ID').asInteger;
canCont := true; canCont := true;
lQry2:= TFDQuery.Create(nil);
lQry2.Connection:= sqlConnX;
lQry2.Open ('SELECT COUNT(ID) AS Pocet FROM dbo._hdc_ph_Log WITH(NOLOCK) WHERE IntValue=' + idTask.ToString + ' AND LogText LIKE N''%Zpracova%'''); lQry2.Open ('SELECT COUNT(ID) AS Pocet FROM dbo._hdc_ph_Log WITH(NOLOCK) WHERE IntValue=' + idTask.ToString + ' AND LogText LIKE N''%Zpracova%''');
lQry2.First; lQry2.First;
cnt := lQry2.FieldByName('Pocet').AsInteger; cnt := lQry2.FieldByName('Pocet').AsInteger;
FreeAndNil(lQry2);
if (cnt>3) then if (cnt>3) then
canCont:= false; canCont:= false;
if (canCont) then if (canCont) then
begin begin
lQry2.ExecSQL('INSERT dbo._hdc_ph_Log (IntValue, LogText) SELECT ' + idTask.ToString + ', N''Zpracovani API json''');
sqlConnX.ExecSQL('INSERT dbo._hdc_ph_Log (IntValue, LogText) SELECT ' + idTask.ToString + ', N''Zpracovani API json''');
datMod.LogInfo (Quick.Logger.etInfo, 'Zpracovani prijatych JSON dat - idTask ' + idTask.ToString); datMod.LogInfo (Quick.Logger.etInfo, 'Zpracovani prijatych JSON dat - idTask ' + idTask.ToString);
// LogInfo(Quick.Logger.etError, 'Zpracovani PrijataJSONData ID ' + idTask.ToString); // LogInfo(Quick.Logger.etError, 'Zpracovani PrijataJSONData ID ' + idTask.ToString);
try try
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=1 WHERE ID=' + idTask.ToString); lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=1 WHERE ID=' + idTask.ToString);
lSQL:= ''; lSQL:= '';
{$IFDEF DEBUG} {$IFDEF DEBUG}
Write ('Zpracovani prijateho JSON id ' + idTask.ToString); Write ('Zpracovani prijateho JSON id ' + idTask.ToString);
@ -559,8 +559,8 @@ uses
{$ELSE} {$ELSE}
lSQL:= lSQL + 'IF OBJECT_ID(N''dbo.ep_HDCDZApi_ZpracujPrijataData'', N''P'') IS NOT NULL' + CRLF + ' EXEC dbo.ep_HDCDZApi_ZpracujPrijataData @idJson=' + idTask.ToString; lSQL:= lSQL + 'IF OBJECT_ID(N''dbo.ep_HDCDZApi_ZpracujPrijataData'', N''P'') IS NOT NULL' + CRLF + ' EXEC dbo.ep_HDCDZApi_ZpracujPrijataData @idJson=' + idTask.ToString;
{$ENDIF} {$ENDIF}
sqlConnX.ExecSQL(lSQL); lQry2.ExecSQL(lSQL);
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=NULL WHERE ID=' + idTask.ToString); lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=NULL WHERE ID=' + idTask.ToString);
{$IFDEF DEBUG} {$IFDEF DEBUG}
Writeln(' - OK'); Writeln(' - OK');
@ -572,7 +572,7 @@ uses
{$IFDEF DEBUG} {$IFDEF DEBUG}
WriteLn ('Chyba zpracovani prijateho JSON id ' + idTask.ToString + ' >> ' + errMsg); WriteLn ('Chyba zpracovani prijateho JSON id ' + idTask.ToString + ' >> ' + errMsg);
{$ENDIF} {$ENDIF}
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=N' + errMsg.QuotedString + ' WHERE ID=' + idTask.ToString); lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=N' + errMsg.QuotedString + ' WHERE ID=' + idTask.ToString);
{$IFDEF CUSTOM_CTRL_Rootvin} {$IFDEF CUSTOM_CTRL_Rootvin}
datMod.LogInfo (Quick.Logger.etError, 'Chyba evidence start/stop operace PrijataJSONData ID ' + idTask.ToString + ' : ' + errMsg); datMod.LogInfo (Quick.Logger.etError, 'Chyba evidence start/stop operace PrijataJSONData ID ' + idTask.ToString + ' : ' + errMsg);
{$ELSE} {$ELSE}
@ -580,19 +580,21 @@ uses
{$ENDIF} {$ENDIF}
end; end;
end; end;
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=0 WHERE ID=' + idTask.ToString); lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=0 WHERE ID=' + idTask.ToString);
end; end;
lQry.Next; lQry.Next;
end; end;
finally finally
lQry2.Close;
FreeAndNil (lQry2);
lQry.Close; lQry.Close;
FreeAndNil (lQry); FreeAndNil (lQry);
end; end;
inProg:= false; inProg:= false;
end; // sql Connected end; // sql Connected
sqlConnX.Close; if Assigned(sqlConnx) then
FreeAndNil (sqlConnX); sqlConnX.Free;
end; end;
end; end;

2
ukazBlokovanePorty.cmd Normal file
View File

@ -0,0 +1,2 @@
@echo off
netsh interface ipv4 show excludedportrange protocol=tcp