Imports System.IO
Imports System.Globalization
Imports System.Xml
Imports Renci.SshNet
Imports System.Net
Imports System.Text

Public Class frmTRNCTS_NachrichtenVerarbeitung_ATEZ
    Dim cntDatenEingelesen As Integer = 0
    Dim dsNichtErkannt As Integer = 0
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
    Dim allowClose = False
    '  Dim DY_PFAD = "C:\Users\DEVELOPER1\Desktop\test\TEST\"

    Dim TELOTEC_PFAD = "" '"C:\Users\DEVELOPER1\Desktop\test\TEST\Nachrichtendaten_Einarbeitung\"
    Dim VERARBEITUNGS_PFAD = "" '"C:\Users\DEVELOPER1\Desktop\test\TEST\Nachrichtendaten_Einarbeitung\"
    Dim ZIEL_PFAD = "" '"C:\Users\DEVELOPER1\Desktop\test\TEST\Nachrichtendaten_Ablage\"
    Dim ERROR_PFAD = "" '"C:\Users\DEVELOPER1\Desktop\test\TEST\Nachrichtendaten_ERROR\"
    Dim PARTNERSYSTEM = "ATEZ"
    Dim SERVER_Path = ""
    Dim SERVER_Path_TEST = ""
    ' Dim BOX_VERSION = "8.8"

    Dim Dateiname = ""

    Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    Sub New(allowClose) 'autostart

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.allowClose = allowClose
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub

    Sub initPfade()
        Me.SERVER_Path = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("SERVER_Path", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        Me.SERVER_Path_TEST = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("SERVER_Path_TEST", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        Me.TELOTEC_PFAD = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("BEREITSTELLUNGS_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        Me.VERARBEITUNGS_PFAD = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("VERARBEITUNGS_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        'VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\TESTSYSTEM\Nachrichtendaten_Einarbeitung\"
        Me.ZIEL_PFAD = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("ZIEL_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        'VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\TESTSYSTEM\Nachrichtendaten_Ablage\"
        Me.ERROR_PFAD = cNCTSPartnerWorker.cATEZ_Paramter.GET_PARAM_ByName("ERROR_PFAD", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)
        'VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\TESTSYSTEM\Nachrichtendaten_ERROR\"
        If Not System.IO.Directory.Exists(VERARBEITUNGS_PFAD) Then System.IO.Directory.CreateDirectory(VERARBEITUNGS_PFAD)
        If Not System.IO.Directory.Exists(ZIEL_PFAD) Then System.IO.Directory.CreateDirectory(ZIEL_PFAD)
        If Not System.IO.Directory.Exists(ERROR_PFAD) Then System.IO.Directory.CreateDirectory(ERROR_PFAD)

        'Me.BOX_VERSION = NCTSTR_Worker.cDY_Paramter.GET_PARAM_ByName("BOX_VERSION", VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM)

    End Sub


    Private Sub frmDYNachrichtenVerarbeitung_Load(sender As Object, e As EventArgs) Handles Me.Load
        initPfade()
        For Each d In System.IO.Directory.GetFiles(VERARBEITUNGS_PFAD)
            ListBox3.Items.Add(frmStartOptions.cut_file(d))
            Me.Refresh()
        Next
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Enabled = False
        Try
            Label9.Visible = True
            Dim cnt = getNachrichtenDatenFromMAVIServices()
            Label9.Text = cnt & " Datensätze empfangen."

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Me.Enabled = True

    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Enabled = False
        Try
            Label5.Visible = True

            DatenEinlesen() '<<<<------------

            If dsNichtErkannt > 0 Then

                Label6.Text = dsNichtErkannt & " Datensätze nicht " & vbNewLine & "erkannt."
                Label6.Visible = True
            End If
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Me.Enabled = True
        Label5.Text = cntDatenEingelesen & " Datensätze verarbeitet."

    End Sub


    Function getNachrichtenDatenFromMAVIServices() As Integer
        Dim cnt = 0
        Try
            Dim SERVER_Path = ""

            If VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then

                SERVER_Path = Me.SERVER_Path '"\\ftps.verag.ag\FTP\MAVI\IN\"
            Else

                SERVER_Path = Me.SERVER_Path_TEST '"\\ftps.verag.ag\FTP\MAVI\IN\"
            End If


            For Each f In System.IO.Directory.GetFiles(SERVER_Path)
                Dim fi As New System.IO.FileInfo(f)
                If Not fi.Name.StartsWith(".") Then
                    Dim zielPfad = VERARBEITUNGS_PFAD & "\" & fi.Name
                    While System.IO.File.Exists(zielPfad)
                        zielPfad = VERARBEITUNGS_PFAD & "\" & Now.ToString("yyyyMMdd_HHmmss_") & fi.Name
                    End While
                    System.IO.File.Copy(f, zielPfad)
                    If Not VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM Then
                        If System.IO.File.Exists(zielPfad) Then System.IO.File.Delete(f)
                    End If

                    ListBox3.Items.Add(frmStartOptions.cut_file((New FileInfo(zielPfad)).Name)) 'zur Liste hinzufügen

                    cnt += 1
                End If
            Next


            Return cnt


        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try

        Return cnt
    End Function


    Function getNachrichtenDatenFromMAVIServices_ALTERNATIV() As Integer
        Dim cnt = 0
        Try
            For Each f In System.IO.Directory.GetFiles(TELOTEC_PFAD)
                Dim FI As New FileInfo(f)
                If Not FI.Name.StartsWith(".") Then
                    'Temp. DownloadPfad
                    Dim destFilenameTMP = VERARBEITUNGS_PFAD + "." & If(System.IO.File.Exists(VERARBEITUNGS_PFAD & "." & FI.Name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & FI.Name

                    'Datei herunterladen
                    System.IO.File.Copy(f, destFilenameTMP)
                    If System.IO.File.Exists(destFilenameTMP) Then System.IO.File.Delete(f) 'Datei nach erfolgreichem Herunterladen vom Server löschen

                    'Gültiger Filename
                    Dim destFilename = VERARBEITUNGS_PFAD & If(System.IO.File.Exists(VERARBEITUNGS_PFAD & FI.Name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & FI.Name
                    System.IO.File.Move(destFilenameTMP, destFilename) 'Datei umbenennen

                    Dim fi_dest As FileInfo = New FileInfo(destFilename)
                    ListBox3.Items.Add(frmStartOptions.cut_file(fi_dest.Name)) 'zur Liste hinzufügen
                    cnt += 1
                    lblDatenCnt.Text = cnt
                    Me.Refresh()
                End If
            Next
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try

        Return cnt

        'Dim cnt = 0
        'Try
        '    Dim DY_server = ""
        '    Dim DY_name = ""
        '    Dim DY_pwd = ""
        '    Dim DY_port = ""
        '    Dim DY_PFAD_out = ""

        '    DAKOSY_Worker.cDakosyFunftions.getSFTPLoginData(DY_server, DY_name, DY_pwd, DY_port, "", DY_PFAD_out)


        '    Dim ConnectionInfo As New ConnectionInfo(DY_server, DY_port, DY_name, New PasswordAuthenticationMethod(DY_name, DY_pwd))
        '    Using client = New SftpClient(ConnectionInfo)
        '        client.Connect()

        '        For Each f In client.ListDirectory(DY_PFAD_out)
        '            '   MsgBox(f.Name)
        '            If Not f.Name.StartsWith(".") Then
        '                'Temp. DownloadPfad
        '                Dim destFilenameTMP = VERARBEITUNGS_PFAD + "." & If(IO.File.Exists(VERARBEITUNGS_PFAD & "." & f.Name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & f.Name

        '                'Datei herunterladen
        '                Dim downloadFileStream As Stream = File.OpenWrite(destFilenameTMP)
        '                client.DownloadFile(f.FullName, downloadFileStream)
        '                If IO.File.Exists(destFilenameTMP) Then client.DeleteFile(f.FullName) 'Datei nach erfolgreichem Herunterladen vom Server löschen
        '                downloadFileStream.Dispose()

        '                'Gültiger Filename
        '                Dim destFilename = VERARBEITUNGS_PFAD & If(IO.File.Exists(VERARBEITUNGS_PFAD & f.Name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & f.Name
        '                IO.File.Move(destFilenameTMP, destFilename) 'Datei umbenennen

        '                Dim fi As FileInfo = New FileInfo(destFilename)
        '                ListBox3.Items.Add(frmStartOptions.cut_file(fi.Name)) 'zur Liste hinzufügen
        '                cnt += 1
        '            End If
        '        Next
        '        client.Disconnect()
        '    End Using
        'Catch ex As Exception
        '    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        'End Try

        'Return cnt
    End Function





    ' Dim toEncodeAsBytes() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode)
    '  string returnValue            = System.Convert.ToBase64String(toEncodeAsBytes)
    Public Function stripNonValidXMLCharacters(ByVal textIn As String) As String
        Dim textOut As System.Text.StringBuilder = New System.Text.StringBuilder()
        Dim current As Char
        If textIn Is Nothing OrElse textIn = String.Empty Then Return String.Empty
        For i As Integer = 0 To textIn.Length - 1
            current = textIn(i)
            If (current = "9" OrElse current = "10" OrElse current = "13") OrElse ((current >= "32") AndAlso (current <= "55295")) OrElse ((current >= "57344") AndAlso (current <= "65533")) OrElse ((current >= "65536") AndAlso (current <= "1114111")) Then
                textOut.Append(current)
            End If
        Next

        Return textOut.ToString()
    End Function

    Public Function SanitizeXmlString(ByVal xml As String) As String
        If xml Is Nothing Then
            Throw New ArgumentNullException("xml")
        End If

        Dim buffer As System.Text.StringBuilder = New System.Text.StringBuilder(xml.Length)
        For Each c As Char In xml
            If IsLegalXmlChar(Asc(c)) Then
                buffer.Append(c)
            End If
        Next

        Return buffer.ToString()
    End Function

    Public Function IsLegalXmlChar(ByVal character As Integer) As Boolean
        Return (character = 9 OrElse character = 10 OrElse character = 13 OrElse (character >= 32 AndAlso character <= 55295) OrElse (character >= 57344 AndAlso character <= 65533) OrElse (character >= 65536 AndAlso character <= 1114111))
    End Function



    Sub DatenEinlesen()

        VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.MAIL

        If ListBox3.Items.Count = 0 Then
            Label6.Text = "Keine Daten zum Einlesen vorhanden."
            Label6.Visible = True
            Exit Sub
        End If


        For NACHRICHTENTYP = 1 To 10 'Nach Nachrichtentyp abarbeteiten

            For Each d In System.IO.Directory.GetFiles(VERARBEITUNGS_PFAD)
                Try
                    Dateiname = d
                    cWorker_NCTS.Dateiname = d
                    If System.IO.File.Exists(d) Then
                        Dim found = False
                        Dim nr_id As Integer = -1
                        Dim fi As FileInfo = New FileInfo(d)
                        If Not fi.Name.StartsWith(".") Then


                            '   EDIFACT
                            ' If fi.Extension = ".edi" Then
                            Dim alreadyMoved = False

                            Dim NACHRICHTENTYP_notfound = False

                            If fi.Extension.ToLower = ".xml" Then
                                Dim xmlWriterSettings As XmlWriterSettings = New XmlWriterSettings With {.Encoding = System.Text.Encoding.UTF8, .CheckCharacters = True}

                                Dim doc As New XmlDocument()
                                Dim XML_Code = System.IO.File.ReadAllText(d, System.Text.UTF8Encoding.Default)

                                doc.LoadXml(SanitizeXmlString(XML_Code))
                                Dim VERSION As String = ""

                                '------------------------------------------------------------------------------------------------------------------------------
                                '                                                                  eZOLL
                                '------------------------------------------------------------------------------------------------------------------------------


                                '------------------------------------------
                                '------------------ Anmeldung ------------------
                                '------------------------------------------
                                'MAVI: CC015B - Versandanmeldung Final

                                Select Case NACHRICHTENTYP
                                    Case 1
                                        'NCTS: Versandanmeldung
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_VersandanmeldungXML_CC015B(doc) Then
                                            If cATEZWorker.readNCTS_VersandanmeldungXML_CC015B(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If

                                    Case 2
                                        'NCTS: Versandanmeldung - Ergänzung GUID
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_VersandanmeldungXML_CC015B_RES(doc) Then
                                            If cATEZWorker.readNCTS_VersandanmeldungXML_CC015B_RES(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If
                                    Case 3
                                        'NCTS: BestätigungZoll
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_BestaetigungZollXML_CC029B(doc) Then
                                            If cATEZWorker.readNCTS_BestaetigungZollXML_CC029B(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If
                                    Case 4
                                        'NCTS: Guarantee
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_BestaetigungZollXML_GUA_INF(doc) Then
                                            If cATEZWorker.readNCTS_BestaetigungZollXML_GUA_INF(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If
                                    Case 5
                                        'NCTS: Ankunftsanzeige
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_BestaetigungZollXML_ARR_INF(doc) Then
                                            If cATEZWorker.readNCTS_BestaetigungZollXML_ARR_INF(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If

                                    Case 6
                                        'NCTS: Erledigungsmitteilung
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_ErledigungsmitteilungXML_CC045A(doc) Then
                                            If cATEZWorker.readNCTS_ErledigungsmitteilungXML_CC045A(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If

                                    Case 7
                                        'NCTS: Cancellation decision  CC009A
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_AbbruchXML_CC009A(doc) Then
                                            If cATEZWorker.readNCTS_AbbruchXML_CC009A(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If
                                    Case 8
                                        'NCTS: Declaration rejected CC016A
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_RueckweisungXML_CC016A(doc) Then
                                            If cATEZWorker.readNCTS_RueckweisungXML_CC016A(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If
                                    Case 9
                                        'NCTS: No release for transit – type B CC051B
                                        If Not found And cNCTSPartnerWorker.cMAVIGetMsgType.isTRNCTS_KeineFreigabeXML_CC051B(doc) Then
                                            If cATEZWorker.readNCTS_KeineFreigabeXML_CC051B(PARTNERSYSTEM, Me, doc, nr_id) <> "" Then found = True
                                        End If

                                    Case 10
                                        NACHRICHTENTYP_notfound = True ' alle nciht zu verarbeitenden
                                End Select
                            End If


                            Dim destPath = ""
                            If found Then
                                If Not System.IO.Directory.Exists(ZIEL_PFAD & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\") Then System.IO.Directory.CreateDirectory(ZIEL_PFAD & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
                                frmStartOptions.moveFile(d, ZIEL_PFAD & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\", destPath)
                                cntDatenEingelesen += 1
                            Else
                                If NACHRICHTENTYP_notfound Then
                                    frmStartOptions.moveFile(d, ERROR_PFAD, destPath) ' nciht gefunden, oder durch ERROR nicht eingearbt,.
                                    dsNichtErkannt += 1
                                End If
                            End If

                            If destPath <> "" And nr_id > 0 Then
                                VERAG_PROG_ALLGEMEIN.cNCTS_TR_Nachrichten.updatePath(nr_id, destPath)
                            End If

                            '   If found Then Else dsNichtErkannt += 1

                            Me.Refresh()
                        End If
                    End If
                Catch ex As Exception
                    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
                End Try
            Next


        Next

    End Sub



    Function getString(doc As XmlDocument) As Boolean
        If doc.HasChildNodes Then
            '  If doc.GetElementsByTagName("DakosyMessageInternal").Count > 0 Then
            Dim sw = New StringWriter()
            Dim xw = New XmlTextWriter(sw)
            doc.WriteTo(xw)
            Dim XmlString = sw.ToString()
        End If
        Return False
    End Function



    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        Me.Close()
    End Sub

    Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
        Me.Close()
    End Sub



    Sub addDGVEinarbeitung(art, BezugsNr)
        dgvEinarbeitung.Rows.Add(art, BezugsNr)
        Try
            dgvEinarbeitung.FirstDisplayedScrollingRowIndex = dgvEinarbeitung.RowCount - 1
        Catch ex As Exception
        End Try
    End Sub






    Function readPLOSE_Detail(d As String) As String
        '    Try
        '        readPLOSE_Detail = ""
        '        Dim KdnR = ""

        '        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(d, Encoding.UTF8)
        '            MyReader.TextFieldType = FileIO.FieldType.Delimited
        '            MyReader.SetDelimiters(";")
        '            Dim currentRow As String()

        '            Dim cnt = 0
        '            If True Then

        '                While Not MyReader.EndOfData
        '                    Try
        '                        currentRow = MyReader.ReadFields()


        '                        If currentRow.Length > 24 Then
        '                            Dim PLOSE As New cNCTSPartnerWorker.cPLOSE


        '                            PLOSE.plose_Datensatztyp = SQL.isleernothing(currentRow(0))
        '                            PLOSE.plose_KodexMautTankstelle = SQL.isleernothing(currentRow(1))
        '                            PLOSE.plose_BeschreibungMautTankstelle = SQL.isleernothing(currentRow(2))
        '                            PLOSE.plose_KodexEinfahrt = SQL.isleernothing(currentRow(3))
        '                            PLOSE.plose_BeschreibungEinfahrt = SQL.isleernothing(currentRow(4))
        '                            PLOSE.plose_KodexAusfahrt = SQL.isleernothing(currentRow(5))
        '                            PLOSE.plose_BeschreibungAusfahrt = SQL.isleernothing(currentRow(6))
        '                            PLOSE.plose_Kartenkodex = SQL.isleernothing(currentRow(7))
        '                            PLOSE.plose_Kontonummer = SQL.isleernothing(currentRow(8))
        '                            PLOSE.plose_NummerKarteGeraet = SQL.isleernothing(currentRow(9))
        '                            PLOSE.plose_Kennzeichen = SQL.isleernothing(currentRow(10))
        '                            PLOSE.plose_InterneNrFahrzeug = SQL.isleernothing(currentRow(11))
        '                            PLOSE.plose_POLSEKundennummer = SQL.isleernothing(currentRow(12))
        '                            PLOSE.plose_Firmenname = SQL.isleernothing(currentRow(13))
        '                            PLOSE.plose_DatumTransaktion = SQL.isleernothingDateFormatstring(currentRow(14))
        '                            PLOSE.plose_Produktbeschreibung = SQL.isleernothing(currentRow(15))
        '                            PLOSE.plose_Menge = SQL.isNullNothingDbl(currentRow(16))
        '                            PLOSE.plose_Preis = SQL.isNullNothingDbl(currentRow(17))
        '                            PLOSE.Einheitsrabatt = SQL.isleernothing(currentRow(18))
        '                            PLOSE.plose_NettobetragTransaktion = SQL.isNullNothingDbl(currentRow(19))
        '                            PLOSE.plose_MWSTBetrag = SQL.isNullNothingDbl(currentRow(20))
        '                            PLOSE.plose_BruttobetragTransaktion = SQL.isNullNothingDbl(currentRow(21))
        '                            PLOSE.plose_NettobetragWaehrungAbbuchung = SQL.isNullNothingDbl(currentRow(22))
        '                            PLOSE.plose_MWSTBetragWaehrungAbbuchung = SQL.isNullNothingDbl(currentRow(23))
        '                            PLOSE.plose_BruttobetragWaehrungAbbuchung = SQL.isNullNothingDbl(currentRow(24))
        '                            PLOSE.plose_WaehrungLandDiesntleistung = SQL.isleernothing(currentRow(25))
        '                            PLOSE.plose_WaehrungAbbuchung = SQL.isleernothing(currentRow(26))
        '                            PLOSE.plose_DokumentNrQuittungUhrzeit = SQL.isleernothing(currentRow(27))
        '                            PLOSE.plose_ArtTransaktion = SQL.isleernothing(currentRow(28))
        '                            PLOSE.plose_Fahrzeugklasse = SQL.isleernothing(currentRow(29))
        '                            PLOSE.plose_KlassenidentifikationEURO = SQL.isleernothing(currentRow(30))
        '                            PLOSE.plose_ProduktbeschreibungShort = SQL.isleernothing(currentRow(31))
        '                            PLOSE.plose_DokumentNrQuittungUhrzeit = SQL.isleernothing(currentRow(32))
        '                            PLOSE.plose_Geraetetyp = SQL.isleernothing(currentRow(33))
        '                            PLOSE.plose_ProduktCode = SQL.isleernothing(currentRow(34))
        '                            PLOSE.plose_ReferenzenBuchungMaut = SQL.isleernothing(currentRow(35))

        '                            ''''''''''''
        '                            If PLOSE.SAVE() Then

        '                            End If

        '                        End If

        '                        cnt += 1

        '                        'For Each currentField In currentRow
        '                        'Next
        '                    Catch ex As Exception
        '                        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '                    End Try
        '                End While


        '                'Label30.Text = (cnt + 1) & " / " & LineCount
        '                'Label31.Visible = True
        '                readPLOSE_Detail = "Zeilen: " & cnt
        '            Else
        '                MsgBox("FEHLER beim Löschen der vorhandenen OP-Liste.")
        '            End If
        '        End Using




        '        Try
        '            '  System.IO.File.Delete(p)
        '        Catch ex As Exception
        '            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '        End Try

        '        addDGVEinarbeitung("PLOSE: Detail" & KdnR, readPLOSE_Detail)

        '        '    End Using

        '        'End If

        '    Catch ex As Exception
        '        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '        MsgBox(ex.StackTrace & ex.Message)
        '        readPLOSE_Detail = ""
        '    End Try
    End Function


    Private Sub dgvEinarbeitung_SelectionChanged(sender As Object, e As EventArgs) Handles dgvEinarbeitung.SelectionChanged
        dgvEinarbeitung.ClearSelection()

    End Sub






    Private Sub frmTCNachrichtenVerarbeitung_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        If allowClose Then
            Me.Refresh()

            Button2.PerformClick()
            Button1.PerformClick()

            System.Threading.Thread.Sleep(2000)

            Me.Close()
        End If
    End Sub

    Private Sub pnl_Paint(sender As Object, e As PaintEventArgs) Handles pnl.Paint

    End Sub
End Class

