procedures

This commit is contained in:
2025-11-26 09:03:21 +01:00
parent 7918b0d0b8
commit 99bb7d39de
6 changed files with 489 additions and 26 deletions

View File

@@ -320,6 +320,7 @@
<Compile Include="cMeineFunktionen.vb" />
<Compile Include="cProgramFunctions.vb" />
<Compile Include="cSqlDb.vb" />
<Compile Include="cTRCustStat.vb" />
<Compile Include="CultureInfo.vb" />
<Compile Include="DataSet1.Designer.vb">
<AutoGen>True</AutoGen>

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.2.4.5")>
<Assembly: AssemblyFileVersion("1.2.4.5")>
<Assembly: AssemblyVersion("1.2.4.8")>
<Assembly: AssemblyFileVersion("1.2.4.8")>

301
UID/cTRCustStat.vb Normal file
View File

@@ -0,0 +1,301 @@

Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization
Imports ClosedXML.Excel
Public Class cTRCustStat
Private ReadOnly _connectionString As String
Private ReadOnly _de As CultureInfo = CultureInfo.GetCultureInfo("de-DE")
Public Sub New(connectionString As String)
_connectionString = connectionString
End Sub
' Mehrere Dateien importieren
Public Sub ImportFiles(filePaths As IEnumerable(Of String))
For Each p In filePaths
ImportSingleFile(p)
Next
End Sub
Private Sub ImportSingleFile(filePath As String)
Using wb As New XLWorkbook(filePath)
Dim ws = wb.Worksheets.First()
' Header (Zeile 1) normalisieren
Dim lastCol = ws.Row(1).LastCellUsed().Address.ColumnNumber
Dim headers As New List(Of String)
For c = 1 To lastCol
headers.Add(NormalizeHeader(ws.Cell(1, c).GetString()))
Next
Dim layout = DetectLayout(headers)
Select Case layout
Case LayoutType.Exports
Dim dt = CreateExportsDataTable() ' Spaltennamen = SQL-Spalten EN
FillDataTable(ws, headers, dt, isExport:=True, sourceFile:=filePath)
BulkInsert(dt, "dbo.Customs_Exports")
Case LayoutType.Imports
Dim dt = CreateImportsDataTable()
FillDataTable(ws, headers, dt, isExport:=False, sourceFile:=filePath)
BulkInsert(dt, "dbo.Customs_Imports")
Case Else
Throw New InvalidOperationException($"Unknown layout in file: {filePath}")
End Select
End Using
End Sub
Private Enum LayoutType
Unknown = 0
Exports = 1
[Imports] = 2
End Enum
Private Function DetectLayout(headers As List(Of String)) As LayoutType
' Export: hat "tcgb statü açıklaması" ODER "gümrük istatistik tarihi"
If headers.Any(Function(h) h.Contains("tcgb statu aciklamasi") OrElse h.Contains("gumruk istatistik tarihi")) Then
Return LayoutType.Exports
End If
' Import: hat "gümrük idaresi kodu" und "tcgb kapanış tarihi"
If headers.Any(Function(h) h.Contains("gumruk idaresi kodu")) AndAlso
headers.Any(Function(h) h.Contains("tcgb kapanis tarihi")) Then
Return LayoutType.Imports
End If
Return LayoutType.Unknown
End Function
Private Function NormalizeHeader(raw As String) As String
If raw Is Nothing Then Return ""
Dim s = raw.Trim().ToLowerInvariant()
s = s.Replace("ı", "i").Replace("ş", "s").Replace("ğ", "g").Replace("ü", "u").Replace("ö", "o").Replace("ç", "c")
s = System.Text.RegularExpressions.Regex.Replace(s, "\s+", " ")
Return s
End Function
' --- DataTables: Spaltennamen = EN-Tabellenschema ---
Private Function CreateExportsDataTable() As DataTable
Dim dt As New DataTable("Customs_Exports")
dt.Columns.Add("CustomsOfficeName", GetType(String))
dt.Columns.Add("RegistrationNo", GetType(String))
dt.Columns.Add("RegistrationDate", GetType(Date))
dt.Columns.Add("StatisticsDate", GetType(Date))
dt.Columns.Add("ConsignorConsigneeTaxNo", GetType(String))
dt.Columns.Add("ConsignorConsigneeName", GetType(String))
dt.Columns.Add("ConsigneeName", GetType(String))
dt.Columns.Add("DestinationCountryCode", GetType(String))
dt.Columns.Add("DestinationCountryName", GetType(String))
dt.Columns.Add("OriginCountryCode", GetType(String))
dt.Columns.Add("OriginCountryName", GetType(String))
dt.Columns.Add("IncotermCode", GetType(String))
dt.Columns.Add("LineNo", GetType(Integer))
dt.Columns.Add("RegimeCode", GetType(String))
dt.Columns.Add("RegimeDescription", GetType(String))
dt.Columns.Add("HSCode", GetType(String))
dt.Columns.Add("HSDescription", GetType(String))
dt.Columns.Add("CommercialDescription", GetType(String))
dt.Columns.Add("DeclarationStatus", GetType(String))
dt.Columns.Add("InvoiceAmount", GetType(Decimal))
dt.Columns.Add("InvoiceCurrencyCode", GetType(String))
dt.Columns.Add("Quantity", GetType(Decimal))
dt.Columns.Add("QuantityUnit", GetType(String))
dt.Columns.Add("NetWeightKg", GetType(Decimal))
dt.Columns.Add("CalculatedLineValueUSD", GetType(Decimal))
dt.Columns.Add("StatisticalValueUSD", GetType(Decimal))
dt.Columns.Add("SourceFile", GetType(String))
dt.Columns.Add("ImportedAtUtc", GetType(DateTime))
Return dt
End Function
Private Function CreateImportsDataTable() As DataTable
Dim dt As New DataTable("Customs_Imports")
dt.Columns.Add("CustomsOfficeCode", GetType(String))
dt.Columns.Add("CustomsOfficeName", GetType(String))
dt.Columns.Add("RegistrationNo", GetType(String))
dt.Columns.Add("RegistrationDate", GetType(Date))
dt.Columns.Add("ClosingDate", GetType(Date))
dt.Columns.Add("ConsignorConsigneeTaxNo", GetType(String))
dt.Columns.Add("ConsignorConsigneeName", GetType(String))
dt.Columns.Add("SenderName", GetType(String))
dt.Columns.Add("DispatchCountryCode", GetType(String))
dt.Columns.Add("DispatchCountryName", GetType(String))
dt.Columns.Add("OriginCountryCode", GetType(String))
dt.Columns.Add("OriginCountryName", GetType(String))
dt.Columns.Add("IncotermCode", GetType(String))
dt.Columns.Add("LineNo", GetType(Integer))
dt.Columns.Add("RegimeCode", GetType(String))
dt.Columns.Add("RegimeDescription", GetType(String))
dt.Columns.Add("HSCode", GetType(String))
dt.Columns.Add("HSDescription", GetType(String))
dt.Columns.Add("CommercialDescription", GetType(String))
dt.Columns.Add("InvoiceAmount", GetType(Decimal))
dt.Columns.Add("InvoiceCurrencyCode", GetType(String))
dt.Columns.Add("Quantity", GetType(Decimal))
dt.Columns.Add("QuantityUnit", GetType(String))
dt.Columns.Add("NetWeightKg", GetType(Decimal))
dt.Columns.Add("CalculatedLineValueUSD", GetType(Decimal))
dt.Columns.Add("StatisticalValueUSD", GetType(Decimal))
dt.Columns.Add("SourceFile", GetType(String))
dt.Columns.Add("ImportedAtUtc", GetType(DateTime))
Return dt
End Function
' --- Excel -> DataTable ---
Private Sub FillDataTable(ws As IXLWorksheet,
headers As List(Of String),
dt As DataTable,
isExport As Boolean,
sourceFile As String)
Dim rowFirst = 2
Dim rowLast = ws.LastRowUsed().RowNumber()
Dim colLast = ws.Row(1).LastCellUsed().Address.ColumnNumber
Dim map As Dictionary(Of String, String) =
If(isExport, GetExportHeaderMap(), GetImportHeaderMap())
For r = rowFirst To rowLast
Dim dr = dt.NewRow()
dr("SourceFile") = sourceFile
dr("ImportedAtUtc") = DateTime.UtcNow
For c = 1 To colLast
Dim rawHeader = NormalizeHeader(ws.Cell(1, c).GetString())
If Not map.ContainsKey(rawHeader) Then Continue For
Dim targetCol = map(rawHeader)
Dim txt = ws.Cell(r, c).GetFormattedString().Trim()
If String.IsNullOrWhiteSpace(txt) Then
' skip
ElseIf dt.Columns(targetCol).DataType Is GetType(Date) Then
dr(targetCol) = ParseDate(txt)
ElseIf dt.Columns(targetCol).DataType Is GetType(Decimal) Then
dr(targetCol) = ParseDecimal(txt)
ElseIf dt.Columns(targetCol).DataType Is GetType(Integer) Then
Dim i As Integer
If Integer.TryParse(txt, NumberStyles.Any, _de, i) OrElse
Integer.TryParse(txt, NumberStyles.Any, CultureInfo.InvariantCulture, i) Then
dr(targetCol) = i
End If
Else
dr(targetCol) = txt
End If
Next
' Mindestprüfung: RegistrationNo muss da sein
If dt.Columns.Contains("RegistrationNo") AndAlso
Not IsDBNull(dr("RegistrationNo")) AndAlso
Not String.IsNullOrWhiteSpace(CStr(dr("RegistrationNo"))) Then
dt.Rows.Add(dr)
End If
Next
End Sub
Private Function ParseDecimal(s As String) As Decimal
Dim d As Decimal
If Decimal.TryParse(s, NumberStyles.Any, _de, d) Then Return d ' 3.499,09
If Decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, d) Then Return d ' 3499.09
Return 0D
End Function
Private Function ParseDate(s As String) As Date
Dim d As Date
Dim formats = {
"dd.MMM.yyyy", "d.MMM.yyyy",
"dd.MM.yyyy", "d.MM.yyyy",
"dd.MMM.yy", "dd.MM.yy",
"yyyy-MM-dd", "dd-MMM-yyyy"
}
If Date.TryParseExact(s, formats, _de, DateTimeStyles.None, d) Then Return d
If Date.TryParse(s, _de, DateTimeStyles.None, d) Then Return d
If Date.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, d) Then Return d
Return Date.MinValue
End Function
Private Sub BulkInsert(dt As DataTable, targetTable As String)
Using cn As New SqlConnection(_connectionString)
cn.Open()
Using bulk As New SqlBulkCopy(cn)
bulk.DestinationTableName = targetTable
bulk.BulkCopyTimeout = 0
bulk.BatchSize = 10000
For Each col As DataColumn In dt.Columns
bulk.ColumnMappings.Add(col.ColumnName, col.ColumnName)
Next
bulk.WriteToServer(dt)
End Using
End Using
End Sub
' --- Header-Mappings: Türkischer Exceltitel -> EN-Spalte ---
Private Function GetExportHeaderMap() As Dictionary(Of String, String)
Return New Dictionary(Of String, String) From {
{"tcgb", "CustomsOfficeName"},
{"gümrük idaresi adı", "CustomsOfficeName"}, ' manche Dateien haben beide
{"tcgb tescil no", "RegistrationNo"},
{"tcgb tescil tarihi", "RegistrationDate"},
{"gümrük istatistik tarihi (bordro tarihi)", "StatisticsDate"},
{"gonderici / alici vergi no", "ConsignorConsigneeTaxNo"},
{"gonderici/alici adi", "ConsignorConsigneeName"},
{"alici adi", "ConsigneeName"},
{"gidecegi ulke (17) kodu", "DestinationCountryCode"},
{"gidecegi ulke (17) adi", "DestinationCountryName"},
{"mense ulke kodu", "OriginCountryCode"},
{"mense ulke adi", "OriginCountryName"},
{"teslim sekli kodu", "IncotermCode"},
{"kalem sira no", "LineNo"},
{"kalem rejim kodu", "RegimeCode"},
{"kalem rejim aciklamasi", "RegimeDescription"},
{"gtip kodu", "HSCode"},
{"gtip aciklamasi", "HSDescription"},
{"31. ticari tanimi", "CommercialDescription"},
{"tcgb statu aciklamasi", "DeclarationStatus"},
{"fatura tutari", "InvoiceAmount"},
{"fatura tutari doviz turu kodu", "InvoiceCurrencyCode"},
{"olcu (esya) miktari", "Quantity"},
{"olcu birimi aciklamasi", "QuantityUnit"},
{"net agirlik (kg)", "NetWeightKg"},
{"hesaplanmis kalem kiymeti usd degeri", "CalculatedLineValueUSD"},
{"istatistiki kiymet usd degeri", "StatisticalValueUSD"}
}
End Function
Private Function GetImportHeaderMap() As Dictionary(Of String, String)
Return New Dictionary(Of String, String) From {
{"gümrük idaresi kodu", "CustomsOfficeCode"},
{"gumruk idaresi kodu", "CustomsOfficeCode"},
{"gümrük idaresi adı", "CustomsOfficeName"},
{"gumruk idaresi adi", "CustomsOfficeName"},
{"tcgb tescil no", "RegistrationNo"},
{"tcgb tescil tarihi", "RegistrationDate"},
{"tcgb kapanis tarihi", "ClosingDate"},
{"gonderici / alici vergi no", "ConsignorConsigneeTaxNo"},
{"gonderici/alici adi", "ConsignorConsigneeName"},
{"gonderen adi", "SenderName"},
{"cikis ulkesi kodu", "DispatchCountryCode"},
{"cikis ulkesi adi", "DispatchCountryName"},
{"mense ulke kodu", "OriginCountryCode"},
{"mense ulke adi", "OriginCountryName"},
{"teslim sekli kodu", "IncotermCode"},
{"kalem sira no", "LineNo"},
{"kalem rejim kodu", "RegimeCode"},
{"kalem rejim aciklamasi", "RegimeDescription"},
{"gtip kodu", "HSCode"},
{"gtip aciklamasi", "HSDescription"},
{"31. ticari tanimi", "CommercialDescription"},
{"fatura tutari", "InvoiceAmount"},
{"fatura doviz kodu", "InvoiceCurrencyCode"},
{"olcu (esya) miktari", "Quantity"},
{"olcu birimi aciklamasi", "QuantityUnit"},
{"net agirlik (kg)", "NetWeightKg"},
{"hesaplanmis kalem kiymeti usd degeri", "CalculatedLineValueUSD"},
{"istatistiki kiymet usd degeri", "StatisticalValueUSD"}
}
End Function
End Class

View File

@@ -22,7 +22,7 @@ Partial Class usrctlProcedures
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl()
Me.tbTRStat = New System.Windows.Forms.TabControl()
Me.TabPage3 = New System.Windows.Forms.TabPage()
Me.Label16 = New System.Windows.Forms.Label()
Me.txtHMRCApplName = New System.Windows.Forms.TextBox()
@@ -103,6 +103,8 @@ Partial Class usrctlProcedures
Me.Label20 = New System.Windows.Forms.Label()
Me.dtp_von = New System.Windows.Forms.DateTimePicker()
Me.Button52 = New System.Windows.Forms.Button()
Me.TabPage8 = New System.Windows.Forms.TabPage()
Me.btnImportTrStat = New System.Windows.Forms.Button()
Me.Button18 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.lblAnzahl = New System.Windows.Forms.Label()
@@ -156,7 +158,9 @@ Partial Class usrctlProcedures
Me.Button99 = New System.Windows.Forms.Button()
Me.DataGridViewTextBoxColumn1 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.DataGridViewTextBoxColumn2 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TabControl1.SuspendLayout()
Me.TabPage9 = New System.Windows.Forms.TabPage()
Me.Button53 = New System.Windows.Forms.Button()
Me.tbTRStat.SuspendLayout()
Me.TabPage3.SuspendLayout()
Me.TabPage1.SuspendLayout()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
@@ -167,22 +171,26 @@ Partial Class usrctlProcedures
Me.TabPage5.SuspendLayout()
Me.TabPage6.SuspendLayout()
Me.TabPage7.SuspendLayout()
Me.TabPage8.SuspendLayout()
Me.TabPage9.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'tbTRStat
'
Me.TabControl1.Controls.Add(Me.TabPage3)
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Controls.Add(Me.TabPage4)
Me.TabControl1.Controls.Add(Me.TabPage5)
Me.TabControl1.Controls.Add(Me.TabPage6)
Me.TabControl1.Controls.Add(Me.TabPage7)
Me.TabControl1.Location = New System.Drawing.Point(7, 407)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(609, 314)
Me.TabControl1.TabIndex = 2
Me.tbTRStat.Controls.Add(Me.TabPage3)
Me.tbTRStat.Controls.Add(Me.TabPage1)
Me.tbTRStat.Controls.Add(Me.TabPage2)
Me.tbTRStat.Controls.Add(Me.TabPage4)
Me.tbTRStat.Controls.Add(Me.TabPage5)
Me.tbTRStat.Controls.Add(Me.TabPage6)
Me.tbTRStat.Controls.Add(Me.TabPage7)
Me.tbTRStat.Controls.Add(Me.TabPage8)
Me.tbTRStat.Controls.Add(Me.TabPage9)
Me.tbTRStat.Location = New System.Drawing.Point(7, 407)
Me.tbTRStat.Name = "tbTRStat"
Me.tbTRStat.SelectedIndex = 0
Me.tbTRStat.Size = New System.Drawing.Size(609, 314)
Me.tbTRStat.TabIndex = 2
'
'TabPage3
'
@@ -959,6 +967,26 @@ Partial Class usrctlProcedures
Me.Button52.Text = "DAKOSY Daten prüfen"
Me.Button52.UseVisualStyleBackColor = True
'
'TabPage8
'
Me.TabPage8.Controls.Add(Me.btnImportTrStat)
Me.TabPage8.Location = New System.Drawing.Point(4, 22)
Me.TabPage8.Name = "TabPage8"
Me.TabPage8.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage8.Size = New System.Drawing.Size(601, 288)
Me.TabPage8.TabIndex = 7
Me.TabPage8.Text = "TabPage8"
Me.TabPage8.UseVisualStyleBackColor = True
'
'btnImportTrStat
'
Me.btnImportTrStat.Location = New System.Drawing.Point(7, 43)
Me.btnImportTrStat.Name = "btnImportTrStat"
Me.btnImportTrStat.Size = New System.Drawing.Size(131, 48)
Me.btnImportTrStat.TabIndex = 0
Me.btnImportTrStat.Text = "Import TrStat"
Me.btnImportTrStat.UseVisualStyleBackColor = True
'
'Button18
'
Me.Button18.Location = New System.Drawing.Point(59, 183)
@@ -1438,6 +1466,26 @@ Partial Class usrctlProcedures
Me.DataGridViewTextBoxColumn2.HeaderText = "anz"
Me.DataGridViewTextBoxColumn2.Name = "DataGridViewTextBoxColumn2"
'
'TabPage9
'
Me.TabPage9.Controls.Add(Me.Button53)
Me.TabPage9.Location = New System.Drawing.Point(4, 22)
Me.TabPage9.Name = "TabPage9"
Me.TabPage9.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage9.Size = New System.Drawing.Size(601, 288)
Me.TabPage9.TabIndex = 8
Me.TabPage9.Text = "T1 Serice"
Me.TabPage9.UseVisualStyleBackColor = True
'
'Button53
'
Me.Button53.Location = New System.Drawing.Point(228, 120)
Me.Button53.Name = "Button53"
Me.Button53.Size = New System.Drawing.Size(145, 49)
Me.Button53.TabIndex = 25
Me.Button53.Text = "T1 Servcie"
Me.Button53.UseVisualStyleBackColor = True
'
'usrctlProcedures
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
@@ -1492,11 +1540,11 @@ Partial Class usrctlProcedures
Me.Controls.Add(Me.lblAnzahl)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button18)
Me.Controls.Add(Me.TabControl1)
Me.Controls.Add(Me.tbTRStat)
Me.Controls.Add(Me.Button26)
Me.Name = "usrctlProcedures"
Me.Size = New System.Drawing.Size(931, 724)
Me.TabControl1.ResumeLayout(False)
Me.tbTRStat.ResumeLayout(False)
Me.TabPage3.ResumeLayout(False)
Me.TabPage3.PerformLayout()
Me.TabPage1.ResumeLayout(False)
@@ -1514,11 +1562,13 @@ Partial Class usrctlProcedures
Me.TabPage6.PerformLayout()
Me.TabPage7.ResumeLayout(False)
Me.TabPage7.PerformLayout()
Me.TabPage8.ResumeLayout(False)
Me.TabPage9.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents tbTRStat As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
@@ -1652,4 +1702,8 @@ Partial Class usrctlProcedures
Friend WithEvents Button52 As Button
Friend WithEvents Label22 As Label
Friend WithEvents dtpbis As DateTimePicker
Friend WithEvents TabPage8 As TabPage
Friend WithEvents btnImportTrStat As Button
Friend WithEvents TabPage9 As TabPage
Friend WithEvents Button53 As Button
End Class

View File

@@ -123,10 +123,4 @@
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@@ -4304,6 +4304,119 @@ OPTION (MAXRECURSION 1000);", "AVISO") '
End Sub
Private Sub btnImportTrStat_Click(sender As Object, e As EventArgs) Handles btnImportTrStat.Click
' SQL Connection String (ggf. anpassen)
Dim connectionString As String = "Data Source=DEVELOPER\DEVSQL;Initial Catalog=TRCustStat;Integrated Security=false;User ID=sa;Password=BmWr501956;"
' FileDialog vorbereiten
Using ofd As New OpenFileDialog()
ofd.Title = "Select one or more Customs Excel files"
ofd.Filter = "Excel Files (*.xlsx;*.xls;*.xlsm)|*.xlsx;*.xls;*.xlsm|All Files (*.*)|*.*"
ofd.Multiselect = True
ofd.InitialDirectory = "D:\CustomsUploads" ' optionaler Startordner
If ofd.ShowDialog() = DialogResult.OK Then
Dim selectedFiles = ofd.FileNames
Try
Dim importer As New cTRCustStat(connectionString)
importer.ImportFiles(selectedFiles)
MessageBox.Show($"✅ Import completed successfully." & vbCrLf &
$"Files imported: {selectedFiles.Length}",
"Import Finished", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("❌ Error during import:" & vbCrLf & ex.Message,
"Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Using
End Sub
Private Sub Button53_Click(sender As Object, e As EventArgs) Handles Button53.Click
TESTs("D:\Andreas\TMP\TESTT1.pdf")
End Sub
Private Async Sub TESTs(pdfPath As String)
Try
Dim READ As New VERAG_PROG_ALLGEMEIN.cATEZ_Read_T1
' dieselbe Instanz verwenden
Dim result As T1ProcessResult = Await READ.ProcessPdfAsync(pdfPath)
Dim sb As New System.Text.StringBuilder()
sb.AppendLine("=== Grunddaten ===")
sb.AppendLine("Status: " & If(result.Status, ""))
sb.AppendLine("Document Count: " & result.DocumentCount)
sb.AppendLine("Document Type: " & If(result.DocumentType, ""))
sb.AppendLine("Processing Time (s): " & result.ProcessingTimeSeconds)
sb.AppendLine()
sb.AppendLine("=== Kopf-T1-Daten ===")
sb.AppendLine("Date: " & If(result.DateField, ""))
sb.AppendLine("Dispatch Country: " & If(result.DispatchCountry, ""))
sb.AppendLine("Dispatch Place: " & If(result.DispatchPlace, ""))
sb.AppendLine("Loading Place: " & If(result.LoadingPlace, ""))
sb.AppendLine("Destination Country: " & If(result.DestinationCountry, ""))
sb.AppendLine("Destination Customs Authority: " & If(result.DestinationCustomsAuthority, ""))
sb.AppendLine("Mode of Transport: " & If(result.ModeOfTransport, ""))
sb.AppendLine("Type of Transport: " & If(result.TypeOfTransport, ""))
sb.AppendLine("Transit ID: " & If(result.TransitId, ""))
sb.AppendLine("Truck ID Border: " & If(result.TruckIdBorder, ""))
sb.AppendLine("Truck ID Transit: " & If(result.TruckIdTransit, ""))
sb.AppendLine()
sb.AppendLine("=== Items ===")
If result.Items IsNot Nothing AndAlso result.Items.Count > 0 Then
For i As Integer = 0 To result.Items.Count - 1
Dim it = result.Items(i)
sb.AppendLine($"Item #{i + 1}")
sb.AppendLine($" Export ID: {it.ExportId}")
sb.AppendLine($" Invoice No: {it.InvoiceNo}")
sb.AppendLine($" Item Index: {it.ItemIndex}")
sb.AppendLine($" Sender: {it.Sender}")
sb.AppendLine($" Total Package: {it.TotalPackage}")
sb.AppendLine($" Total Weight: {it.TotalWeight}")
sb.AppendLine()
Next
Else
sb.AppendLine("Keine Items vorhanden.")
End If
sb.AppendLine("=== Additional Data (ungeparst) ===")
If result.AdditionalData IsNot Nothing AndAlso result.AdditionalData.Count > 0 Then
For Each kvp In result.AdditionalData
sb.AppendLine($" {kvp.Key}: {kvp.Value.ToString()}")
Next
Else
sb.AppendLine("Keine zusätzlichen Felder.")
End If
MessageBox.Show(sb.ToString(), "T1 Dokument verarbeitet", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch apiEx As T1ApiException
Dim sbErr As New System.Text.StringBuilder()
sbErr.AppendLine("T1 API Fehler")
sbErr.AppendLine("HTTP-Status: " & CInt(apiEx.StatusCode))
If Not String.IsNullOrEmpty(apiEx.ErrorKey) Then
sbErr.AppendLine("Error Key: " & apiEx.ErrorKey)
End If
sbErr.AppendLine("Nachricht: " & apiEx.Message)
If Not String.IsNullOrEmpty(apiEx.RawResponse) Then
sbErr.AppendLine()
sbErr.AppendLine("Raw Response:")
sbErr.AppendLine(apiEx.RawResponse)
End If
MessageBox.Show(sbErr.ToString(), "T1 API Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.ToString(), "Allgemeiner Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'Private Sub Button26_Click(sender As Object, e As EventArgs)