Merge branch 'newMaster2024' of https://dev.azure.com/VeragAG/_git/SDL into newMaster2024

This commit is contained in:
2024-12-18 14:31:42 +01:00
4 changed files with 304 additions and 92 deletions

View File

@@ -1,102 +1,165 @@
Imports System.Text.RegularExpressions
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel
Imports Newtonsoft.Json
Imports VERAG_PROG_ALLGEMEIN.cATEZ_Tariff
Public Class cATEZ_Tariff
' Klasse zur Darstellung der Ergebnisse
Public Class cATEZ_TariffItem
Public Property Id As Integer
Public Property CommodityCode As String
Public Property Description As String
Public Property HeadingId As Integer
Public Property LanguageCode As String
Public Property Type As String
Private Shared apiKeyProd = "9a55eba363c2796364ddc1c3b9b126a8"
Private Shared apiKeyTest = "305f9e546067631848548b461765a3f8"
Private Shared username = "verag"
Private Shared baseUrlTest As String = "https://test-tariff.singlewindow.io/api/v2-0/tariff-query/commodity-codes/mappings"
Private Shared baseUrlProd As String = "https://test-tariff.singlewindow.io/api/v2-0/tariff-query/commodity-codes/mappings"
Public Class cATEZ_TariffItem_RootItem
Public Property code As String
Public Property mappings As List(Of cATEZ_TariffItem_Mapping)
Public Property [error] As String
End Class
Public Shared Function GetTariffInfo_SingleOrEmpty(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
If GetTariffInfo(searchText, countryCode, languageCode, measureType, result) = "OK" Then
If result.Count > 1 Then
Return ""
Public Class cATEZ_TariffItem_Mapping
Public Property commodity_code As String
Public Property description As String
End Class
Public Shared Function GetTariffInfo(commodities As List(Of String), fromCountry As String, Optional toCountry As String = "EU", Optional languageCode As String = "DE") As List(Of cATEZ_TariffItem_RootItem)
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
' Create an instance of the HTTP object
Dim http As New Chilkat.Http()
Dim baseUrl = ""
If True Then 'VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
' Set the headers
http.SetRequestHeader("x-api-key", apiKeyTest)
http.SetRequestHeader("x-username", username)
' Build the base URL
baseUrl = baseUrlTest
Else
Return result(0).CommodityCode
' Set the headers
http.SetRequestHeader("x-api-key", apiKeyProd)
http.SetRequestHeader("x-username", username)
' Build the base URL
baseUrl = baseUrlProd
End If
Else
Return ""
End If
End Function
Public Shared Function GetTariffInfo(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
' Manuell den Query-String erstellen
Dim queryParams As String = "?from=" & fromCountry &
"&to=" & toCountry &
"&language-code=" & languageCode &
"&commodites=" & String.Join(",", commodities)
If searchText = String.Empty Then Return "Error: Empty search String"
searchText = Regex.Replace(searchText, "[^\d]", "")
If searchText.Length > 8 Then searchText = searchText.Substring(0, 8)
' Kombiniere die Basis-URL mit den Query-Parametern
Dim url As String = baseUrl & queryParams
' Chilkat HTTP-Objekt erstellen
Dim http As New Chilkat.Http()
' Führe die GET-Anfrage aus
Dim response As String = http.QuickGetStr(url)
' API-URL und Parameter definieren
Dim baseUrl As String = "https://tariff.singlewindow.io/api/v2-0/tariff-query/public/commodity-codes"
'Dim countryCode As String = "DE"
'Dim languageCode As String = "DE"
'Dim measureType As String = "import"
' Anfrage-URL mit Parametern erstellen
Dim url As String = $"{baseUrl}?countryCode={countryCode}&searchText={searchText}&languageCode={languageCode}&measureType={measureType}"
' HTTP-GET-Anfrage senden
Dim response As String = http.QuickGetStr(url)
' Fehlerüberprüfung
If http.LastMethodSuccess = False Then
Return $"Error: {http.LastErrorText}"
End If
' Statuscode überprüfen
Dim statusCode As Integer = http.LastStatus
If statusCode <> 200 Then
Return $"Error: HTTP Status {statusCode}"
End If
result = ProcessApiResponse(response)
' Antwort zurückgeben
If result.Count = 0 Then
Return "Error: 0 results"
End If
Return "OK"
End Function
Private Shared Function ProcessApiResponse(jsonResponse As String) As List(Of cATEZ_TariffItem)
' Deserialisiere die JSON-Antwort in eine Liste von Objekten
Dim items As List(Of Dictionary(Of String, Object)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, Object)))(jsonResponse)
' Liste für deklarierbare Elemente erstellen
Dim declarableItems As New List(Of cATEZ_TariffItem)()
' Ergebnisse durchlaufen
For Each item As Dictionary(Of String, Object) In items
If item.ContainsKey("declarable") AndAlso CBool(item("declarable")) = True Then
Dim tariffItem As New cATEZ_TariffItem() With {
.Id = CInt(item("id")),
.CommodityCode = item("commodity_code").ToString(),
.Description = item("description").ToString(),
.HeadingId = CInt(item("heading_id")),
.LanguageCode = item("language_code").ToString(),
.Type = item("type").ToString()
}
declarableItems.Add(tariffItem)
' Prüfe auf Fehler
If http.LastMethodSuccess = False Then
Throw New Exception("HTTP Request failed: " & http.LastErrorText)
End If
Next
Return declarableItems
' Return the response
Return ConvertJsonToClass(response.ToString)
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
Return Nothing
End Function
Sub Example()
' Beispielaufruf der Funktion
Dim searchText As String = "6207220000"
Dim result As String = GetTariffInfo(searchText)
Private Shared Function ConvertJsonToClass(response As String) As List(Of cATEZ_TariffItem_RootItem)
Try
' Deserialisiere den JSON-String in eine Liste von RootItem-Objekten
Dim result As List(Of cATEZ_TariffItem_RootItem) = JsonConvert.DeserializeObject(Of List(Of cATEZ_TariffItem_RootItem))(response)
Return result
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
Throw New Exception("Fehler bei der JSON-Konvertierung: " & ex.Message)
End Try
End Function
' Ergebnis ausgeben
Console.WriteLine(result)
End Sub
'Private Shared Function ProcessApiResponse(jsonResponse As String) As List(Of CommodityMappingData)
' Try
' Dim result As List(Of RootItem) = JsonConvert.DeserializeObject(Of List(Of RootItem))(response)
' Dim response As List(Of RootItem) = GetCommodityMappings(apiKey, username, fromCountry, toCountry, languageCode, commodities)
' ' Verarbeite und zeige die Antwort an
' For Each item In response
' Console.WriteLine("Code: " & item.code)
' If item.mappings IsNot Nothing Then
' For Each mapping In item.mappings
' Console.WriteLine(" Commodity Code: " & mapping.commodity_code)
' Console.WriteLine(" Description: " & mapping.description)
' Next
' End If
' If Not String.IsNullOrEmpty(item.error) Then
' Console.WriteLine(" Error: " & item.error)
' End If
' Next
' Catch ex As Exception
' Console.WriteLine("Fehler: " & ex.Message)
' End Try
' Try
' '' Example usage
' 'Dim apiKey As String = "305f9e546067631848548b461765a3f8"
' 'Dim username As String = "verag"
' 'Dim fromCountry As String = "TR"
' 'Dim toCountry As String = "EU"
' 'Dim languageCode As String = "DE"
' 'Dim commodities As New List(Of String) From {
' ' "010121000000",
' ' "010129100000",
' ' "010229290000",
' ' "abcd",
' ' "efgg",
' ' "0123",
' ' "123456789012",
' ' "3926909790"
' '}
' Dim items As List(Of Dictionary(Of String, Object)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, Object)))(jsonResponse)
' ' Liste für deklarierbare Elemente erstellen
' Dim declarableItems As New List(Of CommodityMappingData)()
' ' Ergebnisse durchlaufen
' For Each item As Dictionary(Of String, Object) In items
' Dim tariffItem As New CommodityMappingData() With {
' .CommodityCode = item("CommodityCode").ToString(),
' .MappedCode = item("MappedCode").ToString(),
' .Description = item(item("Description")),
' .AdditionalInfo = item("AdditionalInfo").ToString()
' }
' declarableItems.Add(tariffItem)
' Next
' Return declarableItems
' Catch ex As Exception
' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
' Console.WriteLine("Error: " & ex.Message)
' End Try
' Return Nothing
'End Function
End Class

View File

@@ -0,0 +1,102 @@
Imports System.Text.RegularExpressions
Imports Newtonsoft.Json
Public Class cATEZ_Tariff_simple
' Klasse zur Darstellung der Ergebnisse
Public Class cATEZ_TariffItem
Public Property Id As Integer
Public Property CommodityCode As String
Public Property Description As String
Public Property HeadingId As Integer
Public Property LanguageCode As String
Public Property Type As String
End Class
Public Shared Function GetTariffInfo_SingleOrEmpty(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
If GetTariffInfo(searchText, countryCode, languageCode, measureType, result) = "OK" Then
If result.Count > 1 Then
Return ""
Else
Return result(0).CommodityCode
End If
Else
Return ""
End If
End Function
Public Shared Function GetTariffInfo(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
If searchText = String.Empty Then Return "Error: Empty search String"
searchText = Regex.Replace(searchText, "[^\d]", "")
If searchText.Length > 8 Then searchText = searchText.Substring(0, 8)
' Chilkat HTTP-Objekt erstellen
Dim http As New Chilkat.Http()
' API-URL und Parameter definieren
Dim baseUrl As String = "https://tariff.singlewindow.io/api/v2-0/tariff-query/public/commodity-codes"
'Dim countryCode As String = "DE"
'Dim languageCode As String = "DE"
'Dim measureType As String = "import"
' Anfrage-URL mit Parametern erstellen
Dim url As String = $"{baseUrl}?countryCode={countryCode}&searchText={searchText}&languageCode={languageCode}&measureType={measureType}"
' HTTP-GET-Anfrage senden
Dim response As String = http.QuickGetStr(url)
' Fehlerüberprüfung
If http.LastMethodSuccess = False Then
Return $"Error: {http.LastErrorText}"
End If
' Statuscode überprüfen
Dim statusCode As Integer = http.LastStatus
If statusCode <> 200 Then
Return $"Error: HTTP Status {statusCode}"
End If
result = ProcessApiResponse(response)
' Antwort zurückgeben
If result.Count = 0 Then
Return "Error: 0 results"
End If
Return "OK"
End Function
Private Shared Function ProcessApiResponse(jsonResponse As String) As List(Of cATEZ_TariffItem)
' Deserialisiere die JSON-Antwort in eine Liste von Objekten
Dim items As List(Of Dictionary(Of String, Object)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, Object)))(jsonResponse)
' Liste für deklarierbare Elemente erstellen
Dim declarableItems As New List(Of cATEZ_TariffItem)()
' Ergebnisse durchlaufen
For Each item As Dictionary(Of String, Object) In items
If item.ContainsKey("declarable") AndAlso CBool(item("declarable")) = True Then
Dim tariffItem As New cATEZ_TariffItem() With {
.Id = CInt(item("id")),
.CommodityCode = item("commodity_code").ToString(),
.Description = item("description").ToString(),
.HeadingId = CInt(item("heading_id")),
.LanguageCode = item("language_code").ToString(),
.Type = item("type").ToString()
}
declarableItems.Add(tariffItem)
End If
Next
Return declarableItems
End Function
Sub Example()
' Beispielaufruf der Funktion
Dim searchText As String = "6207220000"
Dim result As String = GetTariffInfo(searchText)
' Ergebnis ausgeben
Console.WriteLine(result)
End Sub
End Class

View File

@@ -420,6 +420,7 @@
<Compile Include="Schnittstellen\ATEZ\NCTS_API\NCTS-P5\CC015C.Designer.vb" />
<Compile Include="Schnittstellen\ATEZ\NCTS_API\NCTS-P5\cNCTS_FREMD.vb" />
<Compile Include="Schnittstellen\ATEZ\TARIFF\cATEZ_Tariff.vb" />
<Compile Include="Schnittstellen\ATEZ\TARIFF\cATEZ_Tariff_simple.vb" />
<Compile Include="Schnittstellen\CBAM\QReport_v17.00.Designer.vb" />
<Compile Include="Schnittstellen\cTariffKN8.vb" />
<Compile Include="Schnittstellen\Digicast\cDigicustAPI.vb" />