Po hlavnich upravach sdileni sponeni a uvolnovani connection poolu
This commit is contained in:
Binary file not shown.
@ -133,7 +133,7 @@ IF (@genDokladMat=1) OR (@genDokladFin=1)
|
||||
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
|
||||
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)
|
||||
)
|
||||
IF (@cnt<=1)
|
||||
|
||||
@ -794,6 +794,7 @@ uses
|
||||
var lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
lSQL, where, errMsg: string;
|
||||
lokIDcka: TList<integer>;
|
||||
cnt, rNo, idVPr: integer;
|
||||
typPrikazu: integer;
|
||||
operace, material, spustene: boolean;
|
||||
@ -804,311 +805,346 @@ uses
|
||||
p: TVyrobniPrikaz;
|
||||
vpSvr: TVyrobniPrikazService;
|
||||
locParams: TDictionary<string, string>;
|
||||
lokIDcko: TObject;
|
||||
begin
|
||||
cisOper:= '';
|
||||
|
||||
locParams:= TDictionary<string, string>.Create;
|
||||
|
||||
|
||||
operace:= false;
|
||||
if (params.ContainsKey('operace')) then
|
||||
if (params.Items['operace']='1') then
|
||||
begin
|
||||
operace:= true;
|
||||
locParams.Add('operace', params.Items['operace']);
|
||||
end;
|
||||
|
||||
material:= false;
|
||||
if (params.ContainsKey('material')) then
|
||||
if (params.Items['material']='1') then
|
||||
begin
|
||||
material:= true;
|
||||
locParams.Add('material', params.Items['material']);
|
||||
end;
|
||||
|
||||
spustene:= false;
|
||||
if (params.ContainsKey('spustene')) then
|
||||
if (params.Items['spustene']='1') then
|
||||
begin
|
||||
spustene:= true;
|
||||
locParams.Add('spustene', params.Items['spustene']);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
where:= '';
|
||||
lSQL:= 'SELECT DISTINCT(main.ID) AS ID FROM ' + tblVPr + ' main';
|
||||
|
||||
|
||||
if (spustene) then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM ' + tblPrPost + ' pp INNER JOIN ' + tblRozpracOperR
|
||||
+ ' r ON (r.DokladPrPostup=pp.Doklad AND r.AltPrPostup=pp.Alt AND r.IDPrikaz=pp.IDPrikaz)'
|
||||
+ ' INNER JOIN ' + tblRozpracOper + ' h ON (h.ID=r.IDEvidRozpracOper)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL AND pp.IDPrikaz=main.ID AND h.DatumUzavreni IS NULL)';
|
||||
|
||||
|
||||
typPrikazu:= 0;
|
||||
if (params.ContainsKey('typ')) then
|
||||
if not(TryStrToInt(params.Items['typ'], typPrikazu)) then
|
||||
typPrikazu:= 0;
|
||||
|
||||
locParams.Add('rtn', '1');
|
||||
locParams.Add('typPrikazu', typPrikazu.ToString);
|
||||
|
||||
if (typPrikazu=0) then // obecny
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0)';
|
||||
|
||||
|
||||
|
||||
if (typPrikazu=1) then // pro micharnu se nacitaji vyssi prikazy, tj. kde testo skonci
|
||||
begin
|
||||
locParams.Add('nazevOp', 'michani');
|
||||
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada=N''003'' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo=N''701'')';
|
||||
|
||||
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + ' AND (main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje=' + params.Items['idstroj'] + ')'
|
||||
+ ' OR main.IDPrikazVyssi IN (SELECT ID FROM ' + tblPrikaz
|
||||
+ ' WHERE IDPrikazVyssi IN (SELECT px.ID FROM ' + tblPrPost + ' ppx'
|
||||
+ ' INNER JOIN dbo.TabPrikaz px ON (px.ID=ppx.IDPrikaz)'
|
||||
+ ' WHERE ppx.IDOdchylkyDo IS NULL'
|
||||
+ ' AND px.StavPrikazu IN (30,40)'
|
||||
+ ' AND ppx.IDStroje=' + params.Items['idstroj'] + '))'
|
||||
+ ')';
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje=' + params.Items['idstroj'] + ')'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo=N''701'')'
|
||||
}
|
||||
end;
|
||||
{
|
||||
else
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo=N''701'')';
|
||||
}
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + ' AND (main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN ' + params.Items['idstroju'] + ')'
|
||||
+ ' OR main.IDPrikazVyssi IN (SELECT ID FROM ' + tblPrikaz
|
||||
+ ' WHERE IDPrikazVyssi IN (SELECT px.ID FROM ' + tblPrPost + ' ppx'
|
||||
+ ' INNER JOIN dbo.TabPrikaz px ON (px.ID=ppx.IDPrikaz)'
|
||||
+ ' WHERE ppx.IDOdchylkyDo IS NULL'
|
||||
+ ' AND px.StavPrikazu IN (30,40)'
|
||||
+ ' AND ppx.IDStroje IN ' + params.Items['idstroju'] + '))'
|
||||
+ ')';
|
||||
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo=N''701'')'
|
||||
}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=2) then // pro macirnu
|
||||
begin
|
||||
locParams.Add('nazevOp', 'máčení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada IN (N''004'', N''002'') AND EXISTS (SELECT 1 FROM ' + tblPrPost + ' pp INNER JOIN ' + tblCisStroj + ' cs'
|
||||
+ ' ON (cs.ID=pp.IDStroje) INNER JOIN ' + tblCisStrojE + ' cse ON (cse.ID=cs.ID) WHERE pp.IDPrikaz=main.ID'
|
||||
+ ' AND pp.IDOdchylkyDo IS NULL AND pp.priorita=0 AND cse._MaceciStroj=1)';
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada=N''004'' AND main.IDZakazModif IN (SELECT ID FROM '
|
||||
+ tblZakazModif + ' WHERE Schvaleno=1 AND Kod LIKE N''COKO%'')';
|
||||
}
|
||||
{
|
||||
if (params.ContainsKey('idpracovist')) then
|
||||
if (params.Items['idpracovist']<>'') then
|
||||
begin
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.pracoviste IN (' + params.Items['idpracovist'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
}
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroj'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
{
|
||||
else
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')';
|
||||
}
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=3) then // pro baleni (interni)
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND LOWER(Nazev) LIKE N''%balení%'' AND IDStroje NOT IN (SELECT ID FROM ' + tblCisStroj
|
||||
+ ' WHERE Blokovano=0 AND Kod LIKE N''BAL-%'') AND priorita=0)'; // main.Rada=N''004''
|
||||
{
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroj'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')';
|
||||
end;
|
||||
}
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=4) then // pro balicku finalu
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND IDStroje IN (SELECT ID FROM ' + tblCisStroj + ' WHERE Blokovano=0 AND Kod LIKE N''BAL-%''))';
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=5) then // pro EWB
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND IDStroje IN (SELECT ID FROM ' + tblCisStroj + ' WHERE Blokovano=0 AND Kod LIKE N''EWB%''))';
|
||||
end;
|
||||
|
||||
|
||||
|
||||
if (params.ContainsKey('odDatum')) then
|
||||
if (params.Items['odDatum']<>'') then
|
||||
odDatum:= params.Items['odDatum'];
|
||||
if (odDatum<>'') then
|
||||
begin
|
||||
if (Length(odDatum)=8) then
|
||||
odDatum:= odDatum + '000000';
|
||||
if (Length(odDatum)=10) then
|
||||
odDatum:= odDatum + '00';
|
||||
odDatum:= MidStr(odDatum, 7, 2) + '.' + MidStr(odDatum, 5, 2) + '.' + LeftStr(odDatum, 4) + ' ' + MidStr(odDatum, 9, 2) + ':' + MidStr(odDatum, 11, 2) + ':' + MidStr(odDatum, 13, 2);
|
||||
if not(TryStrToDateTime(odDatum, datOd)) then
|
||||
datOd:= IncDay(Now, -180)
|
||||
end
|
||||
else
|
||||
datOd:= IncDay(Now, -180);
|
||||
|
||||
if (params.ContainsKey('doDatum')) then
|
||||
if (params.Items['doDatum']<>'') then
|
||||
odDatum:= params.Items['doDatum'];
|
||||
if (doDatum<>'') then
|
||||
begin
|
||||
if (Length(doDatum)=8) then
|
||||
doDatum:= doDatum + '235959';
|
||||
if (Length(doDatum)=10) then
|
||||
doDatum:= doDatum + '59';
|
||||
doDatum:= MidStr(doDatum, 7, 2) + '.' + MidStr(doDatum, 5, 2) + '.' + LeftStr(doDatum, 4) + ' ' + MidStr(doDatum, 9, 2) + ':' + MidStr(doDatum, 11, 2) + ':' + MidStr(doDatum, 13, 2);
|
||||
if not(TryStrToDateTime(doDatum, datDo)) then
|
||||
datDo:= Now
|
||||
end
|
||||
else
|
||||
datDo:= Now;
|
||||
|
||||
if (odDatum<>'') then
|
||||
begin
|
||||
strTemp:= 'CONVERT(datetime, N' + FormatDateTime('dd.mm.yyyy', datOd).QuotedString + ',104)';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.DatPorizeni>=' + strTemp;
|
||||
end;
|
||||
|
||||
if (doDatum<>'') then
|
||||
begin
|
||||
strTemp:= 'CONVERT(datetime, N' + FormatDateTime('dd.mm.yyyy', datDo).QuotedString + ',104)';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.DatPorizeni<=' + strTemp;
|
||||
end;
|
||||
|
||||
|
||||
// pro micharnu nejsou prikazy pozastavovany
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.StavPrikazu IN (30' + IfThen(typPrikazu<>1, ',40', '') + ')';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada<>N''009''';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada LIKE N''0%''';
|
||||
|
||||
|
||||
if (where<>'') then
|
||||
lSQL:= lSQL + ' WHERE ' + where;
|
||||
lSQL:= lSQL + ' GROUP BY main.ID ORDER BY main.ID';
|
||||
|
||||
|
||||
vpSvr:= TVyrobniPrikazService.Create (self.FDM);
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Open(lSQL);
|
||||
cnt:= lQry.RecordCount;
|
||||
vpList:= TObjectList<TVyrobniPrikaz>.Create;
|
||||
try
|
||||
if not(lQry.Active) then
|
||||
lQry.Open(lSQL);
|
||||
lQry.First;
|
||||
rNo:= 1;
|
||||
while (rNo<=cnt) do
|
||||
begin
|
||||
lQry.RecNo:= rNo;
|
||||
idVPr:= lQry.FieldByName('ID').AsInteger;
|
||||
p:= vpSvr.GetByID (idVPr, locParams);
|
||||
vpList.Add(p);
|
||||
if not(lQry.Active) then
|
||||
lQry.Open;
|
||||
Inc(rNo);
|
||||
end;
|
||||
result:= vpList;
|
||||
except on E:Exception do
|
||||
|
||||
operace:= false;
|
||||
if (params.ContainsKey('operace')) then
|
||||
if (params.Items['operace']='1') then
|
||||
begin
|
||||
errMsg:= e.Message;
|
||||
raise EServiceException.Create('Chyba načítání naskenované položky/položek dokladu: ' + E.Message);
|
||||
operace:= true;
|
||||
locParams.Add('operace', params.Items['operace']);
|
||||
end;
|
||||
|
||||
material:= false;
|
||||
if (params.ContainsKey('material')) then
|
||||
if (params.Items['material']='1') then
|
||||
begin
|
||||
material:= true;
|
||||
locParams.Add('material', params.Items['material']);
|
||||
end;
|
||||
|
||||
spustene:= false;
|
||||
if (params.ContainsKey('spustene')) then
|
||||
if (params.Items['spustene']='1') then
|
||||
begin
|
||||
spustene:= true;
|
||||
locParams.Add('spustene', params.Items['spustene']);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
where:= '';
|
||||
lSQL:= 'SELECT DISTINCT(main.ID) AS ID FROM ' + tblVPr + ' main';
|
||||
|
||||
|
||||
if (spustene) then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM ' + tblPrPost + ' pp INNER JOIN ' + tblRozpracOperR
|
||||
+ ' r ON (r.DokladPrPostup=pp.Doklad AND r.AltPrPostup=pp.Alt AND r.IDPrikaz=pp.IDPrikaz)'
|
||||
+ ' INNER JOIN ' + tblRozpracOper + ' h ON (h.ID=r.IDEvidRozpracOper)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL AND pp.IDPrikaz=main.ID AND h.DatumUzavreni IS NULL)';
|
||||
|
||||
|
||||
typPrikazu:= 0;
|
||||
if (params.ContainsKey('typ')) then
|
||||
if not(TryStrToInt(params.Items['typ'], typPrikazu)) then
|
||||
typPrikazu:= 0;
|
||||
|
||||
locParams.Add('rtn', '1');
|
||||
locParams.Add('typPrikazu', typPrikazu.ToString);
|
||||
|
||||
if (typPrikazu=0) then // obecny
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0)';
|
||||
|
||||
|
||||
|
||||
if (typPrikazu=1) then // pro micharnu se nacitaji vyssi prikazy, tj. kde testo skonci
|
||||
begin
|
||||
locParams.Add('nazevOp', 'michani');
|
||||
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada=N''003'' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo=N''701'')';
|
||||
|
||||
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + ' AND (main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje=' + params.Items['idstroj'] + ')'
|
||||
+ ' OR main.IDPrikazVyssi IN (SELECT ID FROM ' + tblPrikaz
|
||||
+ ' WHERE IDPrikazVyssi IN (SELECT px.ID FROM ' + tblPrPost + ' ppx'
|
||||
+ ' INNER JOIN dbo.TabPrikaz px ON (px.ID=ppx.IDPrikaz)'
|
||||
+ ' WHERE ppx.IDOdchylkyDo IS NULL'
|
||||
+ ' AND px.StavPrikazu IN (30,40)'
|
||||
+ ' AND ppx.IDStroje=' + params.Items['idstroj'] + '))'
|
||||
+ ')';
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje=' + params.Items['idstroj'] + ')'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo=N''701'')'
|
||||
}
|
||||
end;
|
||||
{
|
||||
else
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo=N''701'')';
|
||||
}
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + ' AND (main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN ' + params.Items['idstroju'] + ')'
|
||||
+ ' OR main.IDPrikazVyssi IN (SELECT ID FROM ' + tblPrikaz
|
||||
+ ' WHERE IDPrikazVyssi IN (SELECT px.ID FROM ' + tblPrPost + ' ppx'
|
||||
+ ' INNER JOIN dbo.TabPrikaz px ON (px.ID=ppx.IDPrikaz)'
|
||||
+ ' WHERE ppx.IDOdchylkyDo IS NULL'
|
||||
+ ' AND px.StavPrikazu IN (30,40)'
|
||||
+ ' AND ppx.IDStroje IN ' + params.Items['idstroju'] + '))'
|
||||
+ ')';
|
||||
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDPrikazVyssi IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo=N''701'')'
|
||||
}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=2) then // pro macirnu
|
||||
begin
|
||||
locParams.Add('nazevOp', 'máčení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada IN (N''004'', N''002'') AND EXISTS (SELECT 1 FROM ' + tblPrPost + ' pp INNER JOIN ' + tblCisStroj + ' cs'
|
||||
+ ' ON (cs.ID=pp.IDStroje) INNER JOIN ' + tblCisStrojE + ' cse ON (cse.ID=cs.ID) WHERE pp.IDPrikaz=main.ID'
|
||||
+ ' AND pp.IDOdchylkyDo IS NULL AND pp.priorita=0 AND cse._MaceciStroj=1)';
|
||||
{
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada=N''004'' AND main.IDZakazModif IN (SELECT ID FROM '
|
||||
+ tblZakazModif + ' WHERE Schvaleno=1 AND Kod LIKE N''COKO%'')';
|
||||
}
|
||||
{
|
||||
if (params.ContainsKey('idpracovist')) then
|
||||
if (params.Items['idpracovist']<>'') then
|
||||
begin
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.IDOdchylkyDo IS NULL'
|
||||
+ ' AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.pracoviste IN (' + params.Items['idpracovist'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
}
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroj'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
{
|
||||
else
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')';
|
||||
}
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=3) then // pro baleni (interni)
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND LOWER(Nazev) LIKE N''%balení%'' AND IDStroje NOT IN (SELECT ID FROM ' + tblCisStroj
|
||||
+ ' WHERE Blokovano=0 AND Kod LIKE N''BAL-%'') AND priorita=0)'; // main.Rada=N''004''
|
||||
{
|
||||
if (params.ContainsKey('idstroj')) then
|
||||
begin
|
||||
if (params.Items['idstroj']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroj'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Blokovano=0 AND SkupZbo<>N''701'')'
|
||||
end;
|
||||
|
||||
if (params.ContainsKey('idstroju')) then
|
||||
begin
|
||||
if (params.Items['idstroju']<>'') then
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.ID IN (SELECT p.ID FROM ' + tblPrPost + ' pp INNER JOIN dbo.TabPrikaz p ON (p.ID=pp.IDPrikaz)'
|
||||
+ ' WHERE pp.Typ=1 AND pp.IDOdchylkyDo IS NULL AND p.StavPrikazu IN (30,40)'
|
||||
+ ' AND pp.IDStroje IN (' + params.Items['idstroju'] + '))'
|
||||
+ ' AND main.IDTabKmen IN (SELECT ID FROM ' + tblKZ + ' WHERE Dilec=1 AND Blokovano=0 AND SkupZbo<>N''701'')';
|
||||
end;
|
||||
}
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=4) then // pro balicku finalu
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND IDStroje IN (SELECT ID FROM ' + tblCisStroj + ' WHERE Blokovano=0 AND Kod LIKE N''BAL-%''))';
|
||||
end;
|
||||
|
||||
|
||||
if (typPrikazu=5) then // pro EWB
|
||||
begin
|
||||
locParams.Add('nazevOp', 'balení');
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'EXISTS (SELECT 1 FROM dbo.TabPrPostup WHERE IDPrikaz=main.ID AND IdOdchylkyDo IS NULL'
|
||||
+ ' AND IDStroje IN (SELECT ID FROM ' + tblCisStroj + ' WHERE Blokovano=0 AND Kod LIKE N''EWB%''))';
|
||||
end;
|
||||
|
||||
|
||||
|
||||
if (params.ContainsKey('odDatum')) then
|
||||
if (params.Items['odDatum']<>'') then
|
||||
odDatum:= params.Items['odDatum'];
|
||||
if (odDatum<>'') then
|
||||
begin
|
||||
if (Length(odDatum)=8) then
|
||||
odDatum:= odDatum + '000000';
|
||||
if (Length(odDatum)=10) then
|
||||
odDatum:= odDatum + '00';
|
||||
odDatum:= MidStr(odDatum, 7, 2) + '.' + MidStr(odDatum, 5, 2) + '.' + LeftStr(odDatum, 4) + ' ' + MidStr(odDatum, 9, 2) + ':' + MidStr(odDatum, 11, 2) + ':' + MidStr(odDatum, 13, 2);
|
||||
if not(TryStrToDateTime(odDatum, datOd)) then
|
||||
datOd:= IncDay(Now, -180)
|
||||
end
|
||||
else
|
||||
datOd:= IncDay(Now, -180);
|
||||
|
||||
if (params.ContainsKey('doDatum')) then
|
||||
if (params.Items['doDatum']<>'') then
|
||||
doDatum:= params.Items['doDatum'];
|
||||
if (doDatum<>'') then
|
||||
begin
|
||||
if (Length(doDatum)=8) then
|
||||
doDatum:= doDatum + '235959';
|
||||
if (Length(doDatum)=10) then
|
||||
doDatum:= doDatum + '59';
|
||||
doDatum:= MidStr(doDatum, 7, 2) + '.' + MidStr(doDatum, 5, 2) + '.' + LeftStr(doDatum, 4) + ' ' + MidStr(doDatum, 9, 2) + ':' + MidStr(doDatum, 11, 2) + ':' + MidStr(doDatum, 13, 2);
|
||||
if not(TryStrToDateTime(doDatum, datDo)) then
|
||||
datDo:= Now
|
||||
end
|
||||
else
|
||||
datDo:= Now;
|
||||
|
||||
if (odDatum<>'') then
|
||||
begin
|
||||
strTemp:= 'CONVERT(datetime, N' + FormatDateTime('dd.mm.yyyy', datOd).QuotedString + ',104)';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.DatPorizeni>=' + strTemp;
|
||||
end;
|
||||
|
||||
if (doDatum<>'') then
|
||||
begin
|
||||
strTemp:= 'CONVERT(datetime, N' + FormatDateTime('dd.mm.yyyy', datDo).QuotedString + ',104)';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.DatPorizeni<=' + strTemp;
|
||||
end;
|
||||
|
||||
|
||||
// pro micharnu nejsou prikazy pozastavovany
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.StavPrikazu IN (30' + IfThen(typPrikazu<>1, ',40', '') + ')';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada<>N''009''';
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.Rada LIKE N''0%''';
|
||||
|
||||
|
||||
if (where<>'') then
|
||||
lSQL:= lSQL + ' WHERE ' + where;
|
||||
lSQL:= lSQL + ' GROUP BY main.ID ORDER BY main.ID';
|
||||
|
||||
|
||||
vpSvr := TVyrobniPrikazService.Create (self.FDM);
|
||||
try
|
||||
sqlConnX := TFDConnection.Create (nil);
|
||||
try
|
||||
sqlConnX.ConnectionDefName := sqlPoolName;
|
||||
sqlConnX.Open;
|
||||
|
||||
lokIDcka := TList<Integer>.Create;
|
||||
try
|
||||
lQry := TFDQuery.Create (nil);
|
||||
try
|
||||
lQry.Connection := sqlConnX;
|
||||
lQry.FetchOptions.Mode := fmAll;
|
||||
lQry.Open (lSQL);
|
||||
|
||||
cnt := lQry.RecordCount;
|
||||
|
||||
if not lQry.Active then
|
||||
lQry.Open (lSQL);
|
||||
|
||||
lQry.First;
|
||||
rNo := 1;
|
||||
|
||||
try
|
||||
while (rNo <= cnt) do
|
||||
begin
|
||||
lQry.RecNo := rNo;
|
||||
idVPr := lQry.FieldByName('ID').AsInteger;
|
||||
lokIDcka.Add (idVPr);
|
||||
if not lQry.Active then
|
||||
lQry.Open (lSQL);
|
||||
Inc(rNo);
|
||||
end;
|
||||
|
||||
except
|
||||
on E: Exception do
|
||||
begin
|
||||
{$IF CompilerVersion >= 37.0} // Delphi 13+
|
||||
raise EServiceException.Create ('Chyba načítání naskenované položky/položek dokladu') from E;
|
||||
{$ELSE}
|
||||
raise EServiceException.Create ('Chyba načítání naskenované položky/položek dokladu: ' + E.Message) at ExceptAddr;
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
|
||||
finally
|
||||
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;
|
||||
end;
|
||||
|
||||
finally
|
||||
vpSvr.Free;
|
||||
end;
|
||||
|
||||
finally
|
||||
begin
|
||||
vpSvr.Free;
|
||||
FreeAndNil(lQry);
|
||||
end;
|
||||
locParams.Free;
|
||||
end;
|
||||
|
||||
locParams.Free;
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@
|
||||
var lSQL, errMsg, url, outData, fName, loopCasTyp: string;
|
||||
lLoop, idDigiFile, cnt, idx: Integer;
|
||||
lLoopMax, koefProCas: integer;
|
||||
logRunCnt: integer;
|
||||
logRunCnt, intTemp: integer;
|
||||
Msg: TMsg;
|
||||
firstRun, inProg, inDL: boolean;
|
||||
lQry: TFDQuery;
|
||||
@ -95,137 +95,140 @@
|
||||
|
||||
attrIdx:= attribs.IndexOf('zapisObjMatExpPrIntMins');
|
||||
if (attrIdx>-1) then
|
||||
if (attribs.Get(attrIdx).NodeValue<>null) then
|
||||
lLoopMax:= attribs.Get(attrIdx).NodeValue;
|
||||
if TryStrToInt(VarToStr(attribs.Get(attrIdx).NodeValue), intTemp) then
|
||||
lLoopMax:= intTemp;
|
||||
end; // n1 = config
|
||||
end; // specCfgXML.DocumentElement<>nil
|
||||
end; // not specCfgXML.IsEmptyDoc
|
||||
end; // FileExists(cfgFile)
|
||||
except
|
||||
on E: Exception do
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Chyba cteni konfigu THeoRTNZapisObjMatThread: ' + E.Message);
|
||||
end;
|
||||
finally
|
||||
begin
|
||||
if (specCfgXML<>nil) then
|
||||
specCfgXML:= nil;
|
||||
specCfgXML := nil;
|
||||
CoUninitialize;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavek materialu do ExpPr - interval: ' + lLoopMax.ToString + ' min.');
|
||||
lLoopMax:= lLoopMax * 60; // minuty na vteriny
|
||||
lLoopMax := lLoopMax * 60; // minuty na vteriny
|
||||
|
||||
|
||||
firstRun:= true;
|
||||
inProg:= false;
|
||||
FRunning:= true;
|
||||
firstRun := true;
|
||||
inProg := false;
|
||||
FRunning := true;
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
begin
|
||||
FTimer:= CreateWaitableTimer (nil, true, 'RTNZapisObjMatExpPrWaitableTimer');
|
||||
liDueTime.QuadPart:= -1*_Second;
|
||||
FTimer := CreateWaitableTimer (nil, true, 'RTNZapisObjMatExpPrWaitableTimer');
|
||||
liDueTime.QuadPart := -1*_Second;
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create (nil);
|
||||
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
|
||||
if (HDCDZApiService<>nil) then
|
||||
if (HDCDZApiService.Terminated) then
|
||||
begin
|
||||
Terminate;
|
||||
FRunning:= false;
|
||||
end;
|
||||
|
||||
PeekMessage (&Msg, 0, 0, 0, PM_NOREMOVE); { Create message queue }
|
||||
|
||||
if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu
|
||||
while not(Terminated) and FRunning do
|
||||
begin
|
||||
if (HDCDZApiService<>nil) then
|
||||
if (HDCDZApiService.Terminated) then
|
||||
begin
|
||||
idDigiFile:= 0;
|
||||
firstRun:= false;
|
||||
Terminate;
|
||||
FRunning:= false;
|
||||
end;
|
||||
|
||||
if (logRunCnt<4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky materialu do ExpPr c.' + logRunCnt.toString + '...');
|
||||
if (logRunCnt=4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky - bezi, ale dal neloguju');
|
||||
PeekMessage (&Msg, 0, 0, 0, PM_NOREMOVE); { Create message queue }
|
||||
|
||||
try
|
||||
if not(inProg) then // nebezi uz ?
|
||||
begin
|
||||
if (lLoop=lLoopMax) or (firstRun) then // pri startu a pak kazdou minutu
|
||||
begin
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
sqlConnX := TFDConnection.Create (nil);
|
||||
try
|
||||
sqlConnX.Params.SetStrings (datMod.sqlConnParams);
|
||||
lQry := TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.Connection := sqlConnX;
|
||||
|
||||
idDigiFile:= 0;
|
||||
firstRun:= false;
|
||||
|
||||
if (logRunCnt<4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky materialu do ExpPr c.' + logRunCnt.toString + '...');
|
||||
if (logRunCnt=4) then
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Spoustim zapis Objednavky - bezi, ale dal neloguju');
|
||||
|
||||
try
|
||||
if not(inProg) then // nebezi uz ?
|
||||
begin
|
||||
|
||||
if (1=1) then // pro rychle vypnuti
|
||||
begin
|
||||
sqlConnX.Open;
|
||||
if (sqlConnX.Connected) then
|
||||
begin
|
||||
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);
|
||||
if (lQry.RecordCount>0) then
|
||||
begin
|
||||
lQry.First;
|
||||
errMsg:= lQry.FieldByName('ErrMsg').AsString;
|
||||
if (errMsg<>'') then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
|
||||
inProg:= false;
|
||||
end; // sql Connected
|
||||
end; // 1=1
|
||||
end;
|
||||
|
||||
except on E:Exception do
|
||||
begin
|
||||
sqlConnX.Open;
|
||||
if (sqlConnX.Connected) then
|
||||
inProg:= false;
|
||||
errMsg:= E.Message; // datMod.sqlQry11.FieldByName('ErrMsg').AsString;
|
||||
if (mamTabPrijataData) then
|
||||
begin
|
||||
inProg:= true;
|
||||
lQry.Open(lSQL);
|
||||
if (lQry.RecordCount>0) then
|
||||
begin
|
||||
lQry.First;
|
||||
errMsg:= lQry.FieldByName('ErrMsg').AsString;
|
||||
if (errMsg<>'') then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etInfo, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
lQry.Close;
|
||||
inProg:= false;
|
||||
end; // sql Connected
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
except on E:Exception do
|
||||
begin
|
||||
inProg:= false;
|
||||
errMsg:= E.Message; // datMod.sqlQry11.FieldByName('ErrMsg').AsString;
|
||||
if (mamTabPrijataData) then
|
||||
begin
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn('Zapis Objednavky materialu do ExpPr - chyba: ' + errMsg);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
lLoop:= 0;
|
||||
if (logRunCnt<5) then
|
||||
Inc (logRunCnt);
|
||||
finally
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
Inc (lLoop);
|
||||
|
||||
if (FTimer<>0) then
|
||||
SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false);
|
||||
repeat
|
||||
lBusy:= MsgWaitForMultipleObjects (1, FTimer, false, INFINITE, QS_ALLINPUT);
|
||||
until lBusy = WAIT_OBJECT_0;
|
||||
lLoop:= 0;
|
||||
if (logRunCnt<5) then
|
||||
Inc (logRunCnt);
|
||||
end; // if lLoop=lLoopMax...
|
||||
|
||||
Inc (lLoop);
|
||||
|
||||
|
||||
if (FTimer<>0) then
|
||||
SetWaitableTimer (FTimer, TLargeInteger(liDueTime), 0, nil, nil, false);
|
||||
repeat
|
||||
lBusy:= MsgWaitForMultipleObjects (1, FTimer, false, INFINITE, QS_ALLINPUT);
|
||||
until lBusy = WAIT_OBJECT_0;
|
||||
// Sleep (998);
|
||||
|
||||
end;
|
||||
finally
|
||||
end;
|
||||
end; // while not(Terminated) and FRunning
|
||||
|
||||
if (lQry<>nil) then
|
||||
begin
|
||||
lQry.Close;
|
||||
FreeAndNil (lQry);
|
||||
end;
|
||||
if (sqlConnX<>nil) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
FreeAndNil (sqlConnX);
|
||||
end;
|
||||
if (FTimer<>0) then
|
||||
CloseHandle (FTimer);
|
||||
|
||||
end; // 1=1
|
||||
|
||||
|
||||
Binary file not shown.
@ -13,9 +13,7 @@ uses
|
||||
Winapi.Windows,
|
||||
System.Classes,
|
||||
|
||||
{$IFDEF DEBUG}
|
||||
Web.WebReq,
|
||||
{$ENDIF}
|
||||
|
||||
MVCFramework.Middleware.Swagger,
|
||||
MVCFramework.Swagger.Commons,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<FrameworkType>VCL</FrameworkType>
|
||||
<MainSource>hdcDZApi.dpr</MainSource>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Config Condition="'$(Config)'==''">Release</Config>
|
||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||
<TargetedPlatforms>2</TargetedPlatforms>
|
||||
<AppType>Application</AppType>
|
||||
@ -131,9 +131,9 @@
|
||||
<DCC_ImageBase>700000</DCC_ImageBase>
|
||||
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
|
||||
<VerInfo_MajorVer>3</VerInfo_MajorVer>
|
||||
<VerInfo_Release>2025</VerInfo_Release>
|
||||
<VerInfo_Build>1205</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_Release>2026</VerInfo_Release>
|
||||
<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.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>
|
||||
<DCC_MapFile>3</DCC_MapFile>
|
||||
<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\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\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\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>
|
||||
@ -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\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\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\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>
|
||||
|
||||
BIN
hdcDZApi.res
BIN
hdcDZApi.res
Binary file not shown.
@ -246,7 +246,7 @@ uses
|
||||
|
||||
|
||||
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
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
@ -343,7 +343,7 @@ uses
|
||||
|
||||
|
||||
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
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
@ -410,7 +410,7 @@ uses
|
||||
begin
|
||||
params.Add('id', iId.ToString);
|
||||
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
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
@ -550,7 +550,7 @@ uses
|
||||
params.Add('iddoklad', iIdDoklad.ToString);
|
||||
|
||||
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
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
|
||||
@ -854,7 +854,7 @@ uses
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -886,7 +886,7 @@ uses
|
||||
params.Add('id', iId.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidRozpracOperaciService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -974,7 +974,7 @@ uses
|
||||
if (iId>0) then
|
||||
begin
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidenceOperaciService.GetByID (iId)));
|
||||
Render(ObjectDict().Add('data', GetVyrobaEvidenceOperaciService.GetByID (iId, nil, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1040,7 +1040,7 @@ uses
|
||||
params.Add('id', iId.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetTPVCisKoopService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetTPVCisKoopService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1122,7 +1122,7 @@ uses
|
||||
params.Add('spustene', '1');
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params) ));
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params, FDM.sqlConn) ));
|
||||
except on E:Exception do
|
||||
begin
|
||||
RenderStatusMessage (200);
|
||||
@ -1161,7 +1161,7 @@ uses
|
||||
params.Add('jenId', '1');
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
end;
|
||||
@ -1204,7 +1204,7 @@ uses
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByID (iId, params)));
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetByID (iId, params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1330,7 +1330,7 @@ uses
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetDokladOZService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1420,7 +1420,7 @@ uses
|
||||
mnReq:= 0;
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetKusovnik (idVPr, mnReq, jenPlatne, 0)));
|
||||
Render(ObjectDict().Add('data', GetVyrobniPrikazService.GetKusovnik (idVPr, mnReq, jenPlatne, 0, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1477,7 +1477,7 @@ uses
|
||||
params.Add('stavPrikazu', iStav.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1570,7 +1570,7 @@ uses
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1680,7 +1680,7 @@ uses
|
||||
|
||||
|
||||
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
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1721,7 +1721,7 @@ uses
|
||||
params.Add ('kontrolnipostupy', '1');
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByID (iid, params)));
|
||||
Render(ObjectDict().Add('data', GetVyrobniOperaceService.GetByID (iid, params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1840,7 +1840,7 @@ uses
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByParams(params)));
|
||||
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByParams(params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -1876,7 +1876,7 @@ uses
|
||||
bPol:= (p=1);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByID(iId, bPol)));
|
||||
Render(ObjectDict().Add('data', GetKooperacniObjednavkaService.GetByID(iId, bPol, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -2100,7 +2100,7 @@ uses
|
||||
params.Add('dilec', idDilce.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetTPVOperaceDilceService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetTPVOperaceDilceService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
end;
|
||||
@ -2176,7 +2176,7 @@ uses
|
||||
params.Add('id', iId.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetMaterialPrikazuService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
@ -2382,7 +2382,7 @@ uses
|
||||
params.Add ('id', iId.ToString);
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByID (iId, params)));
|
||||
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByID (iId, params, FDM.sqlConn)));
|
||||
except
|
||||
// RenderStatusMessage (200);
|
||||
{
|
||||
@ -2424,7 +2424,7 @@ uses
|
||||
{$ENDIF}
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByParams (params)));
|
||||
Render(ObjectDict().Add('data', GetTPVPrednastaveniOperaciService.GetByParams (params, FDM.sqlConn)));
|
||||
except
|
||||
// RenderStatusMessage (200);
|
||||
{
|
||||
|
||||
188
uDataMod.pas
188
uDataMod.pas
@ -9,7 +9,7 @@ uses
|
||||
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.UI, FireDAC.Phys.MSSQLDef,
|
||||
FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL, FireDAC.Stan.Param, FireDAC.DatS,
|
||||
FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Stan.Consts,
|
||||
Winapi.ActiveX,
|
||||
Winapi.ActiveX, System.RegularExpressions,
|
||||
MVCFramework.Logger,
|
||||
Quick.Logger, Quick.Threads, Quick.Logger.Provider.Files;
|
||||
|
||||
@ -44,6 +44,7 @@ type
|
||||
function SQLRecordExists (sqlText: string): Boolean;
|
||||
function SQLColumnExists (const tabName: string; const colName: string): Boolean;
|
||||
function SQLIDsToString (const tabName: string=''; where: string=''): string;
|
||||
function SQLIsSafe (const S: string): boolean;
|
||||
function SQLGetString (sqlCmd: string=''; sqlConnLoc: TFDConnection=nil): string;
|
||||
|
||||
function StreamToString (const M: TStream): string;
|
||||
@ -57,6 +58,8 @@ type
|
||||
var
|
||||
datMod: TdatMod;
|
||||
ConnDef: IFDStanConnectionDef;
|
||||
ConnInit: Boolean = false;
|
||||
ConnInitLock: TObject;
|
||||
|
||||
|
||||
implementation
|
||||
@ -91,7 +94,7 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
|
||||
|
||||
|
||||
procedure TdatMod.DataModuleDestroy(Sender: TObject);
|
||||
procedure TdatMod.DataModuleDestroy (Sender: TObject);
|
||||
begin
|
||||
if (sqlConnParams<>nil) then
|
||||
sqlConnParams.Free;
|
||||
@ -156,90 +159,13 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
|
||||
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
|
||||
begin
|
||||
try
|
||||
sqlConnParams:= TStringList.Create;
|
||||
sqlConnParams.Clear;
|
||||
oPars:= TStringList.Create;
|
||||
try
|
||||
// sqlConn.Params.Clear;
|
||||
// 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_DriverID + '=MSSQL'); // je definovan v AddConnectionDef
|
||||
oPars.Add(S_FD_ConnParam_Common_Server + '=' + dbServer);
|
||||
oPars.Add(S_FD_ConnParam_Common_Port + '=' + dbPort.ToString);
|
||||
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_LoginTimeout + '=15');
|
||||
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_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('CommandTimeout=120');
|
||||
if (dbEncConn) then
|
||||
oPars.Add(S_FD_ConnParam_MSSQL_Encrypt + '=Yes');
|
||||
|
||||
if (FDManager.FindConnection(sqlPoolName)=nil) then
|
||||
if not(ConnInit) then
|
||||
begin
|
||||
FDManager.AddConnectionDef (sqlPoolName, 'MSSQL', oPars, true);
|
||||
if (FDManager.State<>dmsInactive) then
|
||||
Sleep(0);
|
||||
TMonitor.Enter(ConnInitLock);
|
||||
try
|
||||
if not(ConnInit) then
|
||||
begin
|
||||
if (FDManager.ConnectionDefs.FindConnectionDef(sqlPoolName) = nil) then
|
||||
FDManager.AddConnectionDef(sqlPoolName, 'MSSQL', oPars);
|
||||
if (FDManager.State = dmsInactive) then
|
||||
FDManager.Open;
|
||||
ConnInit := True;
|
||||
end;
|
||||
finally
|
||||
TMonitor.Exit (ConnInitLock);
|
||||
end;
|
||||
end;
|
||||
FDManager.Open;
|
||||
|
||||
// sqlConn.Params.SetStrings(oPars);
|
||||
sqlConn.ConnectionDefName:= sqlPoolName;
|
||||
sqlQry1.ConnectionName:= sqlConn.ConnectionDefName;
|
||||
sqlQry2.ConnectionName:= sqlConn.ConnectionDefName;
|
||||
sqlQry3.ConnectionName:= sqlConn.ConnectionDefName;
|
||||
sqlQry10.ConnectionName:= sqlConn.ConnectionDefName;
|
||||
sqlQry11.ConnectionName:= sqlConn.ConnectionDefName;
|
||||
sqlQry1.Connection:= sqlConn;
|
||||
sqlQry2.Connection:= sqlConn;
|
||||
sqlQry3.Connection:= sqlConn;
|
||||
sqlQry10.Connection:= sqlConn;
|
||||
sqlQry11.Connection:= sqlConn;
|
||||
|
||||
// if (dbConnOleDB) then
|
||||
// sqlMSSQLDrv.ODBCDriver:= '';
|
||||
|
||||
connStr:= '';
|
||||
if (dbEncConn) then
|
||||
begin
|
||||
if (dbConnOleDB) then
|
||||
connStr:= 'Encrypt=True;TrustServerCertificate=True;UseEncryptionForData=True'
|
||||
connStr:= ';Encrypt=True;TrustServerCertificate=True;UseEncryptionForData=True'
|
||||
else
|
||||
connStr:= 'Encrypt=yes;TrustServerCertificate=yes;Encrypt=yes';
|
||||
connStr:= ';Encrypt=yes;TrustServerCertificate=yes;Encrypt=yes';
|
||||
// sqlConn.Params.Add(S_FD_ConnParam_ODBC_ODBCAdvanced + '=' + connStr);
|
||||
end;
|
||||
connStr:= FDManager.ConnectionDefs.ConnectionDefByName(sqlPoolName).Params.Text + connStr;
|
||||
|
||||
connStr:= sqlConn.Params.DelimitedText;
|
||||
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
|
||||
begin
|
||||
result:= E.Message;
|
||||
@ -294,8 +236,8 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
end;
|
||||
end; // try
|
||||
finally
|
||||
if (oPars<>nil) then
|
||||
oPars.Free;
|
||||
// sqlConnParams.Free;
|
||||
oPars.Free;
|
||||
end; // try
|
||||
end;
|
||||
end;
|
||||
@ -458,19 +400,37 @@ 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;
|
||||
var lSQL, s, t: string;
|
||||
c: boolean;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
begin
|
||||
result:= '';
|
||||
result := '';
|
||||
|
||||
try
|
||||
if (self.sqlConn.Connected) then
|
||||
begin
|
||||
s:= '';
|
||||
t:= tabName;
|
||||
s := '';
|
||||
t := tabName;
|
||||
if not(t.Contains('dbo.')) and not(t.Contains('dbo].')) then
|
||||
t:= '[' + t;
|
||||
if not(t.EndsWith(']')) then
|
||||
@ -479,8 +439,8 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
t:= '[dbo].' + t;
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
sqlConnX := TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName := sqlPoolName;
|
||||
try
|
||||
sqlConnX.Open;
|
||||
finally
|
||||
@ -491,15 +451,23 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
begin
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.Connection:= sqlConnX;
|
||||
result := '';
|
||||
lQry.Connection := sqlConnX;
|
||||
where:= where.Replace(';', '').Replace('--', '').Trim; // sanitace podminky
|
||||
lSQL:= 'SELECT STRING_AGG(ID,'','') AS IDs FROM ' + t + IfThen(where<>'', ' WHERE ' + where, '');
|
||||
try
|
||||
lQry.Open(lSQL);
|
||||
result:= lQry.FieldByName('IDs').AsString;
|
||||
except on E:Exception do
|
||||
result:= '';
|
||||
end;
|
||||
|
||||
if not(SQLIsSafe(where)) then
|
||||
lSQL:= '';
|
||||
|
||||
if (lSQL<>'') then
|
||||
begin
|
||||
try
|
||||
lQry.Open (lSQL);
|
||||
result := lQry.FieldByName('IDs').AsString;
|
||||
except on E:Exception do
|
||||
result := '';
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
@ -608,10 +576,12 @@ uses System.StrUtils, Data.Win.ADODB,
|
||||
|
||||
|
||||
initialization
|
||||
ConnInitLock := TObject.Create;
|
||||
// CoInitialize(nil);
|
||||
|
||||
|
||||
finalization
|
||||
ConnInitLock.Free;
|
||||
// CoUninitialize;
|
||||
|
||||
end.
|
||||
|
||||
@ -6,6 +6,9 @@ interface
|
||||
uses
|
||||
System.Generics.Collections,
|
||||
System.SysUtils,
|
||||
FireDAC.Stan.Option,
|
||||
FireDAC.Comp.Client,
|
||||
FireDAC.Stan.Param,
|
||||
JsonDataObjects,
|
||||
uSvc_Base,
|
||||
uCommons,
|
||||
@ -36,7 +39,7 @@ type
|
||||
TKmenZboziService = class(TServiceBase)
|
||||
public
|
||||
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 GetMeta: TJSONObject; virtual;
|
||||
function GetPrepocetMJ (idKmen: integer): TObjectList<TPrepocetMJ>; virtual;
|
||||
@ -49,9 +52,6 @@ implementation
|
||||
uses
|
||||
System.StrUtils,
|
||||
System.Variants,
|
||||
FireDAC.Stan.Option,
|
||||
FireDAC.Comp.Client,
|
||||
FireDAC.Stan.Param,
|
||||
Quick.Logger,
|
||||
MVCFramework.Commons,
|
||||
MVCFramework.FireDAC.Utils,
|
||||
@ -211,6 +211,7 @@ uses
|
||||
sqlConnX:= TFDConnection.Create (nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
|
||||
lSQL:= 'SELECT ' + sqlSelKmen + ' FROM ' + tblKZ + ' ORDER BY ID';
|
||||
|
||||
lQry:= TFDQuery.Create (nil);
|
||||
@ -220,10 +221,9 @@ uses
|
||||
lQry.Open (lSQL);
|
||||
result:= lQry.AsObjectList<TKmenZbozi>;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
lQry.Free;
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
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}
|
||||
const rtnASOLTrideni = '_ASOL_IdentifTrideni';
|
||||
{$ENDIF}
|
||||
var lSQL, extInfoStr: string;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
lokalniConnection: boolean;
|
||||
begin
|
||||
result:= nil;
|
||||
result := nil;
|
||||
|
||||
sqlConnX:= TFDConnection.Create (nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
lokalniConnection:= (AConn = nil);
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX:= TFDConnection.Create (nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX:= AConn;
|
||||
|
||||
extInfoStr:= '';
|
||||
if (SQLTableExists ('dbo', tblKZe)) then
|
||||
@ -288,11 +295,11 @@ uses
|
||||
raise EServiceException.Create ('Chyba nacitani kmenove karty: ' + E.Message);
|
||||
end;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
lQry.Free;
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
if (lokalniConnection) then
|
||||
sqlConnX.Free;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
@ -7,6 +7,9 @@ interface
|
||||
uses
|
||||
System.Generics.Collections,
|
||||
System.SysUtils,
|
||||
FireDAC.Stan.Option,
|
||||
FireDAC.Comp.Client,
|
||||
FireDAC.Stan.Param,
|
||||
JsonDataObjects,
|
||||
uSvc_Base,
|
||||
uCommons,
|
||||
@ -40,7 +43,7 @@ type
|
||||
TSerioveCisloPohybOZService = class(TServiceBase)
|
||||
public
|
||||
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;
|
||||
|
||||
|
||||
@ -48,15 +51,15 @@ type
|
||||
TStavSkladuService = class(TServiceBase)
|
||||
public
|
||||
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;
|
||||
|
||||
|
||||
TDokladOZService = class(TServiceBase)
|
||||
public
|
||||
function GetByID (const AID: integer; sdServer: boolean=false; params: TDictionary<string, string>=nil): TDokladOZ; 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;
|
||||
end;
|
||||
|
||||
@ -64,8 +67,8 @@ type
|
||||
TPolozkaOZService = class(TServiceBase)
|
||||
public
|
||||
function GetMeta: TJSONObject; virtual;
|
||||
function GetByID (const AID: integer; sdServer: boolean=false): TPohybOZ; virtual;
|
||||
function GetByParams (params: TDictionary<string, string>): TObjectList<TPohybOZ>; virtual;
|
||||
function GetByID (const AID: integer; sdServer: boolean=false; AConn: TFDConnection = nil): TPohybOZ; virtual;
|
||||
function GetByParams (params: TDictionary<string, string>; AConn: TFDConnection = nil): TObjectList<TPohybOZ>; virtual;
|
||||
end;
|
||||
|
||||
|
||||
@ -76,9 +79,6 @@ implementation
|
||||
uses
|
||||
System.StrUtils,
|
||||
System.DateUtils,
|
||||
FireDAC.Stan.Option,
|
||||
FireDAC.Comp.Client,
|
||||
FireDAC.Stan.Param,
|
||||
MVCFramework.FireDAC.Utils,
|
||||
MVCFramework.DataSet.Utils,
|
||||
MVCFramework.Serializer.Commons;
|
||||
@ -90,15 +90,26 @@ uses
|
||||
|
||||
{ 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;
|
||||
datOd, datDo: TDateTime;
|
||||
id: integer;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
lokalniConnection: boolean;
|
||||
begin
|
||||
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;
|
||||
|
||||
where:= '';
|
||||
@ -129,14 +140,14 @@ uses
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
try
|
||||
sqlConnX.Connected := true;
|
||||
lQry.Connection:= sqlConnX;
|
||||
try
|
||||
lQry.Open(lSQL);
|
||||
result:= lQry.AsObjectList<TStavSkladu>;
|
||||
lQry.Close;
|
||||
except on E:Exception do
|
||||
raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message);
|
||||
end;
|
||||
@ -144,9 +155,11 @@ uses
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
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;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
datOd, datDo: TDateTime;
|
||||
id, iDZ, idPrikaz, cnt, rNo: integer;
|
||||
jenSeznam, polozky, minimum: Boolean;
|
||||
d: TDokladOZ;
|
||||
dList: TObjectList<TDokladOZ>;
|
||||
resList: TObjectList<TDokladOZ>;
|
||||
resObj: TDokladOZ;
|
||||
noDatum, snZSDServeru: boolean;
|
||||
radyD, sklady, dpz: string;
|
||||
p: TDictionary<string, string>;
|
||||
lokalniConnection: boolean;
|
||||
lokIDcka: TList<integer>;
|
||||
begin
|
||||
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;
|
||||
radyD:= '';
|
||||
dpz:= '';
|
||||
@ -421,20 +446,19 @@ uses
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.Open(lSQL);
|
||||
cnt:= lQry.RecordCount;
|
||||
sqlConnX.Connected := true;
|
||||
lQry.FetchOptions.Mode := fmAll;
|
||||
lQry.Connection := sqlConnX;
|
||||
lQry.Open (lSQL);
|
||||
cnt := lQry.RecordCount;
|
||||
if (cnt>0) then
|
||||
begin
|
||||
lQry.Close;
|
||||
lokIDcka:= TList<integer>.Create;
|
||||
try
|
||||
d:= TDokladOZ.Create;
|
||||
dList:= TObjectList<TDokladOZ>.Create;
|
||||
try
|
||||
rNo:= 1;
|
||||
lQry.First;
|
||||
@ -442,44 +466,71 @@ uses
|
||||
begin
|
||||
lQry.RecNo:= rNo;
|
||||
iDZ:= lQry.FieldByName('ID').AsInteger;
|
||||
d:= self.GetByID (iDZ, snZSDServeru, p);
|
||||
dList.Add(d);
|
||||
lokIDcka.Add (iDZ);
|
||||
if not(lQry.Active) then
|
||||
lQry.Open;
|
||||
Inc(rNo);
|
||||
end;
|
||||
result:= dList; // FDM.sqlQry1.AsObjectList<TDokladOZ>;
|
||||
lQry.Close;
|
||||
except on E:Exception do
|
||||
raise EServiceException.Create('Chyba na<6E><61>t<EFBFBD>n<EFBFBD> dokladu: ' + E.Message);
|
||||
end;
|
||||
// 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
|
||||
resList.Free;
|
||||
end;
|
||||
|
||||
finally
|
||||
lokIDcka.Free;
|
||||
end;
|
||||
end
|
||||
else
|
||||
raise EServiceException.Create('Vybran<61>m podm<64>nk<6E>m neodpov<6F>d<EFBFBD> <20><>dn<64> doklad');
|
||||
finally
|
||||
p.Free;
|
||||
lQry.Close;
|
||||
FreeAndNil(lQry);
|
||||
lQry.Free;
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
p.Free;
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
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;
|
||||
minimumDat, polozky: boolean;
|
||||
p: TDictionary<string, string>;
|
||||
ps: TPolozkaOZService;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
lokalniConnection: boolean;
|
||||
begin
|
||||
result:= nil;
|
||||
result := nil;
|
||||
|
||||
lokalniConnection := (AConn = nil);
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX:= AConn;
|
||||
|
||||
|
||||
extInfoStr:= '';
|
||||
if (SQLTableExists ('dbo', tblDZe)) then
|
||||
@ -491,6 +542,7 @@ uses
|
||||
lQry.Open(lSQL, [AID]);
|
||||
if (lQry.RecordCount>0) then
|
||||
extInfoStr:= lQry.AsJSONObject;
|
||||
lQry.Close;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
@ -532,11 +584,9 @@ uses
|
||||
lSQL:= lSQL + ' FROM ' + tblDZ + ' WHERE ID=:ID';
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
sqlConnX.Connected := true;
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.Open(lSQL, [AID]);
|
||||
@ -550,16 +600,19 @@ uses
|
||||
result.PohybyOZ:= ps.GetByParams (p);
|
||||
end
|
||||
else
|
||||
raise EServiceException.Create('Doklad ob<6F>hu zbo<62><6F> s ID ' + AID.ToString + ' nebyl nalezen.');
|
||||
raise EServiceException.Create('Doklad ob<6F>hu zbo<62><6F> s ID ' + AID.ToString + ' nebyl nalezen.');
|
||||
finally
|
||||
p.Free;
|
||||
ps.Free;
|
||||
FreeAndNil(lQry);
|
||||
lQry.Close;
|
||||
lQry.Free;
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
@ -589,19 +642,28 @@ uses
|
||||
|
||||
{ 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;
|
||||
id, AID, cnt, rNo: integer;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
pList: TObjectList<TPohybOZ>;
|
||||
p: TPohybOZ;
|
||||
resList: TObjectList<TPohybOZ>;
|
||||
resObj: TPohybOZ;
|
||||
sdServer: boolean;
|
||||
lokalniConnection: boolean;
|
||||
lokIDcka: TList<integer>;
|
||||
begin
|
||||
result:= nil;
|
||||
|
||||
p:= TPohybOZ.Create;
|
||||
// pList:= TObjectList<TPohybOZ>.Create;
|
||||
lokalniConnection := (AConn = nil);
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX := AConn;
|
||||
|
||||
|
||||
lSQL:= 'SELECT ' + GetTabCols('dbo', tblPZ, '', false) + ' FROM ' + tblPZ;
|
||||
|
||||
@ -634,48 +696,61 @@ uses
|
||||
// lSQL:= lSQL.Replace('TabPohybyZbozi.', 'main.');
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
|
||||
sqlConnX.Connected := true;
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.Open(lSQL);
|
||||
cnt:= lQry.RecordCount;
|
||||
pList:= TObjectList<TPohybOZ>.Create;
|
||||
lQry.FetchOptions.Mode := fmAll;
|
||||
lQry.Connection := sqlConnX;
|
||||
lQry.Open (lSQL);
|
||||
cnt := lQry.RecordCount;
|
||||
lokIDcka := TList<integer>.Create;
|
||||
try
|
||||
lQry.First;
|
||||
rNo:= 1;
|
||||
rNo := 1;
|
||||
while (rNo<=cnt) do
|
||||
begin
|
||||
lQry.RecNo:= rNo;
|
||||
AID:= lQry.FieldByName('ID').AsInteger;
|
||||
p:= self.GetByID (AID, sdServer);
|
||||
pList.Add(p);
|
||||
lQry.RecNo := rNo;
|
||||
AID := lQry.FieldByName('ID').AsInteger;
|
||||
lokIDcka.Add (AID);
|
||||
if not(lQry.Active) then
|
||||
lQry.Open;
|
||||
Inc(rNo);
|
||||
Inc (rNo);
|
||||
end;
|
||||
result:= pList;
|
||||
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);
|
||||
end;
|
||||
// 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
|
||||
resList.Free;
|
||||
end;
|
||||
|
||||
finally
|
||||
lokIDcka.Free;
|
||||
lQry.Close;
|
||||
FreeAndNil(lQry);
|
||||
FreeAndNil (lQry);
|
||||
end;
|
||||
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
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;
|
||||
p: TDictionary<string, string>;
|
||||
pds: TSerioveCisloPohybOZService;
|
||||
@ -684,6 +759,8 @@ uses
|
||||
lQry, lQry2: TFDQuery;
|
||||
sqlConnX, sqlConnX2: TFDConnection;
|
||||
extInfoStr: string;
|
||||
lokalniConnection: boolean;
|
||||
lokIDcka: TList<integer>;
|
||||
{$IFDEF CUSTOM_CTRL_Rootvin}
|
||||
silo: string;
|
||||
siloInt, idMzdy: integer;
|
||||
@ -691,12 +768,21 @@ uses
|
||||
begin
|
||||
result:= nil;
|
||||
|
||||
lokalniConnection := (AConn = nil);
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX := AConn;
|
||||
|
||||
|
||||
{$IFDEF CUSTOM_CTRL_Rootvin}
|
||||
silo:= '';
|
||||
{$ENDIF}
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
sqlConnX.Connected := true;
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
@ -757,48 +843,53 @@ uses
|
||||
{$IFDEF CUSTOM_CTRL_Rootvin}
|
||||
lQry2:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry2.FetchOptions.Mode:= fmAll;
|
||||
lQry2.Connection:= sqlConnX;
|
||||
lQry2.FetchOptions.Mode := fmAll;
|
||||
lQry2.Connection := sqlConnX;
|
||||
|
||||
if (sz='101') and (dpz='0') and ((rDokl='251') or (rDokl='261')) then
|
||||
if (silo='') then
|
||||
begin
|
||||
lSQL:= 'SELECT TOP(1) p.IDUmisteni, u.Kod FROM ' + tblPuvodniVC + ' p INNER JOIN ' + tblUmisteni + ' u ON (u.ID=p.IDUmisteni) WHERE p.IDPohybZbozi=:ID';
|
||||
lSQL := 'SELECT TOP(1) p.IDUmisteni, u.Kod FROM ' + tblPuvodniVC + ' p INNER JOIN ' + tblUmisteni + ' u ON (u.ID=p.IDUmisteni) WHERE p.IDPohybZbozi=:ID';
|
||||
lQry2.Open (lSQL, [AID]);
|
||||
lQry2.First;
|
||||
u:= lQry2.FieldByName('IDUmisteni').AsInteger;
|
||||
silo:= lQry2.FieldByName('Kod').AsString;
|
||||
u := lQry2.FieldByName('IDUmisteni').AsInteger;
|
||||
silo := lQry2.FieldByName('Kod').AsString;
|
||||
if (silo<>'') then
|
||||
begin
|
||||
TryStrToInt (silo, siloInt);
|
||||
if (siloInt>0) then
|
||||
begin
|
||||
lSQL:= 'IF NOT EXISTS (SELECT 1 FROM ' + tblPZe + ' WHERE ID=:ID) INSERT ' + tblPZe + ' (ID) SELECT :ID' + CRLF;
|
||||
lSQL:= lSQL + 'UPDATE ' + tblPZe + ' SET _Mouka_Silo=' + siloInt.ToString + ' WHERE ID=:ID';
|
||||
lSQL := 'IF NOT EXISTS (SELECT 1 FROM ' + tblPZe + ' WHERE ID=:ID) INSERT ' + tblPZe + ' (ID) SELECT :ID' + CRLF;
|
||||
lSQL := lSQL + 'UPDATE ' + tblPZe + ' SET _Mouka_Silo=' + siloInt.ToString + ' WHERE ID=:ID';
|
||||
sqlConnX.ExecSQL (lSQL, [AID]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
lSQL:= 'SELECT IDMzdy FROM ' + tblPMZGenPZ + ' WHERE IDPohybu=:ID';
|
||||
lSQL := 'SELECT IDMzdy FROM ' + tblPMZGenPZ + ' WHERE IDPohybu=:ID';
|
||||
lQry2.Open (lSQL, [AID]);
|
||||
if (lQry2.RecordCount=1) then
|
||||
result.IDMzdy:= lQry2.FieldByName('IDMzdy').AsInteger;
|
||||
result.IDMzdy := lQry2.FieldByName('IDMzdy').AsInteger;
|
||||
|
||||
finally
|
||||
lQry2.Close;
|
||||
FreeAndNil(lQry2);
|
||||
FreeAndNil (lQry2);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX2 := TFDConnection.Create(nil);
|
||||
sqlConnX2.ConnectionDefName := sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX2 := AConn;
|
||||
|
||||
sqlConnX2:= TFDConnection.Create(nil);
|
||||
lQry2:= TFDQuery.Create (nil);
|
||||
sqlConnX2.Connected := true;
|
||||
lQry2 := TFDQuery.Create (nil);
|
||||
try
|
||||
sqlConnX2.ConnectionDefName:= sqlPoolName;
|
||||
lQry2.Connection:= sqlConnX2;
|
||||
|
||||
|
||||
@ -880,13 +971,16 @@ uses
|
||||
|
||||
finally
|
||||
lQry2.Free;
|
||||
sqlConnX2.Close;
|
||||
sqlConnX2.Free;
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX2.Close;
|
||||
sqlConnX2.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
if (extInfoStr<>'') then
|
||||
result.ExtInfo:= ExtInfoStr;
|
||||
result.SerialNums:= pds.GetByParams (p);
|
||||
result.SerialNums:= pds.GetByParams (p, sqlConnX);
|
||||
if (u>0) then
|
||||
begin
|
||||
Result.Umisteni:= us.GetByID (u);
|
||||
@ -905,15 +999,18 @@ uses
|
||||
else
|
||||
raise EServiceException.Create('Polo<6C>ka dokladu ob<6F>hu zbo<62><6F> s ID ' + AID.ToString + ' nebyla nalezena.');
|
||||
finally
|
||||
lokIDcka.Free;
|
||||
p.Free;
|
||||
pds.Free;
|
||||
lQry.Close;
|
||||
FreeAndNil(lQry);
|
||||
FreeAndNil (lQry);
|
||||
end;
|
||||
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -1021,15 +1118,16 @@ uses
|
||||
|
||||
lSQL:= 'SELECT ' + GetTabCols('dbo', tblVyrCP, '', false) + IfThen(sp<>'', ', ' + sp, '') + ' FROM ' + tblVyrCP + ' WHERE 1=0';
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
sqlConnX := TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName := sqlPoolName;
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
try
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.Open(lSQL);
|
||||
Result:= lQry.MetadataAsJSONObject();
|
||||
lQry.FetchOptions.Mode := fmAll;
|
||||
lQry.Connection := sqlConnX;
|
||||
lQry.Open (lSQL);
|
||||
Result := lQry.MetadataAsJSONObject();
|
||||
lQry.Close;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
@ -1043,54 +1141,62 @@ 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;
|
||||
lQry: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
id, idPZ: integer;
|
||||
s: TSerioveCisloPohybOZ;
|
||||
sdServer: boolean;
|
||||
lokalniConnection: boolean;
|
||||
lokIDcka: TList<integer>;
|
||||
begin
|
||||
result:= nil;
|
||||
|
||||
lSQL:= 'SELECT ' + GetTabCols('', tblVyrCP, 'main') + IfThen(selSpecVyrCP<>'', ', ' + selSpecVyrCP.Replace('#', ''), '')
|
||||
+ ', 0 AS ZdrojSD, 0 AS IDDokladGSD FROM ' + tblVyrCP + ' main';
|
||||
where:= '';
|
||||
lokalniConnection := (AConn = nil);
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX := TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName := sqlPoolName;
|
||||
end
|
||||
else
|
||||
sqlConnX := AConn;
|
||||
|
||||
sdServer:= false;
|
||||
|
||||
lSQL := 'SELECT ' + GetTabCols('', tblVyrCP, 'main') + IfThen(selSpecVyrCP<>'', ', ' + selSpecVyrCP.Replace('#', ''), '')
|
||||
+ ', 0 AS ZdrojSD, 0 AS IDDokladGSD FROM ' + tblVyrCP + ' main';
|
||||
where := '';
|
||||
|
||||
sdServer := false;
|
||||
if (params.ContainsKey('sdServer')) then
|
||||
if (params.Items['sdServer']='1') then
|
||||
sdServer:= true;
|
||||
sdServer := true;
|
||||
|
||||
|
||||
id:= 0;
|
||||
id := 0;
|
||||
if (params.ContainsKey('id')) then
|
||||
if (params.Items['id']<>'') then
|
||||
if (params.Items['id']<>'0') then
|
||||
id:= params.Items['id'].ToInteger;
|
||||
id := params.Items['id'].ToInteger;
|
||||
|
||||
idPZ:= 0;
|
||||
idPZ := 0;
|
||||
if (params.ContainsKey('idPolozkaOZ')) then
|
||||
if (params.Items['idPolozkaOZ']<>'') then
|
||||
if (params.Items['idPolozkaOZ']<>'0') then
|
||||
begin
|
||||
idPZ:= params.Items['idPolozkaOZ'].ToInteger;
|
||||
where:= where + IfThen(where<>'', ' AND ', '') + 'main.IDPolozkaDokladu=' + idPZ.ToString;
|
||||
idPZ := params.Items['idPolozkaOZ'].ToInteger;
|
||||
where := where + IfThen(where<>'', ' AND ', '') + 'main.IDPolozkaDokladu=' + idPZ.ToString;
|
||||
end;
|
||||
|
||||
if (where<>'') then
|
||||
lSQL:= lSQL + ' WHERE ' + IfThen(id>0, 'main.ID=' + id.ToString, where);
|
||||
lSQL:= lSQL + ' ORDER BY main.ID';
|
||||
lSQL := lSQL + ' WHERE ' + IfThen(id>0, 'main.ID=' + id.ToString, where);
|
||||
lSQL := lSQL + ' ORDER BY main.ID';
|
||||
|
||||
lSQL:= lSQL.Replace('TabVyrCP.', 'main.');
|
||||
lSQL := lSQL.Replace('TabVyrCP.', 'main.');
|
||||
if (selSpecVyrCP='') then
|
||||
lSQL:= lSQL.Replace('main.', '');
|
||||
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
lSQL := lSQL.Replace('main.', '');
|
||||
|
||||
lQry := TFDQuery.Create(nil);
|
||||
|
||||
{$IF DEFINED(CUSTOM_CTRL_Rootvin) or DEFINED(CUSTOM_CTRL_GatemaSD)}
|
||||
// test zda polozky pochazi z SD serveru
|
||||
@ -1102,7 +1208,7 @@ uses
|
||||
// typ 510=prijemka (potvrzeni/kontrola)
|
||||
lSQL2:= 'SELECT 1 AS A FROM ' + tblGSDScanData + ' p INNER JOIN ' + tblGSDDoklady + ' h ON (h.Id=p.IDDokladSD) WHERE h.DatGenerovani IS NOT NULL AND h.TypDokladu IN (500,510) AND p.IDPohZbo_New=' + idPZ.ToString;
|
||||
lSQL2:= lSQL2 + ' ORDER BY p.ID';
|
||||
lQry.Open(lSQL2);
|
||||
lQry.Open (lSQL2);
|
||||
if (lQry.RecordCount>0) then
|
||||
lSQL:= lSQL2.Replace(' 1 AS A ', ' 1000000000+p.ID AS ID, p.IDPohZbo_New AS IDPolozkaDokladu, 0 AS IDVyrCis, p.VyrCislo AS VyrCis, p.PopisSarze AS Nazev, p.Mnozstvi'
|
||||
+ ', p.MnozstviEvidence AS MnozstviEvid, p.DatPorizeni AS DatVstup, p.DatumExpirace AS DatExpirace, 1 AS ZdrojSD, h.ID AS IDDokladGSD ');
|
||||
@ -1112,19 +1218,22 @@ uses
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
try
|
||||
lQry.FetchOptions.Mode:= fmAll;
|
||||
lQry.Connection:= sqlConnX;
|
||||
lQry.Open(lSQL);
|
||||
result:= lQry.AsObjectList<TSerioveCisloPohybOZ>;
|
||||
sqlConnX.Connected:= true;
|
||||
lQry.FetchOptions.Mode := fmAll;
|
||||
lQry.Connection := sqlConnX;
|
||||
lQry.Open (lSQL);
|
||||
result := lQry.AsObjectList<TSerioveCisloPohybOZ>;
|
||||
lQry.Close;
|
||||
finally
|
||||
lQry.Free;
|
||||
end;
|
||||
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
|
||||
if (lokalniConnection) then
|
||||
begin
|
||||
sqlConnX.Close;
|
||||
sqlConnX.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
1802
uSvc_Vyroba.pas
1802
uSvc_Vyroba.pas
File diff suppressed because it is too large
Load Diff
@ -451,7 +451,7 @@ uses
|
||||
logRun: Int64;
|
||||
Msg: TMsg;
|
||||
mamTabPrijataData, firstRun, inProg, canCont: boolean;
|
||||
lQry, lQry2: TFDQuery;
|
||||
lQry, lQry2, lQry3: TFDQuery;
|
||||
sqlConnX: TFDConnection;
|
||||
begin
|
||||
lLoop:= 0;
|
||||
@ -507,49 +507,49 @@ uses
|
||||
{$ENDIF}
|
||||
begin
|
||||
|
||||
sqlConnX:= TFDConnection.Create(nil);
|
||||
sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
sqlConnX.Open;
|
||||
// sqlConnX:= TFDConnection.Create(nil);
|
||||
// sqlConnX.ConnectionDefName:= sqlPoolName;
|
||||
// sqlConnX.Open;
|
||||
|
||||
if (sqlConnX.Connected) then
|
||||
if (1=1) then // (sqlConnX.Connected)
|
||||
begin
|
||||
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 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 := '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'''' 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 + ' ORDER BY d.ID';
|
||||
|
||||
lQry:= TFDQuery.Create(nil);
|
||||
lQry := TFDQuery.Create(nil);
|
||||
lQry2:= TFDQuery.Create(nil);
|
||||
// lQry2.Connection:= sqlConnX;
|
||||
try
|
||||
lQry.Connection:= sqlConnX;
|
||||
// lQry.Connection:= sqlConnX;
|
||||
lQry.ConnectionName := sqlPoolName;
|
||||
lQry2.ConnectionName := sqlPoolName;
|
||||
|
||||
lQry.Open(lSQL);
|
||||
lQry.First;
|
||||
|
||||
inProg:= true;
|
||||
inProg := true;
|
||||
|
||||
while not(lQry.EOF) do
|
||||
begin
|
||||
idTask:= lQry.FieldByName('ID').asInteger;
|
||||
canCont:= true;
|
||||
idTask := lQry.FieldByName('ID').asInteger;
|
||||
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;
|
||||
cnt:= lQry2.FieldByName('Pocet').AsInteger;
|
||||
FreeAndNil(lQry2);
|
||||
cnt := lQry2.FieldByName('Pocet').AsInteger;
|
||||
if (cnt>3) then
|
||||
canCont:= false;
|
||||
|
||||
|
||||
if (canCont) then
|
||||
begin
|
||||
|
||||
sqlConnX.ExecSQL('INSERT dbo._hdc_ph_Log (IntValue, LogText) SELECT ' + idTask.ToString + ', N''Zpracovani API json''');
|
||||
lQry2.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);
|
||||
|
||||
// LogInfo(Quick.Logger.etError, 'Zpracovani PrijataJSONData ID ' + idTask.ToString);
|
||||
try
|
||||
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=1 WHERE ID=' + idTask.ToString);
|
||||
lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET Blokovano=1 WHERE ID=' + idTask.ToString);
|
||||
lSQL:= '';
|
||||
{$IFDEF DEBUG}
|
||||
Write ('Zpracovani prijateho JSON id ' + idTask.ToString);
|
||||
@ -559,8 +559,8 @@ uses
|
||||
{$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;
|
||||
{$ENDIF}
|
||||
sqlConnX.ExecSQL(lSQL);
|
||||
sqlConnX.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=NULL WHERE ID=' + idTask.ToString);
|
||||
lQry2.ExecSQL(lSQL);
|
||||
lQry2.ExecSQL('UPDATE ' + tblPrijataJsonData + ' SET PosledniChyba=NULL WHERE ID=' + idTask.ToString);
|
||||
|
||||
{$IFDEF DEBUG}
|
||||
Writeln(' - OK');
|
||||
@ -572,7 +572,7 @@ uses
|
||||
{$IFDEF DEBUG}
|
||||
WriteLn ('Chyba zpracovani prijateho JSON id ' + idTask.ToString + ' >> ' + errMsg);
|
||||
{$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}
|
||||
datMod.LogInfo (Quick.Logger.etError, 'Chyba evidence start/stop operace PrijataJSONData ID ' + idTask.ToString + ' : ' + errMsg);
|
||||
{$ELSE}
|
||||
@ -580,19 +580,21 @@ uses
|
||||
{$ENDIF}
|
||||
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;
|
||||
lQry.Next;
|
||||
end;
|
||||
finally
|
||||
lQry2.Close;
|
||||
FreeAndNil (lQry2);
|
||||
lQry.Close;
|
||||
FreeAndNil (lQry);
|
||||
end;
|
||||
|
||||
inProg:= false;
|
||||
end; // sql Connected
|
||||
sqlConnX.Close;
|
||||
FreeAndNil (sqlConnX);
|
||||
if Assigned(sqlConnx) then
|
||||
sqlConnX.Free;
|
||||
|
||||
end;
|
||||
end;
|
||||
|
||||
2
ukazBlokovanePorty.cmd
Normal file
2
ukazBlokovanePorty.cmd
Normal file
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
netsh interface ipv4 show excludedportrange protocol=tcp
|
||||
Reference in New Issue
Block a user