KN8, DY->Atez

This commit is contained in:
2024-12-03 13:06:11 +01:00
parent 9995db6b02
commit 24a6d93c9e
3 changed files with 266 additions and 1 deletions

View File

@@ -0,0 +1,77 @@

Imports System.IO
Imports System.Globalization
Imports System.Net
Imports io.konik.zugferd.entity
Imports System.Data.SqlClient
' Definieren der Klasse, um die Daten zu repräsentieren
Public Class cTariffKN8
Public Property Spalte1 As String
Public Property Spalte2 As String
Public Property Spalte3 As String
Public Property Spalte4 As String
End Class
Public Class cTariffKN8_Interface
Public Shared Function UPDATE_KN8()
' URL zur Datei
Dim fileUrl As String = "https://www.statistik.at/kdb/downloads/csv/prod/KN" & Now.Year & "_DE_CKT.txt"
'Dim fileUrl As String = "https://www.statistik.at/kdb/downloads/csv/prod/KN2024_DE_CKT.txt"
Try
' WebClient verwenden, um die Datei direkt herunterzuladen
Using client As New WebClient()
Dim fileContent As String = client.DownloadString(fileUrl)
' Datei-Inhalt in Zeilen aufteilen
Dim lines As String() = fileContent.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
' Verbindung zur Datenbank öffnen
Using connection As New SqlConnection(VERAG_PROG_ALLGEMEIN.SQL.GetFMZOLLConnectionString)
connection.Open()
Using command As New SqlCommand("DELETE tblEZTKN8 ", connection)
command.ExecuteNonQuery()
End Using
' Zeilen durchlaufen, Kopfzeile überspringen
For i As Integer = 1 To lines.Length - 1
Dim line As String = lines(i).Trim()
' Überspringen leerer Zeilen
If String.IsNullOrEmpty(line) Then Continue For
' Spalten trennen (Semikolon als Trennzeichen)
Dim columns As String() = line.Split(";")
' Sicherstellen, dass genügend Spalten vorhanden sind
If columns.Length >= 4 Then
' Daten in die Datenbank einfügen
Using command As New SqlCommand("INSERT INTO tblEZTKN8 (Ebene, EDV_Code, Code, Kurztitel) VALUES (@Spalte1, @Spalte2, @Spalte3, @Spalte4)", connection)
command.Parameters.AddWithValue("@Spalte1", columns(0).Trim().Replace("""", ""))
command.Parameters.AddWithValue("@Spalte2", columns(1).Trim().Replace("""", ""))
command.Parameters.AddWithValue("@Spalte3", columns(2).Trim().Replace("""", ""))
command.Parameters.AddWithValue("@Spalte4", columns(3).Trim().Replace("""", ""))
command.ExecuteNonQuery()
End Using
End If
Next
End Using
End Using
Return True
Console.WriteLine("Daten erfolgreich in die Datenbank geladen.")
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
Return False
End Function
End Class