{"id":30000,"date":"2023-03-14T10:02:43","date_gmt":"2023-03-14T09:02:43","guid":{"rendered":"https:\/\/help.qualiware.it\/qw-help\/?p=30000"},"modified":"2023-03-14T10:02:43","modified_gmt":"2023-03-14T09:02:43","slug":"action-link-per-laggiunta-di-articoli-in-anagrafica","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/action-link-per-laggiunta-di-articoli-in-anagrafica\/","title":{"rendered":"Action link per l&#8217;aggiunta di articoli in anagrafica"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\">' Action link per l'aggiunta di articoli in anagrafica\r\n' Lo snippet segue il seguente JSON di esempio\r\n'\r\n'{\r\n'  \"Token\": \"ec161f8b-ba19-4dac-aab0-2ee16ab94391\",\r\n'  \"Articoli\": [\r\n'\t{\r\n'\t  \"ID\": \"ACITAR\",\r\n'\t  \"Descrizione\": \"ACIDO TARTARICO\",\r\n'\t  \"Tipo\": \"ENO\",\r\n'\t  \"StatoFisico\": \"Confezionato\",\r\n'\t  \"CatMIPAAF\": \"107\",\r\n'\t  \"Formato\": 0,\r\n'\t  \"UM\": \"Kg\",\r\n'\t  \"Categoria\": \"\",\r\n'\t  \"Vendibile\": false,\r\n'\t  \"IDComm\": \"\",\r\n'\t  \"IDCED\": \"\",\r\n'\t  \"EANBottiglia\": \"\",\r\n'\t  \"EANCartone\": \"\",\r\n'\t  \"Inattivo\": false,\r\n'\t  \"GestLotti\": true,\r\n'\t  \"Esistenza\": 0,\r\n'\t  \"Disponibilita\": 0\r\n'\t}\r\n'  ]\r\n'}\r\n\r\n\r\nDim nomeActionLink As String = \"Action Link ARTICOLI\"\r\n\r\nDim OK As Boolean = True\r\nDim esito As String = \"\"\r\nDim erroreRequest As String = \"\"\r\nDim errcode As Integer\r\nDim jsonr As String\r\nDim res As New Newtonsoft.Json.Linq.JObject\r\n\r\nTry\r\n  'OTTENGO LA RICHIESTA IN JSON\r\n  Page.Request.InputStream.Seek(0, System.IO.SeekOrigin.Begin)\r\n\r\n  Using ReceiveStream As System.IO.Stream = Page.Request.InputStream\r\n    Using ReadStream As System.IO.StreamReader = New System.IO.StreamReader(ReceiveStream, System.Text.Encoding.UTF8)\r\n      jsonr = ReadStream.ReadToEnd()\r\n    End Using\r\n  End Using\r\n\r\n  Dim objtmp As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(jsonr)\r\n\r\n  Dim token As String = CType(objtmp(\"Token\"), Newtonsoft.Json.Linq.JValue).Value\r\n\r\n  Dim tokenIsValid As Boolean = qwlib.WebUtils.CheckToken2(token)\r\n\r\n  If tokenIsValid Then\r\n    ' copia il json in una directory locale\r\n    Dim path As String = \"C:\\dati\\Json\\Articoli.json\"\r\n\r\n    Dim writer As New System.IO.StreamWriter(path)\r\n\r\n    writer.WriteLine(\"\" &amp; jsonr)\r\n    writer.Close()\r\n\r\n    '------------------------------------------------------------------------------------------------------------------'\r\n    Dim parsedJson As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(jsonr)\r\n\r\n    Dim artic As New QWTable\r\n\r\n    artic.DataBase = DB\r\n\r\n    If Not parsedJson.SelectToken(\"Articoli\") Is Nothing Then\r\n      For i As Integer = 0 To parsedJson.SelectToken(\"Articoli\").Count - 1\r\n        Dim erroreSalvataggio As String = \"\"\r\n\r\n        artic.SQL = \"select * \"\r\n        artic.SQL += \"from ARTIC \"\r\n        artic.SQL += \"where CODICE = \" &amp; Chr(39) &amp; parsedJson.SelectToken(\"Articoli[\" &amp; i &amp; \"].ID\").ToString &amp; Chr(39)\r\n        artic.Active = True\r\n\r\n        'SE NON ESISTE UN RECORD CON QUEL CODICE ARTICOLO, NE CREO UNO NUOVO\r\n        If Not artic.RowSet.First() Then\r\n          artic.BeginAppend()\r\n\r\n          artic.Replace(\"CODICE\", SqlStr(parsedJson.SelectToken(\"Articoli[\" &amp; i &amp; \"].ID\").ToString))\r\n          artic.Replace(\"UNMIS\", SqlStr(parsedJson.SelectToken(\"Articoli[\" &amp; i &amp; \"].UM\").ToString))\r\n        End If\r\n\r\n        'SALVO LE INFORMAZIONI DEL JSON NELLE VARIE COLONNE DI ARTIC\r\n        artic.Replace(\"DESCRIZION\", SqlStr(parsedJson.SelectToken(\"Articoli[\" &amp; i &amp; \"].Descrizione\").ToString))\r\n\r\n        OK = artic.SaveRecord(erroreSalvataggio)\r\n\r\n        If Not OK Then\r\n          esito += erroreSalvataggio &amp; vbCrLf\r\n          WriteLog(nomeActionLink &amp; vbCrLf &amp; erroreSalvataggio)\r\n        End If\r\n\r\n        artic.Active = False\r\n      Next\r\n    Else\r\n      esito += \"Non ci sono Articoli !\" &amp; vbCrLf\r\n      WriteLog(nomeActionLink &amp; vbCrLf &amp; esito)\r\n    End If\r\n\r\n    artic.Dispose()\r\n    '-----------------------------------------------------------------------------------------------------------'\r\n  Else\r\n    errcode = 1\r\n    esito += \"Token non valido !\" &amp; vbCrLf\r\n  End If\r\n\r\n  If Not String.IsNullOrEmpty(esito) Then\r\n    OK = False\r\n  End If\r\nCatch e As Exception\r\n  OK = False\r\n  errcode = -1\r\n  erroreRequest = e.Message &amp; vbCrLf &amp; e.StackTrace\r\n  WriteLog(nomeActionLink &amp; vbCrLf &amp; erroreRequest)\r\nEnd Try\r\n\r\nDim ret_obj = New With {.ResultCode = errcode, .Result = IIf(OK, \"OK\", \"KO\"), .ErrResult = esito &amp; vbCrLf &amp; vbCrLf &amp; erroreRequest}\r\n\r\nReturn Newtonsoft.Json.JsonConvert.SerializeObject(ret_obj)<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Action link per l&#8217;aggiunta di articoli in anagrafica &#8216; Lo snippet segue il seguente JSON di esempio &#8216; &#8216;{ &#8216; &#8220;Token&#8221;: &#8220;ec161f8b-ba19-4dac-aab0-2ee16ab94391&#8221;, &#8216; &#8220;Articoli&#8221;: [ &#8216; { &#8216; &#8220;ID&#8221;: &#8220;ACITAR&#8221;, &#8216; &#8220;Descrizione&#8221;: &#8220;ACIDO TARTARICO&#8221;, &#8216; &#8220;Tipo&#8221;: &#8220;ENO&#8221;, &#8216; &#8220;StatoFisico&#8221;: &#8220;Confezionato&#8221;, &#8216; &#8220;CatMIPAAF&#8221;: &#8220;107&#8221;, &#8216; &#8220;Formato&#8221;: 0, &#8216; &#8220;UM&#8221;: &#8220;Kg&#8221;, &#8216; &#8220;Categoria&#8221;: &#8220;&#8221;, &#8216; &#8220;Vendibile&#8221;:&hellip;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[263],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/30000"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=30000"}],"version-history":[{"count":1,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/30000\/revisions"}],"predecessor-version":[{"id":30001,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/30000\/revisions\/30001"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=30000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=30000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=30000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}