95 lines
3.8 KiB
VB.net
95 lines
3.8 KiB
VB.net
|
|
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 getKN8FromTNR(TNR)
|
|
If TNR Is Nothing Then Return ""
|
|
If TNR Is DBNull.Value Then Return ""
|
|
If TNR.ToString = String.Empty Then Return ""
|
|
TNR = TNR.ToString.Replace(".", "")
|
|
TNR = TNR.ToString.Replace(" ", "")
|
|
If TNR.ToString.Length > 8 Then TNR = TNR.ToString.Substring(0, 8)
|
|
|
|
'If TNR.Length < 8 Then
|
|
' ' Mit Nullen auffüllen
|
|
' TNR = TNR.PadRight(8, "0"c)
|
|
'End If
|
|
Dim sql As New VERAG_PROG_ALLGEMEIN.SQL
|
|
Return sql.getValueTxtBySql("SELECT TOP 1 [Kurztitel] FROM [tblEZTKN8] where EDV_Code like '" & TNR & "'", "FMZOLL",,, "")
|
|
End Function
|
|
|
|
|
|
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
|