OBS/Kostenpflichtige Module/RESTServer/Beispiel2: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Böhrer (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „Esta é uma das perguntas mais frequentes que recebo no weblog, quando as pessoas começam a vender seus doces, salgados, bolos feitos em casa. Excelente para…“) |
Prakti (Diskussion | Beiträge) (Seitentitel und Codeblock wurden eingefügt) |
||
Zeile 1: | Zeile 1: | ||
= Endpuntk-Script = | |||
<syntaxhighlight> | |||
procedure _AddJob(oArr: TJSONArray; id: String); | |||
var oWert : TJSONObject; | |||
cSql : String; | |||
A_Query : TxFQuery; | |||
begin | |||
cSql := 'SELECT CONCAT(za_text, ":",sys_uid) AS Job FROM zeiterfart ' + | |||
'WHERE za_psnr = ' + DB_SQLVal(id) + ' AND za_inaktiv <> "1" ' + | |||
'ORDER BY za_order'; | |||
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin | |||
while (not A_Query.EoF) do begin | |||
oArr.Add(A_Query.A2C('Job')); | |||
A_Query.Next(); | |||
end; | |||
end; | |||
DB_Close(A_Query); | |||
end; | |||
procedure _AddCustomer(oArr: TJSONArray); | |||
var oWert : TJSONObject; | |||
cSql : String; | |||
A_Query : TxFQuery; | |||
begin | |||
cSql :=' SELECT * FROM' + | |||
' (SELECT' + | |||
' ps_nr,' + | |||
' ps_such AS Kunde,' + | |||
' perssta.sys_uid AS ps_sys_uid,' + | |||
' "PE" AS TYP' + | |||
' FROM eigenschaften' + | |||
' LEFT JOIN perssta ON se_ref1 AND perssta.sys_uid = se_ref2' + | |||
' WHERE se_nr = 0087' + | |||
' AND ps_nr <> 100000' + | |||
' UNION SELECT p_nr AS ps_nr,' + | |||
' p_name1 AS ps_such,' + | |||
' projekte.sys_uid AS ps_sys_uid,' + | |||
' "PR" AS TYP' + | |||
' FROM eigenschaften' + | |||
' LEFT JOIN projekte ON se_ref1 = p_nr' + | |||
' AND projekte.sys_uid = se_ref2 WHERE se_nr = 0087)' + | |||
' A WHERE ps_nr IS NOT NULL' + | |||
' ORDER BY Kunde '; | |||
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin | |||
while (not A_Query.EoF) do begin | |||
oArr.Add(A_Query.A2C('Kunde')); | |||
A_Query.Next(); | |||
end; | |||
end; | |||
DB_Close(A_Query); | |||
end; | |||
procedure _AddID(kunde: String; oArr: TJSONArray); | |||
var oWert : TJSONObject; | |||
cSql : String; | |||
A_Query : TxFQuery; | |||
begin | |||
cSql :=' SELECT * FROM' + | |||
' (SELECT' + | |||
' ps_nr,' + | |||
' ps_such AS Kunde,' + | |||
' perssta.sys_uid AS ps_sys_uid,' + | |||
' "PE" AS TYP' + | |||
' FROM eigenschaften' + | |||
' LEFT JOIN perssta ON se_ref1 AND perssta.sys_uid = se_ref2' + | |||
' WHERE se_nr = 0087' + | |||
' AND ps_nr <> 100000' + | |||
' UNION SELECT p_nr AS ps_nr,' + | |||
' p_name1 AS ps_such,' + | |||
' projekte.sys_uid AS ps_sys_uid,' + | |||
' "PR" AS TYP' + | |||
' FROM eigenschaften' + | |||
' LEFT JOIN projekte ON se_ref1 = p_nr' + | |||
' AND projekte.sys_uid = se_ref2 WHERE se_nr = 0087)' + | |||
' A WHERE ps_nr IS NOT NULL' + | |||
' AND Kunde = ' + DB_SQLVal(kunde) + | |||
' ORDER BY Kunde '; | |||
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin | |||
while (not A_Query.EoF) do begin | |||
oArr.Add(A_Query.A2C('ps_nr')); | |||
A_Query.Next(); | |||
end; | |||
end; | |||
DB_Close(A_Query); | |||
end; | |||
procedure _AddCHECK(oArr: TJSONArray); | |||
var oWert : TJSONObject; | |||
cSql : String; | |||
A_Query : TxFQuery; | |||
begin | |||
cSql := 'SELECT ze_starttime, zeiterfuser.sys_uid AS sysuid, zk_psnr, ' + | |||
'za_text, ps_such, ze_startdate FROM ' + | |||
'zeiterfuser LEFT JOIN zeiterfkomm ON ' + | |||
'zk_messunguid = zeiterfuser.SYS_UID LEFT JOIN zeiterfart ' + | |||
'ON zeiterfart.sys_uid = zeiterfuser.ze_uid AND ' + | |||
'za_psnr = zeiterfkomm.zk_psnr LEFT JOIN perssta ON ' + | |||
'ps_nr = zeiterfkomm.zk_psnr WHERE ze_status = 01 '; | |||
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin | |||
while (not A_Query.EoF) do begin | |||
oArr.Add(A_Query.A2C('ze_starttime')); | |||
oArr.Add(A_Query.A2C('zk_psnr')); | |||
oArr.Add(A_Query.A2C('za_text')); | |||
oArr.Add(A_Query.A2C('ps_such')); | |||
oArr.Add(A_Query.A2C('sysuid')); | |||
oArr.Add(A_Query.A2C('ze_startdate')); | |||
A_Query.Next(); | |||
end; | |||
end; | |||
DB_Close(A_Query); | |||
end; | |||
procedure _getPauseTime(sysuid: String; oArr: TJSONArray); | |||
var oWert : TJSONObject; | |||
cSql : String; | |||
A_Query : TxFQuery; | |||
begin | |||
cSql := 'SELECT * FROM zeiterfuser WHERE sys_uid = ' + DB_SQLVal(sysuid); | |||
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin | |||
while (not A_Query.EoF) do begin | |||
oArr.Add(A_Query.A2C('ze_pausezeit')); | |||
A_Query.Next(); | |||
end; | |||
end; | |||
DB_Close(A_Query); | |||
end; | |||
//----------------Funktionen----------------------------------// | |||
function POST(oParams: TStrings): string; | |||
var | |||
oArr1 : TJSONArray; | |||
cSql : String; | |||
startTime : TDateTime; | |||
elapsedTime : Integer; | |||
millisec, seconds, minutes, hours : Word; | |||
year, month, day : Word; | |||
uhrzeit, datum : String; | |||
begin | |||
if (oParams.values['choice']='job') then begin | |||
oArr1 := TJSONArray.Create(); | |||
_AddJob(oArr1, oParams.values['id']); | |||
result := oArr1.ToJSON(); | |||
end else if (oParams.values['choice']='customer') then begin | |||
oArr1 := TJSONArray.Create(); | |||
_AddCustomer(oArr1); | |||
result := oArr1.ToJSON(); | |||
end else if (oParams.values['choice']='id') then begin | |||
oArr1 := TJSONArray.Create(); | |||
_AddID(oParams.values['selectedKunde'], oArr1); | |||
result := oArr1.ToJSON(); | |||
end else if (oParams.values['choice']='check') then begin | |||
oArr1 := TJSONArray.Create(); | |||
_AddCHECK(oArr1); | |||
result := oArr1.ToJSON(); | |||
end else if (oParams.values['choice']='pauseTime') then begin | |||
oArr1 := TJSONArray.Create(); | |||
_GetPauseTime(oParams.values['sysuid'], oArr1); | |||
result := oArr1.ToJSON(); | |||
end; | |||
end; | |||
function PUT(oParams: TStrings): string; | |||
var | |||
xZeit : TqSQL; | |||
cUSER_SYSUID : String; | |||
cKOMM_SYSUID : String; | |||
lNew : Boolean; | |||
cSql : String; | |||
dDBNow : TDateTime; | |||
begin | |||
writeln('Choice: ' + oParams.values['choice']); | |||
if (oParams.values['choice']='start') then | |||
begin | |||
dDBNow := DB_Now(oDB); | |||
lNew := True; | |||
if (empty(cUSER_SYSUID)) then begin | |||
cUSER_SYSUID := GetNewId(oDB); | |||
end; | |||
xZeit := qSqlInit(oDB, 'zeiterfuser'); | |||
xZeit.lNoSysUID := True; | |||
writeln('SYSUID: ' + oParams.values['jobID']); | |||
xZeit.qSet('ze_user' , oParams.values['user']); | |||
xZeit.qSet('ze_starttime' , oParams.values['uhrzeit']); | |||
xZeit.qSet('ze_eigen' , '0101'); | |||
xZeit.qSet('ze_startdate' , oParams.values['datum']); | |||
xZeit.qSet('ze_endtime' , oParams.values['endTime']); | |||
xZeit.qSet('ze_enddate' , oParams.values['endDate']); | |||
xZeit.qSet('ze_zeit' , '0'); | |||
xZeit.qSet('ze_pausezeit' , '0'); | |||
xZeit.qSet('ze_status' , oParams.values['status']); | |||
xZeit.qSet('ze_berechnen' , 0); | |||
xZeit.qSet('ze_officestar' , 0); | |||
xZeit.qSet('ze_repa' , 0); | |||
xZeit.qSet('ze_vorbereitung' , 0); | |||
xZeit.qSet('ze_uid' , oParams.values['jobID']); | |||
xZeit.qSet('sys_uid' , cUSER_SYSUID); | |||
xZeit.SaveData(lNew); | |||
qSQLFree(xZeit); | |||
//--------------------------------------------------------------------- | |||
xZeit := qSqlInit(oDB,'ZEITERFKOMM'); | |||
xZeit.lNoSysUID := True; | |||
if (empty(cKOMM_SYSUID)) then begin | |||
cKOMM_SYSUID := GetNewId(oDB); | |||
end; | |||
xZeit.qSet('zk_psnr' , oParams.values['psnr']); | |||
xZeit.qSet('zk_starttime' , oParams.values['uhrzeit']); | |||
xZeit.qSet('zk_startdate' , oParams.values['datum']); | |||
xZeit.qSet('zk_kommentar' , oParams.values['comm']); | |||
xZeit.qSet('zk_messunguid' , cUSER_SYSUID); | |||
xZeit.qSet('sys_uid' , cKOMM_SYSUID); | |||
xZeit.SaveData(lNew); | |||
qSQLFree(xZeit); | |||
result := cUser_SYSUID; | |||
end else if (oParams.values['choice']='stop') then | |||
begin | |||
cSql := 'UPDATE zeiterfuser SET ze_zeit = ' + oParams.values['elapsedTime'] + | |||
', ze_endtime = ' + oParams.values['vergZeit'] + | |||
', ze_enddate = ' + oParams.values['stopTimeValue'] + | |||
', ze_pausezeit = ' + oParams.values['elapsedPauseTime'] + | |||
', ze_status = ' + oParams.values['status'] + | |||
' WHERE sys_uid = ' + DB_SQLVal(oParams.values['uid']); | |||
if DB_SQLExec(oDB,cSql) then | |||
begin | |||
result := 'Die Daten wurden erfolgreich gespeichert!'; | |||
end else begin | |||
result := 'Fehler!'; | |||
end; | |||
end else if (oParams.values['choice']='pause') then | |||
begin | |||
writeln('Pausezeit: ' + oParams.values['pauseTime']); | |||
cSql := 'UPDATE zeiterfuser SET ze_pausezeit ' + | |||
'= ze_pausezeit + ' + oParams.values['pauseTime'] + | |||
' WHERE sys_uid = ' + DB_SQLVal(oParams.values['sysuid']); | |||
if DB_SQLExec(oDB,cSql) then | |||
begin | |||
result := 'Die Daten wurden erfolgreich gespeichert!'; | |||
end else begin | |||
result := 'Fehler!'; | |||
end; | |||
end; | |||
end; | |||
</syntaxhighlight> |
Version vom 13. Oktober 2023, 08:52 Uhr
Endpuntk-Script
procedure _AddJob(oArr: TJSONArray; id: String);
var oWert : TJSONObject;
cSql : String;
A_Query : TxFQuery;
begin
cSql := 'SELECT CONCAT(za_text, ":",sys_uid) AS Job FROM zeiterfart ' +
'WHERE za_psnr = ' + DB_SQLVal(id) + ' AND za_inaktiv <> "1" ' +
'ORDER BY za_order';
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin
while (not A_Query.EoF) do begin
oArr.Add(A_Query.A2C('Job'));
A_Query.Next();
end;
end;
DB_Close(A_Query);
end;
procedure _AddCustomer(oArr: TJSONArray);
var oWert : TJSONObject;
cSql : String;
A_Query : TxFQuery;
begin
cSql :=' SELECT * FROM' +
' (SELECT' +
' ps_nr,' +
' ps_such AS Kunde,' +
' perssta.sys_uid AS ps_sys_uid,' +
' "PE" AS TYP' +
' FROM eigenschaften' +
' LEFT JOIN perssta ON se_ref1 AND perssta.sys_uid = se_ref2' +
' WHERE se_nr = 0087' +
' AND ps_nr <> 100000' +
' UNION SELECT p_nr AS ps_nr,' +
' p_name1 AS ps_such,' +
' projekte.sys_uid AS ps_sys_uid,' +
' "PR" AS TYP' +
' FROM eigenschaften' +
' LEFT JOIN projekte ON se_ref1 = p_nr' +
' AND projekte.sys_uid = se_ref2 WHERE se_nr = 0087)' +
' A WHERE ps_nr IS NOT NULL' +
' ORDER BY Kunde ';
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin
while (not A_Query.EoF) do begin
oArr.Add(A_Query.A2C('Kunde'));
A_Query.Next();
end;
end;
DB_Close(A_Query);
end;
procedure _AddID(kunde: String; oArr: TJSONArray);
var oWert : TJSONObject;
cSql : String;
A_Query : TxFQuery;
begin
cSql :=' SELECT * FROM' +
' (SELECT' +
' ps_nr,' +
' ps_such AS Kunde,' +
' perssta.sys_uid AS ps_sys_uid,' +
' "PE" AS TYP' +
' FROM eigenschaften' +
' LEFT JOIN perssta ON se_ref1 AND perssta.sys_uid = se_ref2' +
' WHERE se_nr = 0087' +
' AND ps_nr <> 100000' +
' UNION SELECT p_nr AS ps_nr,' +
' p_name1 AS ps_such,' +
' projekte.sys_uid AS ps_sys_uid,' +
' "PR" AS TYP' +
' FROM eigenschaften' +
' LEFT JOIN projekte ON se_ref1 = p_nr' +
' AND projekte.sys_uid = se_ref2 WHERE se_nr = 0087)' +
' A WHERE ps_nr IS NOT NULL' +
' AND Kunde = ' + DB_SQLVal(kunde) +
' ORDER BY Kunde ';
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin
while (not A_Query.EoF) do begin
oArr.Add(A_Query.A2C('ps_nr'));
A_Query.Next();
end;
end;
DB_Close(A_Query);
end;
procedure _AddCHECK(oArr: TJSONArray);
var oWert : TJSONObject;
cSql : String;
A_Query : TxFQuery;
begin
cSql := 'SELECT ze_starttime, zeiterfuser.sys_uid AS sysuid, zk_psnr, ' +
'za_text, ps_such, ze_startdate FROM ' +
'zeiterfuser LEFT JOIN zeiterfkomm ON ' +
'zk_messunguid = zeiterfuser.SYS_UID LEFT JOIN zeiterfart ' +
'ON zeiterfart.sys_uid = zeiterfuser.ze_uid AND ' +
'za_psnr = zeiterfkomm.zk_psnr LEFT JOIN perssta ON ' +
'ps_nr = zeiterfkomm.zk_psnr WHERE ze_status = 01 ';
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin
while (not A_Query.EoF) do begin
oArr.Add(A_Query.A2C('ze_starttime'));
oArr.Add(A_Query.A2C('zk_psnr'));
oArr.Add(A_Query.A2C('za_text'));
oArr.Add(A_Query.A2C('ps_such'));
oArr.Add(A_Query.A2C('sysuid'));
oArr.Add(A_Query.A2C('ze_startdate'));
A_Query.Next();
end;
end;
DB_Close(A_Query);
end;
procedure _getPauseTime(sysuid: String; oArr: TJSONArray);
var oWert : TJSONObject;
cSql : String;
A_Query : TxFQuery;
begin
cSql := 'SELECT * FROM zeiterfuser WHERE sys_uid = ' + DB_SQLVal(sysuid);
if (DB_xSOpen('Y009LHNBTY', oDB, cSql, A_Query, False)) then begin
while (not A_Query.EoF) do begin
oArr.Add(A_Query.A2C('ze_pausezeit'));
A_Query.Next();
end;
end;
DB_Close(A_Query);
end;
//----------------Funktionen----------------------------------//
function POST(oParams: TStrings): string;
var
oArr1 : TJSONArray;
cSql : String;
startTime : TDateTime;
elapsedTime : Integer;
millisec, seconds, minutes, hours : Word;
year, month, day : Word;
uhrzeit, datum : String;
begin
if (oParams.values['choice']='job') then begin
oArr1 := TJSONArray.Create();
_AddJob(oArr1, oParams.values['id']);
result := oArr1.ToJSON();
end else if (oParams.values['choice']='customer') then begin
oArr1 := TJSONArray.Create();
_AddCustomer(oArr1);
result := oArr1.ToJSON();
end else if (oParams.values['choice']='id') then begin
oArr1 := TJSONArray.Create();
_AddID(oParams.values['selectedKunde'], oArr1);
result := oArr1.ToJSON();
end else if (oParams.values['choice']='check') then begin
oArr1 := TJSONArray.Create();
_AddCHECK(oArr1);
result := oArr1.ToJSON();
end else if (oParams.values['choice']='pauseTime') then begin
oArr1 := TJSONArray.Create();
_GetPauseTime(oParams.values['sysuid'], oArr1);
result := oArr1.ToJSON();
end;
end;
function PUT(oParams: TStrings): string;
var
xZeit : TqSQL;
cUSER_SYSUID : String;
cKOMM_SYSUID : String;
lNew : Boolean;
cSql : String;
dDBNow : TDateTime;
begin
writeln('Choice: ' + oParams.values['choice']);
if (oParams.values['choice']='start') then
begin
dDBNow := DB_Now(oDB);
lNew := True;
if (empty(cUSER_SYSUID)) then begin
cUSER_SYSUID := GetNewId(oDB);
end;
xZeit := qSqlInit(oDB, 'zeiterfuser');
xZeit.lNoSysUID := True;
writeln('SYSUID: ' + oParams.values['jobID']);
xZeit.qSet('ze_user' , oParams.values['user']);
xZeit.qSet('ze_starttime' , oParams.values['uhrzeit']);
xZeit.qSet('ze_eigen' , '0101');
xZeit.qSet('ze_startdate' , oParams.values['datum']);
xZeit.qSet('ze_endtime' , oParams.values['endTime']);
xZeit.qSet('ze_enddate' , oParams.values['endDate']);
xZeit.qSet('ze_zeit' , '0');
xZeit.qSet('ze_pausezeit' , '0');
xZeit.qSet('ze_status' , oParams.values['status']);
xZeit.qSet('ze_berechnen' , 0);
xZeit.qSet('ze_officestar' , 0);
xZeit.qSet('ze_repa' , 0);
xZeit.qSet('ze_vorbereitung' , 0);
xZeit.qSet('ze_uid' , oParams.values['jobID']);
xZeit.qSet('sys_uid' , cUSER_SYSUID);
xZeit.SaveData(lNew);
qSQLFree(xZeit);
//---------------------------------------------------------------------
xZeit := qSqlInit(oDB,'ZEITERFKOMM');
xZeit.lNoSysUID := True;
if (empty(cKOMM_SYSUID)) then begin
cKOMM_SYSUID := GetNewId(oDB);
end;
xZeit.qSet('zk_psnr' , oParams.values['psnr']);
xZeit.qSet('zk_starttime' , oParams.values['uhrzeit']);
xZeit.qSet('zk_startdate' , oParams.values['datum']);
xZeit.qSet('zk_kommentar' , oParams.values['comm']);
xZeit.qSet('zk_messunguid' , cUSER_SYSUID);
xZeit.qSet('sys_uid' , cKOMM_SYSUID);
xZeit.SaveData(lNew);
qSQLFree(xZeit);
result := cUser_SYSUID;
end else if (oParams.values['choice']='stop') then
begin
cSql := 'UPDATE zeiterfuser SET ze_zeit = ' + oParams.values['elapsedTime'] +
', ze_endtime = ' + oParams.values['vergZeit'] +
', ze_enddate = ' + oParams.values['stopTimeValue'] +
', ze_pausezeit = ' + oParams.values['elapsedPauseTime'] +
', ze_status = ' + oParams.values['status'] +
' WHERE sys_uid = ' + DB_SQLVal(oParams.values['uid']);
if DB_SQLExec(oDB,cSql) then
begin
result := 'Die Daten wurden erfolgreich gespeichert!';
end else begin
result := 'Fehler!';
end;
end else if (oParams.values['choice']='pause') then
begin
writeln('Pausezeit: ' + oParams.values['pauseTime']);
cSql := 'UPDATE zeiterfuser SET ze_pausezeit ' +
'= ze_pausezeit + ' + oParams.values['pauseTime'] +
' WHERE sys_uid = ' + DB_SQLVal(oParams.values['sysuid']);
if DB_SQLExec(oDB,cSql) then
begin
result := 'Die Daten wurden erfolgreich gespeichert!';
end else begin
result := 'Fehler!';
end;
end;
end;