Po hlavnich upravach sdileni sponeni a uvolnovani connection poolu
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user