Public Class cVERAG_out_eza
    Shared SQL As New VERAG_PROG_ALLGEMEIN.SQL


    Shared GLO_EZA_DY As DAKOSY_Worker.cDakosyEZA = Nothing
    Shared GLO_DY As DAKOSY_Worker.cDakosy_Zollanmeldungen = Nothing
    Shared GLO_EZA_TC As TELOTEC_Worker.cTelotec_Anmeldung = Nothing

    Shared GLO_AVISO As VERAG_PROG_ALLGEMEIN.cAviso = Nothing
    Shared GLO_SND As VERAG_PROG_ALLGEMEIN.cSendungen = Nothing
    Shared cVERAG_Interface_Settings As New cVERAG_Interface_Settings 'defalut: Alles true

    'Shared Function copyFileFTP_OLD(EZA_TMP As DAKOSY_Worker.cDakosyEZa, DY_TMP As DAKOSY_Worker.cDakosy_Zollanmeldungen) ', filePath As String)
    '    Try
    '        If EZA_TMP Is Nothing Then Return False
    '        If EZA_TMP.EZA_ObjectName Is Nothing Then Return False
    '        If EZA_TMP.EZA_ObjectName.ToString.StartsWith("DU") Then Return False
    '        If EZA_TMP.EZA_firma.ToString = "DURMAZ" Then Return False

    '        Dim filePath = SQL.getValueTxtBySql("select [dySt_pfad] from [tblDakosy_Statusmeldungen] where dySt_BezugsNr='" & EZA_TMP.EZA_ObjectName & "' and [dySt_status]=5 and [dySt_pfad] is not null ", "FMZOLL")
    '        If filePath = "" Then Return False

    '        EZA_TMP.LOAD_Sicherheitsangaben()
    '        If EZA_TMP.EZA_SICHERHEITSANGABEN IsNot Nothing AndAlso EZA_TMP.EZA_SICHERHEITSANGABEN.Count > 0 Then
    '            Dim GRN = EZA_TMP.EZA_SICHERHEITSANGABEN(0).EZASA_GRN
    '            Dim destFile = ""
    '            Select Case GRN
    '                                ' --> FTP Bereitstellung
    '            '\\192.168.0.91\Datenarchiv\DAKOSY\ECHTSYSTEM\FTP\TOBB
    '                Case "15TR0004000020917", "12TR0004000004665", "17TR0004000032349", "17TR0004000029518"
    '                    frmStartOptions.copyFile(filePath, "\\ftps.verag.ag\FTP\TOBB\OUT\", destFile)
    '                    If IO.File.Exists(destFile) Then insertFTPLOG(destFile, "TOBB") Else VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Datei existiert nicht: " & destFile & vbNewLine & EZA_TMP.EZA_ObjectName, "", "copyFileFTP")
    '                Case "18DE0000000073276", "19DE0000000075520", "18DE0000000075520"
    '                    frmStartOptions.copyFile(filePath, "\\ftps.verag.ag\FTP\OREGON\OUT\", destFile)
    '                    If IO.File.Exists(destFile) Then insertFTPLOG(destFile, "OREGON") Else VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Datei existiert nicht: " & destFile & vbNewLine & EZA_TMP.EZA_ObjectName, "", "copyFileFTP")
    '                Case "17DE0000000071678", "05AT510000G000FP7" 'VERAG
    '                    frmStartOptions.copyFile(filePath, VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\ECHTSYSTEM\FTP\VERAG\", destFile)
    '                    If IO.File.Exists(destFile) Then insertFTPLOG(destFile, "VERAG") Else VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Datei existiert nicht: " & destFile & vbNewLine & EZA_TMP.EZA_ObjectName, "", "copyFileFTP")
    '            End Select
    '        End If
    '        Return True
    '    Catch ex As Exception
    '        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.EZA_ObjectName, System.Reflection.MethodInfo.GetCurrentMethod.Name)
    '        Return False
    '    End Try
    'End Function



    Shared Function copyFileFTP_VERAGEZA_DY_ByBezugsNr(BezugsNr As String, ISett As cVERAG_Interface_Settings) As Boolean
        cVERAG_Interface_Settings = ISett
        Dim DY_TMP = DAKOSY_Worker.cDakosy_Zollanmeldungen.LOADByBezugsNr(BezugsNr)
        Dim EZA_TMP = DAKOSY_Worker.cDakosyEZA.LOADByBezugsNr(BezugsNr, True)
        If DY_TMP Is Nothing Then Return False
        If EZA_TMP Is Nothing Then Return False
        Return copyFileFTP_VERAGEZA_DY(EZA_TMP, DY_TMP, False)
    End Function


    Shared Function copyFileFTP_VERAGEZA_DY(EZA_TMP As DAKOSY_Worker.cDakosyEZA, DY_TMP As DAKOSY_Worker.cDakosy_Zollanmeldungen, Optional checkAlreadyProvided As Boolean = True) As Boolean
        Try
            If EZA_TMP Is Nothing Then Return False
            If EZA_TMP.eza_ObjectName Is Nothing Then Return False
            If EZA_TMP.eza_ObjectName.ToString.StartsWith("DU") Then Return False
            If If(EZA_TMP.eza_firma, "").ToString = "DURMAZ" Then Return False

            GLO_EZA_DY = EZA_TMP
            GLO_DY = DY_TMP

            GLO_SND = Nothing
            GLO_AVISO = Nothing

            If DY_TMP.dy_SendungsId IsNot Nothing AndAlso DY_TMP.dy_SendungsId > 0 Then
                GLO_SND = New VERAG_PROG_ALLGEMEIN.cSendungen(DY_TMP.dy_SendungsId)
            End If

            If DY_TMP.dy_AvisoId IsNot Nothing AndAlso DY_TMP.dy_AvisoId > 0 Then
                GLO_AVISO = VERAG_PROG_ALLGEMEIN.cAviso.getAvisoById(DY_TMP.dy_AvisoId)
            End If


            ' Dim filePath = SQL.getValueTxtBySql("select [dySt_pfad] from [tblDakosy_Statusmeldungen] where dySt_BezugsNr='" & EZA_TMP.EZA_ObjectName & "' and [dySt_status]=5 and [dySt_pfad] is not null ", "FMZOLL")



            Dim destFile = ""
            Dim filePath = ""
            Dim UniqueId = ""
            ' --> FTP Bereitstellung
            '  Dim VERAG_OUT_EZA As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza = Nothing

            Dim found As Boolean = False
            Dim vorsystem = "DY"
            Dim IF_Obj As New List(Of cVERAG_InterfaceSharedObjects)

            If getFTP_Paths(IF_Obj) Then

                For Each o In IF_Obj
                    Select Case o.CooName
                        '  Case "EKOL"
                        Case Else
                            Dim VERAG_OUT_EZA = genVERAG_OUT_EZA_FromDAKOSY(EZA_TMP, DY_TMP, UniqueId)
                            copyEZAToFTP(VERAG_OUT_EZA, o, vorsystem, filePath, destFile, UniqueId, checkAlreadyProvided, found)
                    End Select
                Next
            End If


            Return found
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.eza_ObjectName, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            Return False
        End Try
    End Function

    Shared Function copyFileFTP_VERAGEZA_TC_ByBezugsNr(BezugsNr As String, ISett As cVERAG_Interface_Settings) As Boolean
        cVERAG_Interface_Settings = ISett
        Dim EZA_TMP = TELOTEC_Worker.cTelotec_Anmeldung.LOAD_ByBezugsNr(BezugsNr)
        If EZA_TMP Is Nothing Then Return False
        Return copyFileFTP_VERAGEZA_TC(EZA_TMP, False)
    End Function

    Shared Function copyFileFTP_VERAGEZA_TC(EZA_TMP As TELOTEC_Worker.cTelotec_Anmeldung, Optional checkAlreadyProvided As Boolean = True) As Boolean
        Return False
        'Try
        '    If EZA_TMP Is Nothing Then Return False
        '    If EZA_TMP.telanm_BezugsNr Is Nothing Then Return False
        '    'If EZA_TMP.telanm_firma.ToString = "DURMAZ" Then Return False
        '    'Select Case EZA_TMP.telanm_ART
        '    '    Case "T1", "T2", "T2L", "T-"
        '    '    Case Else
        '    '        Return False
        '    'End Select

        '    GLO_SND = Nothing
        '    GLO_AVISO = Nothing
        '    GLO_EZA_TC = EZA_TMP

        '    If EZA_TMP.telanm_SendungsId IsNot Nothing AndAlso EZA_TMP.telanm_SendungsId > 0 Then
        '        GLO_SND = New VERAG_PROG_ALLGEMEIN.cSendungen(EZA_TMP.telanm_SendungsId)
        '    End If

        '    If EZA_TMP.telanm_AvisoId IsNot Nothing AndAlso EZA_TMP.telanm_AvisoId > 0 Then
        '        GLO_AVISO = VERAG_PROG_ALLGEMEIN.cAviso.getAvisoById(EZA_TMP.telanm_AvisoId)
        '    End If

        '    ' Dim filePath = SQL.getValueTxtBySql("select [dySt_pfad] from [tblDakosy_Statusmeldungen] where dySt_BezugsNr='" & EZA_TMP.EZA_ObjectName & "' and [dySt_status]=5 and [dySt_pfad] is not null ", "FMZOLL")

        '    '  EZA_TMP.LOAD_Sicherheitsangaben()

        '    Dim destFile = ""
        '    Dim filePath = ""
        '    Dim UniqueId = ""

        '    ' --> FTP Bereitstellung
        '    'Dim VERAG_OUT_EZA As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza = Nothing
        '    Dim found As Boolean = False
        '    Dim vorsystem = "TC"

        '    Dim IF_Obj As New List(Of cVERAG_InterfaceSharedObjects)
        '    If getFTP_Paths(IF_Obj) Then
        '        For Each o In IF_Obj
        '            Select Case o.CooName
        '                '  Case ""
        '                Case Else
        '                    Dim VERAG_OUT_EZA = genVERAG_OUT_EZA_FromTELOTEC(EZA_TMP, UniqueId)
        '                    copyEZAToFTP(VERAG_OUT_EZA, o, vorsystem, filePath, destFile, UniqueId, checkAlreadyProvided, found)
        '            End Select
        '        Next
        '    End If



        '    Return found
        'Catch ex As Exception
        '    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.telanm_BezugsNr, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '    Return False
        'End Try
    End Function

    Shared Sub copyEZAToFTP(ByRef VERAG_OUT_EZA As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza, IF_Obj As cVERAG_InterfaceSharedObjects, ByRef vorsystem As String, ByRef filePath As String, ByRef destFile As String, ByRef UniqueId As String, Optional checkAlreadyProvided As Boolean = True, ByRef Optional found As Boolean = False)
        If VERAG_OUT_EZA IsNot Nothing AndAlso Not alreadyProvidedInInterface(VERAG_OUT_EZA.ProcessData.ReferenzNumber, VERAG_OUT_EZA.ProcessData.ProcedureCode, VERAG_OUT_EZA.ProcessData.Status, vorsystem, IF_Obj.CooName, checkAlreadyProvided) Then
            If genXMLFile(VERAG_OUT_EZA, filePath, vorsystem, UniqueId) <> "" Then

                If Not System.IO.File.Exists(destFile) Then frmStartOptions.copyFile(filePath, IF_Obj.FTP_Path, destFile)
                If System.IO.File.Exists(destFile) Then
                    insertFTPLOG(destFile, IF_Obj.CooName, VERAG_OUT_EZA.ProcessData.ReferenzNumber, VERAG_OUT_EZA.ProcessData.ProcedureCode, VERAG_OUT_EZA.ProcessData.Status, vorsystem)
                    found = True
                Else
                    Try
                        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Datei existiert nicht: " & destFile, "", "copyEZAToFTP",,,,, VERAG_OUT_EZA.ProcessData.ReferenzNumber)
                    Catch
                        VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR("Datei existiert nicht: " & destFile, "", "copyEZAToFTP")
                    End Try
                End If
            End If
        End If

    End Sub

    Shared Function copyFileFTP_VERAGEZA_EZOLL_ByBezugsNr(LRN As String, ISett As cVERAG_Interface_Settings) As Boolean
        cVERAG_Interface_Settings = ISett
        Dim AnmId = SQL.getValueTxtBySql("SELECT TOP 1 AnmId  FROM zsAnmRefs WHERE (VorgangID = 'AV') AND (LRN = '" & LRN & "')", "EZOLL")
        If AnmId = "" Then Return False
        Return copyFileFTP_VERAGEZA_EZOLL(AnmId, False)
    End Function

    Shared Function copyFileFTP_VERAGEZA_EZOLL(AnmId As String, Optional checkAlreadyProvided As Boolean = True) As Boolean
        Return False
        'Dim LRN = ""
        'Try

        '    Dim dEZOLL As DataTable = SQL.loadDgvBySql("SELECT LizenzNr, OperatorID, VorgangID, AnmID, GeaendertAm, GeaendertVon, CRN, LRN" &
        '            " FROM zsAnmRefs" &
        '            " WHERE (VorgangID = 'AV') AND (AnmId = '" & AnmId & "')" &
        '            " ORDER BY GeaendertAm DESC", "EZOLL")


        '    If dEZOLL Is Nothing Then Return False
        '    If dEZOLL.Rows.Count <= 0 Then Return False
        '    'If EZA_TMP.telanm_firma.ToString = "DURMAZ" Then Return False



        '    GLO_SND = Nothing
        '    GLO_AVISO = Nothing


        '    LRN = dEZOLL.Rows(0)("LRN")
        '    Select Case SQL.getValueTxtBySql("SELECT TOP 1 DecTy  FROM zsAnmHea WHERE (VorgangID = 'AV') AND (AnmId = '" & AnmId & "')", "EZOLL")
        '        Case "T1", "T2", "T2L", "T-"
        '        Case Else
        '            Return False
        '    End Select

        '    ' Tabelle zsAnmGrteeGrteeRef lesen.
        '    Dim destFile = ""
        '    Dim filePath = ""
        '    Dim UniqueId = ""

        '    ' --> FTP Bereitstellung
        '    Dim found As Boolean = False
        '    Dim vorsystem = "DHF"
        '    Dim IF_Obj As New List(Of cVERAG_InterfaceSharedObjects)
        '    If getFTP_Paths(IF_Obj) Then
        '        For Each o In IF_Obj
        '            Select Case o.CooName
        '                ' Case "EKOL"
        '                Case Else
        '                    Dim VERAG_OUT_EZA = genVERAG_OUT_EZA_FromEZOLLByAnmId(AnmId, UniqueId)
        '                    copyEZAToFTP(VERAG_OUT_EZA, o, vorsystem, filePath, destFile, UniqueId, checkAlreadyProvided, found)
        '            End Select
        '        Next
        '    End If



        '    Return found
        'Catch ex As Exception
        '    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & LRN, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '    Return False
        'End Try
    End Function


    Shared Function getFTP_Paths(ByRef IF_Obj As List(Of cVERAG_InterfaceSharedObjects)) As Boolean
        IF_Obj = New List(Of cVERAG_InterfaceSharedObjects)
        Try

            If cVERAG_Interface_Settings.acticeInterface_VERAG Then IF_Obj.Add(New cVERAG_InterfaceSharedObjects(VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "DAKOSY\ECHTSYSTEM\FTP\VERAG\", "VERAG"))

            Return True

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            Return False
        End Try
    End Function


    Shared Function isFTP_TEST_EZA() As Boolean
        Try
            If GLO_AVISO IsNot Nothing Then ' AndAlso GLO_AVISO.Frächter_KdNr > 0 Then ' FRÄCHTER,AVISIERER
                If GLO_AVISO.Frächter.ToUpper.StartsWith("IBRAH") Then Return True
                If GLO_AVISO.Auftraggeber.ToUpper.StartsWith("IBRAH") Then Return True
            End If

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return False
    End Function

    Shared Function alreadyProvidedInInterface(ReferenzNumber As String, ProcedureCode As String, Status As String, vorsystem As String, ftp_CooName As String, Optional checkAlreadyProvided As Boolean = True) As Boolean
        If Not checkAlreadyProvided Then Return False ' wenn es nicht geprüft werden soll, dann wird "Nicht bereitgestellt" zurückgegeben
        Try
            'Return SQL.doSQL("INSERT INTO tblFTP_Log (ftp_filepath,ftp_user,ftp_BezugsNr,ftp_art,ftp_status,ftp_vorsystem) VALUES ('" & filePath & "','" & user & "','" & VERAG_OUT_EZA.ProcessData.ReferenzNumber & "','" & VERAG_OUT_EZA.ProcessData.ProcedureCode & "','" & VERAG_OUT_EZA.ProcessData.Status & "','')", "FMZOLL")
            If SQL.getValueTxtBySql("SELECT count(*)  FROM  [tblFTP_Log]  where [ftp_BezugsNr]='" & ReferenzNumber & "' AND [ftp_art]='" & ProcedureCode & "' AND [ftp_status]='" & Status & "' AND [ftp_vorsystem]='" & vorsystem & "' AND [ftp_CooName]='" & ftp_CooName & "'   ", "FMZOLL",,, 0, 15) = 0 Then
                Return False
            End If
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return True
    End Function

    Shared Function genXMLFile(VERAG_EZA As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza, ByRef XMLFilePath As String, Code As String, UniqueId As String) As String
        Try
            If XMLFilePath = "" Then
                Dim dir = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "ZOLL_SCHNITTSTELLEN\VERAG\EZA_OUT\" & Code & "\" & Now.Year & "\" & Now.ToShortDateString & "\"
                If Not System.IO.Directory.Exists(dir) Then System.IO.Directory.CreateDirectory(dir)
                XMLFilePath = dir & "VERAG_EZA_OUT_" & Now.ToString("ddMMyyyHHmmss") & "_" & Code & "_" & UniqueId & ".xml"
                While System.IO.File.Exists(XMLFilePath)
                    XMLFilePath = dir & "VERAG_EZA_OUT_" & Now.ToString("ddMMyyyHHmmssffff") & "_" & Code & "_" & UniqueId & ".xml"
                End While
            End If
            If VERAG_EZA IsNot Nothing Then
                VERAG_EZA.SaveToFile(XMLFilePath)
                removeTypeFromXML(XMLFilePath) ' Type-Attribute entfernen
            End If
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return XMLFilePath
    End Function

    Shared Function removeTypeFromXML(XMLFilePath) As String
        Try
            Dim fileContents = System.IO.File.ReadAllText(XMLFilePath)
            fileContents = fileContents.Replace(" xsi:type=""xsd:string""", "")
            fileContents = fileContents.Replace(" xsi:type=""xsd:dateTime""", "")
            fileContents = fileContents.Replace(" xsi:type=""xsd:decimal""", "")
            fileContents = fileContents.Replace(" xsi:type=""xsd:int""", "")
            System.IO.File.WriteAllText(XMLFilePath, fileContents)
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return XMLFilePath
    End Function


    Shared Function genVERAG_OUT_EZA_FromDAKOSY(EZA_TMP As DAKOSY_Worker.cDakosyEZA, DY_TMP As DAKOSY_Worker.cDakosy_Zollanmeldungen, ByRef UniqueId As String) As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        Dim VERAG_EZA As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        Try
            If DY_TMP Is Nothing Then Return Nothing
            If EZA_TMP Is Nothing Then Return Nothing
            If EZA_TMP.eza_ObjectName Is Nothing Then Return Nothing
            EZA_TMP.LOAD_Warenposition()

            VERAG_EZA.Version = "1.0.0" ' Automaitsch, weil default ' doch nicht?

            If EZA_TMP.eza_firma <> "" Then
                VERAG_EZA.Company = EZA_TMP.eza_firma
            Else
                VERAG_EZA.Company = "VERAG"
            End If
            VERAG_EZA.Department = EZA_TMP.eza_niederlassung

            'VERAG_EZA.InternalReference.OfficeCode = If(
            'VERAG_EZA.InternalReference.PositionNumber = EZA_TMP.EZA_niederlassung

            Select Case DY_TMP.dy_Status
                Case < 50
                    VERAG_EZA.ProcessData.Status = 0
                Case 50, 53
                    VERAG_EZA.ProcessData.Status = 50
                Case 60
                    VERAG_EZA.ProcessData.Status = 60
            End Select
            If GLO_SND IsNot Nothing Then
                VERAG_EZA.InternalReference.OfficeCode = GLO_SND.FilialenNr
                VERAG_EZA.InternalReference.PositionNumber = GLO_SND.AbfertigungsNr

                VERAG_EZA.EZA_Data.Sender.Name = GLO_SND.tblSnd_Absender
                VERAG_EZA.EZA_Data.Consignee.Name = GLO_SND.tblSnd_Empfaenger

            End If

            If GLO_AVISO IsNot Nothing Then
                VERAG_EZA.EZA_Data.LicensePlateContainerNo = GLO_AVISO.LKW_Nr


            End If

            VERAG_EZA.ProcessData.TransactionDate = EZA_TMP.eza_Trans_DatumZeit
            VERAG_EZA.ProcessData.ReferenzNumber = EZA_TMP.eza_ObjectName
            VERAG_EZA.ProcessData.CustomsReferenzNumber = EZA_TMP.eza_ANR
            VERAG_EZA.EZA_Data.SumGrossWeight = If(EZA_TMP.eza_GesamtRohmasse, "0")

            VERAG_EZA.ProcessData.ReferenzNumber = If(EZA_TMP.eza_ObjectName, "")
            '   VERAG_EZA.ProcessData.ProcedureCode = If(EZA_TMP.eza_AnmeldungArt, "") ______-----> ART

            'VERAGCustomerCode


            If VERAG_EZA.EZA_Data.LicensePlateContainerNo Is Nothing Then VERAG_EZA.EZA_Data.LicensePlateContainerNo = If(EZA_TMP.eza_BeförderungsmittelGrenze, "")

            If EZA_TMP.eza_AdressierteZollstelle IsNot Nothing Then VERAG_EZA.EZA_Data.DestinationCustomsOffice = "DE00" & EZA_TMP.eza_AdressierteZollstelle
            VERAG_EZA.EZA_Data.DepartureCountry = If(EZA_TMP.eza_VersendungsLandCode, "")
            VERAG_EZA.EZA_Data.DestinationCountry = If(EZA_TMP.eza_Bestimmungsland, "")



            ''Versender
            'VERAG_EZA.EZA_Data.Sender.Name = If(EZA_TMP.EZA_Versender_Name, "")
            'VERAG_EZA.EZA_Data.Sender.EORI = If(EZA_TMP.EZA_Versender_EORI, "")
            'VERAG_EZA.EZA_Data.Sender.EORI_NL = If(EZA_TMP.EZA_Versender_NLNR, "")
            ''VERAG_EZA.EZA_Data.Sender.UID_Nr = If(EZA_TMP.vers, "")
            'VERAG_EZA.EZA_Data.Sender.Adress.Country = If(EZA_TMP.EZA_Versender_Land, "")
            'VERAG_EZA.EZA_Data.Sender.Adress.Postcode = If(EZA_TMP.EZA_Versender_PLZ, "")
            'VERAG_EZA.EZA_Data.Sender.Adress.Street = If(EZA_TMP.EZA_Versender_StrasseHausnummer, "")
            'VERAG_EZA.EZA_Data.Sender.Adress.City = If(EZA_TMP.EZA_Versender_Ort, "")

            ''Empfänger
            'VERAG_EZA.EZA_Data.Consignee.Name = If(EZA_TMP.EZA_Empfaenger_Name, "")
            'VERAG_EZA.EZA_Data.Consignee.EORI = If(EZA_TMP.EZA_Empfaenger_EORI, "")
            'VERAG_EZA.EZA_Data.Consignee.EORI_NL = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
            ''VERAG_EZA.EZA_Data.Consignee.UID_Nr = If(EZA_TMP.vers, "")
            'VERAG_EZA.EZA_Data.Consignee.Adress.Country = If(EZA_TMP.EZA_Empfaenger_Land, "")
            'VERAG_EZA.EZA_Data.Consignee.Adress.Postcode = If(EZA_TMP.EZA_Empfaenger_PLZ, "")
            'VERAG_EZA.EZA_Data.Consignee.Adress.Street = If(EZA_TMP.EZA_Empfaenger_StrasseHausnummer, "")
            'VERAG_EZA.EZA_Data.Consignee.Adress.City = If(EZA_TMP.EZA_Empfaenger_Ort, "")

            For Each ABG In EZA_TMP.eza_AUFSCHUB
                If ABG.ezaAfb_Abgabenbetrag IsNot Nothing AndAlso ABG.ezaAfb_Abgabenbetrag > 0 Then
                    Dim V_ABG As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaEZA_DataDuty
                    '   V_ABG.Kind = ABG.ezaAfb_ArtAufschubantrag
                    V_ABG.EORI = ABG.ezaAfb_AufschubnehmerEORI
                    V_ABG.AccountNumber = ABG.ezaAfb_KontoNr

                    Select Case ABG.ezaAfb_ArtAufschubantrag
                        Case "A0000"
                            V_ABG.Kind = "01" ' ZOLL
                        Case "B0000"
                            V_ABG.Kind = "02"  'EUST
                    End Select
                End If
            Next

            Dim cntPos = 1
            If EZA_TMP.eza_WARENPOS IsNot Nothing Then
                For Each POS In EZA_TMP.eza_WARENPOS
                    Dim V_POS As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaEZA_DataPosition
                    V_POS.PosNr = cntPos

                    V_POS.Quantity = POS.ezaWP_PackstueckAnzahl
                    V_POS.Packaging = POS.ezaWP_PackstueckArt
                    V_POS.GrossWeight = POS.ezaWP_Rohmasse
                    V_POS.GoodsDescription = POS.ezaWP_Warenbezeichnung
                    'V_POS.DepartureCountry=POS.ezaWP_Aussenhandelsstatistik_Versendungsland

                    V_POS.TariffNumber = POS.ezaWP_WarennummerEZT

                    V_POS.GoodsValue.Value = POS.ezaWP_Artikelpreis

                    For Each UL In POS.ezaWP_UNTERLAGEN
                        If If(UL.ezaWpUl_Art, "") = "N380" Then 'Handelsrechnung
                            Dim V_DOC As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaEZA_DataPositionDocuments
                            V_DOC.Invoice.InvoiceNumber = UL.ezaWpUl_Nummer
                            V_DOC.Invoice.InvoiceDate = UL.ezaWpUl_DatumAusstellung
                        End If
                    Next
                    VERAG_EZA.EZA_Data.Position.Add(V_POS)
                    cntPos += 1
                Next
            End If

            If False Then
                Try
                    If DY_TMP.dy_VBD_dsId IsNot Nothing AndAlso IsNumeric(DY_TMP.dy_VBD_dsId) Then
                        Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER(DY_TMP.dy_VBD_dsId)
                        Dim Path = DS.GET_TOP1_PATH()
                        If Path <> "" And System.IO.File.Exists(Path) Then
                            Dim ATT As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaAttachment
                            '  ATT.DocumentType = VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaAttachmentDocumentType.EZA
                            ATT.FileType = "PDF"
                            ATT.Name = "EZA_VBD_" & If(VERAG_EZA.ProcessData.ProcedureCode, "") & ".pdf"
                            Convert.ToBase64String(System.IO.File.ReadAllBytes(Path))
                            'ATT.base64BinaryStream = Convert.ToBase64CharArray(System.IO.File.ReadAllBytes(Path))
                            ATT.base64BinaryStream = System.Text.Encoding.UTF8.GetBytes(System.Convert.ToBase64String(System.IO.File.ReadAllBytes(Path)))
                            VERAG_EZA.Attachments.Add(ATT)
                        End If
                    End If
                Catch ex As Exception
                    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.eza_ObjectName, System.Reflection.MethodInfo.GetCurrentMethod.Name)
                End Try

            End If
            'If XMLFilePath = "" Then
            '    Dim dir = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "ZOLL_SCHNITTSTELLEN\VERAG\EZA_OUT\DY\" & Now.Year & "\" & Now.ToShortDateString & "\"
            '    If Not IO.Directory.Exists(dir) Then IO.Directory.CreateDirectory(dir)
            '    XMLFilePath = dir & "VERAG_EZA_OUT_" & Now.ToString("ddMMyyyHHmmss") & "_DY_" & DY_TMP.dy_Id & ".xml"
            'End If

            UniqueId = DY_TMP.dy_Id
            'VERAG_EZA.SaveToFile(XMLFilePath)

        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.eza_ObjectName, System.Reflection.MethodInfo.GetCurrentMethod.Name)
            Return Nothing
        End Try
        Return VERAG_EZA

    End Function





    Shared Function genVERAG_OUT_EZA_FromEZOLLByLRN(LRN As String, ByRef UniqueId As String) As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza

        Dim dEZOLL As DataTable = SQL.loadDgvBySql("SELECT LizenzNr, OperatorID, VorgangID, AnmID, GeaendertAm, GeaendertVon, CRN, LRN" &
                    " FROM zsAnmRefs" &
                    " WHERE (VorgangID = 'AV') AND (LRN = '" & LRN & "')" &
                    " ORDER BY GeaendertAm DESC", "EZOLL")
        If dEZOLL Is Nothing Then Return Nothing
        If dEZOLL.Rows.Count = 0 Then Return Nothing

        Dim r As DataRow = dEZOLL.Rows(0)

        Return genVERAG_OUT_EZA_FromEZOLLByAnmId(r.Item("AnmID"), UniqueId)
    End Function

    Shared Function genVERAG_OUT_EZA_FromEZOLLByAnmId(AnmID As String, ByRef UniqueId As String) As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        Return Nothing
        'Dim VERAG_EZA As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        'Dim LRN = ""
        'Try

        '    VERAG_EZA.Version = "1.0.0" ' Automaitsch, weil default ' doch nicht?

        '    Dim Bestimmungszollstelle = ""
        '    Dim Bürgschaft = ""

        '    Dim dEZOLL As DataTable = SQL.loadDgvBySql("SELECT LizenzNr, OperatorID, VorgangID, AnmID, GeaendertAm, GeaendertVon, CRN, LRN" &
        '            " FROM zsAnmRefs" &
        '            " WHERE (VorgangID = 'AV') AND (AnmID = '" & AnmID & "')" &
        '            " ORDER BY GeaendertAm DESC", "EZOLL")

        '    If dEZOLL Is Nothing Then Return Nothing
        '    If dEZOLL.Rows.Count = 0 Then Return Nothing

        '    'TextBox2.ForeColor = Color.Green
        '    Dim r As DataRow = dEZOLL.Rows(0)

        '    LRN = r.Item("LRN")

        '    If Not SQL.IsNull(r.Item("OperatorID")) Then
        '        Select Case r.Item("OperatorID")
        '            Case "1"
        '                VERAG_EZA.Company = "VERAG"
        '                VERAG_EZA.Department = "SUB"
        '            Case "2"
        '                VERAG_EZA.Company = "VERAG"
        '                VERAG_EZA.Department = "SBG"

        '            Case "3"
        '                VERAG_EZA.Company = "VERAG"
        '                VERAG_EZA.Department = "NKD"
        '            Case "4", "5"
        '                VERAG_EZA.Company = "ATILLA"
        '                VERAG_EZA.Department = "SUB"
        '            Case "6"
        '                If LRN.StartsWith("4801") Then
        '                    VERAG_EZA.Company = "ATILLA"
        '                Else
        '                    VERAG_EZA.Company = "VERAG"
        '                End If
        '                VERAG_EZA.Department = "SUB"
        '            Case "8"
        '                VERAG_EZA.Company = "DURMAZ"
        '                VERAG_EZA.Department = "SBG"
        '                Return Nothing
        '            Case Else
        '                VERAG_EZA.Company = "ATILLA"
        '                VERAG_EZA.Department = "SUB"

        '        End Select
        '    End If


        '    If r.Item("GeaendertAm") IsNot DBNull.Value AndAlso IsDate(r.Item("GeaendertAm")) Then
        '        VERAG_EZA.ProcessData.TransactionDate = CDate(r.Item("GeaendertAm")) 'default
        '    Else
        '        VERAG_EZA.ProcessData.TransactionDate = Now.ToShortDateString
        '    End If

        '    VERAG_EZA.ProcessData.MRN = r.Item("CRN")
        '    VERAG_EZA.ProcessData.ReferenzNumber = LRN

        '    Select Case (SQL.getValueTxtBySql("SELECT ErledigungsTypID FROM zsAnmDHFRefs WHERE AnmID=" & AnmID & " ORDER BY GeaendertAm DESC", "EZOLL"))
        '        Case "F"
        '            VERAG_EZA.ProcessData.Status = 50
        '        Case "FB"
        '            VERAG_EZA.ProcessData.Status = 60
        '        Case Else
        '            VERAG_EZA.ProcessData.Status = 0
        '    End Select

        '    Dim DTzsAnmHea As DataTable = SQL.loadDgvBySql("SELECT * FROM zsAnmHea WHERE  (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmHea.Rows().Count > 0 Then
        '        Dim rDTzsAnmHea = DTzsAnmHea.Rows(0)
        '        VERAG_EZA.ProcessData.ProcedureCode = rDTzsAnmHea("DecTy")
        '        VERAG_EZA.EZA_Data.SumGrossWeight = rDTzsAnmHea("TotGross") 'If(EZA_TMP.EZA_GesamtRohmasse, "0")
        '        VERAG_EZA.ProcessData.TransactionDate = CDate(rDTzsAnmHea("DecDT"))
        '    End If



        '    VERAG_EZA.EZA_Data.DepartureCustomsOffice = SQL.isleernothing(SQL.getValueTxtBySql("SELECT Ref FROM zsAnmDepCO WHERE AnmID=" & AnmID & " ORDER BY GeaendertAm DESC", "EZOLL"))
        '    VERAG_EZA.EZA_Data.DatDeterminationLimit = SQL.isleernothing(SQL.getValueTxtBySql("SELECT DLimit FROM zsAnmCtrlRslt WHERE AnmID=" & AnmID & " ORDER BY GeaendertAm DESC", "EZOLL"))

        '    'BestimmungsstelleDienststelle
        '    Dim DTzsAnmDestCo As DataTable = SQL.loadDgvBySql("SELECT Ref  FROM zsAnmDestCo  WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmDestCo.Rows().Count > 0 Then
        '        If Not SQL.IsNull(DTzsAnmDestCo.Rows(0).Item("ref")) Then VERAG_EZA.EZA_Data.DestinationCustomsOffice = DTzsAnmDestCo.Rows(0).Item("ref")
        '    End If

        '    ' Kennzeichen
        '    Dim DTzsAnmTransp As DataTable = SQL.loadDgvBySql("SELECT DepIdnt  FROM zsAnmTransp WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmTransp.Rows().Count > 0 Then
        '        If Not SQL.IsNull(DTzsAnmTransp.Rows(0).Item("DepIdnt")) Then
        '            VERAG_EZA.EZA_Data.LicensePlate = DTzsAnmTransp.Rows(0).Item("DepIdnt")
        '        End If
        '    End If

        '    'Versender
        '    Dim DTzsAnmSender As DataTable = SQL.loadDgvBySql("SELECT * FROM [zsAnmConorTra]  WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmSender.Rows().Count > 0 Then
        '        'VERAG_EZA.EZA_Data.Sender.Name = DTzsAnmSender.Rows(0).Item("Na")
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("Na")) Then VERAG_EZA.EZA_Data.Consignee.Name = DTzsAnmSender.Rows(0).Item("Na")
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("Pst")) Then VERAG_EZA.EZA_Data.Sender.Adress.Postcode = DTzsAnmSender.Rows(0).Item("Pst")
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("Strt")) Then VERAG_EZA.EZA_Data.Sender.Adress.Street = DTzsAnmSender.Rows(0).Item("Strt")
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("Cty")) Then VERAG_EZA.EZA_Data.Sender.Adress.City = DTzsAnmSender.Rows(0).Item("Cty")
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("Ctry")) Then
        '            VERAG_EZA.EZA_Data.Sender.Adress.Country = DTzsAnmSender.Rows(0).Item("Ctry")
        '            VERAG_EZA.EZA_Data.DepartureCountry = DTzsAnmSender.Rows(0).Item("Ctry")
        '        End If
        '        If Not SQL.IsNull(DTzsAnmSender.Rows(0).Item("TIN")) Then VERAG_EZA.EZA_Data.Sender.EORI = DTzsAnmSender.Rows(0).Item("TIN")
        '        'VERAG_EZA.EZA_Data.Sender.EORI_NL = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '        'VERAG_EZA.EZA_Data.Sender.UID_Nr = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '    End If


        '    'Empfänger
        '    Dim DTzsAnmConeeTra As DataTable = SQL.loadDgvBySql("SELECT * FROM zsAnmConeeTra  WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmConeeTra.Rows().Count > 0 Then
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("Na")) Then VERAG_EZA.EZA_Data.Consignee.Name = DTzsAnmConeeTra.Rows(0).Item("Na")
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("Pst")) Then VERAG_EZA.EZA_Data.Consignee.Adress.Postcode = DTzsAnmConeeTra.Rows(0).Item("Pst")
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("Strt")) Then VERAG_EZA.EZA_Data.Consignee.Adress.Street = DTzsAnmConeeTra.Rows(0).Item("Strt")
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("Cty")) Then VERAG_EZA.EZA_Data.Consignee.Adress.City = DTzsAnmConeeTra.Rows(0).Item("Cty")
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("Ctry")) Then
        '            VERAG_EZA.EZA_Data.Consignee.Adress.Country = DTzsAnmConeeTra.Rows(0).Item("Ctry")
        '            VERAG_EZA.EZA_Data.DestinationCountry = DTzsAnmConeeTra.Rows(0).Item("Ctry")
        '        End If
        '        If Not SQL.IsNull(DTzsAnmConeeTra.Rows(0).Item("TIN")) Then VERAG_EZA.EZA_Data.Consignee.EORI = DTzsAnmConeeTra.Rows(0).Item("TIN")
        '        'VERAG_EZA.EZA_Data.Consignee.EORI_NL = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '        'VERAG_EZA.EZA_Data.Consignee.UID_Nr = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '    End If


        '    'Frächter
        '    Dim DTzsAnmCarrier As DataTable = SQL.loadDgvBySql("SELECT * FROM [zsAnmCarrTra]  WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")", "EZOLL")
        '    If DTzsAnmCarrier.Rows().Count > 0 Then
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("Na")) Then VERAG_EZA.EZA_Data.Consignee.Name = DTzsAnmCarrier.Rows(0).Item("Na")
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("Pst")) Then VERAG_EZA.EZA_Data.Carrier.Adress.Postcode = DTzsAnmCarrier.Rows(0).Item("Pst")
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("Strt")) Then VERAG_EZA.EZA_Data.Carrier.Adress.Street = DTzsAnmCarrier.Rows(0).Item("Strt")
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("Cty")) Then VERAG_EZA.EZA_Data.Carrier.Adress.City = DTzsAnmCarrier.Rows(0).Item("Cty")
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("Ctry")) Then VERAG_EZA.EZA_Data.Carrier.Adress.Country = DTzsAnmCarrier.Rows(0).Item("Ctry")
        '        If Not SQL.IsNull(DTzsAnmCarrier.Rows(0).Item("TIN")) Then VERAG_EZA.EZA_Data.Carrier.EORI = DTzsAnmCarrier.Rows(0).Item("TIN")
        '        'VERAG_EZA.EZA_Data.Carrier.EORI_NL = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '        'VERAG_EZA.EZA_Data.Carrier.UID_Nr = If(EZA_TMP.EZA_Empfaenger_NLNR, "")
        '    End If


        '    ' Tabelle zsAnmGrteeGrteeRef lesen.
        '    Dim DTzsAnmGrteeGrteeRef As DataTable = SQL.loadDgvBySql("SELECT GRN, GVal" &
        '            " FROM zsAnmGrteeGrteeRef" &
        '            " WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")" &
        '            " ORDER BY GrteeID, GrteeRefID", "EZOLL")

        '    If DTzsAnmGrteeGrteeRef.Rows().Count > 0 Then
        '        VERAG_EZA.EZA_Data.Guarantee.Amount = 0
        '        For Each DTzsAnmGrteeGrteeRef_row In DTzsAnmGrteeGrteeRef.Rows()
        '            If Not SQL.IsNull(DTzsAnmGrteeGrteeRef_row.item("GRN")) Then VERAG_EZA.EZA_Data.Guarantee.GRN = DTzsAnmGrteeGrteeRef_row.item("GRN")
        '            If Not SQL.IsNull(DTzsAnmGrteeGrteeRef_row.item("GVal")) Then VERAG_EZA.EZA_Data.Guarantee.Amount += DTzsAnmGrteeGrteeRef_row.item("GVal")
        '        Next
        '    End If

        '    'POSITIONEN
        '    Dim cntPos = 1
        '    Dim DTzsAnmGdsitem As DataTable = SQL.loadDgvBySql("SELECT * FROM zsAnmGdsitem WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")  ORDER BY GdsItemID", "EZOLL")
        '    If DTzsAnmGdsitem.Rows().Count > 0 Then
        '        For Each DTzsAnmGdsitem_row In DTzsAnmGdsitem.Rows()
        '            Dim V_POS As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaEZA_DataPosition
        '            V_POS.PosNr = cntPos
        '            Dim pkGes = 0
        '            Dim pkArt = ""

        '            Dim DTzsAnmGdsitemPk As DataTable = SQL.loadDgvBySql("SELECT * FROM [zsAnmGdsItemPack] WHERE (LizenzNr = '" & r.Item("LizenzNr") & "') And (OperatorID = " & r.Item("OperatorID") & ") And (VorgangID = '" & r.Item("VorgangID") & "') And (AnmID = " & AnmID & ")  AND GdsItemID='" & DTzsAnmGdsitem_row.Item("GdsItemID") & "' ORDER BY GdsItemID", "EZOLL")
        '            If DTzsAnmGdsitemPk.Rows().Count > 0 Then
        '                For Each DTzsAnmGdsitemPk_row In DTzsAnmGdsitemPk.Rows()
        '                    If Not SQL.IsNull(DTzsAnmGdsitemPk_row.item("Kind")) Then pkArt = DTzsAnmGdsitemPk_row.item("Kind")
        '                    If Not SQL.IsNull(DTzsAnmGdsitemPk_row.item("Nr")) Then pkGes += DTzsAnmGdsitemPk_row.item("Nr")
        '                Next
        '            End If

        '            V_POS.Quantity = pkGes
        '            V_POS.Packaging = pkArt
        '            If Not SQL.IsNull(DTzsAnmGdsitem_row.item("Gross")) Then V_POS.GrossWeight = DTzsAnmGdsitem_row.item("Gross")

        '            V_POS.GoodsDescription = DTzsAnmGdsitem_row.item("GdsDes")

        '            VERAG_EZA.EZA_Data.Position.Add(V_POS)
        '            cntPos += 1
        '        Next
        '    End If


        '    UniqueId = AnmID
        'Catch ex As Exception
        '    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & LRN, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '    Return Nothing
        'End Try
        'Return VERAG_EZA

    End Function

    Shared Function getGRTY_fromEZOLL(LRN As String) As String
        Try
            Return SQL.getValueTxtBySql("SELECT TOP 1 GRN FROM zsAnmRefs inner join zsAnmGrteeGrteeRef on zsAnmGrteeGrteeRef.AnmID=zsAnmRefs.AnmID WHERE (zsAnmRefs.VorgangID = 'AV') AND (LRN = '" & LRN & "')", "EZOLL")
        Catch ex As Exception
            VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & LRN, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
        Return ""
    End Function


    Shared Function genVERAG_OUT_EZA_FromTELOTEC(EZA_TMP As TELOTEC_Worker.cTelotec_Anmeldung, ByRef UniqueId As String) As VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        Return Nothing
        'Dim VERAG_EZA As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_eza
        'Try
        '    If EZA_TMP Is Nothing Then Return Nothing
        '    If EZA_TMP.telanm_BezugsNr Is Nothing Then Return Nothing
        '    If EZA_TMP.Hea_DecTy Is Nothing Then Return Nothing
        '    If EZA_TMP.Hea_DecTy <> "T1" And EZA_TMP.Hea_DecTy <> "T2" And EZA_TMP.Hea_DecTy <> "T2L" And EZA_TMP.Hea_DecTy <> "T-" Then Return Nothing

        '    VERAG_EZA.Version = "1.0.0" ' Automaitsch, weil default ' doch nicht?

        '    If EZA_TMP.telanm_firma <> "" Then
        '        VERAG_EZA.Company = EZA_TMP.telanm_firma
        '    Else
        '        VERAG_EZA.Company = "IMEX"
        '    End If
        '    VERAG_EZA.Department = EZA_TMP.telanm_niederlassung


        '    'VERAG_EZA.InternalReference.OfficeCode = If(
        '    'VERAG_EZA.InternalReference.PositionNumber = EZA_TMP.EZA_niederlassung
        '    Select Case EZA_TMP.telanm_Status
        '        Case < 50
        '            VERAG_EZA.ProcessData.Status = 0
        '        Case 50, 53
        '            VERAG_EZA.ProcessData.Status = 50
        '        Case 60
        '            VERAG_EZA.ProcessData.Status = 60
        '    End Select

        '    VERAG_EZA.ProcessData.TransactionDate = EZA_TMP.dec_CreateDate

        '    VERAG_EZA.ProcessData.MRN = If(EZA_TMP.telanm_CRN, "")
        '    VERAG_EZA.ProcessData.ReferenzNumber = If(EZA_TMP.telanm_BezugsNr, "")
        '    VERAG_EZA.ProcessData.ProcedureCode = If(EZA_TMP.telanm_ART, "")

        '    If EZA_TMP.CtrlRslt_DLimit IsNot Nothing AndAlso EZA_TMP.CtrlRslt_DLimit.ToString <> "" Then
        '        VERAG_EZA.EZA_Data.DatDeterminationLimit = CDate(EZA_TMP.CtrlRslt_DLimit)
        '    End If
        '    VERAG_EZA.EZA_Data.LicensePlate = If(EZA_TMP.Transp_DepIdnt, "")
        '    VERAG_EZA.EZA_Data.DepartureCustomsOffice = If(EZA_TMP.DepCO_Ref, "")
        '    VERAG_EZA.EZA_Data.DestinationCustomsOffice = If(EZA_TMP.DestCO_Ref, "")
        '    VERAG_EZA.EZA_Data.DepartureCountry = EZA_TMP.Locs_Disp
        '    VERAG_EZA.EZA_Data.DestinationCountry = If(EZA_TMP.Locs_Dest, "")

        '    'Versender
        '    VERAG_EZA.EZA_Data.Sender.Name = If(EZA_TMP.ConorTra_Na, "")
        '    VERAG_EZA.EZA_Data.Sender.EORI = If(EZA_TMP.ConorTra_TIN, "")
        '    'VERAG_EZA.EZA_Data.Sender.EORI_NL = If(EZA_TMP.EZA_Versender_NLNR, "")
        '    VERAG_EZA.EZA_Data.Sender.UID_Nr = If(EZA_TMP.ConorTra_UIDCtry, "") & If(EZA_TMP.ConorTra_UID, "")
        '    VERAG_EZA.EZA_Data.Sender.Adress.Country = If(EZA_TMP.ConorTra_Ctry, "")
        '    VERAG_EZA.EZA_Data.Sender.Adress.Postcode = If(EZA_TMP.ConorTra_Pst, "")
        '    VERAG_EZA.EZA_Data.Sender.Adress.Street = If(EZA_TMP.ConorTra_Strt, "")
        '    VERAG_EZA.EZA_Data.Sender.Adress.City = If(EZA_TMP.ConorTra_Cty, "")

        '    'Empfänger
        '    VERAG_EZA.EZA_Data.Consignee.Name = If(EZA_TMP.ConeeTra_Na, "")
        '    VERAG_EZA.EZA_Data.Consignee.EORI = If(EZA_TMP.ConeeTra_TIN, "")
        '    'VERAG_EZA.EZA_Data.Consignee.EORI_NL = If(EZA_TMP.EZA_Versender_NLNR, "")
        '    VERAG_EZA.EZA_Data.Consignee.UID_Nr = If(EZA_TMP.ConeeTra_UIDCtry, "") & If(EZA_TMP.ConeeTra_UID, "")
        '    VERAG_EZA.EZA_Data.Consignee.Adress.Country = If(EZA_TMP.ConeeTra_Ctry, "")
        '    VERAG_EZA.EZA_Data.Consignee.Adress.Postcode = If(EZA_TMP.ConeeTra_Pst, "")
        '    VERAG_EZA.EZA_Data.Consignee.Adress.Street = If(EZA_TMP.ConeeTra_Strt, "")
        '    VERAG_EZA.EZA_Data.Consignee.Adress.City = If(EZA_TMP.ConeeTra_Cty, "")

        '    ''Frächter
        '    'VERAG_EZA.EZA_Data.Carrier.Name = If(EZA_TMP.ConorTra_Na, "")
        '    'VERAG_EZA.EZA_Data.Carrier.EORI = If(EZA_TMP.ConorTra_TIN, "")
        '    ''VERAG_EZA.EZA_Data.Carrier.EORI_NL = If(EZA_TMP.EZA_Versender_NLNR, "")
        '    'VERAG_EZA.EZA_Data.Carrier.UID_Nr = If(EZA_TMP.ConorTra_UIDCtry, "") & If(EZA_TMP.ConorTra_UID, "")
        '    'VERAG_EZA.EZA_Data.Carrier.Adress.Country = If(EZA_TMP.ConorTra_Ctry, "")
        '    'VERAG_EZA.EZA_Data.Carrier.Adress.Postcode = If(EZA_TMP.ConorTra_Pst, "")
        '    'VERAG_EZA.EZA_Data.Carrier.Adress.Street = If(EZA_TMP.ConorTra_Strt, "")
        '    'VERAG_EZA.EZA_Data.Carrier.Adress.City = If(EZA_TMP.ConorTra_Cty, "")

        '    If EZA_TMP.SICHERHEIT IsNot Nothing AndAlso EZA_TMP.SICHERHEIT.Count > 0 Then
        '        VERAG_EZA.EZA_Data.Guarantee.GRN = If(EZA_TMP.SICHERHEIT(0).GRN, "")
        '        VERAG_EZA.EZA_Data.Guarantee.Amount = If(EZA_TMP.SICHERHEIT(0).GVal, "0")
        '    End If

        '    VERAG_EZA.EZA_Data.SumGrossWeight = If(EZA_TMP.Hea_TotGross, "0")
        '    Dim cntPos = 1
        '    If EZA_TMP.POSITIONSDATEN IsNot Nothing Then
        '        For Each POS In EZA_TMP.POSITIONSDATEN
        '            Dim V_POS As New VERAG_PROG_ALLGEMEIN.VERAG_OUT_EZA.VERAG_out_ezaEZA_DataPosition
        '            V_POS.PosNr = cntPos
        '            Dim pkGes = 0
        '            Dim pkArt = ""
        '            If POS.PACKSTUECKE IsNot Nothing Then
        '                For Each PK In POS.PACKSTUECKE
        '                    If PK.Pack_Nr IsNot Nothing Then pkGes += PK.Pack_Nr 'verpackt
        '                    If PK.Pack_Piec IsNot Nothing Then pkGes += PK.Pack_Piec 'unverpackt
        '                    If PK.Pack_Kind IsNot Nothing Then pkArt = PK.Pack_Kind
        '                Next
        '            End If
        '            V_POS.Quantity = pkGes
        '            V_POS.Packaging = pkArt
        '            V_POS.GrossWeight = POS.Item_Gross
        '            V_POS.GoodsDescription = POS.Item_GdsDes

        '            VERAG_EZA.EZA_Data.Position.Add(V_POS)
        '            cntPos += 1
        '        Next
        '    End If
        '    UniqueId = EZA_TMP.telanm_id

        '    'If XMLFilePath = "" Then
        '    '    Dim dir = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getRootDir() & "ZOLL_SCHNITTSTELLEN\VERAG\EZA_OUT\TC\" & Now.Year & "\" & Now.ToShortDateString & "\"
        '    '    If Not IO.Directory.Exists(dir) Then IO.Directory.CreateDirectory(dir)
        '    '    XMLFilePath = dir & "VERAG_EZA_OUT_" & Now.ToString("ddMMyyyHHmmss") & "_TC_" & EZA_TMP.telanm_id & ".xml"
        '    'End If


        '    'VERAG_EZA.SaveToFile(XMLFilePath)

        'Catch ex As Exception
        '    VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & vbNewLine & "BezugsNr: " & EZA_TMP.telanm_BezugsNr, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        '    Return Nothing
        'End Try
        'Return VERAG_EZA

    End Function


    Shared Function insertFTPLOG(filePath As String, user As String, ReferenzNumber As String, ProcedureCode As String, Status As String, vorsystem As String)
        Return SQL.doSQL("INSERT INTO tblFTP_Log (ftp_filepath,ftp_user,ftp_BezugsNr,ftp_art,ftp_status,ftp_vorsystem) VALUES ('" & filePath & "','" & user & "','" & ReferenzNumber & "','" & ProcedureCode & "','" & Status & "','" & vorsystem & "')", "FMZOLL")
    End Function


    Shared Function insertFTPLOG(filePath, user, ftp_BezugsNr, ftp_art, ftp_status, ftp_vorsystem)
        Return SQL.doSQL("INSERT INTO tblFTP_Log (ftp_filepath,ftp_user,ftp_BezugsNr,ftp_art,ftp_status,ftp_vorsystem) VALUES ('" & filePath & "','" & user & "','" & ftp_BezugsNr & "','" & ftp_art & "','" & ftp_status & "','" & ftp_vorsystem & "')", "FMZOLL")
    End Function


End Class

