This commit is contained in:
2025-12-23 11:09:44 +01:00
parent 31f391b4f9
commit 33621096c1
3 changed files with 270 additions and 172 deletions

View File

@@ -68,18 +68,18 @@ Partial Class usrCntlCBAM
Me.Button3 = New System.Windows.Forms.Button()
Me.lblKafkaCnt = New System.Windows.Forms.Label()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Label7 = New System.Windows.Forms.Label()
Me.Label8 = New System.Windows.Forms.Label()
Me.Label9 = New System.Windows.Forms.Label()
Me.Label10 = New System.Windows.Forms.Label()
Me.Label11 = New System.Windows.Forms.Label()
Me.Button4 = New System.Windows.Forms.Button()
Me.txtCalcLand = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.txtCalcErg = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.txtCalcJahr = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Label11 = New System.Windows.Forms.Label()
Me.txtCalcEmission = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Label10 = New System.Windows.Forms.Label()
Me.Label9 = New System.Windows.Forms.Label()
Me.txtCalcGewicht = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Label8 = New System.Windows.Forms.Label()
Me.txtCalcKN8 = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Label7 = New System.Windows.Forms.Label()
Me.MyPanel1 = New VERAG_PROG_ALLGEMEIN.MyPanel(Me.components)
Me.cbxUNISPED = New System.Windows.Forms.CheckBox()
Me.cbxIMEX = New System.Windows.Forms.CheckBox()
@@ -89,6 +89,8 @@ Partial Class usrCntlCBAM
Me.txtVon = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.txtBis = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.txtEori = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.txtBenchmark = New VERAG_PROG_ALLGEMEIN.MyTextBox()
Me.Label12 = New System.Windows.Forms.Label()
Me.cntxtAddSdl.SuspendLayout()
Me.Panel1.SuspendLayout()
Me.MyPanel1.SuspendLayout()
@@ -610,6 +612,8 @@ Partial Class usrCntlCBAM
'
Me.Panel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Panel1.BackColor = System.Drawing.Color.FloralWhite
Me.Panel1.Controls.Add(Me.txtBenchmark)
Me.Panel1.Controls.Add(Me.Label12)
Me.Panel1.Controls.Add(Me.txtCalcLand)
Me.Panel1.Controls.Add(Me.txtCalcErg)
Me.Panel1.Controls.Add(Me.Button4)
@@ -622,67 +626,11 @@ Partial Class usrCntlCBAM
Me.Panel1.Controls.Add(Me.Label8)
Me.Panel1.Controls.Add(Me.txtCalcKN8)
Me.Panel1.Controls.Add(Me.Label7)
Me.Panel1.Location = New System.Drawing.Point(818, 317)
Me.Panel1.Location = New System.Drawing.Point(818, 301)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(223, 315)
Me.Panel1.Size = New System.Drawing.Size(223, 331)
Me.Panel1.TabIndex = 52
'
'Label7
'
Me.Label7.AutoSize = True
Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label7.Location = New System.Drawing.Point(3, 3)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(84, 13)
Me.Label7.TabIndex = 53
Me.Label7.Text = "CBAM-Rechner:"
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(3, 25)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(59, 13)
Me.Label8.TabIndex = 55
Me.Label8.Text = "Tarif (8 St.)"
'
'Label9
'
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(3, 45)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(64, 13)
Me.Label9.TabIndex = 57
Me.Label9.Text = "Gewicht(to):"
'
'Label10
'
Me.Label10.AutoSize = True
Me.Label10.Location = New System.Drawing.Point(3, 65)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(67, 13)
Me.Label10.TabIndex = 59
Me.Label10.Text = "(Emis.CO2/t)"
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Location = New System.Drawing.Point(3, 85)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(68, 13)
Me.Label11.TabIndex = 61
Me.Label11.Text = "(Jahr)/(Land)"
'
'Button4
'
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button4.Location = New System.Drawing.Point(3, 106)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(217, 28)
Me.Button4.TabIndex = 53
Me.Button4.Text = "Berechnen"
Me.Button4.UseVisualStyleBackColor = True
'
'txtCalcLand
'
Me.txtCalcLand._DateTimeOnly = False
@@ -699,7 +647,7 @@ Partial Class usrCntlCBAM
Me.txtCalcLand._WaehrungZeichen = True
Me.txtCalcLand.Enabled = False
Me.txtCalcLand.ForeColor = System.Drawing.Color.Black
Me.txtCalcLand.Location = New System.Drawing.Point(149, 82)
Me.txtCalcLand.Location = New System.Drawing.Point(149, 101)
Me.txtCalcLand.MaxLength = 2
Me.txtCalcLand.MaxLineLength = -1
Me.txtCalcLand.MaxLines_Warning = ""
@@ -727,7 +675,7 @@ Partial Class usrCntlCBAM
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtCalcErg.BackColor = System.Drawing.Color.FloralWhite
Me.txtCalcErg.ForeColor = System.Drawing.Color.Black
Me.txtCalcErg.Location = New System.Drawing.Point(6, 134)
Me.txtCalcErg.Location = New System.Drawing.Point(3, 154)
Me.txtCalcErg.MaxLength = 3000
Me.txtCalcErg.MaxLineLength = -1
Me.txtCalcErg.MaxLines_Warning = ""
@@ -735,9 +683,19 @@ Partial Class usrCntlCBAM
Me.txtCalcErg.Multiline = True
Me.txtCalcErg.Name = "txtCalcErg"
Me.txtCalcErg.ReadOnly = True
Me.txtCalcErg.Size = New System.Drawing.Size(214, 181)
Me.txtCalcErg.Size = New System.Drawing.Size(217, 177)
Me.txtCalcErg.TabIndex = 64
'
'Button4
'
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button4.Location = New System.Drawing.Point(3, 126)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(217, 28)
Me.Button4.TabIndex = 53
Me.Button4.Text = "Berechnen"
Me.Button4.UseVisualStyleBackColor = True
'
'txtCalcJahr
'
Me.txtCalcJahr._DateTimeOnly = False
@@ -753,7 +711,7 @@ Partial Class usrCntlCBAM
Me.txtCalcJahr._Waehrung = False
Me.txtCalcJahr._WaehrungZeichen = True
Me.txtCalcJahr.ForeColor = System.Drawing.Color.Black
Me.txtCalcJahr.Location = New System.Drawing.Point(73, 82)
Me.txtCalcJahr.Location = New System.Drawing.Point(73, 101)
Me.txtCalcJahr.MaxLength = 4
Me.txtCalcJahr.MaxLineLength = -1
Me.txtCalcJahr.MaxLines_Warning = ""
@@ -762,6 +720,15 @@ Partial Class usrCntlCBAM
Me.txtCalcJahr.Size = New System.Drawing.Size(70, 20)
Me.txtCalcJahr.TabIndex = 60
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Location = New System.Drawing.Point(3, 104)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(68, 13)
Me.Label11.TabIndex = 61
Me.Label11.Text = "(Jahr)/(Land)"
'
'txtCalcEmission
'
Me.txtCalcEmission._DateTimeOnly = False
@@ -786,6 +753,24 @@ Partial Class usrCntlCBAM
Me.txtCalcEmission.Size = New System.Drawing.Size(147, 20)
Me.txtCalcEmission.TabIndex = 58
'
'Label10
'
Me.Label10.AutoSize = True
Me.Label10.Location = New System.Drawing.Point(3, 65)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(67, 13)
Me.Label10.TabIndex = 59
Me.Label10.Text = "(Emis.CO2/t)"
'
'Label9
'
Me.Label9.AutoSize = True
Me.Label9.Location = New System.Drawing.Point(3, 45)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(64, 13)
Me.Label9.TabIndex = 57
Me.Label9.Text = "Gewicht(to):"
'
'txtCalcGewicht
'
Me.txtCalcGewicht._DateTimeOnly = False
@@ -810,6 +795,15 @@ Partial Class usrCntlCBAM
Me.txtCalcGewicht.Size = New System.Drawing.Size(147, 20)
Me.txtCalcGewicht.TabIndex = 56
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Location = New System.Drawing.Point(3, 25)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(59, 13)
Me.Label8.TabIndex = 55
Me.Label8.Text = "Tarif (8 St.)"
'
'txtCalcKN8
'
Me.txtCalcKN8._DateTimeOnly = False
@@ -834,6 +828,16 @@ Partial Class usrCntlCBAM
Me.txtCalcKN8.Size = New System.Drawing.Size(147, 20)
Me.txtCalcKN8.TabIndex = 54
'
'Label7
'
Me.Label7.AutoSize = True
Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label7.Location = New System.Drawing.Point(3, 3)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(84, 13)
Me.Label7.TabIndex = 53
Me.Label7.Text = "CBAM-Rechner:"
'
'MyPanel1
'
Me.MyPanel1.Controls.Add(Me.cbxUNISPED)
@@ -978,6 +982,39 @@ Partial Class usrCntlCBAM
Me.txtEori.Size = New System.Drawing.Size(341, 20)
Me.txtEori.TabIndex = 1
'
'txtBenchmark
'
Me.txtBenchmark._DateTimeOnly = False
Me.txtBenchmark._numbersOnly = True
Me.txtBenchmark._numbersOnlyKommastellen = ""
Me.txtBenchmark._numbersOnlyTrennzeichen = True
Me.txtBenchmark._Prozent = False
Me.txtBenchmark._ShortDateNew = False
Me.txtBenchmark._ShortDateOnly = False
Me.txtBenchmark._TimeOnly = False
Me.txtBenchmark._TimeOnly_Seconds = False
Me.txtBenchmark._value = ""
Me.txtBenchmark._Waehrung = False
Me.txtBenchmark._WaehrungZeichen = True
Me.txtBenchmark.ForeColor = System.Drawing.Color.Black
Me.txtBenchmark.Location = New System.Drawing.Point(73, 82)
Me.txtBenchmark.MaxLength = 10
Me.txtBenchmark.MaxLineLength = -1
Me.txtBenchmark.MaxLines_Warning = ""
Me.txtBenchmark.MaxLines_Warning_Label = Nothing
Me.txtBenchmark.Name = "txtBenchmark"
Me.txtBenchmark.Size = New System.Drawing.Size(147, 20)
Me.txtBenchmark.TabIndex = 66
'
'Label12
'
Me.Label12.AutoSize = True
Me.Label12.Location = New System.Drawing.Point(3, 85)
Me.Label12.Name = "Label12"
Me.Label12.Size = New System.Drawing.Size(67, 13)
Me.Label12.TabIndex = 67
Me.Label12.Text = "(Benchmark)"
'
'usrCntlCBAM
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
@@ -1110,4 +1147,6 @@ Partial Class usrCntlCBAM
Friend WithEvents txtCalcJahr As VERAG_PROG_ALLGEMEIN.MyTextBox
Friend WithEvents Label11 As Label
Friend WithEvents txtCalcLand As VERAG_PROG_ALLGEMEIN.MyTextBox
Friend WithEvents txtBenchmark As VERAG_PROG_ALLGEMEIN.MyTextBox
Friend WithEvents Label12 As Label
End Class

View File

@@ -365,7 +365,7 @@ Public Class usrCntlCBAM
Private Sub usrCntlCBAM_Load(sender As Object, e As EventArgs) Handles Me.Load
txtJahr.Text = Now.Year
txtCalcJahr.Text = Now.Year
txtCalcLand.Enabled = True
If Now.Month < 3 Then
txtJahr.Text = Now.Year - 1
cboQuartal.Text = "Q4"
@@ -2030,7 +2030,6 @@ Public Class usrCntlCBAM
End Function
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
txtCalcErg.Text = cATEZ_Greenpulse_CBAM_CostCalculation.calcCBAM(txtCalcKN8._value, txtCalcGewicht._value, txtCalcEmission._value, txtCalcJahr._value, txtCalcLand._value)
txtCalcErg.Text = cATEZ_Greenpulse_CBAM_CostCalculation.calcCBAM(txtCalcKN8._value, txtCalcGewicht._value, txtCalcLand._value, txtCalcEmission._value, txtCalcJahr._value, txtBenchmark._value)
End Sub
End Class

View File

@@ -1,15 +1,7 @@
' ============================================================================
' GreenPulse CBAM Carbon Cost API
' Single-file VB.NET implementation using Chilkat
' --------------------------------------------------------------------------
' Contains:
' - cATEZ_Greenpulse_CBAM_CostCalculation (main API class)
' - Request / Response DTO classes
' - Error handling & JSON parsing
'
' Requirements:
' - Chilkat.Http
' - Chilkat.JsonObject
' Adapted to latest Postman Collection (country_code, benchmark_value)
' ============================================================================
Imports Chilkat
@@ -21,45 +13,66 @@ Imports System.Globalization
Public Class cATEZ_Greenpulse_CBAM_CostCalculation
Private ReadOnly _baseUrl As String = "https://test-greenpulse-api.singlewindow.io/api/v1-0/public"
' Private ReadOnly _baseUrl As String = "https://greenpulse-api.singlewindow.io/api/v1-0/public"
'Private ReadOnly _baseUrl As String = "https://greenpulse-api.singlewindow.io/api/v1-0/public"
Private ReadOnly _http As Http
Public Sub New()
'_baseUrl = baseUrl.TrimEnd("/"c)
_http = New Http()
_http.SetRequestHeader("Content-Type", "application/json")
End Sub
' ------------------------------------------------------------------------
' GET /carbon-cost/cn-codes
' Returns raw JSON (ideal for dropdowns / caching)
' ------------------------------------------------------------------------
Public Function GetCnCodesRaw() As String
Dim url As String = _baseUrl & "/carbon-cost/cn-codes"
Public Function GetCnCodes() As cCBAM_CnCode_Response
Dim url As String = _baseUrl & "/carbon-cost/cn-codes"
Dim resp As HttpResponse = _http.QuickGetObj(url)
If resp Is Nothing Then
Throw New Exception(_http.LastErrorText)
End If
Return resp.BodyStr
Dim json As New JsonObject()
json.Load(resp.BodyStr)
Dim result As New cCBAM_CnCode_Response With {
.success = json.BoolOf("success")
}
If result.success Then
result.data = New List(Of cCBAM_CnCode)
Dim arr = json.ArrayOf("data")
For i As Integer = 0 To arr.Size - 1
Dim o = arr.ObjectAt(i)
result.data.Add(New cCBAM_CnCode With {
.cn_code = o.StringOf("cn_code"),
.cn_description = o.StringOf("cn_description")
})
Next
Else
Dim e = json.ObjectOf("error")
result.error = New cCBAM_Error With {
.code = e.StringOf("code"),
.message = e.StringOf("message"),
.statusCode = e.IntOf("statusCode")
}
End If
Return result
End Function
' ------------------------------------------------------------------------
' POST /carbon-cost/calculate
' ------------------------------------------------------------------------
Public Function CalculateCost(req As cCBAM_CostCalculation_Request) As cCBAM_CostCalculation_Response
Public Function CalculateCost(req As cCBAM_CostCalculation_Request) _
As cCBAM_CostCalculation_Response
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim url As String = _baseUrl & "/carbon-cost/calculate"
Dim resp As HttpResponse = _http.PostJson2(
url,
"application/json",
req.ToJson()
)
Dim resp As HttpResponse = _http.PostJson2(url, "application/json", req.ToJson())
If resp Is Nothing Then
Throw New Exception(_http.LastErrorText)
@@ -77,8 +90,9 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
Dim json As New JsonObject()
json.Load(jsonStr)
Dim result As New cCBAM_CostCalculation_Response()
result.success = json.BoolOf("success")
Dim result As New cCBAM_CostCalculation_Response With {
.success = json.BoolOf("success")
}
If result.success Then
Dim d = json.ObjectOf("data")
@@ -114,109 +128,140 @@ Public Class cATEZ_Greenpulse_CBAM_CostCalculation
End Function
' ------------------------------------------------------------------------
' Robust numeric parsing across Chilkat versions:
' Many Chilkat builds don't expose DoubleOf/NumberOf in the .NET wrapper.
' Any JSON value (incl. numbers) can be read via StringOf and converted.
' Robust Decimal Parsing (Chilkat-safe)
' ------------------------------------------------------------------------
Private Shared Function GetDec(obj As JsonObject, name As String) As Decimal
Dim s As String = obj.StringOf(name)
If String.IsNullOrWhiteSpace(s) Then Return 0D
' Ensure dot decimal separator
s = s.Trim().Replace(",", ".")
s = s.Replace(",", ".")
Dim v As Decimal
If Decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, v) Then
Return v
End If
' Fallback: try current culture (last resort)
If Decimal.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, v) Then
Return v
End If
If Decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, v) Then Return v
Return 0D
End Function
Shared Function calcCBAM(cn_code, weight, Optional see_total = "", Optional year = "", Optional country = "") As String
' ------------------------------------------------------------------------
' Convenience Wrapper für einfache CBAM-Kalkulation
' ------------------------------------------------------------------------
Public Shared Function calcCBAM(
cn_code As String,
weight As Object,
country_code As String,
Optional see_total As Object = Nothing,
Optional year As Object = Nothing,
Optional benchmark_value As Object = Nothing
) As String
If cn_code = "" Or Not IsNumeric(cn_code) Then
Return "Fehler: ungültiger CN-Code"
End If
If weight = "" Or Not IsNumeric(weight) Then
Return "Fehler: ungültiges Gewicht"
End If
If see_total <> "" AndAlso Not IsNumeric(see_total) Then
Return "Fehler: ungültige echten Emissionen"
End If
If year <> "" AndAlso Not IsNumeric(year) Then
If Not IsNumeric(year) Then Return "Fehler: ungültiges Phase-in Jahr"
If year.length <> 4 Then Return "Fehler: ungültiges Phase-in Jahr"
End If
If country <> "" AndAlso country.length > 2 Then
' Derzeit nicht unterstützt
Return "Fehler: Land wird derzeit nicht unterstützt"
End If
' ------------------------------------------------------------
' 1) API initialisieren
' Validierung (grundlegend, API macht Rest)
' ------------------------------------------------------------
If String.IsNullOrWhiteSpace(cn_code) OrElse cn_code.Length <> 8 OrElse Not IsNumeric(cn_code) Then
Return "Fehler: ungültiger CN-Code (muss 8-stellig numerisch sein)"
End If
If weight Is Nothing OrElse Not IsNumeric(weight) OrElse CDbl(weight) <= 0 Then
Return "Fehler: ungültiges Gewicht (muss > 0 sein)"
End If
If String.IsNullOrWhiteSpace(country_code) OrElse country_code.Length <> 2 Then
Return "Fehler: country_code muss ein ISO-2 Code sein (z.B. TR)"
End If
If see_total <> "" And (see_total IsNot Nothing AndAlso Not IsNumeric(see_total)) Then
Return "Fehler: ungültige echte Emissionen (see_total)"
End If
If year IsNot Nothing Then
If Not IsNumeric(year) OrElse CInt(year) < 2020 OrElse CInt(year) > 2100 Then
Return "Fehler: ungültiges Jahr"
End If
End If
If benchmark_value <> "" And (benchmark_value IsNot Nothing AndAlso Not IsNumeric(benchmark_value)) Then
Return "Fehler: ungültiger Benchmark-Wert"
End If
' ------------------------------------------------------------
' API initialisieren
' ------------------------------------------------------------
Dim api As New cATEZ_Greenpulse_CBAM_CostCalculation()
' ------------------------------------------------------------
' 2) Request aufbauen
' Request aufbauen
' ------------------------------------------------------------
Dim req As New cCBAM_CostCalculation_Request With {
.cn_code = cn_code,
.weight = CDbl(weight), ' Tonnen
.see_total = If(see_total = "", Nothing, see_total), ' optionale echte Emissionen
.year = If(year = "", Nothing, CInt(year)) ' Phase-in Jahr
}
.cn_code = cn_code,
.country_code = country_code.ToUpperInvariant(),
.weight = CDec(weight)
}
If If(see_total, "") <> "" Then
req.see_total = CDec(see_total)
Else
req.see_total = Nothing
End If
If year IsNot Nothing Then
req.year = CInt(year)
End If
If If(benchmark_value, "") <> "" Then
req.benchmark_value = CDec(benchmark_value)
Else
req.benchmark_value = Nothing
End If
' ------------------------------------------------------------
' 3) Request ausführen
' Request ausführen
' ------------------------------------------------------------
Dim resp As cCBAM_CostCalculation_Response = api.CalculateCost(req)
Dim resp As cCBAM_CostCalculation_Response
Try
resp = api.CalculateCost(req)
Catch ex As Exception
Return "Technischer Fehler bei API-Aufruf: " & ex.Message
End Try
Dim erg = ""
' ------------------------------------------------------------
' 4) Ergebnis auswerten
' Ergebnis aufbereiten
' ------------------------------------------------------------
Dim erg As String = ""
If resp.success Then
erg &= "CBAM Kostenberechnung erfolgreich" & vbNewLine
erg &= "--------------------------------" & vbNewLine
erg &= $"Kosten: {CDbl(resp.data.cost).ToString("N2")} {resp.data.currency}" & vbNewLine
erg &= $"CBAM Emission: {resp.data.cbam_emission}" & vbNewLine
erg &= $"Benchmark: {resp.data.benchmark}" & vbNewLine
erg &= $"Phase-Faktor: {resp.data.phase_factor}" & vbNewLine
erg &= $"CO2 Preis: {resp.data.carbon_price}" & vbNewLine
erg &= "CBAM Kostenberechnung erfolgreich" & vbCrLf
erg &= "--------------------------------" & vbCrLf
erg &= $"CN-Code: {cn_code}" & vbCrLf
erg &= $"Ursprungsland: {req.country_code}" & vbCrLf
erg &= $"Gewicht: {req.weight:N2} t" & vbCrLf
erg &= vbCrLf
erg &= "" & vbNewLine
erg &= "Details:" & vbNewLine
erg &= $" Adjusted Benchmark: {resp.data.calculation_details.adjusted_benchmark}" & vbNewLine
erg &= $" Emission Difference: {resp.data.calculation_details.emission_difference}" & vbNewLine
erg &= $" Gewicht: {CDbl(resp.data.calculation_details.weight).ToString("N2")} t" & vbNewLine
erg &= $"Kosten: {resp.data.cost:N2} {resp.data.currency}" & vbCrLf
erg &= $"CBAM Emission: {resp.data.cbam_emission:N5}" & vbCrLf
erg &= $"Benchmark: {resp.data.benchmark:N5}" & vbCrLf
erg &= $"Phase-Faktor: {resp.data.phase_factor:P2}" & vbCrLf
erg &= $"CO₂ Preis: {resp.data.carbon_price:N2} EUR/t" & vbCrLf
erg &= vbCrLf
erg &= "Details:" & vbCrLf
erg &= $" Adjusted Benchmark: {resp.data.calculation_details.adjusted_benchmark:N5}" & vbCrLf
erg &= $" Emission Difference: {resp.data.calculation_details.emission_difference:N5}" & vbCrLf
erg &= $" Gewicht (berechnet): {resp.data.calculation_details.weight:N2} t" & vbCrLf
Else
erg &= "CBAM Kostenberechnung FEHLER" & vbNewLine
erg &= "--------------------------------" & vbNewLine
erg &= $"Code: {resp.error.code}" & vbNewLine
erg &= $"Message: {resp.error.message}" & vbNewLine
erg &= $"HTTP Status: {resp.error.statusCode}" & vbNewLine
erg &= "CBAM Kostenberechnung FEHLER" & vbCrLf
erg &= "--------------------------------" & vbCrLf
erg &= $"Code: {resp.error.code}" & vbCrLf
erg &= $"Message: {resp.error.message}" & vbCrLf
erg &= $"HTTP Status: {resp.error.statusCode}" & vbCrLf
End If
' Console.ReadKey()
Return erg
End Function
End Class
' ============================================================================
@@ -225,17 +270,20 @@ End Class
Public Class cCBAM_CostCalculation_Request
Public Property cn_code As String
Public Property country_code As String
Public Property weight As Decimal
Public Property see_total As Nullable(Of Decimal)
Public Property year As Nullable(Of Integer)
Public Property benchmark_value As Nullable(Of Decimal)
Public Function ToJson() As String
Dim json As New JsonObject()
json.UpdateString("cn_code", cn_code)
json.UpdateString("country_code", country_code)
json.UpdateNumber("weight", weight.ToString(CultureInfo.InvariantCulture))
If see_total.HasValue Then
If see_total IsNot Nothing AndAlso see_total.HasValue Then
json.UpdateNumber("see_total", see_total.Value.ToString(CultureInfo.InvariantCulture))
End If
@@ -243,13 +291,17 @@ Public Class cCBAM_CostCalculation_Request
json.UpdateInt("year", year.Value)
End If
If benchmark_value IsNot Nothing AndAlso benchmark_value.HasValue Then
json.UpdateNumber("benchmark_value", benchmark_value.Value.ToString(CultureInfo.InvariantCulture))
End If
Return json.Emit()
End Function
End Class
' ============================================================================
' RESPONSE ROOT
' RESPONSE OBJECTS
' ============================================================================
Public Class cCBAM_CostCalculation_Response
Public Property success As Boolean
@@ -257,9 +309,6 @@ Public Class cCBAM_CostCalculation_Response
Public Property [error] As cCBAM_Error
End Class
' ============================================================================
' RESPONSE DATA
' ============================================================================
Public Class cCBAM_CostCalculation_Data
Public Property cost As Decimal
Public Property cbam_emission As Decimal
@@ -270,9 +319,6 @@ Public Class cCBAM_CostCalculation_Data
Public Property calculation_details As cCBAM_CostCalculation_Details
End Class
' ============================================================================
' RESPONSE DETAILS
' ============================================================================
Public Class cCBAM_CostCalculation_Details
Public Property cbam_emission As Decimal
Public Property benchmark As Decimal
@@ -282,6 +328,20 @@ Public Class cCBAM_CostCalculation_Details
Public Property carbon_price As Decimal
End Class
' ============================================================================
' CN CODE RESPONSE
' ============================================================================
Public Class cCBAM_CnCode_Response
Public Property success As Boolean
Public Property data As List(Of cCBAM_CnCode)
Public Property [error] As cCBAM_Error
End Class
Public Class cCBAM_CnCode
Public Property cn_code As String
Public Property cn_description As String
End Class
' ============================================================================
' ERROR OBJECT
' ============================================================================