<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.14">
  <POU Name="FB_DeleteProductById" Id="{be1b9c17-9463-4c8f-9dea-186c112b6925}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_DeleteProductById
VAR_IN_OUT
	fbClient:FB_IotHttpClient;
END_VAR
VAR_OUTPUT
	bBusy:BOOL;
	bError:BOOL;
	
END_VAR
VAR
	fbRequest			: FB_IotHttpRequest;
	fbJsonSend			: FB_JsonDomParser;
	jsonDoc				: SJsonValue;
	nState				: UDINT;
	DeleteRisingEdge			: R_TRIG;
	fbGetProductByBarCode:FB_GetProductByBarCode;
	domParse:FB_JsonDomParser;
	sUri:STRING;
END_VAR

//HMI
VAR
	bSend:BOOL;
	nStatusCode:UINT;
	deleteProductId:DINT;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[DeleteRisingEdge(CLK:=bSend , Q=> );
CASE nState OF
	0:
		
		IF DeleteRisingEdge.Q AND deleteProductId<>0 THEN
			nStatusCode:=0;
			nState:=10;
			bBusy:=TRUE;
			bError:=FALSE;
		END_IF
	
		
	10:
		sUri:=CONCAT('/Product/',DINT_TO_STRING(deleteProductId));
		IF fbRequest.SendRequest(sUri:=sUri,fbClient:=fbClient,eRequestType:=ETcIotHttpRequestType.HTTP_DELETE,0,0,0) THEN
			nState:=20;
		END_IF
	20:
		IF NOT fbRequest.bBusy THEN
			nStatusCode:=fbRequest.nStatusCode;
			IF nStatusCode=200 THEN
				deleteProductId:=0;
			END_IF
			nState:=100;
		END_IF
		
	100:
		bBusy:=FALSE;
		nState:=0;
END_CASE]]></ST>
    </Implementation>
    <LineIds Name="FB_DeleteProductById">
      <LineId Id="32" Count="4" />
      <LineId Id="149" Count="0" />
      <LineId Id="37" Count="1" />
      <LineId Id="40" Count="1" />
      <LineId Id="54" Count="0" />
      <LineId Id="65" Count="1" />
      <LineId Id="76" Count="3" />
      <LineId Id="141" Count="1" />
      <LineId Id="147" Count="0" />
      <LineId Id="143" Count="0" />
      <LineId Id="145" Count="1" />
      <LineId Id="148" Count="0" />
      <LineId Id="144" Count="0" />
      <LineId Id="80" Count="0" />
      <LineId Id="82" Count="2" />
      <LineId Id="9" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>