Imports iTextSharp.text.pdf
Imports System.IO
Imports System.Drawing.Printing
Imports System.Runtime.InteropSerausices
Imports System.Runtime.Serialization
Imports Microsoft.Office.Interop
Imports System.Text
Imports System.Net
Imports GrapeCity.ActiveReports
Imports Microsoft.VisualBasic.ApplicationServices
Imports System.Net.Mail
Imports System.Reflection
Imports System.Text.RegularExpressions
Imports DAKOSY_Worker.NichtAbschliessendeFestsetzung

Public Class frmFormulare
    Dim isSingleForm = False
    Event ShownFIN()
    Dim KdNr As Integer = 0
    Public printed As Boolean = False
    Public SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen = Nothing
    Public AVISO As VERAG_PROG_ALLGEMEIN.cAviso = Nothing

    Sub New()

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

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

    End Sub

    Sub New(KDNR As Integer)

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

    End Sub

    Sub New(PDFArt As String)


        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.KdNr = -1
        Me.isSingleForm = isSingleForm
        AddHandler Me.Shown, Sub()
                                 addForm(PDFArt, Nothing)
                                 RaiseEvent ShownFIN()
                             End Sub

    End Sub

    Sub New(PDFArt As String, KdNr As Integer, Optional param() As Object = Nothing, Optional isSingleForm As Boolean = False)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.KdNr = KdNr
        Me.isSingleForm = isSingleForm
        AddHandler Me.Shown, Sub()
                                 addForm(PDFArt, param)
                                 RaiseEvent ShownFIN()
                             End Sub

    End Sub



    Private Sub Form1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyFlowLayoutPanel1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then
            Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
            For Each path In files
                If path.EndsWith(".pdf") Then
                    addForm("Sonst_PDF", {path})
                Else
                    MsgBox("Es können nur PDF Dateien angefügt werden: " & vbNewLine & vbNewLine & path)
                End If
            Next
        ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
            Dim HandleFileDrops = ""

            Try
                If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                    ' We have a file so lets pass it to the calling form
                    Dim Filename As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
                    HandleFileDrops = Filename(0)
                ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
                    ' We have a embedded file. First lets try to get the file name out of memory
                    Dim theStream As Stream = CType(e.Data.GetData("FileGroupDescriptor"), Stream)
                    Dim fileGroupDescriptor(512) As Byte
                    theStream.Read(fileGroupDescriptor, 0, 512)
                    Dim fileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
                    Dim i As Integer = 76
                    While Not (fileGroupDescriptor(i) = 0)
                        fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
                        System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
                    End While
                    theStream.Close()
                    ' We should have the file name or if its a email the subject line. Create our temp file based on the temp path and this info
                    Dim myTempFile As String = Path.GetTempPath & fileName.ToString
                    ' Look to see if this is a email message. If so save that temporarily and get the temp file.
                    If InStr(myTempFile, ".msg") > 0 Then
                        Dim objOL As New Microsoft.Office.Interop.Outlook.Application
                        Dim objMI As Microsoft.Office.Interop.Outlook.MailItem
                        If objOL.ActiveExplorer.Selection.Count > 1 Then
                            MsgBox("Es können nur einzelne Elemente angefügt werden!", "")
                        End If
                        For Each objMI In objOL.ActiveExplorer.Selection()
                            objMI.SaveAs(myTempFile)
                            Exit For
                        Next
                        objOL = Nothing
                        objMI = Nothing
                    Else
                        ' If its a attachment we need to pull the file itself out of memory
                        Dim ms As MemoryStream = CType(e.Data.GetData("FileContents", True), MemoryStream)
                        Dim FileBytes(CInt(ms.Length)) As Byte
                        ' read the raw data into our variable
                        ms.Position = 0
                        ms.Read(FileBytes, 0, CInt(ms.Length))
                        ms.Close()
                        ' save the raw data into our temp file
                        Dim fs As FileStream = New FileStream(myTempFile, FileMode.OpenOrCreate, FileAccess.Write)
                        fs.Write(FileBytes, 0, FileBytes.Length)
                        fs.Close()
                    End If
                    ' Make sure we have a actual file and also if we do make sure we erase it when done
                    If File.Exists(myTempFile) Then
                        ' Assign the file name to the add dialog
                        HandleFileDrops = myTempFile
                        '  Call AddTempFileToArray(myTempFile)
                    Else
                        HandleFileDrops = String.Empty
                    End If
                Else
                    Throw New System.Exception("An exception has occurred.")
                End If
            Catch ex As Exception
                MsgBox(ex.Message & ex.StackTrace)
                HandleFileDrops = String.Empty
            End Try
            If HandleFileDrops.EndsWith(".pdf") Then
                addForm("Sonst_PDF", {HandleFileDrops})
            Else
                MsgBox("Es können nur PDF Dateien angefügt werden: " & vbNewLine & vbNewLine & HandleFileDrops)
            End If
        End If
    End Sub

    Private Sub Form1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles MyFlowLayoutPanel1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
            e.Effect = DragDropEffects.Copy
        Else
        End If
    End Sub

    Private Shared Function GetIP() As String
        Dim thisIp As IPAddress = Nothing

        Dim strHostName As String = Dns.GetHostName()
        Dim iphostentry As IPHostEntry = Dns.GetHostEntry(strHostName)
        ' Find host name
        For Each ipAddress As IPAddress In iphostentry.AddressList
            ' Grab the first IP addresses
            If ipAddress.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
                thisIp = ipAddress
            End If
        Next

        Return thisIp.ToString
    End Function

    Private Sub frmFormulare_Load(sender As Object, e As EventArgs) Handles Me.Load

        'Dim IPs As Net.IPAddress = Net.Dns.GetHostEntry(My.Computer.Name).AddressList(0)
        Try

            ' If GetIP() = "192.168.0.96" And Not isSingleForm Then
            ' btnPrint.Visible = False
            ' End If

        Catch ex As Exception

        End Try

        cboTextkonserve.fillWithSQL("SELECT distinct([txt_bezeichnung])  FROM [tblTextkonserve]  where [txt_kategorie] ='FRM_MNGR_MailText'  and [txt_FIRMA]='" & VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "' ", False, "FMZOLL", True)

        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX"

                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Vollmacht", FormularManagerArten.DE_Vollmacht))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Fiskal-Vollmacht", FormularManagerArten.DE_Fiskal))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Vollmacht", FormularManagerArten.AT_Vollmacht))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Vollmacht 4200 EV", FormularManagerArten.AT_Vollmacht_EV))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Fiskal-Vollmacht", FormularManagerArten.AT_Fiskal))

                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Export Vollmacht", FormularManagerArten.VERAG_EXPORT))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VUB", FormularManagerArten.VUB_IMEX))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Importaviso Vorauskasse", FormularManagerArten.Importaviso_VK))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Importaviso", FormularManagerArten.Importaviso))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Gestellungsgarantie", FormularManagerArten.Gestellungsgarantie))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verzollungspreise", FormularManagerArten.Verzollungspreise))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Dispoliste", FormularManagerArten.DispoListe))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("SA_Gestellung", FormularManagerArten.SA_Gestellung))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Informationsblatt Fiskalverzollung", FormularManagerArten.AT_InformationsblattFiskalverzollung))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Informationsblatt Fiskalverzollung", FormularManagerArten.DE_InformationsblattFiskalverzollung))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("EORI-Antrag", FormularManagerArten.EORI_Antrag))


                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verbundenheit Käufer/Verkäufer", FormularManagerArten.Verbundenheit))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Rechnungsbestätigung", FormularManagerArten.Rechnungsbestaetigung))

                ' MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Auftrag Überwachungsdokument", FormularManagerArten.QS_UeDok))
                ' MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VerpflichtungserklärungFahrer", FormularManagerArten.VerpflichtungserklärungFahrer))




                cboVorlage.Items.Clear()
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde DE", FormularVorlagenGruppe.NeukundeDE_IMEX))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde DE Fiskal", FormularVorlagenGruppe.NeukundeDEFiskal_IMEX))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde AT", FormularVorlagenGruppe.NeukundeAT_IMEX))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde AT Fiskal", FormularVorlagenGruppe.NeukundeATFiskal_IMEX))

            Case "ATILLA"
            Case "AMBAR"
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Vollmacht", FormularManagerArten.DE_Vollmacht))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Vollmacht (EV)", FormularManagerArten.AT_Vollmacht_EV))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Export Vollmacht", FormularManagerArten.VERAG_EXPORT))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("(indirekt) DE VM", FormularManagerArten.DE_Vollmacht_indirekt))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Fiskal-Vollmacht", FormularManagerArten.DE_Fiskal))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VUB", FormularManagerArten.VUB))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Importaviso Vorauskasse", FormularManagerArten.Importaviso_VK))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Gestellungsgarantie", FormularManagerArten.Gestellungsgarantie))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verzollungspreise", FormularManagerArten.Verzollungspreise))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Dispoliste", FormularManagerArten.DispoListe))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("SA_Gestellung", FormularManagerArten.SA_Gestellung))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("EORI-Antrag", FormularManagerArten.EORI_Antrag))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verbundenheit Käufer/Verkäufer", FormularManagerArten.Verbundenheit))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Zollbeschau Protokoll", FormularManagerArten.Zollbeschau_Protokoll))

                cboVorlage.Items.Clear()
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde DE", FormularVorlagenGruppe.NeukundeDE))

            Case Else
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Vollmacht", FormularManagerArten.DE_Vollmacht))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Vollmacht", FormularManagerArten.DE_Vollmacht_indirekt))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Fiskal-Vollmacht", FormularManagerArten.DE_Fiskal))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Vollmacht", FormularManagerArten.AT_Vollmacht))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Vollmacht 4200 EV", FormularManagerArten.AT_Vollmacht_EV))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Fiskal-Vollmacht", FormularManagerArten.AT_Fiskal))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("GB Vollmacht Import/Export", FormularManagerArten.GB_Vollmacht_IE))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("GB Vollmacht indirekt", FormularManagerArten.GB_Vollmacht_indirekt))

                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VERAG Export Vollmacht", FormularManagerArten.VERAG_EXPORT))
                MyListBox1.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("ATILLA Export Vollmacht", FormularManagerArten.ATILLA_EXPORT))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VUB (VERAG Spedition AG)", FormularManagerArten.VUB_AG))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VUB (Customs Service GmbH)", FormularManagerArten.VUB_CS))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Importaviso Vorauskasse", FormularManagerArten.Importaviso_VK))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Importaviso", FormularManagerArten.Importaviso))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Gestellungsgarantie", FormularManagerArten.Gestellungsgarantie))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verzollungspreise", FormularManagerArten.Verzollungspreise))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Dispoliste", FormularManagerArten.DispoListe))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("SA_Gestellung", FormularManagerArten.SA_Gestellung))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("AT Informationsblatt Fiskalverzollung", FormularManagerArten.AT_InformationsblattFiskalverzollung))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DE Informationsblatt Fiskalverzollung", FormularManagerArten.DE_InformationsblattFiskalverzollung))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("EORI-Antrag", FormularManagerArten.EORI_Antrag))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Verbundenheit Käufer/Verkäufer", FormularManagerArten.Verbundenheit))
                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Auftrag Überwachungsdokument", FormularManagerArten.QS_UeDok))

                MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Qualitätskontrolle Antrag", FormularManagerArten.Qualitaetskontrolle))
                ' MyListBox2.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VerpflichtungserklärungFahrer", FormularManagerArten.VerpflichtungserklärungFahrer))




                cboVorlage.Items.Clear()
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde DE", FormularVorlagenGruppe.NeukundeDE))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde DE Fiskal", FormularVorlagenGruppe.NeukundeDEFiskal))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde AT", FormularVorlagenGruppe.NeukundeAT))
                cboVorlage.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Neukunde AT Fiskal", FormularVorlagenGruppe.NeukundeATFiskal))

        End Select



        'MyListBox1.fillWithMyListItem()




        initDrucker(cboPrinter)

        If isSingleForm Then
            pnl.Enabled = False
        End If
    End Sub

    Sub initFlowLPHeight()
        Dim h = 0
        For Each c As Control In MyFlowLayoutPanel1.Controls
            h += c.Height + c.Margin.Top + c.Margin.Bottom
        Next
        MyFlowLayoutPanel1.MinimumSize = New Size(1000, If(h < pnlBody.Height, pnlBody.Height - 5, h))
        pnlBody.AutoScrollMinSize = New Size(1000, If(h < pnlBody.Height, pnlBody.Height - 5, h))


        For Each c In MyFlowLayoutPanel1.Controls
            c.width = pnlBody.Width - c.Margin.left + c.Margin.right - If(pnlBody.VerticalScroll.Visible, 20, 0) - 10
        Next

    End Sub

    Public Sub clearExceptMe(usrCntl)
        Dim list As New List(Of Object)
        For Each o In MyFlowLayoutPanel1.Controls
            If o.GetType IsNot usrCntl.GetType Then
                list.Add(o)
            End If
        Next
        For Each i In list
            MyFlowLayoutPanel1.Controls.Remove(i)
        Next
    End Sub

    Public Sub MyListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles MyListBox1.DoubleClick, MyListBox2.DoubleClick
        Dim lb = DirectCast(sender, VERAG_PROG_ALLGEMEIN.MyListBox)
        If lb.SelectedItems().Count = 0 Then Exit Sub
        Try
            addForm(DirectCast(lb.SelectedItems(0), VERAG_PROG_ALLGEMEIN.MyListItem).Value)
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Sub


    Public Sub addForm(valueTMP As String, Optional param() As Object = Nothing)
        Try
            Select Case valueTMP
                Case FormularManagerArten.DE_Vollmacht
                    Dim c As New usrcntlVollmacht_DE
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.DE_Vollmacht_indirekt
                    Dim c As New usrcntlVollmacht_DE_indirekt
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.DE_Fiskal
                    Dim c As New usrcntlVollmacht_DE_Fiskal
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown

                        If cboTextkonserve._value = "" Then cboTextkonserve._value = "Neukunde Fiskal DE"
                        If cboTextKonserveSprache._value = "" Then cboTextKonserveSprache._value = "DE"

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.AT_Vollmacht
                    Dim c As New usrcntlVollmacht_AT
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.AT_Vollmacht_EV
                    Dim c As New usrcntlVollmacht_AT_EV
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.AT_Fiskal
                    Dim c As New usrcntlVollmacht_AT_Fiskal
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown

                        If cboTextkonserve._value = "" Then cboTextkonserve._value = "Neukunde Fiskal AT"
                        If cboTextKonserveSprache._value = "" Then cboTextKonserveSprache._value = "DE"

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.GB_Vollmacht_IE
                    Dim c As New usrcntlVollmacht_GB_IE
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.GB_Vollmacht_indirekt
                    Dim c As New usrcntlVollmacht_GB_indirekt
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.ATILLA_EXPORT
                    Dim c As New usrcntlVollmacht_ATILLA_EXPORT
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.VERAG_EXPORT
                    Dim c As New usrcntlVollmacht_VERAG_EXPORT
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Importaviso_VK
                    Dim c As usrcntlVorauskasse
                    If param Is Nothing Then
                        c = New usrcntlVorauskasse
                    Else
                        c = New usrcntlVorauskasse(param)
                        If param.Length > 3 Then AVISO = param(3)
                    End If
                    '   Dim c As New usrcntlVorauskasse(param(0))
                    If cboTextkonserve._value = "" Then cboTextkonserve._value = "Vorauskasse"
                    If cboTextKonserveSprache._value = "" Then cboTextKonserveSprache._value = "DE"

                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Importaviso
                    Dim c As usrcntlImportaviso
                    If param Is Nothing Then
                        c = New usrcntlImportaviso
                    Else
                        c = New usrcntlImportaviso(param)

                    End If
                    '   Dim c As New usrcntlVorauskasse(param(0))
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Gestellungsgarantie
                    Dim c As New usrcntlGestellungsgarantie
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Verzollungspreise
                    Dim c As New usrcntlVerzollungspreise
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        AddHandler c.LOADED, Sub()
                                                 If param IsNot Nothing Then
                                                     c.MyComboBox1.changeItem(param(0))
                                                     c.btnStandardPreiseLaden.PerformClick()
                                                 End If
                                             End Sub
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Boniteatsauskunft
                    Dim c As New usrcntlCreditreformBoniAuskunft
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        AddHandler c.LOADED, Sub()
                                                 If param IsNot Nothing Then c.LoadValues(param(0))
                                             End Sub
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Rechnungsbestaetigung
                    Dim c As New usrcntlRechnungsbestaetigung
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If

                Case FormularManagerArten.DispoListe
                    If param Is Nothing Then param = {0}
                    Dim c As New usrCntlDispoliste(param(0))
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        AddHandler c.SizeChanged, Sub()
                                                      initFlowLPHeight()
                                                  End Sub
                        AddHandler Me.ShownFIN, Sub()
                                                    c.initAVISOID()
                                                End Sub
                        If cboTextkonserve._value = "" Then cboTextkonserve._value = "Dispoliste"
                        If cboTextKonserveSprache._value = "" Then cboTextKonserveSprache._value = "DE"

                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If




                Case FormularManagerArten.SA_Gestellung
                    If param Is Nothing Then param = {0}
                    isSingleForm = True
                    btn.Visible = False
                    Button2.BackgroundImage = My.Resources.Excel_logo
                    Dim c As New usrCntlSA_Gestellung(param(0))
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        AddHandler c.SizeChanged, Sub()
                                                      initFlowLPHeight()
                                                  End Sub
                        AddHandler Me.ShownFIN, Sub()
                                                    c.initAVISOID()
                                                End Sub
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If

                Case FormularManagerArten.VerpflichtungserklärungFahrer
                    If param Is Nothing Then param = {0}
                    Dim c As New usrCntlVerpflichtungserklärungFahrer(param(0))
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.CHANGED, AddressOf ValueChanged
                        AddHandler c.KDNR_CHANGED, AddressOf KDNR_CHANGED
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        AddHandler c.SizeChanged, Sub()
                                                      initFlowLPHeight()
                                                  End Sub
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.Sonst_PDF
                    If param Is Nothing Then Exit Sub
                    Dim c As New usrcntlSonstigesPDF(param(0))
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.Verzollungsunterlagen
                    ' If param Is Nothing Then Exit Sub
                    Dim c As usrcntlVerzollungsunterlagen
                    If param Is Nothing Then
                        c = New usrcntlVerzollungsunterlagen()
                    Else
                        c = New usrcntlVerzollungsunterlagen(param)
                    End If

                    '    Dim c As New usrcntlVerzollungsunterlagen()
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.VerzollungsunterlagenBAR
                    ' If param Is Nothing Then Exit Sub
                    Dim c As New usrcntlVerzollungsunterlagen_BAR()
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.Gelangensbestaetigung
                    ' If param Is Nothing Then Exit Sub
                    Dim c As New usrcntlVerzollungsunterlagen_Verbringsungsnachweis
                    c.KdNR = param(0)
                    c.Path = param(1)
                    c.VBNr = param(2)
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)

                Case FormularManagerArten.AT_InformationsblattFiskalverzollung, FormularManagerArten.DE_InformationsblattFiskalverzollung
                    Dim displayName = ""
                    '   If param Is Nothing Then Exit Sub
                    If valueTMP = FormularManagerArten.AT_InformationsblattFiskalverzollung Then displayName = "AT Informationsblatt Fiskalverzollung"
                    If valueTMP = FormularManagerArten.DE_InformationsblattFiskalverzollung Then displayName = "DE Informationsblatt Fiskalverzollung"
                    Dim c As New usrcntlFiskalInfoschreiben(valueTMP, displayName)
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.EORI_Antrag
                    Dim displayName = ""
                    '   If param Is Nothing Then Exit Sub 
                    If valueTMP = FormularManagerArten.EORI_Antrag Then displayName = "EORI-Antrag"
                    Dim c As New usrcntlEORI_Antrag(valueTMP, displayName)
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.VUB_AG, FormularManagerArten.VUB_CS, FormularManagerArten.VUB_IMEX, FormularManagerArten.VUB
                    Dim displayName = ""
                    If valueTMP = FormularManagerArten.VUB_AG Then displayName = "VUB - VERAG Spedition AG"
                    If valueTMP = FormularManagerArten.VUB_CS Then displayName = "VUB - VERAG Customs Service GmbH"
                    If valueTMP = FormularManagerArten.VUB_IMEX Then displayName = "VUB - IMEX Customs Service GmbH"
                    If valueTMP = FormularManagerArten.VUB Then displayName = "VUB"
                    Dim c As New usrcntlVUB(valueTMP, displayName)
                    If ControlExists_addOK_OhneFelder(c.BEZEICHNUNG, c.DS_ORDNER) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If
                Case FormularManagerArten.QS_UeDok
                    Dim displayName = ""
                    Dim c As New usrcntlQS_UeDok
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)
                Case FormularManagerArten.Verbundenheit
                    Dim displayName = ""
                    Dim c As New usrcntlVerbundenheit
                    c.Width = MyFlowLayoutPanel1.Width - 6
                    c.KdNR = KdNr
                    AddHandler c.DELETE, AddressOf ControlDELETE
                    AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                    AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                    MyFlowLayoutPanel1.Controls.Add(c)

                Case FormularManagerArten.Zollbeschau_Protokoll
                    Dim displayName = ""
                    Dim c As usrCntlZollbeschau
                    If param Is Nothing Then
                        c = New usrCntlZollbeschau
                    Else
                        c = New usrCntlZollbeschau(param)
                    End If
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If

                Case FormularManagerArten.Qualitaetskontrolle
                    Dim displayName = ""
                    Dim c As usrCntlQualitaetskontrolle
                    If param Is Nothing Then
                        c = New usrCntlQualitaetskontrolle
                    Else
                        c = New usrCntlQualitaetskontrolle(param)
                    End If
                    If ControlExists_addOK(c.GetType.ToString) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If




                Case Else '"VUB_AG", "VUB_CS"
                    Dim displayName = ""
                    If valueTMP = FormularManagerArten.VUB_AG Then displayName = "VUB - VERAG Spedition AG"
                    If valueTMP = FormularManagerArten.VUB_CS Then displayName = "VUB - VERAG Customs Service GmbH"
                    If valueTMP = FormularManagerArten.VUB Then displayName = "VUB"
                    Dim c As New usrcntlFormOhneFelder(valueTMP, "SONSTIGE", displayName)
                    If ControlExists_addOK_OhneFelder(c.BEZEICHNUNG, c.DS_ORDNER) Then
                        c.Width = MyFlowLayoutPanel1.Width - 6
                        c.KdNR = KdNr
                        AddHandler c.DELETE, AddressOf ControlDELETE
                        AddHandler c.MOVE_UP, AddressOf ControlMoveUp
                        AddHandler c.MOVE_DOWN, AddressOf ControlMoveDown
                        MyFlowLayoutPanel1.Controls.Add(c)
                    End If




            End Select

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Sub

    Function ControlExists_addOK(t, Optional BEZ = "", Optional ORDNER = "") As Boolean
        For Each c As Control In MyFlowLayoutPanel1.Controls
            If c.GetType.ToString = t Then
                Return vbYes = MsgBox("Dieses Formular existiert bereits - Möchten Sie es ein weiteres Mal hinzufügen?", vbYesNoCancel)
            End If
        Next
        Return True
    End Function
    Function ControlExists_addOK_OhneFelder(BEZEICHNUNG, ORDNER) As Boolean
        For Each c As Control In MyFlowLayoutPanel1.Controls
            If c.GetType.ToString = GetType(usrcntlFormOhneFelder).ToString Then
                If DirectCast(c, usrcntlFormOhneFelder).BEZEICHNUNG = BEZEICHNUNG And DirectCast(c, usrcntlFormOhneFelder).DS_ORDNER = ORDNER Then
                    Return vbYes = MsgBox("Dieses Formular existiert bereits - Möchten Sie es ein weiteres Mal hinzufügen?", vbYesNoCancel)
                End If
            End If
        Next
        Return True
    End Function

    Sub ValueChanged(name, value)
        If Not cbxAnderungGliecherFelderBeiAllenFormularenBerucksichtigen.Checked Then Exit Sub
        For Each c As Control In MyFlowLayoutPanel1.Controls
            For Each cc As Control In c.Controls
                If cc.Name = name Then
                    Select Case cc.GetType().ToString
                        Case GetType(VERAG_PROG_ALLGEMEIN.MyTextBox).ToString : DirectCast(cc, VERAG_PROG_ALLGEMEIN.MyTextBox).Text = value
                        Case GetType(TextBox).ToString : DirectCast(cc, TextBox).Text = value
                        Case GetType(VERAG_PROG_ALLGEMEIN.MyComboBox).ToString : DirectCast(cc, VERAG_PROG_ALLGEMEIN.MyComboBox).changeItem(value)
                    End Select
                End If
            Next
        Next
        If name = "txtEmail" Then
            Me.txtEmail.Text = value
        End If
    End Sub

    Sub KDNR_CHANGED(kdnr)
        If Not cbxAnderungGliecherFelderBeiAllenFormularenBerucksichtigen.Checked Then Exit Sub
        For Each c As Control In MyFlowLayoutPanel1.Controls
            If TypeOf c Is FormualrInterface Then
                DirectCast(c, FormualrInterface).ChangeKDNr(kdnr)
            End If
        Next
    End Sub



    Sub ControlDELETE(CONTROL As Control)
        '  If Not cbxAnderungGliecherFelderBeiAllenFormularenBerucksichtigen.Checked Then Exit Sub
        MyFlowLayoutPanel1.Controls.Remove(CONTROL)
        'For Each c As Control In MyFlowLayoutPanel1.Controls

        'Next
    End Sub

    Sub ControlMoveDown(CONTROL As Control)
        Dim tmp = Nothing
        For Each c As Control In MyFlowLayoutPanel1.Controls
            If tmp IsNot Nothing Then
                ' MyFlowLayoutPanel1.Controls.SetChildIndex(c, MyFlowLayoutPanel1.Controls.GetChildIndex(tmp))
                MyFlowLayoutPanel1.Controls.SetChildIndex(tmp, MyFlowLayoutPanel1.Controls.GetChildIndex(c))
                Exit Sub
            End If
            If c Is CONTROL Then
                tmp = c
            End If
        Next
    End Sub

    Sub ControlMoveUp(CONTROL As Control)
        ' MyFlowLayoutPanel1.Controls(0).
        Dim tmp = Nothing
        For Each c As Control In MyFlowLayoutPanel1.Controls
            If c Is CONTROL Then
                If tmp Is Nothing Then Exit Sub
                '  MyFlowLayoutPanel1.Controls.SetChildIndex(c, MyFlowLayoutPanel1.Controls.GetChildIndex(tmp))
                MyFlowLayoutPanel1.Controls.SetChildIndex(tmp, MyFlowLayoutPanel1.Controls.GetChildIndex(c))
                Exit Sub
            End If
            'MyFlowLayoutPanel1.Controls.
            tmp = c
        Next
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click, btn.Click, btnPrint.Click
        Me.Cursor = Cursors.WaitCursor


        Dim listMail As New List(Of FormMangagerEmail)

        Try

            'VALIDIERUNG:
            txtErr.Text = ""
            Dim hassValidErr = False
            For Each c In MyFlowLayoutPanel1.Controls
                Dim err = ""
                If Not FormularManagerNEU.validFormulare(c, err) Then
                    txtErr.Text &= err
                    hassValidErr = True
                End If
            Next
            If hassValidErr Then
                MsgBox("Es sind Validierungsfehler aufgetreten!")
                Me.Cursor = Cursors.Default
                Exit Sub
            End If


            If isSingleForm And sender Is btnPrint Then 'Sofortdruck --> wir bei ActiveRepots benötigt --> schneller, als zuerst pdf....
                If Not MyFlowLayoutPanel1.Controls.Count = 1 Then Me.Cursor = Cursors.Default : Exit Sub 'funkt. nur bei genau 1 Control
                FormularManagerNEU.genPDF(MyFlowLayoutPanel1.Controls(0), , True, cboPrinter.SelectedItem.ToString,, listMail)
            Else

                Dim list As New List(Of String) ' Sammlung PDFs

                For Each c In MyFlowLayoutPanel1.Controls
                    Dim pfadList As List(Of String) = FormularManagerNEU.genPDF(c,,,,, listMail)
                    For Each pfad In pfadList
                        If pfad <> "" Then list.Add(pfad)
                    Next
                Next


                Dim dest_path = ""
                If list.Count = 0 Then Me.Cursor = Cursors.Default : Exit Sub

                If list.Count = 1 Then
                    dest_path = list(0)
                Else
                    dest_path = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "_Formular.pdf", ".pdf", False, False)
                    If Not FormularManagerNEU.MergePdfFiles(list, dest_path) Then
                        dest_path = "" : MsgBox("Fehler PDF")
                    End If
                End If

                If dest_path <> "" Then
                    If sender Is Button2 Then
                        Process.Start(dest_path)
                    ElseIf sender Is btn Then
                        'System.Diagnostics.Process.Start("mailto:" & "" & "?subject=" & "?" & "&body=" & "?" & "&attachment=" & dest_path)
                        Try




                            'Dim Mail As New MailMessage

                            'Try
                            '    Dim SMTP As New SmtpClient("smtp.gmail.com")
                            '    SMTP.EnableSsl = True
                            '    SMTP.Credentials = New System.Net.NetworkCredential("[your gmail address@gmail.com]", "[the associated password]")
                            '    SMTP.Port = 587

                            '    Mail.From = New MailAddress("""[Friendly Name]"" <[your gmail address@gmail.com>")


                            '    Mail.Subject = ""
                            '    Mail.Body = ""
                            '    If dest_path <> "" Then Mail.Attachments.Add(New Mail.Attachment(dest_path))
                            '    Mail.IsBodyHtml = True

                            '    ' SMTP.Send(Mail)

                            '    'Clear Mail Object
                            '    Mail.Dispose()

                            '    'Function Return
                            '    Return True

                            'Catch ex As Exception

                            '    'Function Return
                            '    Return False

                            'End Try



                            If False Then
                                Dim mapi As New VERAG_PROG_ALLGEMEIN.SendFileTo.MAPI

                                mapi.AddAttachment(dest_path)
                                mapi.SendMailPopup("testing", "body text")
                                Exit Sub
                            End If

                            If False Then




                                Call ShellExecute(Me.Handle, "open", "mailto:" & "" & "?subject=" & "?" & "&body=" & "?" & "&Attach=""" & dest_path & """", vbNullString, vbNullString, SW_SHOW)
                                '    Call ShellExecute(Me.Handle, "open", "mailto:" & "" & "?subject=" & "?" & "&body=" & "?", "", "", SW_SHOW)


                                Exit Sub


                                Dim MailMessage As New System.Net.Mail.MailMessage()
                                '                                MailMessage.From = New MailAddress("someone@yourdomain.com")
                                MailMessage.Subject = "" ' "Your subject here"
                                MailMessage.IsBodyHtml = True
                                '   MailMessage.Body = MailHTMLText '"<span style='font-size: 12pt; color: red;'>My HTML formatted body</span>"

                                MailMessage.Attachments.Add(New Attachment(dest_path))

                                Dim filename = "C://Temp/mymessage.eml"

                                'save the MailMessage to the filesystem
                                ' MailMessage.save(filename)
                                Save(MailMessage, filename)
                                'Open the file with the default associated application registered on the local machine




                                Process.Start(filename)

                                'Dim mapi As New VERAG_PROG_ALLGEMEIN.SendFileTo.cSendMailAttach

                                'mapi.AddAttachment(dest_path)
                                ''mapi.AddRecipientTo("person1@somewhere.com")
                                ''mapi.AddRecipientTo("person2@somewhere.com")
                                'mapi.SendMailPopup("", "")
                                Exit Sub
                            End If

                            'Dim Mail As Outlook.MailItem = CType(Application.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)

                            ' If VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "IMEX" Then
                            ' Else
                            '                            Dim outl = CreateObject("Outlook.Application")
                            ' Dim Mail = CreateObject("Microsoft.Office.Interop.Outlook.MailItem")

                            If listMail IsNot Nothing AndAlso listMail.Count > 0 Then
                                For Each l In listMail
                                    Dim outl As New Outlook.Application
                                    Dim Mail As Microsoft.Office.Interop.Outlook.MailItem
                                    Mail = outl.CreateItem(0)

                                    If l.MailHTMLText <> "" Then Mail.HTMLBody = l.MailHTMLText
                                    If l.Mail_To <> "" Then Mail.To = l.Mail_To
                                    If l.Mail_CC <> "" Then Mail.CC = l.Mail_CC
                                    If l.Mail_BCC <> "" Then Mail.CC = l.Mail_BCC
                                    If l.Mail_Subject <> "" Then Mail.Subject = l.Mail_Subject


                                    Mail.Attachments.Add(dest_path, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, , VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "_Formular.pdf")
                                    Mail.Display()

                                Next
                            Else
                                Dim outl As New Outlook.Application
                                Dim Mail As Microsoft.Office.Interop.Outlook.MailItem
                                Mail = outl.CreateItem(0)

                                If Me.txtEmail.Text <> "" Then Mail.To = Me.txtEmail.Text
                                If cboTextkonserve._value <> "" AndAlso cboTextKonserveSprache._value <> "" Then
                                    Dim tX As New VERAG_PROG_ALLGEMEIN.cTextkonserve("FRM_MNGR_MailText", cboTextkonserve._value, cboTextKonserveSprache._value, VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA)

                                    Dim TextHTML = ""
                                    TextHTML &= tX.txt_text
                                    TextHTML &= "<br>"
                                    TextHTML &= "<br>"
                                    TextHTML &= "Mit freundlichen Grüßen<br>"
                                    TextHTML &= VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME & "<br>"
                                    TextHTML &= "<br>"
                                    TextHTML &= cFakturierung.getSignature(cboTextKonserveSprache._value, tX.txt_firmaSig, True, True)


                                    Mail.HTMLBody = "<div style=""font-family:Calibri, Arial"">" & TextHTML & "</div>"


                                    Mail.Subject = tX.txt_betreff
                                    If AVISO IsNot Nothing Then
                                        Mail.Subject = Mail.Subject.Replace("%LKW%", AVISO.LKW_Nr)
                                        Mail.Subject = Mail.Subject.Replace("%LKWKennzeichen%", AVISO.LKW_Nr)
                                    End If
                                    Mail.Subject = Mail.Subject.Replace("%LKW%", "")
                                    Mail.Subject = Mail.Subject.Replace("%LKWKennzeichen%", "")
                                End If

                                Mail.Attachments.Add(dest_path, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, , VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "_Formular.pdf")
                                Mail.Display()

                            End If


                            'Dim matilPath = "C:\TEMP\VERAG_Mail.msg"
                            ' Mail.SaveAs(matilPath)
                            ' Process.Start(matilPath)

                        Catch ex As Exception
                            MsgBox("Fehler beim erstellen der E-Mail:" & vbNewLine & ex.Message & ex.StackTrace)
                        End Try
                    ElseIf sender Is btnPrint Then
                        'VERAG_PROG_ALLGEMEIN.cFormularManager.PrintFile(dest_path, "")
                        If dest_path.ToUpper.EndsWith("PDF") Then
                            VERAG_PROG_ALLGEMEIN.cFormularManager.PrintViaSpirePDF({dest_path}, cboPrinter.SelectedItem.ToString)
                        Else
                            VERAG_PROG_ALLGEMEIN.cFormularManager.PrintViaGS(dest_path, cboPrinter.SelectedItem.ToString)
                        End If

                    End If
                End If
            End If

            printed = True

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
        Me.Cursor = Cursors.Default
        '        If list.Count > 0 Then 
    End Sub

    Const SW_SHOW = 5
    Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" (
  ByVal hwnd As Integer,
  ByVal lpOperation As String,
  ByVal lpFile As String,
  ByVal lpParameters As String,
  ByVal lpDirectory As String,
  ByVal nShowCmd As Long) As Long

    '   <Extension()>
    Public Shared Sub Save(ByVal Message As MailMessage, ByVal FileName As String)
        Dim assembly As Assembly = GetType(SmtpClient).Assembly
        Dim _mailWriterType As Type = assembly.[GetType]("System.Net.Mail.MailWriter")

        Using _fileStream As FileStream = New FileStream(FileName, FileMode.Create)
            Dim _mailWriterContructor As ConstructorInfo = _mailWriterType.GetConstructor(BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Type() {GetType(Stream)}, Nothing)
            Dim _mailWriter As Object = _mailWriterContructor.Invoke(New Object() {_fileStream})
            Dim _sendMethod As MethodInfo = GetType(MailMessage).GetMethod("Send", BindingFlags.Instance Or BindingFlags.NonPublic)
            _sendMethod.Invoke(Message, BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Object() {_mailWriter, True}, Nothing)
            Dim _closeMethod As MethodInfo = _mailWriter.[GetType]().GetMethod("Close", BindingFlags.Instance Or BindingFlags.NonPublic)
            _closeMethod.Invoke(_mailWriter, BindingFlags.Instance Or BindingFlags.NonPublic, Nothing, New Object() {}, Nothing)
        End Using
    End Sub

    Public Shared Sub initDrucker(cboPrinter As ComboBox, Optional srch As String = "")
        ' alle installierten Drucker ermitteln und 
        ' in in ein ArrayList-Objekt speichern
        Dim sPrinters As New ArrayList
        For Each sPrinter As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            sPrinters.Add(sPrinter)
        Next

        ' Array sortieren
        sPrinters.Sort()

        ' jetzt alle Drucker in sortierter Reihenfolge in einer
        ' ComboBox zur Auswahl anbieten
        Dim oPS As New System.Drawing.Printing.PrinterSettings
        For i As Integer = 0 To sPrinters.Count - 1
            cboPrinter.Items.Add(sPrinters(i))
        Next




        If sPrinters.Count > 0 Then
            cboPrinter.SelectedIndex = 0
            If srch <> "" Then
                For Each i In cboPrinter.Items
                    If i.ToString.ToLower.Contains(srch.ToLower) Then
                        cboPrinter.SelectedItem = i
                        Exit Sub
                    End If
                Next
            Else
                If VERAG_PROG_ALLGEMEIN.cAllgemein.PRINTER_STANDARD <> String.Empty Then
                    For Each i In cboPrinter.Items
                        If i.ToString.ToLower = VERAG_PROG_ALLGEMEIN.cAllgemein.PRINTER_STANDARD.ToLower Then
                            cboPrinter.SelectedItem = i
                            Exit Sub
                        End If
                    Next
                End If
                For Each i In cboPrinter.Items
                    If i.ToString = oPS.PrinterName Then
                        cboPrinter.SelectedItem = i
                        Exit Sub
                    End If
                Next

            End If
        End If
    End Sub


    Private Sub MyFlowLayoutPanel1_ControlAdded(sender As Object, e As ControlEventArgs) Handles MyFlowLayoutPanel1.ControlAdded, MyFlowLayoutPanel1.ControlRemoved
        initFlowLPHeight()
    End Sub

    Private Sub pnlBody_SizeChanged(sender As Object, e As EventArgs) Handles pnlBody.SizeChanged
        initFlowLPHeight()

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim fd As New OpenFileDialog
        fd.Title = "PDF auswählen"
        fd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        fd.Filter = "PDF|*.PDF"
        fd.FilterIndex = 2
        fd.DefaultExt = ".pdf"
        fd.RestoreDirectory = True
        Dim result As DialogResult = fd.ShowDialog()

        If result = System.Windows.Forms.DialogResult.OK Then
            addForm("Sonst_PDF", {fd.FileName})
        End If

    End Sub

    Private Sub cboVorlage_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboVorlage.SelectedIndexChanged
        If cboVorlage._value = "" Then Exit Sub
        If MyFlowLayoutPanel1.Controls.Count = 0 OrElse vbYes = MsgBox("Beim Laden einer Vorlagengruppe werden alle vohanden Elemente gelöscht. Möchten Sie fortfahren?", vbYesNoCancel) Then
            Select Case cboVorlage._value
                Case FormularVorlagenGruppe.NeukundeAT
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.AT_Vollmacht_EV)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_EV"})
                    addForm(FormularManagerArten.VUB_CS)
                Case FormularVorlagenGruppe.NeukundeATFiskal
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.AT_Fiskal)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_FISKAL"})
                    addForm(FormularManagerArten.VUB_CS)
                    addForm(FormularManagerArten.AT_InformationsblattFiskalverzollung)
                Case FormularVorlagenGruppe.NeukundeDE
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.DE_Vollmacht)
                    addForm(FormularManagerArten.Verzollungspreise)
                    addForm(FormularManagerArten.VUB_AG)
                Case FormularVorlagenGruppe.NeukundeDEFiskal
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.DE_Fiskal)
                    addForm(FormularManagerArten.DE_Vollmacht)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_FISKAL_DE"})
                    addForm(FormularManagerArten.VUB_AG)
                    addForm(FormularManagerArten.DE_InformationsblattFiskalverzollung)




                Case FormularVorlagenGruppe.NeukundeAT_IMEX
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.AT_Vollmacht_EV)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_EV"})
                    addForm(FormularManagerArten.VUB_IMEX)
                Case FormularVorlagenGruppe.NeukundeATFiskal_IMEX
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.AT_Fiskal)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_FISKAL"})
                    addForm(FormularManagerArten.VUB_IMEX)
                    addForm(FormularManagerArten.AT_InformationsblattFiskalverzollung)
                Case FormularVorlagenGruppe.NeukundeDE_IMEX
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.DE_Vollmacht)
                    addForm(FormularManagerArten.Verzollungspreise)
                    addForm(FormularManagerArten.VUB_IMEX)
                Case FormularVorlagenGruppe.NeukundeDEFiskal_IMEX
                    MyFlowLayoutPanel1.Controls.Clear()
                    addForm(FormularManagerArten.DE_Fiskal)
                    addForm(FormularManagerArten.DE_Vollmacht)
                    addForm(FormularManagerArten.Verzollungspreise, {"VZ_FISKAL_DE"})
                    addForm(FormularManagerArten.VUB_IMEX)
                    addForm(FormularManagerArten.DE_InformationsblattFiskalverzollung)
            End Select
        End If
    End Sub

    Private Sub cboPrinter_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPrinter.SelectedIndexChanged

    End Sub

    Private Sub MyComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTextkonserve.SelectedIndexChanged
        cboTextKonserveSprache.Items.Clear()
        If cboTextkonserve._value <> "" Then cboTextKonserveSprache.fillWithSQL("SELECT distinct([txt_sprache])  FROM [tblTextkonserve]  where [txt_kategorie] ='FRM_MNGR_MailText' and [txt_bezeichnung]='" & cboTextkonserve._value & "' and [txt_FIRMA]='" & VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "' ", False, "FMZOLL", True)
    End Sub

End Class


Public Class FormularManagerNEU

    Shared VSQL As New VERAG_PROG_ALLGEMEIN.SQL
    Shared Function genPDF(c As Control, Optional open As Boolean = False, Optional printReportElsePdf As Boolean = False, Optional printerName As String = "", Optional openWord As Boolean = False, Optional ByRef listMail As List(Of FormMangagerEmail) = Nothing) As List(Of String)
        Dim retStr = ""
        Dim striList As New List(Of String)
        Select Case c.GetType.ToString
            Case GetType(usrcntlVollmacht_DE).ToString
                retStr = FormularManagerNEU.VM_De(c)
            Case GetType(usrcntlVollmacht_DE_indirekt).ToString
                retStr = FormularManagerNEU.VM_De_indirekt(c)
            Case GetType(usrcntlVollmacht_AT).ToString
                retStr = FormularManagerNEU.VM_AT(c)
            Case GetType(usrcntlFormOhneFelder).ToString
                retStr = FormularManagerNEU.SimplePDF(c)

            Case GetType(usrcntlVollmacht_DE_Fiskal).ToString
                retStr = FormularManagerNEU.VM_DE_Fiskal(c)
            Case GetType(usrcntlVollmacht_AT_EV).ToString
                retStr = FormularManagerNEU.VM_AT_EV(c)
            Case GetType(usrcntlVollmacht_AT_Fiskal).ToString
                retStr = FormularManagerNEU.VM_AT_Fiskal(c)
            Case GetType(usrcntlVollmacht_GB_IE).ToString
                retStr = FormularManagerNEU.VM_VERAG_GB_IE(c)
            Case GetType(usrcntlVollmacht_GB_indirekt).ToString
                retStr = FormularManagerNEU.VM_VERAG_GB_indirect(c)
            Case GetType(usrcntlVollmacht_ATILLA_EXPORT).ToString
                retStr = FormularManagerNEU.VM_ATILLA_EXPORT(c)
            Case GetType(usrcntlVollmacht_VERAG_EXPORT).ToString
                retStr = FormularManagerNEU.VM_VERAG_EXPORT(c)
            Case GetType(usrcntlVorauskasse).ToString
                retStr = FormularManagerNEU.Importaviso_VK(c)
            Case GetType(usrcntlImportaviso).ToString
                retStr = FormularManagerNEU.Importaviso(c)
            Case GetType(usrcntlGestellungsgarantie).ToString
                retStr = FormularManagerNEU.Gestellungsgarantie(c)
            Case GetType(usrcntlVerzollungspreise).ToString
                retStr = FormularManagerNEU.Verzollungspreise(c)
            Case GetType(usrcntlCreditreformBoniAuskunft).ToString
                retStr = FormularManagerNEU.Bonitaetsauskunft(c)
            Case GetType(usrcntlSonstigesPDF).ToString
                retStr = FormularManagerNEU.SonstPDF(c)
            Case GetType(usrCntlDispoliste).ToString
                retStr = FormularManagerNEU.DispoListe(c)

            Case GetType(usrCntlSA_Gestellung).ToString
                open = False
                retStr = FormularManagerNEU.SA_Gestellung(c, printReportElsePdf, printerName)
            Case GetType(usrCntlVerpflichtungserklärungFahrer).ToString
                ' striList = FormularManagerNEU.VerpflichtungserklärungFahrer(c)
                striList = FormularManagerNEU.VerpflichtungserklärungFahrerRpt(c, printReportElsePdf, printerName)
            Case GetType(usrcntlFiskalInfoschreiben).ToString
                retStr = FormularManagerNEU.FiskalInfoschreiben(c)
            Case GetType(usrcntlEORI_Antrag).ToString
                retStr = FormularManagerNEU.EORI_Antrag(c)
            Case GetType(usrcntlVerzollungsunterlagen).ToString
                striList = FormularManagerNEU.Verzollungsunterlagen(c, printReportElsePdf, printerName, openWord)
            Case GetType(usrcntlVerzollungsunterlagen_BAR).ToString
                striList = FormularManagerNEU.VerzollungsunterlagenBAR(c, listMail)
            Case GetType(usrcntlVerzollungsunterlagen_Verbringsungsnachweis).ToString
                striList = FormularManagerNEU.Verzollungsunterlagen_Verbringungsnachweis(c, listMail)
            Case GetType(usrCntlQualitaetskontrolle).ToString
                retStr = FormularManagerNEU.Qualitaetskontrolle(c)

            Case GetType(usrcntlQS_UeDok).ToString
                retStr = FormularManagerNEU.QS_UeDok(c)
            Case GetType(usrcntlVerbundenheit).ToString
                retStr = FormularManagerNEU.Verbundenheit(c)
            Case GetType(usrcntlRechnungsbestaetigung).ToString
                retStr = FormularManagerNEU.Rechnungsbestaetigung(c)

            Case GetType(usrcntlVUB).ToString
                retStr = FormularManagerNEU.VUB(c)

            Case GetType(usrCntlZollbeschau).ToString
                retStr = FormularManagerNEU.Zollbeschau(c)

        End Select
        If retStr <> "" Then
            striList.Add(retStr)
        End If
        If open Then
            For Each r In striList
                If r <> "" Then Process.Start(r)
            Next
        End If
        Return striList
    End Function

    Shared Function validFormulare(c As Control, ByRef err As String) As Boolean
        validFormulare = True

        Dim striList As New List(Of String)

        Select Case c.GetType.ToString
            Case GetType(usrcntlVollmacht_DE).ToString
                '  retStr = FormularManagerNEU.VM_De(c)
            Case GetType(usrcntlVollmacht_DE_indirekt).ToString
                '  retStr = FormularManagerNEU.VM_De(c)
            Case GetType(usrcntlVollmacht_AT).ToString
                '    retStr = FormularManagerNEU.VM_AT(c)
            Case GetType(usrcntlFormOhneFelder).ToString
                '   retStr = FormularManagerNEU.SimplePDF(c)

            Case GetType(usrcntlVollmacht_DE_Fiskal).ToString
                '    retStr = FormularManagerNEU.VM_DE_Fiskal(c)
            Case GetType(usrcntlVollmacht_AT_EV).ToString
                '   retStr = FormularManagerNEU.VM_AT_EV(c)
            Case GetType(usrcntlVollmacht_AT_Fiskal).ToString
                '   retStr = FormularManagerNEU.VM_AT_Fiskal(c)
            Case GetType(usrcntlVollmacht_ATILLA_EXPORT).ToString
                '   retStr = FormularManagerNEU.VM_ATILLA_EXPORT(c)
            Case GetType(usrcntlVollmacht_VERAG_EXPORT).ToString
                '  retStr = FormularManagerNEU.VM_VERAG_EXPORT(c)
            Case GetType(usrcntlVorauskasse).ToString
                If Not DirectCast(c, usrcntlVorauskasse).ValidValues(err) Then validFormulare = False
            Case GetType(usrcntlGestellungsgarantie).ToString
                ' retStr = FormularManagerNEU.Gestellungsgarantie(c)
            Case GetType(usrcntlVerzollungspreise).ToString
                ' retStr = FormularManagerNEU.Verzollungspreise(c)
            Case GetType(usrcntlCreditreformBoniAuskunft).ToString
                'retStr = FormularManagerNEU.Bonitaetsauskunft(c)
            Case GetType(usrcntlSonstigesPDF).ToString
                ' retStr = FormularManagerNEU.SonstPDF(c)
            Case GetType(usrCntlDispoliste).ToString
                'retStr = FormularManagerNEU.DispoListe(c)
            Case GetType(usrCntlVerpflichtungserklärungFahrer).ToString
                ' striList = FormularManagerNEU.VerpflichtungserklärungFahrer(c)
            Case GetType(usrcntlFiskalInfoschreiben).ToString
                ' retStr = FormularManagerNEU.FiskalInfoschreiben(c)
            Case GetType(usrcntlVerzollungsunterlagen).ToString
                If Not DirectCast(c, usrcntlVerzollungsunterlagen).ValidValues(err) Then validFormulare = False

            Case GetType(usrcntlVUB).ToString
                '  retStr = FormularManagerNEU.VUB(c)
        End Select


    End Function


    Shared Function VM_De(usrCntl As usrcntlVollmacht_DE) As String

        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 36, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 50, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 56, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 62, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 68, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 119, 68, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 74, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 119, 74, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 81, 90, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Dim top = 0
        If VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "IMEX" Or VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "AMBAR" Then
            top = 25
        End If

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 0, top + 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 0, top + 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "")
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_EN", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "DE_VM", listTowrite)
        End Select
        Return ""
    End Function

    Shared Function VM_De_indirekt(usrCntl As usrcntlVollmacht_DE_indirekt) As String

        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 36, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 50, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 56, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 62, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 68, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 119, 68, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 74, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 119, 74, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 80, 90, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        Dim top = 0
        If VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "IMEX" Or VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "AMBAR" Then
            top = 25
        End If

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 0, top + 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 0, top + 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "")
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_INDIREKT_EN", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_INDIREKT", listTowrite)
        End Select
        Return ""
    End Function

    Shared Function VM_AT(usrCntl As usrcntlVollmacht_AT) As String

        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 34, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 49, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 55, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 61, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 40, 67, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 129, 67, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 75, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 129, 75, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 82, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 129, 82, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 88, 65, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFaStNr.Text, 132, 88, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 0, 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 0, 220, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "")
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                MsgBox("AT - Vollmacht ist nicht auf Englisch verfügbar!")
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "AT_VM", listTowrite)
        End Select
        Return ""
    End Function


    Shared Function SimplePDF(usrCntl As usrcntlFormOhneFelder) As String
        Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", usrCntl.DS_ORDNER, "", "", usrCntl.BEZEICHNUNG)
        Return DS.OPEN_SINGLE(False)
    End Function


    Shared Function VUB(usrCntl As usrcntlVUB) As String

        ' Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", usrCntl.DS_ORDNER, "", "", usrCntl.BEZEICHNUNG)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager
        If usrCntl.BEZEICHNUNG = FormularManagerArten.VUB_AG Then
            Select Case usrCntl.cboSprache._value
                Case "EN"
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB_ENGLISCH", Nothing)
                Case Else
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB_AG", Nothing)
            End Select
        ElseIf usrCntl.BEZEICHNUNG = FormularManagerArten.VUB_CS Then
            Select Case usrCntl.cboSprache._value
                Case "EN"
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB_CS_ENGLISCH", Nothing)
                Case Else
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB_CS", Nothing)
            End Select
        Else
            Select Case usrCntl.cboSprache._value
                Case "EN"
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB_ENGLISCH", Nothing)
                Case Else
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VUB", Nothing)
            End Select
        End If

    End Function


    Shared Function SonstPDF(usrCntl As usrcntlSonstigesPDF) As String
        If System.IO.File.Exists(usrCntl.PFAD) Then
            Return usrCntl.PFAD
        End If
        Return ""
    End Function

    Shared Function DispSendungslisteoListe(AvisoId As Integer, Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional RechnugnAn As String = "AVISIERER") As String
        Dim AVISO = (New VERAG_PROG_ALLGEMEIN.cAvisoDAL).LesenAviso(AvisoId, "")
        If AVISO Is Nothing Then Return ""
        Dim SENDUNG_LIST As New List(Of VERAG_PROG_ALLGEMEIN.cSendungen)
        VERAG_PROG_ALLGEMEIN.cSendungen.LOAD_LIST(SENDUNG_LIST, 0, AvisoId) 'LÄDT alle SENDUNGSDATEN
        If SENDUNG_LIST Is Nothing OrElse SENDUNG_LIST.Count = 0 Then Return ""
        Return DispSendungslisteoListe(AVISO, SENDUNG_LIST,,, RechnugnAn)
    End Function

    Shared Function DispSendungslisteoListe(AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNGEN As List(Of VERAG_PROG_ALLGEMEIN.cSendungen), Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional RechnugnAn As String = "AVISIERER") As String
        '  Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim tmpPath = ""
        Try

            Dim rpt As New rptDispoHaftListe


            rpt.txtLKW.Text = AVISO.LKW_Nr
            rpt.txtLKWId.Text = AVISO.AvisoID


            If AVISO.Zollstelle IsNot Nothing AndAlso AVISO.Zollstelle <> "" Then
                ' rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT basncd_dstnr +' - ' + [basncd_name]  FROM basncd WHERE basncd_dstnr='" & AVISO.Zollstelle & "' ", "ATLAS")
                rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT Code +' - ' + [Description]  FROM tbl_DY_ZollDE_C0141_Zollstellen WHERE Code='" & AVISO.Zollstelle & "' AND ((StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()))", "FMZOLL")

            Else
                Select Case AVISO.Grenzstelle
                    Case "SUB" : rpt.txtGrenzstelle.Text = "SUBEN"
                    Case "WAI" : rpt.txtGrenzstelle.Text = "WAIDHAUS"
                    Case "SBG" : rpt.txtGrenzstelle.Text = "BAD REICHENHALL"
                    Case "SFD" : rpt.txtGrenzstelle.Text = "SPIELFELD"
                    Case "AMB" : rpt.txtGrenzstelle.Text = "AMBAR"
                    Case Else : rpt.txtGrenzstelle.Text = AVISO.Grenzstelle.Replace("???", "")
                End Select
            End If



            rpt.txtDatum.Text = Now.ToShortDateString
            rpt.txtSB.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME

            Dim ort = "Suben"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "IMEX"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_IMEX.Visible = True
                    rpt.picVERAG.Image = My.Resources.IMEX_LOGO_simple
                    rpt.TextBox1.Text = rpt.TextBox1.Text.Replace("%Firma%", "IMEX Customs Service GmbH")
                    rpt.TextBox3.Text = rpt.TextBox3.Text.Replace("%Firma%", "IMEX Customs Service GmbH")
                    rpt.TextBox7.Text = rpt.TextBox7.Text.Replace("%Firma%", "IMEX Customs Service GmbH")
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
            '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                Case "ATILLA"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_ATILLA.Visible = True
                    rpt.picVERAG.Image = My.Resources.Atilla
                    rpt.TextBox1.Text = rpt.TextBox1.Text.Replace("%Firma%", "ATILLA Spedition GmbH")
                    rpt.TextBox3.Text = rpt.TextBox3.Text.Replace("%Firma%", "ATILLA Spedition GmbH")
                    rpt.TextBox7.Text = rpt.TextBox7.Text.Replace("%Firma%", "ATILLA Spedition GmbH")
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
                Case "AMBAR"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.TextBox13.Visible = True
                    rpt.picVERAG.Image = My.Resources.ambar_simple
                    rpt.TextBox1.Text = rpt.TextBox1.Text.Replace("%Firma%", "AMBAR Logistic Services GmbH")
                    rpt.TextBox3.Text = rpt.TextBox3.Text.Replace("%Firma%", "AMBAR Logistic Services GmbH")
                    rpt.TextBox7.Text = rpt.TextBox7.Text.Replace("%Firma%", "AMBAR Logistic Services GmbH")
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
                Case Else
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                        Case "SBG" : ort = "Bad Reichenhall"
                        Case "WAI" : ort = "Waidhaus"
                        Case "NKD" : ort = "Nickelsdorf"
                        Case "NEU" : ort = "Neuhaus am Inn"
                    End Select
                    rpt.TextBox1.Text = rpt.TextBox1.Text.Replace("%Firma%", "VERAG Spedition AG")
                    rpt.TextBox3.Text = rpt.TextBox3.Text.Replace("%Firma%", "VERAG Spedition AG")
                    rpt.TextBox7.Text = rpt.TextBox7.Text.Replace("%Firma%", "VERAG Spedition AG")
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
            End Select

            Select Case RechnugnAn
                Case "AVISERER" : rpt.TextBox32.Text = "Avisierer (*):"
                Case "FRACHTF" : rpt.TextBox32.Text = "Frächter (*):"
                Case "AUFTR" : rpt.TextBox32.Text = "Avisierer (*):"

            End Select

            Dim tb As New DataTable
            tb.Columns.Add("Nr", GetType(Integer))
            '   tb.Columns.Add("Nr", GetType(String))
            '   tb.Columns.Add("PosNr", GetType(String))
            '   tb.Columns.Add("AbfArt", GetType(String))
            Dim cnt = 1

            For Each s In SENDUNGEN
                'Ä tb.Rows.Add(cnt, s.AbfertigungsNr, s.tblSnd_Abfertigungsart_ID)
                tb.Rows.Add(SENDUNGEN.IndexOf(s))
                cnt += 1
            Next



            'MsgBox(tb.Rows.Count)

            rpt.DataSource = tb
            Dim fiskal_bool = False

            AddHandler rpt.Detail.Format, Sub()
                                              Dim SND As VERAG_PROG_ALLGEMEIN.cSendungen = SENDUNGEN(rpt.Fields.Item("Nr").Value)
                                              rpt.txtNr.Text = CInt(rpt.Fields.Item("Nr").Value) + 1

                                              rpt.txtAnmerkung.Text = ""
                                              Dim anmerkung = ""
                                              Dim anmerkung2 = ""
                                              Dim colliGewicht = ""
                                              Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                                                  Case "IMEX"
                                                      If If(SND.tblSnd_Colli, "") <> "" Then colliGewicht &= "Colli: " & SND.tblSnd_Colli & "; "
                                                      If If(SND.tblSnd_Gewicht, "") <> "" Then colliGewicht &= "Gewicht: " & SND.tblSnd_Gewicht & " kg"

                                                      If If(SND.tblSnd_AnmerkungDispoliste, "") <> String.Empty Then anmerkung &= If(SND.tblSnd_AnmerkungDispoliste, "").ToString.Trim
                                                ' If(SND.tblSnd_Anmerkung, "").ToString.Trim & vbNewLine & If(SND.tblSnd_AnmerkungDispoliste, "").ToString.Trim 'Übergangsphase: beide Txt

                                                  Case "AMBAR"
                                                      If If(SND.tblSnd_Colli, "") <> "" Then colliGewicht &= "Colli: " & SND.tblSnd_Colli & "; "
                                                      If If(SND.tblSnd_Gewicht, "") <> "" Then colliGewicht &= "Gewicht: " & SND.tblSnd_Gewicht & " kg"

                                                      If If(SND.tblSnd_AnmerkungDispoliste, "") <> String.Empty Then anmerkung &= If(SND.tblSnd_AnmerkungDispoliste, "").ToString.Trim
                                                      If If(SND.tblSnd_Auftraggeber, "") <> String.Empty Then anmerkung2 &= "Auftraggeber: " & SND.tblSnd_Auftraggeber.ToString.Trim

                                                  Case Else
                                                      If If(SND.tblSnd_Colli, "") <> "" Then colliGewicht &= "Colli: " & SND.tblSnd_Colli & "; "
                                                      If If(SND.tblSnd_Gewicht, "") <> "" Then colliGewicht &= "Gewicht: " & SND.tblSnd_Gewicht & " kg"

                                                      If If(SND.tblSnd_AnmerkungDispoliste, "") <> String.Empty Then anmerkung &= If(SND.tblSnd_AnmerkungDispoliste, "").ToString.Trim
                                              End Select


                                              If SND.tblSnd_Fremdspedition Then
                                                  rpt.txtAbfertigungsart.Text = "FREMD"
                                                  rpt.txtPosNr.Text = SND.tblSnd_FremdspeditionText
                                              Else
                                                  rpt.txtPosNr.Text = If(SND.FilialenNr > 0, SND.FilialenNr & "/", "") & If(SND.AbfertigungsNr > 0, SND.AbfertigungsNr, "-")
                                                  rpt.txtPosNr.Text &= vbNewLine & VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(SND.FilialenNr, False)
                                                  ' rpt.txtPosNr.Text &=  VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(SND.FilialenNr, True)
                                                  If anmerkung <> "" Then
                                                      rpt.txtAnmerkung.Text = "Anmerkung: " & anmerkung.Replace(vbNewLine, "; ").Replace(Chr(10), "; ").Replace(Chr(13), "; ")
                                                      rpt.txtAnmerkung.Text = Regex.Replace(rpt.txtAnmerkung.Text, "\r\n$", String.Empty)
                                                      While rpt.txtAnmerkung.Text.Contains("; ;")
                                                          rpt.txtAnmerkung.Text = rpt.txtAnmerkung.Text.Replace("; ;", "; ") 'Falls dpl-return war
                                                      End While
                                                  End If
                                                  If anmerkung2 <> "" Then
                                                      rpt.txtAnmerkung.Text = (rpt.txtAnmerkung.Text & vbNewLine & anmerkung2).Trim
                                                  End If
                                                  If SND.tblSnd_Abfertigungsart_ID > 0 Then
                                                      Select Case SND.tblSnd_Abfertigungsart_ID
                                                          Case 1 : rpt.txtAbfertigungsart.Text = "Zollabfertigung"
                                                          Case 23 : rpt.txtAbfertigungsart.Text = "ATA-Nr."
                                                          Case 26, 28
                                                              rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                                              fiskal_bool = True
                                                          Case Else : rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                                      End Select
                                                  Else
                                                      rpt.txtAbfertigungsart.Text = "-"
                                                  End If
                                              End If
                                              If colliGewicht <> "" Then rpt.txtAnmerkung.Text = (colliGewicht & vbNewLine & rpt.txtAnmerkung.Text).Trim

                                              If SND.tblSnd_Abfertigungsart_ID = 23 Then 'ATA NR
                                                  If If(SND.tblSnd_ATANr, "") <> "" Then rpt.txtAnmerkung.Text &= vbNewLine & "ATA-Nr.: " & SND.tblSnd_ATANr
                                              End If

                                              Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                                                  Case "IMEX" : rpt.txtPosNr.Text &= vbNewLine & SND.tblSnd_KdAuftragsNrAvisierer
                                              End Select


                                              rpt.txtAbsender.Text = If(SND.tblSnd_Absender, "-")
                                              ' rpt.txtEmpfänger.Text = (If(SND.tblSnd_EmpfaengerKdNr > 0, SND.tblSnd_EmpfaengerKdNr, "") & " " & If(SND.tblSnd_Empfaenger, "")).Trim
                                              rpt.txtEmpfänger.Text = If(SND.tblSnd_Empfaenger, "").Trim
                                              rpt.txtEmpfänger.Text = rpt.txtEmpfänger.Text.Replace("(IMEX)", "").Trim

                                              Dim NCTS_VZAdr = ""
                                              If SND.tblSnd_NCTSaufDISPO Then
                                                  NCTS_VZAdr = If(SND.tblSnd_NCTSVerzollungsadresse, "")
                                                  NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Strasse, "")
                                                  NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Land, "") & " " & If(SND.NCTS_Verzollungsadresse_PLZ, "") & " " & If(SND.NCTS_Verzollungsadresse_Ort, "")
                                                  NCTS_VZAdr &= vbNewLine
                                              End If
                                              If If(SND.NCTS_Bestimmungszollstelle, "") <> "" Then NCTS_VZAdr &= "Best.Zollst.:" & If(SND.NCTS_Bestimmungszollstelle, "") & "   "
                                              '  If If(SENDUNG.NCTS_Verzollungsadresse_EORI, "") <> "" Then VALUES.NCTS_VZAdr &= "EORI:" & If(SND.NCTS_Verzollungsadresse_EORI, "") & If(SND.NCTS_Verzollungsadresse_EORI_NL, "")


                                              rpt.txtVerzollungsadresse.Text = NCTS_VZAdr.Trim


                                              '.Replace("\n","")
                                              rpt.txtAbrechnung.Text = ""
                                              SND.LOAD_ABRECHNUNG()

                                              If SND.ABRECHNUNG IsNot Nothing Then
                                                  For Each a In SND.ABRECHNUNG
                                                      If a.sndabr_abrArt = "ABFKOST" And a.sndabr_beteiligter = RechnugnAn Then '"AVISIERER" Then
                                                          rpt.txtAbrechnung.Text = "X"
                                                      End If

                                                      'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                                                      '    Case "IMEX"
                                                      '        If a.sndabr_abrArt = "ABFKOST" And a.sndabr_beteiligter = "FRACHTF" Then
                                                      '            rpt.txtAbrechnung.Text = "X"
                                                      '        End If
                                                      '    Case Else
                                                      '        If a.sndabr_abrArt = "ABFKOST" And a.sndabr_beteiligter = "AVISIERER" Then
                                                      '            rpt.txtAbrechnung.Text = "X"
                                                      '        End If
                                                      'End Select

                                                  Next
                                              End If


                                          End Sub

            If fiskal_bool Then
                rpt.TextBox10.Visible = True
                rpt.Shape9.Visible = True

            End If



            AddHandler rpt.Detail.BeforePrint, Sub()
                                                   rpt.Shape8.Height = rpt.Detail.Height
                                                   rpt.Shape10.Height = rpt.Detail.Height
                                                   rpt.Shape11.Height = rpt.Detail.Height
                                               End Sub

            If printReportElsePDF Then 'NUR DRUCK!!
                rpt.Run(False)

                rpt.Document.Printer.PrinterName = printername
                rpt.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rpt.Document.Printer.OriginAtMargins = False

                rpt.Document.Print((printername = ""), False)
                rpt.Dispose()
            Else


                tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("Dispoliste.pdf", ".pdf", , False)
                Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
                rpt.Run(False)

                p.NeverEmbedFonts = ""
                p.Export(rpt.Document, tmpPath)

                rpt.Dispose()

            End If



        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try
        Return tmpPath
    End Function

    Shared Function printMRN(MRN) As Boolean
        Try
            If MRN.Length > 30 Or MRN.Length < 5 Then
                MsgBox("Falsches Format")
            Else
                Dim rptMRNDruck As New rptMRNDruck
                Dim barcodeATA As Image = Code128Rendering.MakeBarcodeImage(MRN, 1, True, 20)
                rptMRNDruck.picMRN.Image = barcodeATA
                rptMRNDruck.lblMRN.Text = "MRN: " & MRN
                Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                    Case "IMEX"
                        rptMRNDruck.Label8.Text = "IMEX Customs Service GmbH"
                    Case "UNISPED"
                        rptMRNDruck.Label8.Text = "UNISPED Speditions GmbH"
                    Case "ATILLA"
                        rptMRNDruck.Label8.Text = "ATILLA Spedition GmbH"
                    Case "FRONTOFFICE"
                        rptMRNDruck.Label8.Text = "FRONT-OFFICE Suben eG"
                    Case "AMBAR"
                        rptMRNDruck.Label8.Text = "AMBAR"
                    Case Else
                        rptMRNDruck.Label8.Text = "VERAG Spedition AG"
                End Select
                rptMRNDruck.lblSachbearbeiter.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME

                rptMRNDruck.Run(False)

                rptMRNDruck.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rptMRNDruck.Document.Printer.OriginAtMargins = False
                rptMRNDruck.Document.Print(True, False)
                rptMRNDruck.Dispose()
                Return True
            End If

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
        Return False
    End Function



    Shared Function LaufzettelZollDE(AvisoId As Integer, Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional digital As Boolean = False) As String
        Dim AVISO = (New VERAG_PROG_ALLGEMEIN.cAvisoDAL).LesenAviso(AvisoId, "")
        If AVISO Is Nothing Then Return ""
        Dim SENDUNG_LIST As New List(Of VERAG_PROG_ALLGEMEIN.cSendungen)
        VERAG_PROG_ALLGEMEIN.cSendungen.LOAD_LIST(SENDUNG_LIST, 0, AvisoId) 'LÄDT alle SENDUNGSDATEN
        If SENDUNG_LIST Is Nothing OrElse SENDUNG_LIST.Count = 0 Then Return ""
        Return LaufzettelZollDE(AVISO, SENDUNG_LIST, printReportElsePDF, printername,, digital)
    End Function

    Shared Function LaufzettelZollDE_VP(AvisoId As Integer, Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional Vorpapier As String = "", Optional digital As Boolean = False) As String
        Dim AVISO = (New VERAG_PROG_ALLGEMEIN.cAvisoDAL).LesenAviso(AvisoId, "")
        If AVISO Is Nothing Then Return ""
        Dim SENDUNG_LIST As New List(Of VERAG_PROG_ALLGEMEIN.cSendungen)

        If Vorpapier = "XXXX" Then
            VERAG_PROG_ALLGEMEIN.cSendungen.LOAD_LIST_VP_EMPTY(SENDUNG_LIST, 0, AvisoId) 'LÄDT alle SENDUNGSDATEN
        Else
            VERAG_PROG_ALLGEMEIN.cSendungen.LOAD_LIST_VP(SENDUNG_LIST, 0, AvisoId, Vorpapier) 'LÄDT alle SENDUNGSDATEN
        End If

        If SENDUNG_LIST Is Nothing OrElse SENDUNG_LIST.Count = 0 Then Return ""
        Return LaufzettelZollDE(AVISO, SENDUNG_LIST, printReportElsePDF, printername, Vorpapier, digital)
    End Function

    Shared gesColli As Double = 0
    Shared gesGewicht As Double = 0
    Shared Function LaufzettelZollDE(AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNGEN As List(Of VERAG_PROG_ALLGEMEIN.cSendungen), Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional Vorpapier As String = "", Optional digital As Boolean = False) As String
        '  Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim tmpPath = ""
        Try
            Dim rpt As New rptLaufzettelZollDE
            gesColli = 0
            gesGewicht = 0

            rpt.txtLKW.Text = AVISO.LKW_Nr
            rpt.txtLKWId.Text = AVISO.AvisoID

            If AVISO.Zollstelle IsNot Nothing AndAlso AVISO.Zollstelle <> "" Then
                '   rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT basncd_dstnr +' - ' + [basncd_name]  FROM basncd WHERE basncd_dstnr='" & AVISO.Zollstelle & "' ", "ATLAS")
                rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT Code +' - ' + [Description]  FROM tbl_DY_ZollDE_C0141_Zollstellen WHERE Code='" & AVISO.Zollstelle & "' AND ((StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()))", "FMZOLL")

            Else
                Select Case AVISO.Grenzstelle
                    Case "SUB" : rpt.txtGrenzstelle.Text = "SUBEN"
                    Case "WAI" : rpt.txtGrenzstelle.Text = "WAIDHAUS"
                    Case "SBG" : rpt.txtGrenzstelle.Text = "BAD REICHENHALL"
                    Case "SFD" : rpt.txtGrenzstelle.Text = "SPIELFELD"
                    Case "DTB", "FO_WIHD" : rpt.txtGrenzstelle.Text = "DETTELBACH"
                    Case Else : rpt.txtGrenzstelle.Text = AVISO.Grenzstelle.Replace("???", "")
                End Select
            End If

            rpt.txtDatum.Text = Now.ToShortDateString
            rpt.txtSB.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME

            Dim ort = "Suben"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "IMEX"
                    Select Case AVISO.Grenzstelle
                        Case "DTB", "FO_WIHD" '--> VERAG
                            ort = "Dettelbach"
                            rpt.txtFirmaInfo_VERAG.Visible = False
                            rpt.TextBox11.Visible = True
                            If AVISO.ImEx = "EXPORT" Then rpt.TextBox3.Visible = False
                            rpt.picVERAG.Image = My.Resources.Verag_Spedition_GMBH_Logo

                        Case Else


                            rpt.txtFirmaInfo_VERAG.Visible = False
                            rpt.txtFirmaInfo_IMEX.Visible = True
                            rpt.picVERAG.Image = My.Resources.IMEX_LOGO_simple

                            rpt.TextBox32.Text = "Avisierer (*):"
                            rpt.txtFraechter.Text = AVISO.Auftraggeber

                    End Select
                Case "UNISPED"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirma_UNISPED.Visible = True
                    rpt.picVERAG.Image = My.Resources.Unisped_logo

                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
            '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                Case "ATILLA"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_ATILLA.Visible = True
                    rpt.picVERAG.Image = My.Resources.Atilla
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg

                Case "FRONTOFFICE"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmeninfo_rontoffice.Visible = True
                    rpt.picVERAG.Image = My.Resources.FrontOfficeSUB_Horizontal
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
                Case Else
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                        Case "SBG" : ort = "Bad Reichenhall"
                        Case "WAI"
                            ort = "Waidhaus"
                            rpt.txtFirmaInfo_VERAG.Visible = False
                            rpt.TextBox7.Visible = True
                            If AVISO.ImEx = "EXPORT" Then rpt.TextBox3.Visible = False
                            rpt.picVERAG.Image = My.Resources.Verag_Spedition_GMBH_Logo

                        Case "NKD" : ort = "Nickelsdorf"
                        Case "NEU" : ort = "Neuhaus am Inn"
                        Case "DTB", "FO_WIHD"
                            ort = "Dettelbach"
                            rpt.txtFirmaInfo_VERAG.Visible = False
                            rpt.TextBox11.Visible = True
                            If AVISO.ImEx = "EXPORT" Then rpt.TextBox3.Visible = False
                            rpt.picVERAG.Image = My.Resources.Verag_Spedition_GMBH_Logo
                    End Select
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
            End Select


            rpt.txtDW.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl
            rpt.txtEmail.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_email

            If digital Then
                Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                    Case "FRONTOFFICE"
                        rpt.TextBox3.Text &= vbNewLine & "Die Waren befinden sich am Amtsplatz des ZA Suben-Autobahn."
                    Case Else
                        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                            Case "SBG" : rpt.TextBox3.Text &= vbNewLine & "Die Waren befinden sich am Amtsplatz des ZA Bad Reichenhall Autobahn."
                            Case "WAI"
                            Case "NKD" : rpt.TextBox3.Text &= vbNewLine & "Die Waren befinden sich am Amtsplatz des ZA Nickelsdorf."
                            Case "NEU"
                            Case "DTB", "FO_WIHD"
                            Case Else
                                Select Case AVISO.Grenzstelle
                                    Case "SUB"
                                        rpt.TextBox3.Text &= vbNewLine & "Die Waren befinden sich am Amtsplatz des ZA Suben-Autobahn."
                                    Case Else
                                End Select
                        End Select
                End Select
            End If



            Dim tb As New DataTable
            tb.Columns.Add("Nr", GetType(Integer))
            '   tb.Columns.Add("Nr", GetType(String))
            '   tb.Columns.Add("PosNr", GetType(String))
            '   tb.Columns.Add("AbfArt", GetType(String))
            Dim cnt = 1



            For Each s In SENDUNGEN
                'Ä tb.Rows.Add(cnt, s.AbfertigungsNr, s.tblSnd_Abfertigungsart_ID)
                tb.Rows.Add(SENDUNGEN.IndexOf(s))
                'If s.tblSnd_Colli IsNot Nothing AndAlso IsNumeric(s.tblSnd_Colli.Replace("Pk", "").Replace(".", "").Trim) Then gesColli += s.tblSnd_Colli
                'If s.tblSnd_Gewicht IsNot Nothing AndAlso IsNumeric(s.tblSnd_Gewicht.Replace("kg", "").Trim) Then gesGewicht += s.tblSnd_Gewicht
                cnt += 1
            Next

            'Try
            '    rpt.txtGesColli.Text = If(gesColli = 0, "-", gesColli.ToString("N0")) & " Pk"
            '    rpt.txtGesGewicht.Text = If(gesGewicht = 0, "-", gesGewicht.ToString("N1")) & " kg"
            'Catch ex As Exception
            '    MsgBox(ex.Message & ex.StackTrace)
            'End Try

            rpt.SubReport1.Visible = False

            If Vorpapier = "" Then
                AVISO.LOAD_Vorpapiere()
                If AVISO.VORPAPIERE.Count > 0 Then ' prüfen, ob AT-Zoll ohne Ü-T1 --> dann kein Eintrag!
                    ' rpt.Detail.Visible = False
                    Dim SubRptVP As New subRptLaufzettelZollDE_Vorpapier(AVISO.VORPAPIERE)
                    rpt.SubReport1.Report = SubRptVP
                    rpt.SubReport1.Visible = True
                End If
            Else
                Dim VORPAPIERE As New List(Of VERAG_PROG_ALLGEMEIN.cAvisoVorpapier)
                Dim VP As New VERAG_PROG_ALLGEMEIN.cAvisoVorpapier
                '     VP.vp_Nr = Vorpapier.ToString.Replace("XXXX", "") : VORPAPIERE.Add(VP)
                VP.vp_Nr = Vorpapier : VORPAPIERE.Add(VP)

                Dim SubRptVP As New subRptLaufzettelZollDE_Vorpapier(VORPAPIERE)
                rpt.SubReport1.Report = SubRptVP
                rpt.SubReport1.Visible = True
            End If


            'MsgBox(tb.Rows.Count)

            rpt.DataSource = tb
            Dim fiskal_bool = False

            AddHandler rpt.Detail.Format, Sub()
                                              Dim SND As VERAG_PROG_ALLGEMEIN.cSendungen = SENDUNGEN(rpt.Fields.Item("Nr").Value)

                                              Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                              ZOLLANMELDUNG.getDataByBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString, SND.tblSnd_DakosyRef, AVISO.Grenzstelle) ' Die weiteren Daten werden hier geladen



                                              rpt.txtNr.Text = CInt(rpt.Fields.Item("Nr").Value) + 1
                                              If If(SND.tblSnd_Vorpapier, "") = Vorpapier Then
                                                  rpt.txtPos.Text = If(SND.tblSnd_Vorpapier_Pos, "").ToString.Trim
                                              ElseIf If(SND.tblSnd_Vorpapier2, "") = Vorpapier Then
                                                  rpt.txtPos.Text = If(SND.tblSnd_Vorpapier2_Pos, "").ToString.Trim
                                              ElseIf If(SND.tblSnd_Vorpapier3, "") = Vorpapier Then
                                                  rpt.txtPos.Text = If(SND.tblSnd_Vorpapier3_Pos, "").ToString.Trim
                                              End If


                                              If SND.tblSnd_Fremdspedition Then
                                                  rpt.txtAbfertigungsart.Text = "FREMD"
                                                  rpt.txtPosNr.Text = SND.tblSnd_FremdspeditionText
                                              Else
                                                  rpt.txtPosNr.Text = If(SND.FilialenNr > 0, SND.FilialenNr & "/", "") & If(SND.AbfertigungsNr > 0, SND.AbfertigungsNr, "-")
                                                  rpt.txtPosNr.Text &= vbNewLine & VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(SND.FilialenNr, False)

                                                  If SND.tblSnd_Abfertigungsart_ID > 0 Then
                                                      Select Case SND.tblSnd_Abfertigungsart_ID
                                                          Case 1 : rpt.txtAbfertigungsart.Text = "Zollabfertigung"
                                                          Case 23 : rpt.txtAbfertigungsart.Text = "ATA-Nr."

                                                          Case 26, 28
                                                              rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                                              fiskal_bool = True
                                                          Case Else : rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                                      End Select
                                                  Else
                                                      rpt.txtAbfertigungsart.Text = "-"
                                                  End If
                                              End If


                                              Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                                                  Case "IMEX" : rpt.txtPosNr.Text &= vbNewLine & SND.tblSnd_KdAuftragsNrAvisierer
                                              End Select

                                              rpt.txtAbsender.Text = If(SND.tblSnd_Absender, "-")
                                              ' rpt.txtEmpfänger.Text = (If(SND.tblSnd_EmpfaengerKdNr > 0, SND.tblSnd_EmpfaengerKdNr, "") & " " & If(SND.tblSnd_Empfaenger, "")).Trim
                                              rpt.txtEmpfänger.Text = If(SND.tblSnd_Empfaenger, "").Trim
                                              rpt.txtEmpfänger.Text = rpt.txtEmpfänger.Text.Replace("(IMEX)", "").Trim

                                              Dim NCTS_VZAdr = ""
                                              NCTS_VZAdr = If(SND.tblSnd_NCTSVerzollungsadresse, "")
                                              NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Strasse, "")
                                              NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Land, "") & " " & If(SND.NCTS_Verzollungsadresse_PLZ, "") & " " & If(SND.NCTS_Verzollungsadresse_Ort, "")
                                              NCTS_VZAdr &= vbNewLine
                                              If If(SND.NCTS_Bestimmungszollstelle, "") <> "" Then NCTS_VZAdr &= "Best.Zollst.:" & If(SND.NCTS_Bestimmungszollstelle, "") & "   "
                                              '  If If(SENDUNG.NCTS_Verzollungsadresse_EORI, "") <> "" Then VALUES.NCTS_VZAdr &= "EORI:" & If(SND.NCTS_Verzollungsadresse_EORI, "") & If(SND.NCTS_Verzollungsadresse_EORI_NL, "")



                                              ''-- Handelsrechnung --
                                              ' If SND.tblSnd_Abfertigungsart_ID = 5 Then
                                              ' NCTS_VZAdr &= vbNewLine & "Handelsrg.: " & ZOLLANMELDUNG.Handelsrechnung
                                              ' End If


                                              rpt.txtVerzollungsadresse.Text = NCTS_VZAdr.Trim

                                              Dim ATAMRN_List As New List(Of VERAG_PROG_ALLGEMEIN.cSendHandling)
                                              Dim ATAMRN = ""
                                              SND.LOAD_HANDLING()




                                              If SND.tblSnd_Abfertigungsart_ID = 23 AndAlso SND.tblSnd_ATANr IsNot Nothing Then
                                                  If SND.HANDLING.Count > 0 Then
                                                      ATAMRN_List = SND.HANDLING

                                                      '    Else
                                                      '        ATAMRN = SND.tblSnd_ATANr
                                                      '        If ATAMRN <> "" Then ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, If(IsNumeric(SND.tblSnd_Colli), SND.tblSnd_Colli, ""), If(IsNumeric(SND.tblSnd_Gewicht), SND.tblSnd_Gewicht, "")))
                                                      '    End If
                                                      'Else
                                                      '    Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                                      '    ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString)
                                                      '    If ATAMRN <> "" Then ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, If(IsNumeric(SND.tblSnd_Colli), SND.tblSnd_Colli, ""), If(IsNumeric(SND.tblSnd_Gewicht), SND.tblSnd_Gewicht, "")))
                                                  End If
                                              End If

                                              If ATAMRN_List.Count = 0 Then 'kein Handling
                                                  'Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                                  'ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString)

                                                  'Dim Colli = CDbl(If(IsNumeric(If(SND.tblSnd_Colli, "")), SND.tblSnd_Colli, 0))
                                                  'Dim Gewicht = CDbl(If(IsNumeric(If(SND.tblSnd_Gewicht, "")), SND.tblSnd_Gewicht, 0))
                                                  'ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, Colli, Gewicht))



                                                  ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString, SND.tblSnd_DakosyRef)



                                                  Dim Colli As Double = 0
                                                  Dim Gewicht As Double = 0
                                                  If ZOLLANMELDUNG.num_Colli > 0 Then
                                                      Colli = ZOLLANMELDUNG.num_Colli
                                                  Else
                                                      Colli = CDbl(If(IsNumeric(If(SND.tblSnd_Colli, "")), SND.tblSnd_Colli, 0))
                                                  End If

                                                  If ZOLLANMELDUNG.num_Gewicht > 0 Then
                                                      Gewicht = CDbl(ZOLLANMELDUNG.num_Gewicht)
                                                  Else
                                                      Gewicht = CDbl(If(IsNumeric(If(SND.tblSnd_Gewicht, "")), SND.tblSnd_Gewicht, 0))
                                                  End If

                                                  ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, Colli, Gewicht))
                                              End If

                                              If isATZollWithoutUeT(SND, ZOLLANMELDUNG) Then ' prüfen, ob AT-Zoll ohne Ü-T1 --> dann kein Eintrag!
                                                  ' rpt.Detail.Visible = False
                                                  Dim SubRpt As New subRptLaufzettelZollDE_ATZOLL
                                                  rpt.SubReport.Report = SubRpt
                                              Else

                                                  rpt.Detail.Visible = True
                                                  For Each a In ATAMRN_List
                                                      gesColli += a.sndhdg_colli
                                                      gesGewicht += a.sndhdg_gewicht
                                                  Next
                                                  Dim SubRpt As New subRptLaufzettelZollDE_ATA(ATAMRN_List, SND.tblSnd_Fremdspedition, ZOLLANMELDUNG.Vorpapier, SND.tblSnd_Warenwert, SND.tblSnd_WarenwertWaehrung, ZOLLANMELDUNG.Handelsrechnung)
                                                  rpt.SubReport.Report = SubRpt

                                              End If


                                              rpt.txtAnmerkung.Visible = False

                                              'If ATAMRN_List.Count = 0 Then

                                              '    rpt.txtAnmerkung.Text = ""
                                              '    Dim colliGewicht = ""
                                              '    If If(SND.tblSnd_Colli, "") <> "" Then colliGewicht &= "Colli: " & SND.tblSnd_Colli & "; "
                                              '    If If(SND.tblSnd_Gewicht, "") <> "" Then colliGewicht &= "Gewicht: " & SND.tblSnd_Gewicht & " kg"
                                              '    If colliGewicht <> "" Then rpt.txtAnmerkung.Text = (colliGewicht & vbNewLine & rpt.txtAnmerkung.Text).Trim
                                              '    rpt.txtAnmerkung.Visible = True
                                              'Else
                                              '    rpt.txtAnmerkung.Visible = False
                                              'End If





                                          End Sub



            AddHandler rpt.ReportFooter1.Format, Sub()
                                                     Try
                                                         rpt.txtGesColli.Text = If(gesColli = 0, "-", gesColli.ToString("N0")) & " Pk"
                                                         rpt.txtGesGewicht.Text = If(gesGewicht = 0, "-", gesGewicht.ToString("N1")) & " kg"
                                                     Catch ex As Exception
                                                         MsgBox(ex.Message & ex.StackTrace)
                                                     End Try
                                                 End Sub


            AddHandler rpt.Detail.BeforePrint, Sub()
                                                   rpt.Shape8.Height = rpt.Detail.Height
                                                   rpt.Shape10.Height = rpt.Detail.Height
                                                   rpt.Shape11.Height = rpt.Detail.Height


                                               End Sub


            'AddHandler rpt.ReportFooter1.Format, Sub()


            '                                     End Sub
            If printReportElsePDF Then 'NUR DRUCK!!
                rpt.Run(False)

                rpt.Document.Printer.PrinterName = printername
                rpt.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rpt.Document.Printer.OriginAtMargins = False

                rpt.Document.Print((printername = ""), False)
                rpt.Dispose()
            Else

                If (Vorpapier <> "") Then
                    tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("Gestellungsliste_" & Vorpapier & ".pdf", ".pdf", , False)
                Else
                    tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("LaufzettelZollDE.pdf", ".pdf", , False)
                End If

                Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
                rpt.Run(False)

                p.NeverEmbedFonts = ""
                p.Export(rpt.Document, tmpPath)

                rpt.Dispose()

            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try
        Return tmpPath
    End Function


    Shared Function Sammelakt_CheckIn(AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNGEN As List(Of VERAG_PROG_ALLGEMEIN.cSendungen), Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional Vorpapier As String = "") As String
        '  Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim tmpPath = ""
        Try
            Dim rpt As New rptLaufzettelZollDE
            gesColli = 0
            gesGewicht = 0

            rpt.txtLKW.Text = AVISO.LKW_Nr
            rpt.txtLKWId.Text = AVISO.AvisoID

            If AVISO.Zollstelle IsNot Nothing AndAlso AVISO.Zollstelle <> "" Then
                'rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT basncd_dstnr +' - ' + [basncd_name]  FROM basncd WHERE basncd_dstnr='" & AVISO.Zollstelle & "' ", "ATLAS")
                rpt.txtGrenzstelle.Text = VSQL.getValueTxtBySql("SELECT Code +' - ' + [Description]  FROM tbl_DY_ZollDE_C0141_Zollstellen WHERE Code='" & AVISO.Zollstelle & "' AND ((StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()))", "FMZOLL")
            Else
                Select Case AVISO.Grenzstelle
                    Case "SUB" : rpt.txtGrenzstelle.Text = "SUBEN"
                    Case "WAI" : rpt.txtGrenzstelle.Text = "WAIDHAUS"
                    Case "SBG" : rpt.txtGrenzstelle.Text = "BAD REICHENHALL"
                    Case "SFD" : rpt.txtGrenzstelle.Text = "SPIELFELD"
                    Case "DTB", "FO_WIHD" : rpt.txtGrenzstelle.Text = "DETTELBACH"
                    Case Else : rpt.txtGrenzstelle.Text = AVISO.Grenzstelle.Replace("???", "")
                End Select
            End If

            rpt.txtDatum.Text = Now.ToShortDateString
            rpt.txtSB.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME

            Dim ort = "Suben"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "IMEX"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_IMEX.Visible = True
                    rpt.picVERAG.Image = My.Resources.IMEX_LOGO_simple

                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                Case "UNISPED"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirma_UNISPED.Visible = True
                    rpt.picVERAG.Image = My.Resources.Unisped_logo

                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
            '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                Case "ATILLA"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_ATILLA.Visible = True
                    rpt.picVERAG.Image = My.Resources.Atilla
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg

                Case "FRONTOFFICE"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmeninfo_rontoffice.Visible = True
                    rpt.picVERAG.Image = My.Resources.FrontOfficeSUB_Horizontal
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    '   rpt.txtFraechter.Text = If(AVISO.Frächter_KdNr <> "", AVISO.Frächter_KdNr & " ", "") & AVISO.Frächter
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
                Case Else
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                        Case "SBG" : ort = "Bad Reichenhall"
                        Case "WAI" : ort = "Waidhaus"
                        Case "NKD" : ort = "Nickelsdorf"
                        Case "NEU" : ort = "Neuhaus am Inn"
                    End Select
                    rpt.TextBox32.Text = "Avisierer (*):"
                    rpt.txtFraechter.Text = AVISO.Auftraggeber
                    'rpt.TextBox19.Text = "Rechnung Fatura" 'Stern weg
            End Select


            rpt.txtDW.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl
            rpt.txtEmail.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_email



            'Dim tb As New DataTable
            'tb.Columns.Add("Nr", GetType(Integer))
            'Dim cnt = 1



            'For Each s In SENDUNGEN
            '    tb.Rows.Add(SENDUNGEN.IndexOf(s))
            '    cnt += 1
            'Next



            ' rpt.DataSource = tb
            Dim fiskal_bool = False

            AddHandler rpt.Detail.Format, Sub()
                                              'Dim SND As VERAG_PROG_ALLGEMEIN.cSendungen = SENDUNGEN(rpt.Fields.Item("Nr").Value)

                                              'Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                              'ZOLLANMELDUNG.getDataByBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString, SND.tblSnd_DakosyRef) ' Die weiteren Daten werden hier geladen



                                              'rpt.txtNr.Text = CInt(rpt.Fields.Item("Nr").Value) + 1
                                              'If If(SND.tblSnd_Vorpapier, "") = Vorpapier Then
                                              '    rpt.txtPos.Text = If(SND.tblSnd_Vorpapier_Pos, "").ToString.Trim
                                              'ElseIf If(SND.tblSnd_Vorpapier2, "") = Vorpapier Then
                                              '    rpt.txtPos.Text = If(SND.tblSnd_Vorpapier2_Pos, "").ToString.Trim
                                              'ElseIf If(SND.tblSnd_Vorpapier3, "") = Vorpapier Then
                                              '    rpt.txtPos.Text = If(SND.tblSnd_Vorpapier3_Pos, "").ToString.Trim
                                              'End If

                                              'If SND.tblSnd_Fremdspedition Then
                                              '    rpt.txtAbfertigungsart.Text = "FREMD"
                                              '    rpt.txtPosNr.Text = SND.tblSnd_FremdspeditionText
                                              'Else
                                              '    rpt.txtPosNr.Text = If(SND.FilialenNr > 0, SND.FilialenNr & "/", "") & If(SND.AbfertigungsNr > 0, SND.AbfertigungsNr, "-")
                                              '    rpt.txtPosNr.Text &= vbNewLine & VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(SND.FilialenNr, False)

                                              '    If SND.tblSnd_Abfertigungsart_ID > 0 Then
                                              '        Select Case SND.tblSnd_Abfertigungsart_ID
                                              '            Case 1 : rpt.txtAbfertigungsart.Text = "Zollabfertigung"
                                              '            Case 23 : rpt.txtAbfertigungsart.Text = "ATA-Nr."
                                              '            Case 26, 28
                                              '                rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                              '                fiskal_bool = True
                                              '            Case Else : rpt.txtAbfertigungsart.Text = VERAG_PROG_ALLGEMEIN.cAbfertigungsarten.getAbfertigungsartBezById(SND.tblSnd_Abfertigungsart_ID)
                                              '        End Select
                                              '    Else
                                              '        rpt.txtAbfertigungsart.Text = "-"
                                              '    End If
                                              'End If


                                              'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                                              '    Case "IMEX" : rpt.txtPosNr.Text &= vbNewLine & SND.tblSnd_KdAuftragsNrAvisierer
                                              'End Select

                                              'rpt.txtAbsender.Text = If(SND.tblSnd_Absender, "-")
                                              '' rpt.txtEmpfänger.Text = (If(SND.tblSnd_EmpfaengerKdNr > 0, SND.tblSnd_EmpfaengerKdNr, "") & " " & If(SND.tblSnd_Empfaenger, "")).Trim
                                              'rpt.txtEmpfänger.Text = If(SND.tblSnd_Empfaenger, "").Trim
                                              'rpt.txtEmpfänger.Text = rpt.txtEmpfänger.Text.Replace("(IMEX)", "").Trim

                                              'Dim NCTS_VZAdr = ""
                                              'NCTS_VZAdr = If(SND.tblSnd_NCTSVerzollungsadresse, "")
                                              'NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Strasse, "")
                                              'NCTS_VZAdr &= vbNewLine & If(SND.NCTS_Verzollungsadresse_Land, "") & " " & If(SND.NCTS_Verzollungsadresse_PLZ, "") & " " & If(SND.NCTS_Verzollungsadresse_Ort, "")
                                              'NCTS_VZAdr &= vbNewLine
                                              'If If(SND.NCTS_Bestimmungszollstelle, "") <> "" Then NCTS_VZAdr &= "Best.Zollst.:" & If(SND.NCTS_Bestimmungszollstelle, "") & "   "
                                              ''  If If(SENDUNG.NCTS_Verzollungsadresse_EORI, "") <> "" Then VALUES.NCTS_VZAdr &= "EORI:" & If(SND.NCTS_Verzollungsadresse_EORI, "") & If(SND.NCTS_Verzollungsadresse_EORI_NL, "")


                                              'rpt.txtVerzollungsadresse.Text = NCTS_VZAdr.Trim

                                              'Dim ATAMRN_List As New List(Of VERAG_PROG_ALLGEMEIN.cSendHandling)
                                              'Dim ATAMRN = ""
                                              'SND.LOAD_HANDLING()

                                              'If SND.tblSnd_Abfertigungsart_ID = 23 AndAlso SND.tblSnd_ATANr IsNot Nothing Then
                                              '    If SND.HANDLING.Count > 0 Then
                                              '        ATAMRN_List = SND.HANDLING

                                              '        '    Else
                                              '        '        ATAMRN = SND.tblSnd_ATANr
                                              '        '        If ATAMRN <> "" Then ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, If(IsNumeric(SND.tblSnd_Colli), SND.tblSnd_Colli, ""), If(IsNumeric(SND.tblSnd_Gewicht), SND.tblSnd_Gewicht, "")))
                                              '        '    End If
                                              '        'Else
                                              '        '    Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                              '        '    ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString)
                                              '        '    If ATAMRN <> "" Then ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, If(IsNumeric(SND.tblSnd_Colli), SND.tblSnd_Colli, ""), If(IsNumeric(SND.tblSnd_Gewicht), SND.tblSnd_Gewicht, "")))
                                              '    End If
                                              'End If

                                              'If ATAMRN_List.Count = 0 Then 'kein Handling
                                              '    'Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
                                              '    'ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString)

                                              '    'Dim Colli = CDbl(If(IsNumeric(If(SND.tblSnd_Colli, "")), SND.tblSnd_Colli, 0))
                                              '    'Dim Gewicht = CDbl(If(IsNumeric(If(SND.tblSnd_Gewicht, "")), SND.tblSnd_Gewicht, 0))
                                              '    'ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, Colli, Gewicht))



                                              '    ATAMRN = ZOLLANMELDUNG.getATAMRNBezugsnummer(SND.FilialenNr & "/" & SND.AbfertigungsNr, SND.tblSnd_Abfertigungsart_ID.ToString, SND.tblSnd_DakosyRef)

                                              '    Dim Colli As Double = 0
                                              '    Dim Gewicht As Double = 0
                                              '    If ZOLLANMELDUNG.num_Colli > 0 Then
                                              '        Colli = ZOLLANMELDUNG.num_Colli
                                              '    Else
                                              '        Colli = CDbl(If(IsNumeric(If(SND.tblSnd_Colli, "")), SND.tblSnd_Colli, 0))
                                              '    End If

                                              '    If ZOLLANMELDUNG.num_Gewicht > 0 Then
                                              '        Gewicht = CDbl(ZOLLANMELDUNG.num_Gewicht)
                                              '    Else
                                              '        Gewicht = CDbl(If(IsNumeric(If(SND.tblSnd_Gewicht, "")), SND.tblSnd_Gewicht, 0))
                                              '    End If

                                              '    ATAMRN_List.Add(New VERAG_PROG_ALLGEMEIN.cSendHandling(-1, "", ATAMRN, Colli, Gewicht))
                                              'End If

                                              'If isATZollWithoutUeT(SND, ZOLLANMELDUNG) Then ' prüfen, ob AT-Zoll ohne Ü-T1 --> dann kein Eintrag!
                                              '    ' rpt.Detail.Visible = False
                                              '    Dim SubRpt As New subRptLaufzettelZollDE_ATZOLL
                                              '    rpt.SubReport.Report = SubRpt
                                              'Else

                                              '    rpt.Detail.Visible = True
                                              '    For Each a In ATAMRN_List
                                              '        gesColli += a.sndhdg_colli
                                              '        gesGewicht += a.sndhdg_gewicht
                                              '    Next
                                              '    Dim SubRpt As New subRptLaufzettelZollDE_ATA(ATAMRN_List, SND.tblSnd_Fremdspedition, ZOLLANMELDUNG.Vorpapier, SND.tblSnd_Warenwert, SND.tblSnd_WarenwertWaehrung)
                                              '    rpt.SubReport.Report = SubRpt

                                              'End If


                                              'rpt.txtAnmerkung.Visible = False

                                              ''If ATAMRN_List.Count = 0 Then

                                              ''    rpt.txtAnmerkung.Text = ""
                                              ''    Dim colliGewicht = ""
                                              ''    If If(SND.tblSnd_Colli, "") <> "" Then colliGewicht &= "Colli: " & SND.tblSnd_Colli & "; "
                                              ''    If If(SND.tblSnd_Gewicht, "") <> "" Then colliGewicht &= "Gewicht: " & SND.tblSnd_Gewicht & " kg"
                                              ''    If colliGewicht <> "" Then rpt.txtAnmerkung.Text = (colliGewicht & vbNewLine & rpt.txtAnmerkung.Text).Trim
                                              ''    rpt.txtAnmerkung.Visible = True
                                              ''Else
                                              ''    rpt.txtAnmerkung.Visible = False
                                              ''End If





                                          End Sub



            AddHandler rpt.ReportFooter1.Format, Sub()
                                                     Try
                                                         rpt.txtGesColli.Text = If(gesColli = 0, "-", gesColli.ToString("N0")) & " Pk"
                                                         rpt.txtGesGewicht.Text = If(gesGewicht = 0, "-", gesGewicht.ToString("N1")) & " kg"
                                                     Catch ex As Exception
                                                         MsgBox(ex.Message & ex.StackTrace)
                                                     End Try
                                                 End Sub


            AddHandler rpt.Detail.BeforePrint, Sub()
                                                   rpt.Shape8.Height = rpt.Detail.Height
                                                   rpt.Shape10.Height = rpt.Detail.Height
                                                   rpt.Shape11.Height = rpt.Detail.Height


                                               End Sub

            If printReportElsePDF Then 'NUR DRUCK!!
                rpt.Run(False)

                rpt.Document.Printer.PrinterName = printername
                rpt.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rpt.Document.Printer.OriginAtMargins = False

                rpt.Document.Print((printername = ""), False)
                rpt.Dispose()
            Else


                tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("Sammelakt_CheckIn.pdf", ".pdf", , False)


                Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
                rpt.Run(False)

                p.NeverEmbedFonts = ""
                p.Export(rpt.Document, tmpPath)

                rpt.Dispose()

            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try
        Return tmpPath
    End Function

    Shared Function isATZollWithoutUeT(SND As VERAG_PROG_ALLGEMEIN.cSendungen, ZOLLANMELDUNG As DAKOSY_Worker.cZollsysteme_Aktenbeschriftung) As Boolean
        If SND IsNot Nothing And ZOLLANMELDUNG IsNot Nothing Then
            Select Case SND.tblSnd_Abfertigungsart_ID
                Case 38, 26 'AT
                    If Not ZOLLANMELDUNG.isUeT1 Then
                        Return True
                    End If
            End Select

        End If
        Return False
    End Function


    Shared Function DispoListe(usrCntl As usrCntlDispoliste) As String
        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim odoc As Microsoft.Office.Interop.Word.Document = Nothing
        Dim oWord As New Microsoft.Office.Interop.Word.Application
        Try
            Dim nameDispo = ""
            Select Case usrCntl.cboSprache._value
                Case "TR"
                    nameDispo = "Dispoliste_TR"
                Case Else
                    nameDispo = "Dispoliste_EN"
            End Select

            Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", nameDispo)
            Dim pfadWord = DS.GET_TOP1_PATH(False)

            Dim cGenWord As New cGenWord

            odoc = cGenWord.openWord(pfadWord, False, oWord)

            Dim oTable As Word.Table

            odoc.FormFields("An1").Range.Text = usrCntl.txtFirma.Text
            odoc.FormFields("An2").Range.Text = usrCntl.txtAnsprechpartner.Text
            odoc.FormFields("An3").Range.Text = usrCntl.txtAdresse1.Text
            odoc.FormFields("An4").Range.Text = usrCntl.txtAdresse2.Text
            odoc.FormFields("An5").Range.Text = usrCntl.txtAdresse3.Text
            odoc.FormFields("LKW").Range.Text = usrCntl.txtLKWKennzeichen.Text
            odoc.FormFields("SB").Range.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME

            If odoc.Range.Bookmarks.Exists("Tabelle") Then
                If odoc.Bookmarks("Tabelle").Range.Tables.Count > 0 Then
                    oTable = odoc.Bookmarks("Tabelle").Range.Tables(1)
                    Dim i = 1
                    Dim kfzTmp = ""
                    'For Each r As DataRow In dt.Rows
                    For Each c In usrCntl.MyFlowLayoutPanel1.Controls
                        Dim tmp = DirectCast(c, usrCnrlDispolisteElemente) 'For i = 1 To i = 3
                        oTable.Rows.Add()
                        oTable.Rows(i + 1).Cells(1).Range.Text = tmp.RichTextBox.Text
                        oTable.Rows(i + 1).Cells(2).Range.Text = tmp.RichTextBox1.Text
                        oTable.Rows(i + 1).Cells(3).Range.Text = tmp.RichTextBox2.Text
                        oTable.Rows(i + 1).Cells(4).Range.Text = tmp.RichTextBox3.Text
                        'oTable.Rows(i + 1).Cells(3).Range.Text = tmp.RichTextBox4.Text
                        i += 1
                    Next
                End If
            Else
                MessageBox.Show("Textmarke nicht vorhanden!")
            End If
            odoc.Save() : odoc.Activate()


            Dim path = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(nameDispo & ".pdf", ".pdf", True, False)

            odoc.SaveAs(path, Word.WdSaveFormat.wdFormatPDF)

            Try
                odoc.Close()
                oWord.Quit()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

            Return path



        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return ""
    End Function

    Shared Function SA_Gestellung(usrCntl As usrCntlSA_Gestellung, Optional printReportElsePDF As Boolean = False, Optional printername As String = "") As String
        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        ' Dim odoc As Microsoft.Office.Interop.Excel.Sheets = Nothing
        Dim oExc As New Microsoft.Office.Interop.Excel.Application

        Dim excelBook As Excel.Workbook

        Try
            Dim nameDispo = "SA_Gestellung"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                Case "WAI" : nameDispo = "SA_Gestellung_WAI"
            End Select

            Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", nameDispo)
            Dim pfadWord = DS.GET_TOP1_PATH(False)

            ' Dim cGenWord As New cGenWord

            '  oExc = cGenWord.openWord(pfadWord, False, oWord)
            excelBook = oExc.Workbooks.Open(pfadWord)


            Dim vname = ""
            If VERAG_PROG_ALLGEMEIN.cAllgemein.USR_VNAME.Length > 0 Then vname = VERAG_PROG_ALLGEMEIN.cAllgemein.USR_VNAME.Substring(0, 1) & "."

            oExc.Range("C4").Value = VERAG_PROG_ALLGEMEIN.cAllgemein.USR_NNAME & " " & vname
            oExc.Range("C5").Value = usrCntl.txtFilialeLKWId.Text
            oExc.Range("I7").Value = usrCntl.txtLKWKennzeichen.Text

            oExc.Range("C8").Value = usrCntl.txtGesColli.Text.Replace(".", "") ' Damit nicht falsche kommastelle erzuegt wird
            oExc.Range("D8").Value = usrCntl.txtGesGewicht.Text.Replace(".", "")
            oExc.Range("I5").Value = Now.ToShortDateString
            oExc.Range("C7").Value = usrCntl.txtT1Gestellung.Text
            oExc.Range("F7").Value = usrCntl.txtBezugsNrSumA.Text


            oExc.Range("F4").Value = If(VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl <> "", VERAG_PROG_ALLGEMEIN.cAllgemein.MITARBEITER.mit_durchwahl, "+43 7711 / 2777 - 0")
            'oExc.Range("F5").Value = usrCntl.txtT1Gestellung.Text


            'Wenn die Excel-Vorlage nciht reicht, werden neue Zeilen eingefügt
            For cnt = 13 To usrCntl.MyFlowLayoutPanel1.Controls.Count
                oExc.Range("A11").EntireRow.Copy()
                oExc.Range("A11").EntireRow.Insert(Excel.XlDirection.xlDown)
            Next


            Dim i = 0
            For Each c In usrCntl.MyFlowLayoutPanel1.Controls
                Dim tmp = DirectCast(c, usrCntlSA_GestellungElemente) 'For i = 1 To i = 3
                oExc.Range("A" & (i + 11)).Value = tmp.lbl1.Text ' (i + 1)
                oExc.Range("B" & (i + 11)).Value = tmp.txtWarenbezeichnung.Text
                oExc.Range("C" & (i + 11)).Value = tmp.txtColli.Text.Replace(".", "") ' Damit nicht falsche kommastelle erzuegt wird
                oExc.Range("D" & (i + 11)).Value = tmp.txtGewicht.Text
                oExc.Range("E" & (i + 11)).Value = tmp.txtAbsender.Text
                oExc.Range("F" & (i + 11)).Value = tmp.txtEmpfaenger.Text
                oExc.Range("G" & (i + 11)).Value = tmp.cboAbfertigungsart.Text
                oExc.Range("H" & (i + 11)).Value = tmp.txtAtaMrn.Text
                oExc.Range("I" & (i + 11)).Value = tmp.rtbBemerkung.Text

                i += 1
            Next


            Dim p = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(nameDispo & ".xlsx", ".xlsx", True, False)

            excelBook.SaveAs(p) ': oExc.Activate()


            If printReportElsePDF Then 'NUR DRUCK!!
                oExc.Visible = False

                'Print
                oExc.Workbooks(1).PrintOutEx() '1, 1, 1, True)

                Try
                    oExc.Workbooks.Close()
                    oExc.Quit()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                oExc.Visible = True
            End If


            '  Dim path = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(nameDispo & ".pdf", ".pdf", True, False)

            '            odoc.SaveAs(path, Word.WdSaveFormat.wdFormatPDF)


            Return ""
            '   Return pfadWord



        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return ""
    End Function


    Shared Function VerpflichtungserklärungFahrerRpt(usrCntl As usrCntlVerpflichtungserklärungFahrer, Optional printReportElsePDF As Boolean = False, Optional printername As String = "") As List(Of String)
        '  Dim odoc As Microsoft.Office.Interop.Word.Document = Nothing
        ' Dim oWord As New Microsoft.Office.Interop.Word.Application
        Dim striList As New List(Of String)
        Try




            '  s()
            Dim rpt As New rptVerpflichtungserklaerung


            rpt.txtFraechter.Text = usrCntl.txtFirma.Text
            rpt.txtLKWKennz.Text = usrCntl.txtLKWKennzeichen.Text
            rpt.txtFahrername.Text = usrCntl.txtFahrername.Text
            rpt.txtPassnummer.Text = usrCntl.txtPassnummer.Text

            rpt.txtWohnort.Text = usrCntl.txtAdresseFahrer.Text
            'If usrCntl.txtAdresseFahrer.Lines.Count > 0 Then odoc.FormFields("Adresse1").Range.Text = usrCntl.txtAdresseFahrer.Lines(0) Else odoc.FormFields("Adresse1").Range.Text = ""
            'If usrCntl.txtAdresseFahrer.Lines.Count > 1 Then odoc.FormFields("Adresse2").Range.Text = usrCntl.txtAdresseFahrer.Lines(1) Else odoc.FormFields("Adresse2").Range.Text = ""

            rpt.txtMobilTel.Text = usrCntl.txtMobilNr.Text
            rpt.txtAvisoId.Text = usrCntl.AVISOID
            Dim ort = "Suben"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "IMEX"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_IMEX.Visible = True
                    rpt.picVERAG.Image = My.Resources.IMEX_LOGO_simple
                Case "ATILLA"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_ATILLA.Visible = True
                    rpt.picVERAG.Image = My.Resources.Atilla
                Case "UNISPED"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirma_UNISPED.Visible = True
                    rpt.picVERAG.Image = My.Resources.Unisped_logo
                Case "FRONTOFFICE"
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmeninfo_rontoffice.Visible = True
                    rpt.picVERAG.Image = My.Resources.FrontOfficeSUB_Horizontal
                Case Else
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                        Case "SBG" : ort = "Bad Reichenhall"
                        Case "WAI" : ort = "Waidhaus"
                        Case "NKD" : ort = "Nickelsdorf"
                        Case "NEU" : ort = "Neuhaus am Inn"
                    End Select
            End Select


            rpt.txtDatumOrt.Text = ort & ", den " & Now.ToShortDateString


            Dim barcodeLKW As Image = Code128Rendering.MakeBarcodeImage("VE-" & If(usrCntl.AVISOID Is Nothing, 0, usrCntl.AVISOID) & "", 1, True, 20)
            'Dim bc As New List(Of VERAG_PROG_ALLGEMEIN.barcodeToPdf)
            'Dim b = New VERAG_PROG_ALLGEMEIN.barcodeToPdf(barcodeLKW, 20, 200, 20, 20, 1, Drawing.RotateFlipType.Rotate270FlipNone)
            'bc.Add(b)
            barcodeLKW.RotateFlip(RotateFlipType.Rotate270FlipNone)
            rpt.picBarcodeVerpfl.Image = barcodeLKW


            Dim tb As New DataTable
            tb.Columns.Add("MRN1", GetType(String))
            tb.Columns.Add("MRN2", GetType(String))
            Dim cnt = 0

            Dim v1 = ""
            Dim v2 = ""

            For Each c As DataGridViewRow In usrCntl.MyDatagridview1.Rows
                If c.Cells(0).Value <> "" Then 'Wenn Zeile nicht leer
                    If cnt Mod 2 = 0 Then 'gerade
                        v1 = (cnt + 1) & ". " & c.Cells(0).Value
                    Else
                        v2 = (cnt + 1) & ". " & c.Cells(0).Value
                        tb.Rows.Add(v1, v2)
                        v1 = ""
                        v2 = ""
                    End If
                    cnt += 1
                End If
            Next
            If v1 <> "" Then
                tb.Rows.Add(v1, "")
            End If

            'MsgBox(tb.Rows.Count)

            rpt.DataSource = tb

            AddHandler rpt.Detail.Format, Sub()
                                              rpt.txtMRN1.Text = nullStr(rpt.Fields.Item(0).Value)
                                              rpt.txtMRN2.Text = nullStr(rpt.Fields.Item(1).Value)
                                          End Sub


            If printReportElsePDF Then 'NUR DRUCK!!
                rpt.Run(False)

                rpt.Document.Printer.PrinterName = printername
                rpt.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rpt.Document.Printer.OriginAtMargins = False

                rpt.Document.Print((printername = ""), False)
                rpt.Dispose()
            Else


                Dim tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("tmp_Verpfichtungserklärung.pdf", ".pdf", , False)
                Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
                rpt.Run(False)

                p.NeverEmbedFonts = ""
                p.Export(rpt.Document, tmpPath)

                striList.Add(tmpPath)
                rpt.Dispose()
            End If


        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return striList
    End Function

    Shared Function nullStr(o As Object) As String
        Try
            If o Is DBNull.Value Then Return ""
            Return CStr(o)
        Catch ex As Exception
            Return ""
        End Try

    End Function
    Shared Function VerpflichtungserklärungFa9hrer(usrCntl As usrCntlVerpflichtungserklärungFahrer) As List(Of String)
        Dim odoc As Microsoft.Office.Interop.Word.Document = Nothing
        Dim oWord As New Microsoft.Office.Interop.Word.Application
        Dim striList As New List(Of String)
        Try
            Dim nameDispo = ""
            nameDispo = "VerpflichtungserklärungFahrer"
            'Select Case usrCntl.cboSprache._value
            'End Select

            Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", nameDispo)
            Dim pfadWord = DS.GET_TOP1_PATH(False)

            Dim cGenWord As New cGenWord

            odoc = cGenWord.openWord(pfadWord, False, oWord)
            If odoc Is Nothing Then Return striList

            Dim oTable As Word.Table

            odoc.FormFields("Frächter").Range.Text = usrCntl.txtFirma.Text
            odoc.FormFields("LKW").Range.Text = usrCntl.txtLKWKennzeichen.Text
            odoc.FormFields("Fahrer").Range.Text = usrCntl.txtFahrername.Text
            odoc.FormFields("Pass").Range.Text = usrCntl.txtPassnummer.Text


            If usrCntl.txtAdresseFahrer.Lines.Count > 0 Then odoc.FormFields("Adresse1").Range.Text = usrCntl.txtAdresseFahrer.Lines(0) Else odoc.FormFields("Adresse1").Range.Text = ""
            If usrCntl.txtAdresseFahrer.Lines.Count > 1 Then odoc.FormFields("Adresse2").Range.Text = usrCntl.txtAdresseFahrer.Lines(1) Else odoc.FormFields("Adresse2").Range.Text = ""

            odoc.FormFields("Mobil").Range.Text = usrCntl.txtMobilNr.Text
            odoc.FormFields("AvisoId").Range.Text = "VERAG LKW-ID: " & usrCntl.AVISOID

            If odoc.Range.Bookmarks.Exists("Tabelle") Then
                If odoc.Bookmarks("Tabelle").Range.Tables.Count > 0 Then
                    oTable = odoc.Bookmarks("Tabelle").Range.Tables(1)
                    Dim i = 0
                    Dim cnt = 1
                    Dim kfzTmp = ""
                    'For Each r As DataRow In dt.Rows
                    Dim newrow = True
                    For Each c As DataGridViewRow In usrCntl.MyDatagridview1.Rows
                        If c.Cells(0).Value <> "" Then
                            If newrow Then
                                If i > 0 Then oTable.Rows.Add()
                                i += 1
                                oTable.Rows(i + 1).Cells(1).Range.Text = cnt & " - " & c.Cells(0).Value : cnt += 1
                            Else
                                oTable.Rows(i + 1).Cells(2).Range.Text = cnt & " - " & c.Cells(0).Value : cnt += 1
                            End If
                            newrow = Not newrow
                        End If
                    Next
                End If
            Else
                MessageBox.Show("Textmarke nicht vorhanden!")
            End If
            odoc.Save() : odoc.Activate()

            'VE_ für Verpflichtungserklärung
            Dim barcodeLKW As Image = Code128Rendering.MakeBarcodeImage("VE-" & If(usrCntl.AVISOID Is Nothing, 0, usrCntl.AVISOID) & "", 1, True, 20)
            Dim bc As New List(Of VERAG_PROG_ALLGEMEIN.barcodeToPdf)
            Dim b = New VERAG_PROG_ALLGEMEIN.barcodeToPdf(barcodeLKW, 20, 200, 20, 20, 1, System.Drawing.RotateFlipType.Rotate270FlipNone)
            bc.Add(b)

            Dim path = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(nameDispo & ".pdf", ".pdf", True, False)

            odoc.SaveAs(path, Word.WdSaveFormat.wdFormatPDF)

            Try
                odoc.Close()
                oWord.Quit()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

            'Aufdruck ORT DATUM:
            Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager
            Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
            Dim ort = "Suben"
            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
                Case "SBG" : ort = "Bad Reichenhall"
                Case "WAI" : ort = "Waidhaus"
                Case "NKD" : ort = "Nickelsdorf"
                Case "NEU" : ort = "Neuhaus am Inn"
            End Select
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(ort & ", den " & Now.ToShortDateString, 25, 270, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

            striList.Add(fm.fillPDFVorhandenesLokalesPDF_Path(path, listTowrite, , , , , bc))

            If usrCntl.DS_FD IsNot Nothing AndAlso usrCntl.DS_FD.DATA_LIST.LIST.Count > 0 AndAlso usrCntl.cbxPassDrucken.Checked Then
                striList.Add(usrCntl.DS_FD.OPEN_SINGLE(False))
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return striList
    End Function

    Shared Function VM_DE_Fiskal(usrCntl As usrcntlVollmacht_DE_Fiskal) As String
        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 33, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 45, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 51, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 56, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Select Case usrCntl.cboSprache._value
            Case "EN" : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 50, 62, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            Case Else : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 40, 62, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End Select

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 129, 62, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 70, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 129, 70, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 75, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 129, 75, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 81, 90, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 88, 110, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text, True)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 88, 110, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "", True)
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_Fiskal_EN", listTowrite)
            Case "FR"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_Fiskal_FR", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_DE_Fiskal", listTowrite)
        End Select
        Return ""
    End Function

    Shared Function UID_PRUEFUNG_PROTOKOLL(uid_id) As String
        Dim UID As New VERAG_PROG_ALLGEMEIN.cUIDPruefung(uid_id)
        Dim msgErgebnis = ""
        Select Case UID.uid_valid
            Case 1 : msgErgebnis = "UID-Nr. GÜLTIG   -   OK"
            Case 0 : msgErgebnis = "UID-Nr. UNGÜLTIG"
        End Select

        Dim uid_firma = ""
        uid_firma &= If(UID.uid_firma, "") & vbNewLine
        uid_firma &= If(UID.uid_adr1, "") & vbNewLine
        uid_firma &= If(UID.uid_adr2, "") & vbNewLine
        uid_firma &= If(UID.uid_adr3, "") & vbNewLine
        uid_firma &= If(UID.uid_adr4, "") & vbNewLine
        uid_firma &= If(UID.uid_adr5, "") & vbNewLine
        uid_firma &= If(UID.uid_adr6, "")
        uid_firma = uid_firma.Trim

        If UID.uid_stufe = "1" Then
            uid_firma = "*Keine Daten bei Stufe 1 Prüfung*"
        End If

        Dim Tid = ""
        Select Case UID.Firma
            Case "VERAG" : Tid = "13390891m005"
            Case "IMEX" : Tid = "19435107n654"
            Case "FRONTOFFICE" : Tid = "67493371k039"
            Case "ATILLA" : Tid = "16626209i537"
                'Case "UNISPED" : Tid = "16626209i537"
        End Select
        Dim PdfTmp = SDL.FormularManagerNEU.UID_PRUEFUNG(msgErgebnis, uid_firma, UID.uid_sessionId, UID.uid_abfrageUid, UID.uid_UstIdKz & UID.uid_UstIdNr, Tid,  ,  , UID.uid_Sachbearbeiter, UID.uid_Datum, UID.uid_stufe)
        Return PdfTmp
    End Function

    Shared Function UID_PRUEFUNG(ErgebnisTXT, firma, sessionID, uidAntragsteller, uidAbfrage, tid, Optional AvisoId = -1, Optional SendungsId = -1, Optional SB = "", Optional abfrageDatum = Nothing, Optional stufe = "2") As String
        Try
            If abfrageDatum Is Nothing Then abfrageDatum = Now


            'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
            Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

            Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Stufe " & stufe, 73, 86.5, 150, 10, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(ErgebnisTXT, 73, 110, 150, 10, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(abfrageDatum.ToShortDateString & " " & abfrageDatum.ToShortTimeString & " Uhr", 73, 118, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(uidAbfrage, ""), 73, 126, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(firma, ""), 73, 133, 150, 30, If(If(firma, "").ToString.StartsWith("*"), "normal", "bold"), 10, , itextsharp.text.Element.ALIGN_LEFT))


            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(tid, ""), 73, 163, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(uidAntragsteller, 73, 170, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(SB <> "", SB, VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME), 73, 179, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(sessionID, ""), 73, 191, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

            ' Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "UID_Prüfung", listTowrite)
            Dim PdfTmp = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2_FO, "", "UID_Prufung", listTowrite)

            Return PdfTmp

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
            Return ""
        End Try
    End Function



    Shared Function EORI_PRUEFUNG(ErgebnisTXT, firma, sessionID, txtEORI, Optional AvisoId = -1, Optional SendungsId = -1) As String
        Try
            'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
            Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

            Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(ErgebnisTXT, 73, 110, 150, 10, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString & " Uhr", 73, 118, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(txtEORI, 73, 126, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(firma, 73, 133, 150, 30, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


            '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(tid, 73, 163, 55, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))

            '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(uidAntragsteller, 73, 170, 55, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME, 73, 158, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(sessionID, 73, 191, 70, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))

            ' Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "UID_Prüfung", listTowrite)
            Dim PdfTmp = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2_FO, "", "EORI_Prufung", listTowrite)

            Return PdfTmp

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
            Return ""
        End Try
    End Function

    Shared Function VM_AT_EV(usrCntl As usrcntlVollmacht_AT_EV) As String
        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 33, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 47, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 53, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 59, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Select Case usrCntl.cboSprache._value
            Case "EN" : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 52, 66, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            Case Else : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 40, 66, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End Select

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 129, 66, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 74, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 129, 74, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 80, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 129, 80, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 86, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFaStNr.Text, If(usrCntl.cboSprache._value = "EN", 135, 129), 86, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxEVVerzollung.Checked, "x", ""), 38, 94, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxKonto.Checked, "x", ""), 38, 98, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 0, 225, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 0, 225, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "")
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_AT_4200_EN", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_AT_4200", listTowrite)
        End Select
        Return ""
    End Function



    Shared Function VM_AT_Fiskal(usrCntl As usrcntlVollmacht_AT_Fiskal) As String

        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 36, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 42, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 47, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Select Case usrCntl.cboSprache._value
            Case "EN", "FR" : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 45, 53, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            Case Else : listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechtsform.Text, 40, 53, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End Select

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 61, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 66, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 72, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite = addEinmaligeVM(listTowrite, 88, 100, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text, True)
        ElseIf usrCntl.cbxEinmaligeVollmachtCarnetATA.Checked Then
            listTowrite = addEinmaligeVMCarnetATA(listTowrite, 88, 100, usrCntl.cboSprache._value, usrCntl.txtEinmalig_CarnetATA.Text, "", True)
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 24, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 140, 53, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 66, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 133, 61, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_AT_Fiskal_EN", listTowrite)
            Case "FR"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 145, 24, 130, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 140, 53, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 66, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 133, 61, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_AT_Fiskal_FR", listTowrite)
            Case Else
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 24, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInhaber.Text, 129, 53, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 129, 66, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 129, 61, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_AT_Fiskal", listTowrite)
        End Select
        Return ""
    End Function

    Shared Function VM_ATILLA_EXPORT(usrCntl As usrcntlVollmacht_ATILLA_EXPORT) As String
        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 128, 36, 150, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 68, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 74, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 80, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 40, 87, 71, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAEO.Text, 133, 87, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 93, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 93, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 99, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        'If usrCntl.cbxEinmaligeVollmacht.Checked Then
        'listTowrite = addEinmaligeVM(listTowrite, 0, 215, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ' End If
        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 40, 54, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEinmalig_RgNr.Text, 67, 54, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEinmalig_RgDat.Text, 134, 54, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        Else
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 40, 49, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If


        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT_ATILLA_EN", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT_ATILLA", listTowrite)
        End Select
        Return ""
    End Function

    Shared Function VM_VERAG_EXPORT(usrCntl As usrcntlVollmacht_VERAG_EXPORT) As String
        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 68, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 74, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 80, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 40, 87, 71, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAEO.Text, 133, 87, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 93, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 93, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 99, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        'If usrCntl.cbxEinmaligeVollmacht.Checked Then
        'listTowrite = addEinmaligeVM(listTowrite, 0, 215, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ' End If
        If usrCntl.cbxEinmaligeVollmacht.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 40, 54, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEinmalig_RgNr.Text, 67, 54, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEinmalig_RgDat.Text, 134, 54, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        Else
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 40, 49, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If


        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX", "AMBAR", "UNISPED"
                Select Case usrCntl.cboSprache._value
                    Case "EN"
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT_EN", listTowrite)
                    Case Else
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT", listTowrite)
                End Select
            Case Else
                Select Case usrCntl.cboSprache._value
                    Case "EN"
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT_VERAG_EN", listTowrite)
                    Case Else
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "VM_EXPORT_VERAG", listTowrite)
                End Select
        End Select



        Return ""
    End Function


    Shared Function VM_VERAG_GB_IE(usrCntl As usrcntlVollmacht_GB_IE) As String
        'Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim add As Integer = -23

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 68 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 74 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 80 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 40, 87 + add, 71, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 133, 87 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 93 + add, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 93 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 99 + add, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAEO.Text, 133, 99 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'If usrCntl.cbxEinmaligeVollmacht.Checked Then
        'listTowrite = addEinmaligeVM(listTowrite, 0, 215, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ' End If
        If usrCntl.cbxZahlungsaufschub.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZahlungsaufschung.Text, 55, 109 + add, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If

        If usrCntl.cbxPostponed._value = "JA" Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 70, 118.5 + add, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        ElseIf usrCntl.cbxPostponed._value = "NEIN" Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 86, 118.5 + add, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If


        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "VERAG", "UNISPED"
                Select Case usrCntl.cboSprache._value
                    Case "EN"
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                    Case Else
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                End Select
                'Case Else

                'Select Case usrCntl.cboSprache._value
                '    Case "EN"
                '        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                '    Case Else
                '        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                'End Select
        End Select



        Return ""
    End Function

    Shared Function VM_VERAG_GB_indirect(usrCntl As usrcntlVollmacht_GB_indirekt) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim add As Integer = -23

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 68 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 74 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 80 + add, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 40, 87 + add, 71, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 133, 87 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 40, 93 + add, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 133, 93 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 40, 99 + add, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAEO.Text, 133, 99 + add, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'If usrCntl.cbxEinmaligeVollmacht.Checked Then
        'listTowrite = addEinmaligeVM(listTowrite, 0, 215, usrCntl.cboSprache._value, usrCntl.txtEinmalig_RgNr.Text, usrCntl.txtEinmalig_RgDat.Text)
        ' End If
        If usrCntl.cbxZahlungsaufschub.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZahlungsaufschung.Text, 55, 109 + add, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If

        If usrCntl.cbxPostponed._value = "JA" Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 70, 118.5 + add, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        ElseIf usrCntl.cbxPostponed._value = "NEIN" Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("x", 86, 118.5 + add, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        End If


        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "VERAG", "UNISPED"
                Select Case usrCntl.cboSprache._value
                    Case "EN"
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_indirekt", listTowrite)
                    Case Else
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_indirekt", listTowrite)
                End Select
                'Case Else

                'Select Case usrCntl.cboSprache._value
                '    Case "EN"
                '        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                '    Case Else
                '        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "VOLLMACHTEN", getUO2, "", "GB_VM_IE", listTowrite)
                'End Select
        End Select



        Return ""
    End Function


    Shared Function Importaviso_VK(usrCntl As usrcntlVorauskasse) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartnerVERAG.Text, 144, 36, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("– " & usrCntl.txtDW.Text, 45, 30.2, 15, 4, "normal", 8, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text, 32, 52, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 32, 60, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 32, 66, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 32, 71, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 32, 78, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 120, 78, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 32, 85, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 32, 91, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 120, 91, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechnungsnummern.Text, 83, 106, 110, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAbsender.Text, 32, 113, 88, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATUEur1.Text, 145, 113, 40, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLKWKennz.Text, 43, 120, 45, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUnternehmer.Text, 112, 120, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnzVerp.Text, 32, 126, 32, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtWarenbez.Text, 83, 126, 62, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.txtGewicht.Text.Trim.EndsWith("kg"), usrCntl.txtGewicht.Text, usrCntl.txtGewicht.Text & " kg"), 160, 126, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))



        Dim top = 208
        If usrCntl.cboFiliale._value <> "" Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.cboFiliale._value & "/" & usrCntl.txtAbfertigungsNr.Text, 60, top + 71.5, 43, 8, "bold", 13, , itextsharp.text.Element.ALIGN_RIGHT))
        Else
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAbfertigungsNr.Text, 60, top + 71.5, 43, 8, "bold", 13, , itextsharp.text.Element.ALIGN_RIGHT))
        End If

        Dim w = ""
        If usrCntl.cboFirma._value = "26" Then
            w = "GBP" 'VERAG-UNISPED LTD 
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Document-Date: " & Now.ToShortDateString, 100, 185.7, 100, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        Else
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Vorauskasse-Datum: " & Now.ToShortDateString, 100, 185.7, 100, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))

        End If

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.lblRechnungsbetrag.Text, w), 70, top + 0, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtFrachtkostenAusl.Text, w), 70, top + 4, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtZwischensumme.Text, w), 70, top + 8.5, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtZoll.Text, w), 70, top + 12, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZollProzent.Text, 40, top + 12, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtFrachtkostenInl.Text, w), 70, top + 16, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEustSonstText.Text, 13, top + 20.8, 40, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtEustSonstBetrag.Text, w), 70, top + 20.5, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtSumme.Text, w), 70, top + 25, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        Dim eustProz = If(IsNumeric(usrCntl.txtEustProzent._value), CDbl(usrCntl.txtEustProzent._value).ToString("P2"), usrCntl.txtEustProzent._value)
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(eustProz, 40, top + 29, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtEUST.Text, w), 70, top + 29, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))

        top = 209
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtZoll2.Text, w), 170, top + 0, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtEust2.Text, w), 170, top + 4, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAndereAbgabenText.Text, 116.5, top + 8, 40, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtAndereAbgabenBetrag.Text, w), 170, top + 8, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtVerzollungskosten.Text, w), 170, top + 13, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtWeitereTarifPos.Text, w), 170, top + 17, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtATLAS.Text, w), 170, top + 21, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtClearing.Text, w), 170, top + 25, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtKorrRechnung.Text, w), 170, top + 29, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtUebersetzungRg.Text, w), 170, top + 33, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtAviso.Text, w), 170, top + 37, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtSvs.Text, w), 170, top + 41, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonstigeKostenText.Text, 116.5, top + 45, 30, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_LEFT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonstigeKosten.Text, 170, top + 45, 30, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_RIGHT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtMwstProzent.Text, 140, top + 49, 30, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_RIGHT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtMWST.Text, 170, top + 49, 30, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_RIGHT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPapierePorti.Text, 170, top + 56, 30, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtPapierePorti.Text, w), 170, top + 45, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonstigeKostenText.Text, 116.5, top + 49, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtSonstigeKosten.Text, w), 170, top + 49, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtMwstProzent.Text, 140, top + 53, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtMWST.Text, w), 170, top + 53, 30, 6, "normal", 10, , itextsharp.text.Element.ALIGN_RIGHT))



        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.lblWaehrung.Text, w), 140, top + 61, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(chWrg(usrCntl.txtGesamtsumme.Text, w), 170, top + 61, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))



        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("WICHTIGER HINWEIS:", 12, 250, 70, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT, 2))
        Dim cbamTxt = "Ab 01.10.2023 wurde eine Meldepflicht (CBAM) beim Import bestimmter Waren aus Drittländern eingeführt. Sie als Importeur sind für diese Meldung eigenverantwortlich. Informationen unter www.zoll.de oder www.customs-consulting.at Stichwort CBAM"
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(cbamTxt, 12, 258, 180, 30, "bold", 13, , itextsharp.text.Element.ALIGN_LEFT, 2))



        If usrCntl.cbxLKWWartet.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("!!! LKW wartet !!!", 141, 12, 60, 15, "boldRed", 20, , itextsharp.text.Element.ALIGN_LEFT))
        End If

        If usrCntl.cbxBeimErstellenSpeichern.Checked Then
            '   If vbYes = MsgBox("Möchten Sie die Bonitätsauskunft in den Kundendaten speichern?", vbYesNoCancel) Then
            saveVorauskasse(usrCntl)
            'End If
        End If

        Dim destPath = ""
        If usrCntl.cboFirma._value = "26" Then 'VERAG-UNISPED LTD
            destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "VERAG-UNISPED", "", "Importaviso_VK", listTowrite)
        Else

            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "AMBAR"
                    If usrCntl.AVISO IsNot Nothing AndAlso If(usrCntl.AVISO.ImEx, "") = "EXPORT" Then
                        '  fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK", listTowrite)
                        Select Case usrCntl.cboSprache._value 'eig nur AMBAR
                            Case "EN" : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Proforma_RG", listTowrite)
                            Case Else : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Proforma_RG", listTowrite)
                        End Select
                    Else
                        Select Case usrCntl.cboSprache._value 'eig nur AMBAR
                            Case "EN" : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK_EN", listTowrite)
                            Case Else : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK", listTowrite)
                        End Select
                    End If
                Case "IMEX"
                    Select Case usrCntl.cboSprache._value 'eig nur AMBAR
                        Case "EN" : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK_EN", listTowrite)
                        Case Else : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK", listTowrite)
                    End Select
                Case "UNISPED"

                    Select Case usrCntl.cboFirma._value
                        Case "21", "23" : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VORAUSKASSE_AT", listTowrite)
                        Case Else : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_VK", listTowrite)
                    End Select
                Case Else
                    Select Case usrCntl.cboFirma._value
                        Case "11" : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_CS_NEU2", listTowrite)
                        Case Else : destPath = fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_AG_NEU2", listTowrite)
                    End Select

            End Select
        End If

        Try
            If destPath <> "" Then
                If usrCntl.SENDUNG IsNot Nothing AndAlso usrCntl.AVISO IsNot Nothing Then
                    If vbYes = MsgBox("Soll das Vorauskasse-PDF zu den Sendungs-Anhängen hinzugefügt werden?", vbYesNo) Then
                        saveToDS(usrCntl.AVISO.AvisoID, "Vorauskasse.pdf", destPath, "Vorauskasse", "PDF", ,, , usrCntl.SENDUNG.tblSnd_SendungID)
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try

        Return destPath
    End Function

    Public Shared Function chWrg(s As String, w As String)
        Return If(w <> "", s.Replace("€", w), s)
    End Function
    Public Shared Function saveToDS(AvisoId, fileName, sourcePath, Art, Typ, Optional ByRef da_id = -1, Optional ByRef anhId = -1, Optional ByRef destPath = "", Optional SendungsId = Nothing) As Boolean
        Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "AVISO_ANHAENGE", AvisoId, Now.ToString("ddMMyy_HHmmss.ffff"), "", fileName, -1, False)
        If Not DS.uploadDataToDATENSERVER(sourcePath) Then MsgBox("Fehler beim Speichern: Datenserver!") : Return False
        If DS.da_id <= 0 Then MsgBox("Keine DocId!") : Return False
        da_id = DS.da_id
        destPath = DS.GET_TOP1_PATH
        Dim fi As New FileInfo(destPath)
        Dim ANH As New VERAG_PROG_ALLGEMEIN.cAvisoAnhaenge(AvisoId, fileName, DS.da_id, Art, Typ, SendungsId,, fi.Length)
        If Not ANH.SAVE Then MsgBox("Fehler beim Anhang speichern!") : Return False
        anhId = ANH.anh_id
        Return True
    End Function


    Shared Function Importaviso(usrCntl As usrcntlImportaviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = -5
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartnerVERAG.Text, 144, 38 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("– " & usrCntl.txtDW.Text, 45, 32.8 + top, 15, 4, "normal", 8, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text, 32, 53.5 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 32, 60 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 32, 66 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 32, 71.5 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 32, 78 + top, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 120, 78 + top, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 32, 85 + top, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 32, 91 + top, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 120, 91 + top, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        top = -10
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRechnungsnummern.Text, 83, 107.5 + top, 110, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAbsender.Text, 32, 114 + top, 88, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATUEur1.Text, 145, 114 + top, 40, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLKWKennz.Text, 43, 120 + top, 45, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUnternehmer.Text, 112, 120 + top, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnzVerp.Text, 32, 127 + top, 32, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtWarenbez.Text, 83, 127 + top, 62, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.txtGewicht.Text.Trim.EndsWith("kg"), usrCntl.txtGewicht.Text, usrCntl.txtGewicht.Text & " kg"), 163, 127 + top, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))




        'Dim myVermerk As New VERAG_PROG_ALLGEMEIN.cVermerk
        'myVermerk.AvisoID = usrCntl.AVISO.AvisoID
        'myVermerk.SendungID = dt.Rows(0)("tblSnd_SendungID")
        'myVermerk.Datum = If(DatumTmp, Now)
        'myVermerk.VermerkArt = "S"
        'myVermerk.Mitarbeiter = VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME & " (AUTO)"
        'myVermerk.MitarbeiterId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID
        'Select Case VermerkCodeId
        '    Case 13 : myVermerk.Hinweis_Vermerk = "Vorauskasse angefordert"
        '    Case 14 : myVermerk.Hinweis_Vermerk = "Vorauskasse erhalten"
        '    Case Else : Exit Sub
        'End Select
        'myVermerk.VermerkCodeId = VermerkCodeId

        'VermerkeDAL.SpeichernVermerk(myVermerk)


        If usrCntl.cbxLKWWartet.Checked Then
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("!!! LKW wartet !!!", 141, 11, 60, 15, "boldRed", 20, , itextsharp.text.Element.ALIGN_LEFT))
        End If

        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso", listTowrite)
            Case Else

                Select Case usrCntl.cboFirma._value
                    Case "CS" : Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_CS", listTowrite)
                    Case Else : Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Importaviso_AG", listTowrite)
                End Select

        End Select

        Return ""
    End Function

    Shared Function Zollbeschau(usrCntl As usrCntlZollbeschau) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 3

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartnerVERAG.Text, 145, 47 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFilialNr.Text & "/" & usrCntl.txtAbfNr.Text, 40, 47 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtT1.Text, 145, 52 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATB.Text, 145, 57 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATC.Text, 145, 62 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVZDatum.Text, 145, 72 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZollagent.Text, 40, 82 + top, 55, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFrächter.Text, 40, 88 + top, 55, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAbsender.Text, 40, 93 + top, 55, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZollb1.Text, 40, 98 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZollb2.Text, 40, 103 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBeschauDat.Text, 135, 82 + top, 150, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLKWKennz.Text, 135, 88 + top, 135, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 135, 93 + top, 135, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Dim newTimeZoll1 As DateTime
        If usrCntl.txtDurationZoll1.Text <> "" Then
            newTimeZoll1 = DateTime.ParseExact(usrCntl.txtTimeZoll1.Text, "HH:mm", System.Globalization.DateTimeFormatInfo.InvariantInfo)
            Dim newDuration As DateTime
            newDuration = DateTime.ParseExact(usrCntl.txtDurationZoll1.Text, "HH:mm", System.Globalization.DateTimeFormatInfo.InvariantInfo)
            newTimeZoll1 = newTimeZoll1.AddHours(newDuration.ToString("HH"))
            newTimeZoll1 = newTimeZoll1.AddMinutes(newDuration.ToString("mm"))
        End If

        Dim newTimeZoll2 As DateTime
        If usrCntl.txtDurationZoll2.Text <> "" Then
            newTimeZoll2 = DateTime.ParseExact(usrCntl.txtTimeZoll2.Text, "HH:mm", System.Globalization.DateTimeFormatInfo.InvariantInfo)
            Dim newDuration As DateTime
            newDuration = DateTime.ParseExact(usrCntl.txtDurationZoll2.Text, "HH:mm", System.Globalization.DateTimeFormatInfo.InvariantInfo)
            newTimeZoll2 = newTimeZoll2.AddHours(newDuration.ToString("HH"))
            newTimeZoll2 = newTimeZoll2.AddMinutes(newDuration.ToString("mm"))
        End If

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(IIf(usrCntl.txtZoll1Date.Text <> "", usrCntl.txtZoll1Date.Text & " ", "") & IIf(usrCntl.txtTimeZoll1.Text <> "" AndAlso usrCntl.txtDurationZoll1.Text <> "", usrCntl.txtTimeZoll1.Text & " - " & newTimeZoll1.ToString("HH:mm"), ""), 135, 98 + top, 135, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(IIf(usrCntl.txtZoll1Date.Text <> "", usrCntl.txtZoll2Date.Text & " ", "") & IIf(usrCntl.txtTimeZoll2.Text <> "" AndAlso usrCntl.txtDurationZoll2.Text <> "", usrCntl.txtTimeZoll2.Text & " - " & newTimeZoll2.ToString("HH:mm"), ""), 135, 103 + top, 135, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtInfo.Text, 16, 120 + top, 135, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'Sendungsdaten

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnzVerp.Text, 132, 136 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtGewicht.Text, 157, 136 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtWarenbez.Text, 28, 136 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))



        'Tabelle

        If usrCntl.dgvPositionen.Rows.Count() > 0 Then
            Dim x = 154
            For i As Integer = 0 To usrCntl.dgvPositionen.Rows.Count() - 1

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.dgvPositionen.Rows(i).Cells("pos").Value, 17, x + top, 10, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.dgvPositionen.Rows(i).Cells("leistung").Value, 24, x + top, 138, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.dgvPositionen.Rows(i).Cells("stk").Value, 165, x + top, 20, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.dgvPositionen.Rows(i).Cells("preis").Value, 185, x + top, 20, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                x += 5
            Next

        End If

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.lblgesamtpreis.Text, 150, 217 + top, 40, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


        Dim ort As String = ""

        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
            Case "AMB" : ort = "Bad Reichenhall"
        End Select

        'Signatur
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(ort & ", " & Date.Today.ToString("dd.MM.yyyy"), 17, 267 + top, 200, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))


        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "AMBAR"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "ZollbeschauAMBAR", listTowrite)
            Case Else
                MsgBox("Funktion für " & VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & " nicht implementiert! ")

        End Select

        Return ""
    End Function


    Shared Function Gestellungsgarantie(usrCntl As usrcntlGestellungsgarantie) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 53, 82, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 53, 88, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 53, 95, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnsprechpartner.Text, 53, 102, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 53, 108, 55, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFax.Text, 121, 108, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 53, 115, 80, 6, "bold", 8, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEORI.Text, 121, 115, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZulassungsnummer1.Text, 72, 123, 33, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZulassungsnummer2.Text, 114, 123, 33, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))

        Select Case usrCntl.cboSprache._value
            Case "EN"

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung1.Text, 56, 228, 130, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung2.Text, 26, 237, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung3.Text, 26, 246, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBestimmungszollamt.Text, 82, 152, 100, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "GESTELLUNGSGARANTIEN", getUO2, "", "Gestellungsgarantie_EN", listTowrite)
            Case "FR"

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung1.Text, 56, 230, 130, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung2.Text, 26, 239, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung3.Text, 26, 247, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBestimmungszollamt.Text, 85, 152, 100, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "GESTELLUNGSGARANTIEN", getUO2, "", "Gestellungsgarantie_FR", listTowrite)
            Case Else

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung1.Text, 56, 223, 130, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung2.Text, 26, 232, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAnmerkung3.Text, 26, 242, 160, 6, "", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBestimmungszollamt.Text, 92, 152, 100, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "GESTELLUNGSGARANTIEN", getUO2, "", "Gestellungsgarantie_DE", listTowrite)
        End Select

        Return ""
    End Function


    Shared Function getPosNrByLNr(dt As DataTable, dt2 As DataTable, LNr As String) As String
        For i = 0 To dt.Rows.Count - 1
            If dt.Rows(i)("LNr") IsNot DBNull.Value AndAlso dt.Rows(i)("LNr") = LNr Then
                Return If(dt.Rows(i)("Pos"), "")
            End If
        Next
        For i = 0 To dt2.Rows.Count - 1
            If dt2.Rows(i)("ZLNr") IsNot DBNull.Value AndAlso dt2.Rows(i)("ZLNr") = LNr Then
                Return "0"
            End If
        Next
        Return ""
    End Function

    Shared Function Verzollungspreise(usrCntl As usrcntlVerzollungspreise, Optional printReportElsePDF As Boolean = False, Optional printername As String = "") As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager
        '     Dim striList As New List(Of String)
        Verzollungspreise = ""
        Try

            Dim rpt As New rptPreislisten
            Dim subRpt As New subrptPreislisten
            Dim subRpt_Zoll As New subrptPreislisten_Zoll
            rpt.SubReport.Report = subRpt

            Dim dt As DataTable = cProgramFunctions.dgridViewTods(usrCntl.DataGridView)
            Dim dt2 As DataTable = cProgramFunctions.dgridViewTods(usrCntl.dgvZusatzleistung)
            If dt.Rows.Count > 0 Then
                dt.Rows.RemoveAt(dt.Rows.Count - 1) 'leere Zeile
            End If
            If dt2.Rows.Count > 0 Then
                dt2.Rows.RemoveAt(dt2.Rows.Count - 1) 'leere Zeile
            End If


            Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                Case "IMEX"
                    rpt.txtFirmenkennung.Text = "IMEX Customs Service GmbH"
                    rpt.picVERAG.Image = My.Resources.IMEX_LOGO_simple
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_IMEX.Visible = True
                    rpt.TextBox6.Visible = False
                Case "AMBAR"
                    rpt.txtFirmenkennung.Text = "Ambar Logistic Services GmbH"
                    rpt.picVERAG.Image = My.Resources.ambar_simple
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_IMEX.Visible = False
                    rpt.TextBox6.Visible = True
                Case "ATILLA"
                    rpt.txtFirmenkennung.Text = "ATILLA Spedition GmbH"
                    rpt.picVERAG.Image = My.Resources.Atilla
                    rpt.txtFirmaInfo_VERAG.Visible = False
                    rpt.txtFirmaInfo_ATILLA.Visible = True
                    rpt.TextBox6.Visible = False
                Case Else 'Nix 
                    rpt.txtFirmaInfo_VERAG.Visible = True
            End Select

            rpt.DataSource = dt

            If dt2.Rows.Count > 0 Then
                subRpt.DataSource = dt2
            Else
                rpt.SubReport.Visible = False
            End If
            '   rpt.txtDatumOrt.Text = ort & ", den " & Now.ToShortDateString

            Dim PosVorlage = getPosNrByLNr(dt, dt2, 700)
            Dim PosKredit = getPosNrByLNr(dt, dt2, 750)
            Dim PosClearing = getPosNrByLNr(dt, dt2, 347)


            If PosVorlage = "" And PosKredit = "" Then
                rpt.txtVorlageKredit.Visible = False
            ElseIf PosVorlage = "" And PosKredit <> "" Then
                rpt.txtVorlageKredit.Text = "(Bei Bereitstellung eines eigenen Aufschubkontos fällt Pos. " & PosKredit & " weg.)"
            ElseIf PosKredit = "" And PosVorlage <> "" Then
                rpt.txtVorlageKredit.Text = "(Bei Bereitstellung eines eigenen Aufschubkontos fällt Pos. " & PosVorlage & " weg.)"
            Else
                rpt.txtVorlageKredit.Text = rpt.txtVorlageKredit.Text.Replace("[PosVorlage]", "Pos. " & PosVorlage)
                rpt.txtVorlageKredit.Text = rpt.txtVorlageKredit.Text.Replace("[PosKredit]", "Pos. " & PosKredit)
            End If

            If VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "AMBAR" Then
                If rpt.txtVorlageKredit.Text <> "" Then rpt.txtVorlageKredit.Text &= vbNewLine
                rpt.txtVorlageKredit.Text &= "*Zollamtsabwicklungs-/abklärungskosten, Mehraufwand, Antragsstellung, Unkosten, Sendungsstatusüberprüfung."
                rpt.txtVorlageKredit.Text &= vbNewLine
                rpt.txtVorlageKredit.Text &= "**Falls vom Zollamt Beschau der Ware angekündigt wird, werden diese je nach Aufwand verrechnet."
            End If



            rpt.txtZahlungsziel.Text = rpt.txtZahlungsziel.Text.Replace("[Zahlungsziel]", If(usrCntl.txtZahlunsziel.Text = "", "10", usrCntl.txtZahlunsziel.Text))

            If PosKredit = "" Then 'Wenn keine Kredítaufwendung
                rpt.txtZahlungsziel2.Visible = False
            Else
                If usrCntl.txtZahlunsziel.Text = "" Then
                    rpt.txtZahlungsziel2.Text = rpt.txtZahlungsziel2.Text.Replace("[Zahlungsziel]", "10")
                Else
                    rpt.txtZahlungsziel2.Text = rpt.txtZahlungsziel2.Text.Replace("[Zahlungsziel]", usrCntl.txtZahlunsziel.Text)
                End If
                rpt.txtZahlungsziel2.Text = rpt.txtZahlungsziel2.Text.Replace("[PosKredit]", "Pos. " & PosKredit)
            End If


            If PosClearing = "" Then
                rpt.txtClearing.Visible = False
                '  Else
                '     rpt.txtClearing.Text = rpt.txtClearing.Text.Replace("[PosClearing]", "Pos. " & PosClearing)
            End If


            If usrCntl.cboFirma._value = "CS" Then
                rpt.txtFirmenkennung.Text = "VERAG Customs Service GmbH"
                rpt.picVERAG.Image = My.Resources.Verag_Customs_Service_GMBH_Logo_med
                '                rpt.txtAdresse.Text = "A-5071 Wals	Tel.  +43 77 11 / 27 77-39 	      www.verag.ag" & vbNewLine &
                '                                      "Zollstraße 6	Fax  +43 77 11 / 27 88	       cw@verag.ag"
                rpt.txtFirmaInfo_VERAG.Text = "A-5071 Wals" & vbTab & "Tel.  +43 77 11 / 27 77-39" & vbTab & "www.verag.ag" & vbNewLine &
                                      "Zollstraße 6" & vbTab & "Fax  +43 77 11 / 27 88" & vbTab & "cw@verag.ag"

            End If

            If usrCntl.cbxZollpflichtigeAbfertigung.Checked Then
                rpt.SubReport2.Report = subRpt_Zoll
            End If


            AddHandler rpt.Detail.Format, Sub()
                                              Try
                                                  '  MsgBox(rpt.Fields.Item(1).Value)
                                                  rpt.txtNr.Text = nullStr(rpt.Fields.Item("Pos").Value)
                                                  rpt.txtPreis.Text = ""

                                                  If nullStr(rpt.Fields.Item("Preis").Value) = "" Then
                                                      rpt.Line8.Visible = False
                                                      rpt.txtLeistung.Size = New SizeF(rpt.txtLeistung.Size.Width + 2, rpt.txtLeistung.Size.Height)
                                                  Else
                                                      rpt.Line8.Visible = True
                                                      Dim preis = nullStr(rpt.Fields.Item("Preis").Value)
                                                      rpt.txtPreis.Text = If(IsNumeric(preis), CDbl(preis).ToString("C2"), preis)
                                                  End If
                                                  rpt.txtLeistung.Text = nullStr(rpt.Fields.Item("Leistung").Value)

                                              Catch ex As Exception
                                                  MsgBox(ex.Message & ex.StackTrace)
                                              End Try


                                          End Sub

            AddHandler subRpt.Detail.Format, Sub()
                                                 Try
                                                     '  MsgBox(rpt.Fields.Item(1).Value)
                                                     ' subRpt.txtNr.Text = nullStr(subRpt.Fields.Item("Pos").Value)
                                                     subRpt.txtPreis.Text = ""

                                                     If nullStr(subRpt.Fields.Item("ZPreis").Value) = "" Then
                                                         subRpt.Line8.Visible = False
                                                         subRpt.txtLeistung.Size = New SizeF(subRpt.txtLeistung.Size.Width + 2, subRpt.txtLeistung.Size.Height)
                                                     Else
                                                         subRpt.Line8.Visible = True
                                                         Dim preis = nullStr(subRpt.Fields.Item("ZPreis").Value)
                                                         subRpt.txtPreis.Text = If(IsNumeric(preis), CDbl(preis).ToString("C2"), preis)
                                                     End If
                                                     subRpt.txtLeistung.Text = nullStr(subRpt.Fields.Item("ZLeistung").Value)

                                                 Catch ex As Exception
                                                     MsgBox(ex.Message & ex.StackTrace)
                                                 End Try


                                             End Sub

            If printReportElsePDF Then 'NUR DRUCK!!
                rpt.Run(False)

                rpt.Document.Printer.PrinterName = printername
                ' rpt.Document.PrintOptions.Margin = New GrapeCity.ActiveReports.Extensibility.Printing.Margin(0, 0, 0, 0)
                rpt.Document.Printer.OriginAtMargins = False

                rpt.Document.Print((printername = ""), False)
                rpt.Dispose()
            Else
                Dim tmpPath = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("tmp_Verzollunspreise.pdf", ".pdf", , False)
                Dim p As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
                rpt.Run(False)
                p.Export(rpt.Document, tmpPath)

                Verzollungspreise = tmpPath
                rpt.Dispose()
            End If


        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try


    End Function

    Shared Function VerzollungspreiseOLD(usrCntl As usrcntlVerzollungspreise) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        Select Case usrCntl.MyComboBox1._value
            Case "VZ_EV"
                'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVerzollung.Text, 155, 76, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTarifnummer.Text, 155, 84, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPapierePorti.Text, 155, 90, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSVS.Text, 155, 98, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATLAS.Text, 155, 105, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                'txtSonderLeistungBezeichnung()

                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtClearing.Text, 37, 171, 20, 6, "bold", 12, , iTextSharp.text.Element.ALIGN_CENTER))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Verzollungspreise_EV", listTowrite)
            Case "VZ_RW"
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVerzollung.Text, 155, 76, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRueckware.Text, 155, 83, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))

                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTarifnummer.Text, 155, 91, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPapierePorti.Text, 155, 97, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSVS.Text, 155, 105, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATLAS.Text, 155, 112, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtClearing.Text, 37, 190, 20, 6, "bold", 12, , iTextSharp.text.Element.ALIGN_CENTER))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Verzollungspreise_RW", listTowrite)
            Case Else 'VZ
                Dim top = -4.5
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVerzollung.Text, 155, top + 75.5, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTarifnummer.Text, 155, top + 83, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPapierePorti.Text, 155, top + 90, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSVS.Text, 155, top + 97.5, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtATLAS.Text, 155, top + 104.5, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))

                ' If usrCntl.txtSonderLeistungBezeichnung.Text <> "" Then
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("8", 25, top + 126, 7, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_CENTER))
                'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonderLeistungBezeichnung.Text, 36, top + 126, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_LEFT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonderLeistungPreis.Text, 155, top + 126, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                '  End If
                '  If usrCntl.txtSonderLeistungBezeichnung2.Text <> "" Then
                'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("9", 25, top + 133.5, 7, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_CENTER))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonderLeistungBezeichnung2.Text, 36, top + 133.5, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_LEFT))
                '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonderLeistungPreis2.Text, 155, top + 133.5, 30, 6, "normal", 12, , iTextSharp.text.Element.ALIGN_RIGHT))
                ' End If
                '   listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtClearing.Text, 37, top + 188.5, 20, 6, "bold", 12, , iTextSharp.text.Element.ALIGN_CENTER))

                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "VerzollungspreiseV2", listTowrite)
        End Select

        Return ""
    End Function


    Shared Function Qualitaetskontrolle(usrCntl As usrCntlQualitaetskontrolle) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem)


        If usrCntl.dtpBeschauDat IsNot Nothing AndAlso IsDate((usrCntl.dtpBeschauDat.Value)) Then
            list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Datum", usrCntl.dtpBeschauDat.Value.ToString))
        End If

        'list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Teilnehmer", usrCntl.bb_Teilnehmer.ToString))

        'list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Geschäftsführer", BB.bb_Geschaeftsfuehrer.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Ansprechpartner", BB.bb_Anpsprechpartner.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Firma", txtFirma.Text))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Umatz", BB.bb_Umsatz)) 'ACHTUNG -> im Formular wurde das Feld "Umatz" benannt, nicht korrigieren!

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Telefon", BB.bb_Telefon.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Mail", BB.bb_Mail.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("LKWEigentum", BB.bb_FuhrparkEigentum.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("LKWLeasing", BB.bb_FuhrparkLeasing.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Auftraggeber", BB.bb_Auftraggeber.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("TransportRouten", BB.bb_Route.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("DerzeitigerAnbieter", BB.bb_DerzeitigerLieferant.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Bericht", BB.bb_Vermerk.ToString))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Garentie", BB.bb_Garantie)) 'ACHTUNG -> im Formular wurde das Feld "Garentie" benannt, nicht korrigieren!

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Plane", IIf(BB.bb_LKW_Plane = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Kühltransporte", IIf(BB.bb_LKW_Kuehltranporte = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Sondertransporte", IIf(BB.bb_LKW_Sondertransporte = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Sprinter", IIf(BB.bb_LKW_Sprinter = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("SiloTank", IIf(BB.bb_LKW_SiloTank = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Zollabfertigung", IIf(BB.bb_Interesse_Zollabfertigung = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Brexit", IIf(BB.bb_Interesse_Brexit = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Parkplatz", IIf(BB.bb_Interesse_Parkplatz = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("LagerUmladung", IIf(BB.bb_Interesse_LagerUmschlag = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Rola", IIf(BB.bb_Interesse_Rola = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("YesMoney", IIf(BB.bb_Interesse_YesMoney = True, "On", "Off")))

        'List.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("Ferry", IIf(BB.bb_Interesse_Ferry = True, "On", "Off")))



        Select Case usrCntl.cbxTyp.SelectedItem.value

            Case "O"
                list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("persönlich", "On"))

            Case "B"
                list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("persönlich", "On"))

            Case "E"
                list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("persönlich", "On"))

        End Select

        Select Case usrCntl.cbxEinf.SelectedItem.value

            Case "A"
                list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("persönlich", "On"))

            Case "E"
                list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("persönlich", "On"))

        End Select






        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.cbxUrsprungslang.SelectedItem.Text, 61, 85, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.cbxBestimmungsland.SelectedItem.Text, 115, 85, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        '----------------------

        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 25, 98, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text, 25, 105, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtOrt.Text, 25, 198, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 25, 208, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.MyTextBox2.Text, 25, 218, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLand.Text, 25, 188, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPLZ.Text, 45, 188, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        'fm.fillPDF("Qualitatskontrolle", Nothing, list, , , , , , )

        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "", "", "Qualitatskontrolle", listTowrite)


        Return ""
    End Function


    Shared Function FiskalInfoschreiben(usrCntl As usrcntlFiskalInfoschreiben) As String
        Dim odoc As Microsoft.Office.Interop.Word.Document = Nothing
        Dim oWord As New Microsoft.Office.Interop.Word.Application
        Try
            Dim bez = ""
            Select Case usrCntl.BEZEICHNUNG
                Case FormularManagerArten.AT_InformationsblattFiskalverzollung
                    Select Case usrCntl.cboSprache._value
                        Case "EN" : bez = "Informationsblatt Fiskalverzollung AT in GB"
                            ' Case "NL" : bez = "Informationsblatt Fiskalverzollung AT in DE"
                        Case "FR" : bez = "Informationsblatt Fiskalverzollung AT in FR"
                        Case Else
                            bez = "Informationsblatt Fiskalverzollung AT in DE"
                    End Select
                Case FormularManagerArten.DE_InformationsblattFiskalverzollung
                    Select Case usrCntl.cboSprache._value
                        Case "NL" : bez = "Informationsblatt Fiskalverzollung DE in NL"
                        Case "EN" : bez = "Informationsblatt Fiskalverzollung DE in GB"
                        Case "FR" : bez = "Informationsblatt Fiskalverzollung DE in FR"
                        Case Else
                            bez = "Informationsblatt Fiskalverzollung DE in DE"
                    End Select
            End Select



            Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", bez)
            Dim pfadWord = DS.GET_TOP1_PATH(False)

            Return pfadWord

        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return ""
    End Function


    Shared Function EORI_Antrag(usrCntl As usrcntlEORI_Antrag) As String

        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

        Dim top = 0
        If usrCntl.cboPrivatperson.Checked Then top = -2



        Select Case usrCntl.cboSprache._value
            Case "EN"


                Select Case usrCntl.cbxAntragsart._value

                    Case "Neuzugang"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 139, 38, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))

                    Case "Änderung"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 139, 45, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))

                    Case "Beendigung"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 139, 52, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))

                End Select

                If usrCntl.DateTimePicker1 IsNot Nothing AndAlso IsDate((usrCntl.DateTimePicker1.Value)) AndAlso usrCntl.cbxDatum.Checked Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Day, 135, 78, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Month, 145, 78, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Year, 157, 78, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                End If


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 25, 79, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 25, 98, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text, 25, 105, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtOrt.Text, 25, 198, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 25, 208, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.MyTextBox2.Text, 25, 218, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLand.Text, 25, 188, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPLZ.Text, 45, 188, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 25, 176, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 25, 160, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 25, 125, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT, 2))



            Case Else




                Select Case usrCntl.cbxAntragsart._value

                    Case "Neuzugang"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 138, 43 + top, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))


                    Case "Änderung"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 138, 50 + top, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))

                    Case "Beendigung"
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 138, 57 + top, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))

                End Select

                If usrCntl.cboPrivatperson.Checked Then

                    If usrCntl.DateTimePicker1 IsNot Nothing AndAlso IsDate((usrCntl.DateTimePicker1.Value)) Then
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Day, 135, 82 + top, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Month, 145, 82 + top, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Year, 157, 82 + top, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    End If

                    If usrCntl.gebDatum IsNot Nothing AndAlso IsDate((usrCntl.gebDatum.Value)) AndAlso usrCntl.cbxGebDatu.Checked Then
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.gebDatum.Value).Day, 25, 133, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.gebDatum.Value).Month, 35, 133, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.gebDatum.Value).Year, 47, 133, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    End If


                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 25, 84 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                    'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 25, 103, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    'Splittung von Vor und Nachname
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text.Substring(0, usrCntl.txtHerrFrau.Text.IndexOf(" ")).Trim, 25, 96, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text.Substring(usrCntl.txtHerrFrau.Text.IndexOf(" "), usrCntl.txtHerrFrau.TextLength - usrCntl.txtHerrFrau.Text.IndexOf(" ")).Trim(), 25, 113, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtOrt.Text, 25, 158, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 25, 166, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.MyTextBox2.Text, 25, 177, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLand.Text, 25, 147, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPLZ.Text, 45, 147, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 25, 226, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 25, 210, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 25, 184, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT, 2))



                Else

                    If usrCntl.DateTimePicker1 IsNot Nothing AndAlso IsDate((usrCntl.DateTimePicker1.Value)) Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Day, 135, 82, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Month, 145, 82, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CDate(usrCntl.DateTimePicker1.Value).Year, 157, 82, 150, 6, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
                End If


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 25, 84, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 25, 103, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHerrFrau.Text, 25, 110, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtOrt.Text, 25, 216, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 25, 226, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.MyTextBox2.Text, 25, 238, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLand.Text, 25, 205, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtPLZ.Text, 45, 205, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))


                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtTel.Text, 25, 191, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEmail.Text, 25, 173, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 25, 184, 70, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT, 2))

                End If

        End Select


        Select Case usrCntl.cboSprache._value
                    Case "EN"
                        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "EORI_Antrag_EN", listTowrite)

            Case Else
                If usrCntl.cboPrivatperson.Checked Then
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "EORI_Antrag_Privat", listTowrite)
                Else
                    Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "EORI_Antrag", listTowrite)
                End If



        End Select






                Return ""

    End Function


    Shared Function Verzollungsunterlagen(usrCntl As usrcntlVerzollungsunterlagen, Optional printReportElsePDF As Boolean = False, Optional printername As String = "", Optional openWord As Boolean = False) As List(Of String)
        Dim odoc As Microsoft.Office.Interop.Word.Document = Nothing
        Dim oWord As New Microsoft.Office.Interop.Word.Application
        Dim striList As New List(Of String)
        Try
            Dim uOrdner2 = ""
            Dim nameDispo = ""
            nameDispo = "VerzollungsunterlagenAG2"
            Select Case usrCntl.cboFirma._value
                Case "IMEX" : nameDispo = "Verzollungsunterlagen" : uOrdner2 = "IMEX"
                Case "AMBAR" : nameDispo = "Verzollungsunterlagen" : uOrdner2 = "AMBAR"
                Case "UNISPED" : nameDispo = "Verzollungsunterlagen" : uOrdner2 = "UNISPED"
                Case "CS" : nameDispo = "VerzollungsunterlagenCS"
                Case Else : nameDispo = "VerzollungsunterlagenAG2"
            End Select

            Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("DOKUMENTE", "VORLAGEN", "SONSTIGE", uOrdner2, "", nameDispo)
            Dim pfadWord = DS.GET_TOP1_PATH(False)

            Dim cGenWord As New cGenWord

            odoc = cGenWord.openWord(pfadWord, False, oWord)
            If odoc Is Nothing Then Return striList

            '  Dim oTable As Word.Table

            odoc.FormFields("Adresse1").Range.Text = usrCntl.txtFirma.Text
            odoc.FormFields("Adresse2").Range.Text = usrCntl.txtFirma2.Text
            odoc.FormFields("Adresse3").Range.Text = usrCntl.txtAdresse1.Text
            odoc.FormFields("Adresse4").Range.Text = usrCntl.txtAdresse2.Text
            odoc.FormFields("Adresse5").Range.Text = usrCntl.txtAdresse3.Text

            odoc.FormFields("PosNr").Range.Text = usrCntl.txtLKW.Text & "  " & usrCntl.cboFiliale._value & "/" & usrCntl.txtAbfertigungsNr.Text

            odoc.FormFields("Anlage1").Range.Text = usrCntl.txtAnlage1.Text
            odoc.FormFields("Anlage2").Range.Text = usrCntl.txtAnlage2.Text
            odoc.FormFields("Anlage3").Range.Text = usrCntl.txtAnlage3.Text
            odoc.FormFields("Anlage4").Range.Text = usrCntl.txtAnlage4.Text
            odoc.FormFields("Anlage5").Range.Text = usrCntl.txtAnlage5.Text
            odoc.FormFields("Anlage6").Range.Text = usrCntl.txtAnlage6.Text


            odoc.FormFields("Tel").Range.Text = usrCntl.txtTel.Text
            odoc.FormFields("Fax").Range.Text = usrCntl.txtFax.Text
            odoc.FormFields("Email").Range.Text = usrCntl.txtEmail.Text
            odoc.FormFields("Bearbeiter").Range.Text = usrCntl.txtBearbeiter.Text
            odoc.FormFields("Bearbeiter2").Range.Text = usrCntl.txtBearbeiter.Text

            odoc.Save() : odoc.Activate()


            If usrCntl.cbxBeimErstellenSpeichern.Checked Then
                '   If vbYes = MsgBox("Möchten Sie die Bonitätsauskunft in den Kundendaten speichern?", vbYesNoCancel) Then
                savePostversand(usrCntl, usrCntl.POST_ID)
                'End If
            End If

            If openWord Then
                oWord.Visible = True
                Return New List(Of String)
            ElseIf printReportElsePDF Then

                oWord.DisplayAlerts = False
                oWord.PrintOut()
                Try
                    oWord.Documents.Close()
                    'Quit word application
                    oWord.Quit()

                    'Release
                    oWord = Nothing
                Catch ex As Exception
                    'NIX, kann sein, dass noch offen..
                End Try

            Else
                'oWord.Visible = True
                Dim path = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath(nameDispo & ".pdf", ".pdf", True, False)

                odoc.SaveAs(path, Word.WdSaveFormat.wdFormatPDF)

                Try
                    odoc.Close()
                    oWord.Quit()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
                striList.Add(path)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try

        Return striList
    End Function


    Shared Function VerzollungsunterlagenBAR(usrCntl As usrcntlVerzollungsunterlagen_BAR, ByRef listMail As List(Of FormMangagerEmail)) As List(Of String)
        Try

            Dim MailHTMLText = ""
            Dim Mail_Subject = ""

            Dim MailHTMLText_STBFA = ""
            Dim Mail_Subject_STBFA = ""

            Dim mail_To = ""


            Dim mail_To_Stb = ""
            Dim mail_To_FA = ""

            Dim AD As VERAG_PROG_ALLGEMEIN.cAdressen = Nothing
            Dim KD As VERAG_PROG_ALLGEMEIN.cKunde = Nothing

            If usrCntl.KdNR > 0 Then
                AD = New VERAG_PROG_ALLGEMEIN.cAdressen(usrCntl.KdNR)
                KD = New VERAG_PROG_ALLGEMEIN.cKunde(usrCntl.KdNR)
                If AD IsNot Nothing AndAlso AD.E_Mail <> "" Then
                    mail_To = AD.E_Mail
                End If

                Dim FISKAL As New cFiskal_Daten(usrCntl.KdNR)
                If FISKAL IsNot Nothing Then
                    mail_To_Stb = If(FISKAL.fisk_schreibenSB_Mail, "")
                    mail_To_FA = If(FISKAL.fisk_schreibenFA_Mail, "")
                End If

            End If

            Dim posNr = usrCntl.cboFiliale._value & "/" & usrCntl.txtAbfertigungsnummer.Text
            If posNr = "/" Then
                posNr = ""
            Else
                posNr = "  Pos.Nr.: " & posNr
            End If

            'LKW/Constainer-Nr. im Betreff angebgen:
            If usrCntl.txtLKWContainer.Text <> "" Then
                posNr &= " | LKW/Container.: " & usrCntl.txtLKWContainer.Text
            End If


            Dim bool_StbFA = False

            MailHTMLText = "<div style=""font-family:Calibri, Arial"">"
            MailHTMLText_STBFA = "<div style=""font-family:Calibri, Arial"">"

            Dim Firma_idI_Sig_AT = -1
            Dim Firma_idI_Sig_DE = -1
            Dim Firma_idI_Sig_EV = -1
            Dim Postfach_DE = "VERAG CUSTOMS SERVICE GMBH<br>POSTFACH 1013<br>D 94152 NEUHAUS AM INN<br>"

            Dim SonderUID_AT = "ATU68374145"
            Dim SonderUID_DE = "DE813667748"

            Select Case usrCntl.cboFiliale._value
                Case "5501" : Firma_idI_Sig_AT = 20 : Firma_idI_Sig_DE = 20 : Firma_idI_Sig_EV = 20 : SonderUID_AT = "DE295575575" : SonderUID_DE = "DE295575575" : Postfach_DE = "IMEX CUSTOMS SERVICE GMBH<br>HARTHAM 6<br>D 94152 NEUHAUS AM INN<br>"
                Case "5601" : Firma_idI_Sig_AT = 23 : Firma_idI_Sig_DE = 22 : Firma_idI_Sig_EV = 23 : SonderUID_AT = "" : SonderUID_DE = "" : Postfach_DE = "UNISPED Speditions GmbH<br>HARTHAM 6<br>D 94152 NEUHAUS AM INN<br>"
                Case "5701" : Firma_idI_Sig_AT = 24 : Firma_idI_Sig_DE = 24 : Firma_idI_Sig_EV = 24 : SonderUID_AT = "" : SonderUID_DE = "" : Postfach_DE = "AMBAR Logistic Services GmbH<br>Reichenhallerstraße 62<br>D 83435 BAD REICHENHALL<br>"
                Case Else : Firma_idI_Sig_AT = 11 : Firma_idI_Sig_DE = 99 : Firma_idI_Sig_EV = 11 ' VERAG

            End Select

            Select Case usrCntl.cboSprache._value
                Case "DE", ""

                    Mail_Subject_STBFA = "Meldung innergemeinschaftlicher Erwerb" & posNr
                    MailHTMLText_STBFA &= "<b><table style=""font-family:Calibri, Arial;font-weight:bold"">"
                    MailHTMLText_STBFA &= "<tr><td>EORI-Nr.:</td><td>" & If(KD IsNot Nothing, If(KD.EORITIN, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>UID-Nr.:</td><td>" & If(AD IsNot Nothing, If(AD.UstIdKz, ""), "") & If(AD IsNot Nothing, If(AD.UstIdNr, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>Firma:</td><td>" & If(AD IsNot Nothing, AD.Name_1, "") & If(AD IsNot Nothing, If(AD.Name_2, ""), "") & "</td></tr>"
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.Straße, "") & "</td></tr>" : Catch ex As Exception : End Try
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.LandKz, "") & " " & If(AD IsNot Nothing, AD.PLZ, "") & " " & If(AD IsNot Nothing, AD.Ort, "") & "</td></tr>" : Catch ex As Exception : End Try
                    MailHTMLText_STBFA &= "</table></b>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Sehr geehrte Damen und Herren,<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "wir teilen Ihnen mit, dass wir für oben genanntes Unternehmen eine Zollabfertigung mit anschließender<br>"
                    MailHTMLText_STBFA &= "innergemeinschaftlicher Lieferung (Verfahren 4200) lt. beiliegenden Unterlagen durchgeführt haben.<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Dies muss dem Finanzamt als ""innergemeinschaftlicher Erwerb"" gemeldet werden.<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Freundlichen Grüßen<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                Case "EN"

                    Mail_Subject_STBFA = "Notification of intra-Community acquisition" & posNr
                    MailHTMLText_STBFA &= "<b><table style=""font-family:Calibri, Arial;font-weight:bold"">"
                    MailHTMLText_STBFA &= "<tr><td>EORI-Nr.:</td><td>" & If(KD IsNot Nothing, If(KD.EORITIN, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>UID-Nr.:</td><td>" & If(AD IsNot Nothing, If(AD.UstIdKz, ""), "") & If(AD IsNot Nothing, If(AD.UstIdNr, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>Firma:</td><td>" & If(AD IsNot Nothing, AD.Name_1, "") & If(AD IsNot Nothing, If(AD.Name_2, ""), "") & "</td></tr>"
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.Straße, "") & "</td></tr>" : Catch ex As Exception : End Try
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.LandKz, "") & " " & If(AD IsNot Nothing, AD.PLZ, "") & " " & If(AD IsNot Nothing, AD.Ort, "") & "</td></tr>" : Catch ex As Exception : End Try
                    MailHTMLText_STBFA &= "</table></b>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Dear Sir Or Madam!<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "We would like to inform you, that we made the customs clearance and subsequent intra-Community supply of goods for the company above-mentioned. (Code 4200). <br>"
                    MailHTMLText_STBFA &= "The documents are attached.<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "This intra-Community acquisition has to be reported to the tax office.<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Best regards <br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"

                Case "FR"

                    Mail_Subject_STBFA = "Notification of intra-Community acquisition" & posNr
                    MailHTMLText_STBFA &= "<b><table style=""font-family:Calibri, Arial;font-weight:bold"">"
                    MailHTMLText_STBFA &= "<tr><td>EORI-Nr.:</td><td>" & If(KD IsNot Nothing, If(KD.EORITIN, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>UID-Nr.:</td><td>" & If(AD IsNot Nothing, If(AD.UstIdKz, ""), "") & If(AD IsNot Nothing, If(AD.UstIdNr, ""), "") & "</td></tr>"
                    MailHTMLText_STBFA &= "<tr><td>Firma:</td><td>" & If(AD IsNot Nothing, AD.Name_1, "") & If(AD IsNot Nothing, If(AD.Name_2, ""), "") & "</td></tr>"
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.Straße, "") & "</td></tr>" : Catch ex As Exception : End Try
                    Try : MailHTMLText_STBFA &= "<tr><td></td><td>" & If(AD IsNot Nothing, AD.LandKz, "") & " " & If(AD IsNot Nothing, AD.PLZ, "") & " " & If(AD IsNot Nothing, AD.Ort, "") & "</td></tr>" : Catch ex As Exception : End Try
                    MailHTMLText_STBFA &= "</table></b>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Mesdames, Messieurs!<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Nous vous informons par la présente que, pour la société nommée ci-dessus, nous avons effectué un dédouanement suivi de la livraison intercommunautaire (procédure 4200) selon les documents ci-joints. <br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Ceci doit être déclaré au service fiscal comme ""acquisition intercommunautaire"".<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "Cordialemen <br>"
                    MailHTMLText_STBFA &= "<br>"
                    MailHTMLText_STBFA &= "<br>"
            End Select


            Select Case usrCntl.cboTEXT._value
                Case "AT_FISKAL"
                    bool_StbFA = True
                    Select Case usrCntl.cboSprache._value
                        Case "DE", ""
                            Mail_Subject = "Meldung innergemeinschaftlicher Erwerb" & posNr
                            MailHTMLText &= "<b>!!! DRINGENDE ZOLLSACHE !!!</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Sehr geehrte Damen und Herren,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "in der Anlage erhalten Sie die Unterlagen zu der Verzollung im Verfahren 4200.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Bitte melden Sie den Import in Ihrer Steuererklärung (UVA) als <b>""innergemeinschaftlichen Erwerb""</b><br>"
                            MailHTMLText &= "mit unser <b>Sonder - UID-Nr.: " & SonderUID_AT & "  an</b>.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Des Weiteren möchten wir Sie darauf hinweisen, dass eine <b>Intrastat Anmeldung</b> zu machen ist! <br>"
                            MailHTMLText &= "<br>"
                            'MailHTMLText &= "Die österreichische Zollbehörde verlangt in diesem Verfahren die Vorlegung einer gültigen Empfangsbestätigung. Aufgrund dessen ersuchen wir Sie den CMR/Frachtbrief, welchen der Fahrer bei der Abladung abgibt, zu bestätigen. <br>"
                            MailHTMLText &= "Die österreichische Zollbehörde verlangt in diesem Verfahren die Vorlegung einer gültigen Empfangsbestätigung. <br>"
                            MailHTMLText &= "Sie bekommen monatlich eine Aufstellung aller abgewickelten Sendungen durch uns zugesandt.<br>"
                            MailHTMLText &= "<b>Bitte senden Sie uns diese Liste unterzeichnet und <u>im Original</u> wieder per Post an uns zurück!</b><br>" 'MailHTMLText &= "<b>Wir müssen diese <u>im Original</u> vorlegen können, deshalb bitten wir Sie, das Dokument per Post an uns abzusenden!</b><br>"
                            'MailHTMLText &= "Wir müssen diesen im Original vorlegen können, deshalb bitten wir Sie, das Dokument per Post an uns abzusenden!<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<b>Bitte:<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "•	  GUT LESBAR<br>"
                            MailHTMLText &= "•	  VERMERK: WAREN ERHALTEN<br>"
                            MailHTMLText &= "•	  GENAUES DATUM DER WARENÜBERNAHME<br>"
                            MailHTMLText &= "•	  ORIGINAL FIRMENSTEMPEL<br>"
                            MailHTMLText &= "•	  ORIGINAL UNTERSCHRIFT</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<b>Post Adresse:</b><br>"
                            'MailHTMLText &= "VERAG CUSTOMS SERVICE GMBH<br>"
                            'MailHTMLText &= "POSTFACH 1013<br>"
                            'MailHTMLText &= "D 94152 NEUHAUS AM INN<br>"
                            MailHTMLText &= Postfach_DE
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Freundlichen Grüßen<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", Firma_idI_Sig_AT) '11)
                            MailHTMLText_STBFA &= cFakturierung.getSignature("D", Firma_idI_Sig_AT)' 11)
                        Case "EN"

                            Mail_Subject = "intra-community acquisition" & posNr
                            MailHTMLText &= "<b>!! URGENT CUSTOMS MATTER !!</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Dear Sir / Madam,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Please find enclosed the documents regarding the customs clearance (process 4200).<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Please register the import on your tax decleration ( turnover tax advance return ) as <br>"
                            MailHTMLText &= "<b>""intra-community acquisition""</b> with our <b>special value added tax identification number " & SonderUID_AT & ".</b>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Furthermore, we would like to point out that you must fill out an <b>Intrastat decleration!</b> <br>"
                            MailHTMLText &= "<br>"
                            '      MailHTMLText &= "In this procedure, the Austrian customs authority requires the presentation of a valid entry certificate. For this reason, we ask you to confirm the CMR/consignment note which the driver hands out in during unloading. <br>"
                            MailHTMLText &= "In this procedure, the Austrian customs authority requires the presentation of a valid entry certificate.<br>"
                            MailHTMLText &= "You will receive a monthly list of all concerned shipments from us.<br>"
                            MailHTMLText &= "<b>Please sign this list and return it to us <u>in original</u>!</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<b>Please ensure the following:<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "•	  THE DOCUMENT IS FULLY LEGIBLE<br>"
                            MailHTMLText &= "•	  YOU NOTE ON THE FORM: GOODS RECEIVED<br>"
                            MailHTMLText &= "•	  YOU NOTE THE EXACT DATE OF RECEIPT OF GOODS<br>"
                            MailHTMLText &= "•	  YOU PROVIDE AN ORIGINAL COMPANY STAMP<br>"
                            MailHTMLText &= "•	  YOU PROVIDE AN ORIGINAL SIGNATURE</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<b>Adress:</b><br>"
                            'MailHTMLText &= "VERAG CUSTOMS SERVICE GMBH<br>"
                            'MailHTMLText &= "POSTFACH 1013<br>"
                            'MailHTMLText &= "D 94152 NEUHAUS AM INN<br>"
                            MailHTMLText &= Postfach_DE
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Yours faithfully,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("EN", Firma_idI_Sig_AT) '11)
                            MailHTMLText_STBFA &= cFakturierung.getSignature("D", Firma_idI_Sig_AT) ' 11)

                    End Select

                Case "DE_FISKAL"
                    bool_StbFA = True
                    Select Case usrCntl.cboSprache._value
                        Case "EN", "FR"

                            Mail_Subject = "intra-community acquisition" & posNr
                            MailHTMLText &= "<b>!! URGENT CUSTOMS MATTER !!</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Dear Sir / Madam,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Please find enclosed the documents regarding the customs clearance (process 4200).<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Please register the import on your tax declaration (turnover tax advance return) as ""<b>intra-Community acquisition</b>"" with our <b>special value added tax identification number " & SonderUID_DE & ".</b> <br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Furthermore, we would like to point out that you must fill out an Intrastat declaration!<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Yours faithfully<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("EN", Firma_idI_Sig_DE) '99)
                            MailHTMLText_STBFA &= cFakturierung.getSignature("D", Firma_idI_Sig_DE) '99)


                    End Select

                Case "EV"
                    Select Case usrCntl.cboSprache._value
                        Case "DE", ""
                            Mail_Subject = "Verzollungsunterlagen" & posNr
                            MailHTMLText &= "Sehr geehrte Damen und Herren,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "in der Anlage erhalten Sie die Unterlagen zu der Verzollung.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Freundlichen Grüßen<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", Firma_idI_Sig_EV)'11)
                        Case "EN"
                            Mail_Subject = "Verzollungsunterlagen" & posNr
                            MailHTMLText &= "Dear Sir / Madam,<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "attached you will find the documents for customs clearance.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Yours faithfully<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("EN", Firma_idI_Sig_EV) '11)

                    End Select

                    'MailHTMLText &= cFakturierung.getSignature(11)
            End Select

            MailHTMLText &= "</div>"
            'MAIL??



            listMail.Add(New FormMangagerEmail(mail_To, "", "", Mail_Subject, MailHTMLText))
            If bool_StbFA Then listMail.Add(New FormMangagerEmail(mail_To_Stb, mail_To_FA, "", Mail_Subject_STBFA, MailHTMLText_STBFA))


        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try
        Return New List(Of String)
    End Function

    Shared Function Verzollungsunterlagen_Verbringungsnachweis(usrCntl As usrcntlVerzollungsunterlagen_Verbringsungsnachweis, ByRef listMail As List(Of FormMangagerEmail)) As List(Of String)
        Dim striList = New List(Of String)
        Try
            Dim VBNW_Nr = usrCntl.VBNr
            Dim MailHTMLText = "<div style=""font-family:Calibri, Arial"">"
            Dim Mail_Subject = ""
            Dim Mail_CC = ""
            Dim Mail_BCC = ""
            Dim Mail_To = ""

            If usrCntl.KdNR > 0 Then
                'lt. Kerstin: Steuerberater braucht den Verbringungsnachweis nicht
                ' Dim FISKAL As New cFiskal_Daten(usrCntl.KdNR)
                '  If FISKAL IsNot Nothing Then Mail_CC = If(FISKAL.fisk_schreibenSB_Mail, "")
                'Mail aus kunden Kontakte Spezial:
                Dim EMAILTMP = VERAG_PROG_ALLGEMEIN.cKundenKontakte.getMailAdress(usrCntl.KdNR, "Fiskal")
                If EMAILTMP <> "" Then Mail_To = EMAILTMP

                Dim EMAILTMPCC = VERAG_PROG_ALLGEMEIN.cKundenKontakte.getMailAdressCC(usrCntl.KdNR, "Fiskal")
                If EMAILTMPCC <> "" Then Mail_CC = EMAILTMPCC

                Dim EMAILTMPBCC = VERAG_PROG_ALLGEMEIN.cKundenKontakte.getMailAdressBCC(usrCntl.KdNR, "Fiskal")
                If EMAILTMPBCC <> "" Then Mail_BCC = EMAILTMPBCC

                If EMAILTMP = "" Then
                    Dim AD As New VERAG_PROG_ALLGEMEIN.cAdressen(usrCntl.KdNR)
                    If AD IsNot Nothing Then Mail_To = If(AD.E_Mail, "")
                End If
            End If


            Select Case usrCntl.cboTEXT._value
                Case "AT_FISKAL_DIREKT"

                    Mail_Subject = "Verbringungsnachweis AT-Fiskal | Nr.: " & VBNW_Nr

                    MailHTMLText &= "Sehr geehrte Damen und Herren,<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "beiliegend erhalten Sie eine Liste der Sendungen, bei denen eine FIskalverzollung durchgeführt wurde.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Die Aufstellung dient als Verbringungsnachweis der Ware, wir bitten Sie das Eingangsdatum der Sendung auszufüllen und das Formular mit Firmenstempel, Unterschrift und aktuellem Datum zu bestätigen.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "<b>Bitte den <u>Original</u>-Verbringungsnachweis umgehend an folgende Adresse senden:<br>"
                    MailHTMLText &= "<br>"
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                        Case "IMEX"
                            MailHTMLText &= "IMEX Customs Service GmbH<br>"
                            MailHTMLText &= "Suben 15</b><br>"
                            MailHTMLText &= "AT-4975 Suben </b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case "AMBAR"
                            MailHTMLText &= "Ambar Logistic Services GmbH <br>"
                            MailHTMLText &= "Reichenhallerstrasse 62</b><br>"
                            MailHTMLText &= "DE-83435 Bad Reichenhall </b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case Else
                            MailHTMLText &= "Verag Customs Service GmbH<br>"
                            MailHTMLText &= "Postfach 1013<br>"
                            MailHTMLText &= "DE-94152 Neuhaus/Inn</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 11, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                    End Select


                Case "AT_FISKAL_INDIREKT"

                    Mail_Subject = "Verbringungsnachweis AT-Fiskal | Nr.: " & VBNW_Nr

                    MailHTMLText &= "Sehr geehrte Damen und Herren,<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "beiliegend erhalten Sie die Verbringungsnachweise für die jeweiligen Firmen, bei denen eine Fikalverzollung duchgeführt wurde.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Die jeweiligen Kunden sollen den beigefügten Verbringungsnachweis mit dem Eingangsdatum der Sendung ausfüllen und mit Firmenstempel,<br>"
                    MailHTMLText &= "Unterschrift und aktuellem Datum ergänzen.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "<b>Wir bitten Sie den <u>Original</u>-Verbringungsnachweis umgehend an folgende Adresse zu senden:<br>"
                    MailHTMLText &= "<br>"
                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                        Case "IMEX"
                            MailHTMLText &= "IMEX Customs Service GmbH<br>"
                            MailHTMLText &= "Suben 15</b><br>"
                            MailHTMLText &= "AT-4975 Suben </b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case "AMBAR"
                            MailHTMLText &= "Ambar Logistic Services GmbH <br>"
                            MailHTMLText &= "Reichenhallerstrasse 62</b><br>"
                            MailHTMLText &= "DE-83435 Bad Reichenhall </b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case Else
                            MailHTMLText &= "Verag Customs Service GmbH<br>"
                            MailHTMLText &= "Postfach 1013<br>"
                            MailHTMLText &= "DE-94152 Neuhaus/Inn</b><br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= "Vielen Dank im Voraus.<br>"
                            MailHTMLText &= "<br>"
                            MailHTMLText &= cFakturierung.getSignature("D", 11, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                    End Select


                Case "DE_FISKAL_GB"


                    Mail_Subject = "ENTRY CERTIFICATE | Nr.: " & VBNW_Nr

                    MailHTMLText &= "Dear Sir Or Madam,<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "we made german fiscal custom clearances for you at the border.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "In relation to this, we would like to inform you, that you have to register the acquisition and submit an Intrastat declaration.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "You also have to send us the necessary entry certificate.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "<b>Please confirm us the attached entry certificate With the date Of delivery, company stamp, Signature And<br>"
                    MailHTMLText &= "the current date And send it back by E-Mail.</b><br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Thanks in advance.<br>"
                    MailHTMLText &= "<br>"

                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                        Case "IMEX"
                            MailHTMLText &= cFakturierung.getSignature("GB", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case "AMBAR"
                            MailHTMLText &= cFakturierung.getSignature("GB", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case Else
                            MailHTMLText &= cFakturierung.getSignature("GB", 99, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                    End Select


                Case "DE_FISKAL_FR"


                    Mail_Subject = "ATTESTATION DE RECEPTION | Nr.: " & VBNW_Nr

                    MailHTMLText &= "Madame, Monsieur!<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Nous avons transporté pour vous de la marchandise provenant dans le cadre d'une livraison intracommunautaire exemptée de taxes.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Par consequent, nous vous informons du fait que vous êtes tenus de déclarer l'acquisation intracommunautaire et de remettre une déclaration Intrastat.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "En outre, s'il vous plaît envoyer nous la nécessité attestation de reception.<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "<b>Confirmez, simplement la attestation de reception (voir ci-joint) avec du cachet de l'entreprise, signature, <br>"
                    MailHTMLText &= "date de la marchandise d'entrée et la date courante et retourner à mon adresse e-mail.</b><br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Merci d'avance.<br>"
                    MailHTMLText &= "<br>"

                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                        Case "IMEX"
                            MailHTMLText &= cFakturierung.getSignature("FR", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case "AMBAR"
                            MailHTMLText &= cFakturierung.getSignature("FR", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case Else
                            MailHTMLText &= cFakturierung.getSignature("FR", 99, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                    End Select


                Case "DE_FISKAL_TR"


                    Mail_Subject = "Teslimat Belgesini | Nr.: " & VBNW_Nr

                    MailHTMLText &= "Merhabalar,<br>"
                    MailHTMLText &= "<br>"
                    MailHTMLText &= "Ekte göndermis oldugum Teslimat Belgesini, yükü teslim aldiginiza dair onaylayip, <br>"
                    MailHTMLText &= "bana ACILEN geri gönderiniz lütfen.<br>"
                    MailHTMLText &= "<br>"

                    Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
                        Case "IMEX"
                            MailHTMLText &= cFakturierung.getSignature("TR", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case "AMBAR"
                            MailHTMLText &= cFakturierung.getSignature("TR", 20, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                        Case Else
                            MailHTMLText &= cFakturierung.getSignature("TR", 99, (VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG"))
                    End Select


            End Select



            MailHTMLText &= "</div>"

            listMail.Add(New FormMangagerEmail(Mail_To, Mail_CC, Mail_BCC, Mail_Subject, MailHTMLText))


            Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)

            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 53, 82, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

            '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBestimmungszollamt.Text, 82, 152, 100, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            '  Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "GESTELLUNGSGARANTIEN", getUO2, "", "Gestellungsgarantie_EN", listTowrite)


            'oWord.Visible = True


            striList.Add(usrCntl.Path)

        Catch ex As Exception
            MessageBox.Show(ex.ToString & ex.StackTrace)
        End Try
        Return striList
    End Function

    Shared Function Verbundenheit(usrCntl As usrcntlVerbundenheit) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 40, 33 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 40, 38.5 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 40, 43.5 + top, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUid.Text, 40, 51 + top, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 130, 51 + top, 65, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        Select Case usrCntl.cboSprache._value
            Case "EN"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Verbundenheit_EN", listTowrite)
            Case "FR"
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Verbundenheit_FR", listTowrite)
            Case Else
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Verbundenheit", listTowrite)
        End Select

    End Function

    Shared Function Rechnungsbestaetigung(usrCntl As usrcntlRechnungsbestaetigung) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        Select Case usrCntl.cboSprache._value
            Case "EN"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRgNr.Text, 50, 182, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVersender.Text, 50, 200, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Rechnungsbestaetigung_EN", listTowrite)
            Case "FR" '140/102
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRgNr.Text, 115, 182, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVersender.Text, 102, 142, 60, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Rechnungsbestaetigung_FR", listTowrite)
            Case "TR"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRgNr.Text, 26, 165, 30, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVersender.Text, 60, 147, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Rechnungsbestaetigung_TR", listTowrite)
            Case Else
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtRgNr.Text, 80, 148, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVersender.Text, 50, 165, 150, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Rechnungsbestaetigung", listTowrite)
        End Select

    End Function



    Shared Function Finish_AVISO(AVISO As VERAG_PROG_ALLGEMEIN.cAviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0
        If AVISO.Grenzstelle = "SUB" Then

            '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
            'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            '    Case "FRONTOFFICE", "VERAG"
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 37, 46, 120, 12, "bold", 20, , itextsharp.text.Element.ALIGN_LEFT))
            'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            '    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 141, 47, 50, 12, "bold", 16, , iTextSharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString, 141, 47, 50, 12, "bold", 16, , itextsharp.text.Element.ALIGN_LEFT))
            Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "FRONTOFFICE", "", "Finish_AVISO", listTowrite)
            'End Select
            '    End If
        End If
        Return ""
    End Function




    Shared Function zumZOLL_AVISO(AVISO As VERAG_PROG_ALLGEMEIN.cAviso, Optional Zollamt As String = "") As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        If AVISO.Grenzstelle = "SUB" Then
            '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
            'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            '    Case "FRONTOFFICE", "VERAG"
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 37, 46, 120, 12, "bold", 20, , itextsharp.text.Element.ALIGN_LEFT))
            'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 141, 47, 50, 12, "bold", 16, , itextsharp.text.Element.ALIGN_LEFT))
            If Zollamt = "DE" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 215, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))
            If Zollamt = "AT" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 263, 6, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))
            Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "FRONTOFFICE", "", "zumZoll_Aviso", listTowrite)
            'End Select
            '         End If
        End If
        Return ""
    End Function


    Shared Function zumZOLL_AVISO_AT(AVISO As VERAG_PROG_ALLGEMEIN.cAviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        If AVISO.Grenzstelle = "SUB" Then
            '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
            'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            '    Case "FRONTOFFICE", "VERAG"
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 37, 46, 120, 12, "bold", 20, , itextsharp.text.Element.ALIGN_LEFT))
            'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 141, 47, 50, 12, "bold", 16, , itextsharp.text.Element.ALIGN_LEFT))
            'If Zollamt = "DE" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 215, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
            'If Zollamt = "AT" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 263, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
            Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "FRONTOFFICE", "", "zumZoll_Aviso_AT", listTowrite)
            'End Select
            '         End If
        End If
        Return ""
    End Function

    Shared Function zumZOLL_AVISO_DE(AVISO As VERAG_PROG_ALLGEMEIN.cAviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        If AVISO.Grenzstelle = "SUB" Then
            '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
            'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            '    Case "FRONTOFFICE", "VERAG"
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 37, 46, 120, 12, "bold", 20, , itextsharp.text.Element.ALIGN_LEFT))
            'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
            listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 141, 47, 50, 12, "bold", 16, , itextsharp.text.Element.ALIGN_LEFT))
            'If Zollamt = "DE" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 215, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
            'If Zollamt = "AT" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 263, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
            Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", "FRONTOFFICE", "", "zumZoll_Aviso_DE", listTowrite)
            'End Select
            '         End If
        End If
        Return ""
    End Function

    Shared Function zumZOLL_AVISO_WAI(AVISO As VERAG_PROG_ALLGEMEIN.cAviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        '  If AVISO.Grenzstelle = "WAI" Then
        '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
        'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
        '    Case "FRONTOFFICE", "VERAG"
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 55, 23, 65, 8, "bold", 15, , itextsharp.text.Element.ALIGN_CENTER))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 150, 32, 45, 10, "bold", 12, , itextsharp.text.Element.ALIGN_CENTER))
        'If Zollamt = "DE" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 215, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
        'If Zollamt = "AT" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 263, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "zumZoll_Aviso_WAI", listTowrite)
        'End Select
        ' End If
        '   End If
        Return ""
    End Function

    Shared Function zumZOLL_AVISO_DTB(AVISO As VERAG_PROG_ALLGEMEIN.cAviso) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Dim top = 0

        '  If AVISO.Grenzstelle = "WAI" Then
        '  If AVISO.Status = VERAG_PROG_ALLGEMEIN.cGlobal.Status_Freigegeben Then
        'Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
        '    Case "FRONTOFFICE", "VERAG"
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.LKW_Nr, 55, 23, 65, 8, "bold", 15, , itextsharp.text.Element.ALIGN_CENTER))
        'listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(AVISO.Freigabe.ToShortDateString & " " & AVISO.Freigabe.ToShortTimeString, 141, 47, 50, 8, "bold", 10, , iTextSharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString & " " & Now.ToShortTimeString, 150, 32, 45, 10, "bold", 12, , itextsharp.text.Element.ALIGN_CENTER))
        'If Zollamt = "DE" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 215, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
        'If Zollamt = "AT" Then listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("X", 61, 263, 6, 6, "bold", 16, , iTextSharp.text.Element.ALIGN_CENTER))
        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "zumZoll_Aviso_DTB", listTowrite)
        'End Select
        ' End If
        '   End If
        Return ""
    End Function


    Shared Function QS_UeDok(usrCntl As usrcntlQS_UeDok) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 32, 52, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 32, 60, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtEori.Text, 32, 71, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxRechnung.Checked, "x", ""), 13, 91, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxPackUrsprung.Checked, "x", ""), 13, 99, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxAusfuhr.Checked, "x", ""), 13, 107.5, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        Dim netto = usrCntl.txtNettoGewicht.Text
        If IsNumeric(netto) Then netto = CDbl(netto).ToString("N0") & " kg"
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(netto, 45, 114.5, 130, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_EXW.Checked, "x", ""), 13, 135, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_FCA.Checked, "x", ""), 13, 139, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_CPT.Checked, "x", ""), 13, 155.2, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_CIP.Checked, "x", ""), 13, 159, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_CIF.Checked, "x", ""), 13, 163, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_DAP.Checked, "x", ""), 13, 167.5, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxFracht_DDP.Checked, "x", ""), 13, 171, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFrachtkost_1.Text, 167, 138, 20, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFrachtkost_2.Text, 167, 166, 20, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_EXW.Checked, "x", ""), 13, 204, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_FCA.Checked, "x", ""), 13, 208, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_CPT.Checked, "x", ""), 13, 212, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_CIP.Checked, "x", ""), 13, 224, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_CIF.Checked, "x", ""), 13, 228.2, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_DAP.Checked, "x", ""), 13, 232, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(usrCntl.cbxVers_DDP.Checked, "x", ""), 13, 236.3, 3, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVerskost_1.Text, 167, 207, 20, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtVerskost_2.Text, 167, 232, 20, 6, "bold", 10, , itextsharp.text.Element.ALIGN_RIGHT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Now.ToShortDateString, 12, 262, 68, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(VERAG_PROG_ALLGEMEIN.cAllgemein.USRNAME, 125, 262, 68, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))


        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "QS_UeDok", listTowrite)
    End Function


    Shared Function Zollstopp(Zollstop, Entladestelle, Kommentare, Absender) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Absender, 70, 44, 100, 10, "normal", 14, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Zollstop, 50, 80, 110, 30, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Entladestelle, 50, 145, 110, 30, "bold", 14, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(Kommentare, 50, 212, 110, 30, "normal", 12, , itextsharp.text.Element.ALIGN_LEFT))

        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Zollstopp", listTowrite)
    End Function

    Shared Function Bonitaetsauskunft(usrCntl As usrcntlCreditreformBoniAuskunft) As String
        Dim fm As New VERAG_PROG_ALLGEMEIN.cFormularManager

        Dim listTowrite As New List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)


        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.cboCRArt.Text, 192, 44, 80, 6, "normal", 12, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.cboCRFrauHerr.Text, 192, 54, 15, 6, "normal", 12, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtCRGesprochenMit.Text, 207, 54, 70, 6, "normal", 12, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtCRDatum.Text, 248, 64, 25, 6, "normal", 12, , itextsharp.text.Element.ALIGN_CENTER))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtFirma.Text, 153, 82, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse1.Text, 153, 92, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtAdresse2.Text, 153, 102, 130, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))

        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtLetztesBearbeitungsDatum.Text, 195, 115, 25, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBonitaetsindex.Text, 254, 113, 20, 6, "bold", 16, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtGruendungsdatum.Text, 172, 125, 20, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtUmsatz.Text, 210, 125, 35, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtMitarbeiter.Text, 260, 125, 20, 6, "normal", 10, , itextsharp.text.Element.ALIGN_CENTER))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtBankverbindung.Text, 185, 137, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtZahlungsweise.Text, 182, 147, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtHoechstkredit.Text, 182, 157, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtGeschaeftsfuehrerName.Text, 182, 167, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
        listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(usrCntl.txtSonstiges.Text, 182, 177, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))

        If usrCntl.cbxInKundendatenSpeichern.Checked Then
            If vbYes = MsgBox("Möchten Sie die Bonitätsauskunft in den Kundendaten speichern?", vbYesNoCancel) Then
                If IsNumeric(usrCntl.KdNR) AndAlso usrCntl.KdNR > 0 Then
                    saveCreditreform(usrCntl)
                Else
                    MsgBox("Fehler: Keine KundenNr ausgewählt - speichern abgebrochen.")
                End If
            End If
        End If

        Return fm.fillPDF("DOKUMENTE", "VORLAGEN", "SONSTIGE", getUO2, "", "Bonitaetsauskunft", listTowrite)
    End Function

    Public Shared Function getUO2() As String
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX", "ATILLA", "UNISPED", "AMBAR" : Return VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case Else : Return ""
        End Select
    End Function

    Public Shared Function getUO2_FO() As String
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "IMEX", "ATILLA", "UNISPED", "AMBAR", "FRONTOFFICE" : Return VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case Else : Return ""
        End Select
    End Function

    Public Shared Function getUO2(FilialenNr As String) As String
        If FilialenNr = "" Then Return getUO2()
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(FilialenNr)
            Case "IMEX", "ATILLA", "UNISPED" : Return VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(FilialenNr)
            Case Else : Return ""
        End Select
    End Function

    Shared Function saveCreditreform(usrCntl As usrcntlCreditreformBoniAuskunft) As Boolean
        Try
            Dim cBonitaetsauskunft As VERAG_PROG_ALLGEMEIN.cBonitaetsauskunft = VERAG_PROG_ALLGEMEIN.cBonitaetsauskunft.LOADByKdNrDate(usrCntl.KdNR, Now)


            If cBonitaetsauskunft Is Nothing Then
                cBonitaetsauskunft = New VERAG_PROG_ALLGEMEIN.cBonitaetsauskunft
            ElseIf vbYes <> MsgBox("Es wurde heute um '" & cBonitaetsauskunft.ba_Datum.ToShortTimeString & "' bereits eine Bonitätsauskunft für den Kunden eingeholt, möchten Sie diese überschreiben?", vbYesNoCancel) Then
                Return False
            End If

            cBonitaetsauskunft.ba_KundenNr = (usrCntl.KdNR)
            cBonitaetsauskunft.ba_CRAnsprechpartnerHerrFrau = (usrCntl.cboCRFrauHerr._value)
            cBonitaetsauskunft.ba_CRAnsprechpartner = (usrCntl.txtCRGesprochenMit.Text)
            cBonitaetsauskunft.ba_CRArt = (usrCntl.cboCRArt._value)
            cBonitaetsauskunft.ba_Datum = cProgramFunctions.isLeerNothing(usrCntl.txtCRDatum._value)

            cBonitaetsauskunft.ba_Firma = usrCntl.txtFirma.Text
            cBonitaetsauskunft.ba_Adresse1 = usrCntl.txtAdresse1.Text
            cBonitaetsauskunft.ba_Adresse2 = usrCntl.txtAdresse2.Text
            cBonitaetsauskunft.ba_LetztesBearbeitungsDatum = cProgramFunctions.isLeerNothing(usrCntl.txtLetztesBearbeitungsDatum._value)
            cBonitaetsauskunft.ba_BonitaetsIndex = If(IsNumeric(usrCntl.txtBonitaetsindex.Text), usrCntl.txtBonitaetsindex.Text, 0)
            cBonitaetsauskunft.ba_GruendundsDatum = cProgramFunctions.isLeerNothing(usrCntl.txtGruendungsdatum._value)

            Dim umsatz = usrCntl.txtUmsatz.Text
            If IsNumeric(usrCntl.txtUmsatz.Text) Then
                umsatz = CDbl(usrCntl.txtUmsatz.Text).ToString("N2")
            End If
            cBonitaetsauskunft.ba_Umsatz = cProgramFunctions.isLeerNothing(umsatz)
            cBonitaetsauskunft.ba_Mitarbeiter = cProgramFunctions.isLeerNothing(usrCntl.txtMitarbeiter.Text)
            cBonitaetsauskunft.ba_Bankverbindung = usrCntl.txtBankverbindung.Text
            cBonitaetsauskunft.ba_Zahlungsweise = usrCntl.txtZahlungsweise.Text
            cBonitaetsauskunft.ba_Hoechstkredit = cProgramFunctions.isLeerNothingDbl(usrCntl.txtHoechstkredit._value)
            cBonitaetsauskunft.ba_GFName = usrCntl.txtGeschaeftsfuehrerName.Text
            cBonitaetsauskunft.ba_Sonstiges = usrCntl.txtSonstiges.Text
            cBonitaetsauskunft.ba_MaId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID
            cBonitaetsauskunft.ba_Sachbearbeiter = VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME

            If cBonitaetsauskunft.SAVE Then
                usrCntl.lblCRsaved.Text = "(gespeichert)"
                usrCntl.lblCRsaved.ForeColor = Color.Green
                VSQL.doSQL("UPDATE Kunden SET Bonität='" & cBonitaetsauskunft.ba_BonitaetsIndex & "', Bonitätsdatum='" & cBonitaetsauskunft.ba_Datum & "', Höchstkredit=" & If(cBonitaetsauskunft.ba_Hoechstkredit Is Nothing, "null", "'" & cBonitaetsauskunft.ba_Hoechstkredit & "'") & " WHERE KundenNr='" & cBonitaetsauskunft.ba_KundenNr & "'", "FMZOLL")
                Return True
            Else
                Return False
            End If


        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function


    Shared Function saveVorauskasse(usrCntl As usrcntlVorauskasse) As Boolean
        Try
            If Not IsNumeric(usrCntl.cboFiliale._value) Then Return False
            If Not IsNumeric(usrCntl.txtAbfertigungsNr.Text) Then Return False

            Dim cVorauskasse As VERAG_PROG_ALLGEMEIN.cVorauskasse = VERAG_PROG_ALLGEMEIN.cVorauskasse.LOADByFilialeAbfNr(usrCntl.cboFiliale._value, usrCntl.txtAbfertigungsNr.Text, usrCntl.ROLLE)


            If cVorauskasse Is Nothing Then
                cVorauskasse = New VERAG_PROG_ALLGEMEIN.cVorauskasse
            ElseIf vbYes <> MsgBox("Es wurde am '" & cVorauskasse.vk_Datum.ToShortDateString & "' um '" & cVorauskasse.vk_Datum.ToShortTimeString & "' bereits eine Vorauskasse mit dieser Abfertigungsnummer angefordert, möchten Sie diese überschreiben?", vbYesNoCancel) Then
                Return False
            End If

            cVorauskasse.vk_KdNr = If(usrCntl.KdNR > 0, usrCntl.KdNR, Nothing)

            cVorauskasse.vk_FilialeNr = usrCntl.cboFiliale._value
            cVorauskasse.vk_AbfertigungsNr = usrCntl.txtAbfertigungsNr.Text
            cVorauskasse.vk_Datum = Now
            cVorauskasse.vk_LKW = usrCntl.txtLKWKennz.Text

            cVorauskasse.vk_Firma = usrCntl.txtFirma.Text
            cVorauskasse.vk_Betrag = CDbl(usrCntl.txtGesamtsumme._value)
            cVorauskasse.vk_QS_SachbearbeiterId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID
            cVorauskasse.vk_QS_Sachbearbeiter = VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME
            cVorauskasse.vk_QS_Bemerkung = usrCntl.txtVKVermerk.Text
            'cVorauskasse.vk_GeldEingetroffen = usrCntl.XXXXXXX
            'cVorauskasse.vk_BH_SachbearbeiterId = usrCntl.XXXXXXX
            'cVorauskasse.vk_BH_Sachbearbeiter = usrCntl.XXXXXXX
            'cVorauskasse.vk_BH_Bemerkung = usrCntl.XXXXXXX
            'cVorauskasse.vk_BH_DatumGeldeingang = usrCntl.XXXXXXX
            If usrCntl.SENDUNG IsNot Nothing Then
                cVorauskasse.vk_SendungId = usrCntl.SENDUNG.tblSnd_SendungID
                cVorauskasse.vk_AvisoId = usrCntl.SENDUNG.tblSnd_AvisoID
            End If
            usrCntl.getValues(cVorauskasse)

            If cVorauskasse.SAVE Then
                usrCntl.lblCRsaved.Text = "(gespeichert)"
                usrCntl.lblCRsaved.ForeColor = Color.Green
                '  VSQL.doSQL("UPDATE Kunden SET Bonität='" & cVorauskasse.ba_BonitaetsIndex & "', Bonitätsdatum='" & cVorauskasse.ba_Datum & "', Höchstkredit=" & If(cVorauskasse.ba_Hoechstkredit Is Nothing, "null", "'" & cVorauskasse.ba_Hoechstkredit & "'") & " WHERE KundenNr='" & cVorauskasse.ba_KundenNr & "'", "FMZOLL")

                cVorauskasseOptions.insertVermerk(cVorauskasse.vk_FilialeNr, cVorauskasse.vk_AbfertigungsNr, 13,,, cVorauskasse.vk_VermerkId, , cVorauskasse.vk_Betrag, cVorauskasse.vk_id)
                cVorauskasse.SAVE() 'VermerkId speichern
                Return True
            Else
                Return False
            End If


        Catch ex As Exception
            MsgBox("SaveVK: " & ex.Message)
            Return False
        End Try
    End Function


    Shared Function savePostversand(usrCntl As usrcntlVerzollungsunterlagen, ByRef POST_ID As Integer) As Boolean
        Try
            'If Not IsNumeric(usrCntl.cboFiliale._value) Then Return False
            'If Not IsNumeric(usrCntl.txtAbfertigungsNr.Text) Then Return False

            'Dim cPostversand As VERAG_PROG_ALLGEMEIN.cPostversand = VERAG_PROG_ALLGEMEIN.cPostversand.LOADByFilialeAbfNr(usrCntl.cboFiliale._value, usrCntl.txtAbfertigungsNr.Text, usrCntl.ROLLE)
            Dim cPostversand As VERAG_PROG_ALLGEMEIN.cPostversand

            If POST_ID > 0 Then
                cPostversand = New VERAG_PROG_ALLGEMEIN.cPostversand(POST_ID)
            Else
                cPostversand = New VERAG_PROG_ALLGEMEIN.cPostversand
            End If

            'If cPostversand Is Nothing Then
            '    cPostversand = New VERAG_PROG_ALLGEMEIN.cPostversand
            '    'ElseIf vbYes <> MsgBox("Es wurde am '" & cPostversand.post_Datum.ToShortDateString & "' um '" & cPostversand.post_Datum.ToShortTimeString & "' bereits eine Vorauskasse mit dieser Abfertigungsnummer angefordert, möchten Sie diese überschreiben?", vbYesNoCancel) Then
            '    '    Return False
            'End If


            'cPostversand.post_GeldEingetroffen = usrCntl.XXXXXXX
            'cPostversand.post_BH_SachbearbeiterId = usrCntl.XXXXXXX
            'cPostversand.post_BH_Sachbearbeiter = usrCntl.XXXXXXX
            'cPostversand.post_BH_Bemerkung = usrCntl.XXXXXXX
            'cPostversand.post_BH_DatumGeldeingang = usrCntl.XXXXXXX

            usrCntl.getValues(cPostversand)

            If cPostversand.SAVE Then

                usrCntl.btnNEU.Visible = True
                POST_ID = cPostversand.post_id
                usrCntl.lblCRsaved.Text = "(gespeichert)"
                usrCntl.lblCRsaved.ForeColor = Color.Green

                '   cPostversandOptions.insertVermerk(cPostversand.post_FilialeNr, cPostversand.post_AbfertigungsNr, 13)

                Return True
            Else
                Return False
            End If


        Catch ex As Exception
            MsgBox("SaveVK: " & ex.Message)
            Return False
        End Try
    End Function


    Shared Function addEinmaligeVM(listTowrite As List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues), left As Integer, top As Integer, language As String, RgNr As String, RgDat As String, Optional small As Boolean = False) As List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Select Case language
            Case "EN", "FR"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("UNIQUE AUTHORISATION", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("______________________", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(small, "Valid only for the following invoice:", "This power of attorney is valid only for the following invoice:"), left + 62, top + 0, 180, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                If small Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Inv.No.: ________________________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Inv.Dat.:  _______________________________________ ", left + 15, top + 13, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgNr, left + 28, top + 5, 80, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 31, top + 12, 75, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                Else
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Invoice-No.: ______________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Invoice-Date: _____________________ ", left + 103, top + 6, 90, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgNr, left + 33, top + 5, 60, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 126, top + 5, 40, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                End If
            Case Else
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("EINMALIGE VOLLMACHT", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("______________________", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(small, "Gültig für folgende Rechnung:", "Diese Vollmacht ist nur für folgende Rechnung gültig:"), left + 62, top + 0, 180, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                If small Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rg.-Nr.: ________________________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rg.-Datum: _____________________________________ ", left + 15, top + 13, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgNr, left + 28, top + 5, 80, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 31, top + 12, 75, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                Else
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rechnungs-Nr.: ______________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rechnungs-Datum: _____________________ ", left + 103, top + 6, 90, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgNr, left + 41, top + 5, 60, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 136, top + 5, 40, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                End If
        End Select
        Return listTowrite
    End Function

    Shared Function addEinmaligeVMCarnetATA(listTowrite As List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues), left As Integer, top As Integer, language As String, CarnetATAr As String, XXXX As String, Optional small As Boolean = False) As List(Of VERAG_PROG_ALLGEMEIN.cPDFWriteValues)
        Select Case language
            Case "EN"
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("UNIQUE AUTHORISATION", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("______________________", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(small, "Valid only for the following Carnet-ATA:", "This power of attorney is valid only for the following Carnet-ATA:"), left + 62, top + 0, 180, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                If small Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Inv.No.: ________________________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    '     listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Inv.Dat.:  _______________________________________ ", left + 15, top + 13, 100, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CarnetATAr, left + 28, top + 5, 80, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 31, top + 12, 75, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_CENTER))
                Else
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Invoice-No.: ______________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Invoice-Date: _____________________ ", left + 103, top + 6, 90, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CarnetATAr, left + 33, top + 5, 60, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 126, top + 5, 40, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_CENTER))
                End If
            Case Else
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("EINMALIGE VOLLMACHT", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("______________________", left + 15, top + 0, 180, 6, "bold", 10, , itextsharp.text.Element.ALIGN_LEFT))
                listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(If(small, "Gültig für folgendes Carnet-ATA:", "Diese Vollmacht ist nur für folgendes Carnet-ATA gültig:"), left + 62, top + 0, 180, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                If small Then
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Carnet-ATA: ________________________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rg.-Datum: _____________________________________ ", left + 15, top + 13, 100, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CarnetATAr, left + 28, top + 5, 80, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 31, top + 12, 75, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_CENTER))
                Else
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Carnet-ATA-Nr.: ______________________________ ", left + 15, top + 6, 100, 6, "normal", 10, , itextsharp.text.Element.ALIGN_LEFT))
                    ' listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues("Rechnungs-Datum: _____________________ ", left + 103, top + 6, 90, 6, "normal", 10, , iTextSharp.text.Element.ALIGN_LEFT))
                    listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(CarnetATAr, left + 41, top + 5, 60, 6, "bold", 10, , itextsharp.text.Element.ALIGN_CENTER))
                    '  listTowrite.Add(New VERAG_PROG_ALLGEMEIN.cPDFWriteValues(RgDat, left + 136, top + 5, 40, 6, "bold", 10, , iTextSharp.text.Element.ALIGN_CENTER))
                End If
        End Select
        Return listTowrite
    End Function


    Public Shared Function MergePdfFiles(ByVal fileNames As List(Of String), ByVal targetPdf As String) As Boolean
        Dim merged As Boolean = True
        Using stream As FileStream = New FileStream(targetPdf, FileMode.Create)
            stream.Position = 0
            Dim document As New itextsharp.text.Document
            Dim pdf As PdfCopy = New PdfCopy(document, stream)
            Dim reader As PdfReader = Nothing


            reader.unethicalreading = True ' Damit geschützte PDFs gelesen werden können... ' PdfReader not opened with owner password

            Try
                document.Open()
                For Each file As String In fileNames
                    If file.ToUpper.EndsWith(".PDF") Then
                        reader = New PdfReader(file)

                        pdf.AddDocument(reader)
                        reader.Close()
                    End If
                Next
            Catch __unusedException1__ As Exception
                MsgBox(__unusedException1__.Message & __unusedException1__.StackTrace)
                merged = False
                If reader IsNot Nothing Then
                    reader.Close()
                End If

            Finally
                If document IsNot Nothing Then
                    document.Close()
                End If
            End Try
        End Using


        Return merged
    End Function

    'ALT: Hier kam es zum komischen Problemen bei einem PDF: es wurde eine alte Verison ausgegeben, obwohl die alten texte nicht ersichtlich waren?? --> Infoschreiben Fiskal
    Public Shared Function MergePdfFiles2ALT(ByVal pdfFiles As List(Of String), ByVal outputPath As String) As Boolean
        Dim result As Boolean = False
        Dim pdfCount As Integer = 0     'total input pdf file count
        Dim f As Integer = 0    'pointer to current input pdf file
        Dim fileName As String
        Dim reader As itextsharp.text.pdf.PdfReader = Nothing
        Dim pageCount As Integer = 0
        Dim pdfDoc As itextsharp.text.Document = Nothing    'the output pdf document
        Dim writer As PdfWriter = Nothing
        Dim cb As PdfContentByte = Nothing

        Dim page As PdfImportedPage = Nothing
        Dim rotation As Integer = 0

        Try
            pdfCount = pdfFiles.Count
            If pdfCount > 1 Then
                'Open the 1st item in the array PDFFiles
                fileName = pdfFiles(f)
                reader = New itextsharp.text.pdf.PdfReader(fileName)
                'Get page count
                pageCount = reader.NumberOfPages
                pdfDoc = New itextsharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
                writer = PdfWriter.GetInstance(pdfDoc, New FileStream(outputPath, FileMode.OpenOrCreate))

                With pdfDoc
                    .Open()
                End With
                'Instantiate a PdfContentByte object
                cb = writer.DirectContent
                'Now loop thru the input pdfs
                While f < pdfCount
                    'Declare a page counter variable
                    Dim i As Integer = 0
                    'Loop thru the current input pdf's pages starting at page 1
                    While i < pageCount
                        i += 1
                        'Get the input page size
                        pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i))
                        'Create a new page on the output document
                        pdfDoc.NewPage()
                        'If it is the 1st page, we add bookmarks to the page
                        'Now we get the imported page
                        page = writer.GetImportedPage(reader, i)
                        'Read the imported page's rotation
                        rotation = reader.GetPageRotation(i)
                        'Then add the imported page to the PdfContentByte object as a template based on the page's rotation
                        If rotation = 90 Then
                            cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)
                        ElseIf rotation = 270 Then
                            cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)
                        Else
                            cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
                        End If
                    End While
                    'Increment f and read the next input pdf file
                    f += 1
                    If f < pdfCount Then
                        fileName = pdfFiles(f)
                        reader = New itextsharp.text.pdf.PdfReader(fileName)
                        pageCount = reader.NumberOfPages
                    End If
                End While
                'When all done, we close the document so that the pdfwriter object can write it to the output file
                pdfDoc.Close()

                result = True
            End If
        Catch ex As Exception
            MsgBox(ex.Message & vbNewLine & ex.StackTrace)
            Return False
        End Try
        Return result
    End Function


    Shared Sub OPEN_FORM(PDFArt As String)
        Dim f As New frmFormulare(PDFArt) : f.Show()
    End Sub

    Shared Sub OPEN_FORM(KdNr As Integer, Optional param() As Object = Nothing)
        Dim f As New frmFormulare(KdNr) : f.Show()
    End Sub

    Shared Sub OPEN_FORM(PDFArt As String, Optional KdNr As Integer = 0, Optional param() As Object = Nothing, Optional isSingleForm As Boolean = False)
        Dim f As New frmFormulare(PDFArt, KdNr, param, isSingleForm)
        f.Show()

    End Sub

    Shared Sub OPEN_FORM(FORM As Form, PDFArt As String, Optional KdNr As Integer = 0, Optional param() As Object = Nothing, Optional isSingleForm As Boolean = False)
        Dim f As New frmFormulare(PDFArt, KdNr, param, isSingleForm)
        f.Show(FORM)
    End Sub

    Shared Sub OPEN_FORM_Byref(PDFArt As String, Optional KdNr As Integer = 0, Optional param() As Object = Nothing, Optional isSingleForm As Boolean = False, Optional ByRef f As frmFormulare = Nothing)
        f = New frmFormulare(PDFArt, KdNr, param, isSingleForm)
        f.Show()

    End Sub
End Class

Public Interface FormualrInterface
    Sub ChangeKDNr(kdnr As Integer)
End Interface


Public Class FormularManagerArten
    ' Implements IReadOnlyCollection(Of String)

    Shared Property DE_Vollmacht = "DE_Vollmacht"
    Shared Property DE_Vollmacht_indirekt = "DE_Vollmacht_indirekt"

    Shared Property DE_Fiskal = "DE_Fiskal"
    Shared Property AT_Vollmacht = "AT_Vollmacht"
    Shared Property AT_Vollmacht_EV = "AT_Vollmacht_EV"
    Shared Property AT_Fiskal = "AT_Fiskal"

    Shared Property GB_Vollmacht_IE = "GB_Vollmacht_IE"
    Shared Property GB_Vollmacht_indirekt = "GB_Vollmacht_indirekt"

    Shared Property VERAG_EXPORT = "VERAG_EXPORT"
    Shared Property ATILLA_EXPORT = "ATILLA_EXPORT"

    Shared Property VUB = "VUB"
    Shared Property VUB_AG = "VUB_AG"
    Shared Property VUB_IMEX = "VUB_IMEX"
    Shared Property VUB_CS = "VUB_CS"
    Shared Property Importaviso_VK = "Importaviso_VK"
    Shared Property Gestellungsgarantie = "Gestellungsgarantie"
    Shared Property Verzollungspreise = "Verzollungspreise"
    Shared Property Boniteatsauskunft = "Boniteatsauskunft"
    Shared Property Sonst_PDF = "Sonst_PDF"
    Shared Property DispoListe = "DispoListe"
    Shared Property VerpflichtungserklärungFahrer = "VerpflichtungserklärungFahrer"
    Shared Property DE_InformationsblattFiskalverzollung = "DE_InformationsblattFiskalverzollung"
    Shared Property AT_InformationsblattFiskalverzollung = "AT_InformationsblattFiskalverzollung"
    Shared Property EORI_Antrag = "EORI_Antrag"

    Shared Property Verzollungsunterlagen = "Verzollungsunterlagen"
    Shared Property VerzollungsunterlagenBAR = "VerzollungsunterlagenBAR"
    Shared Property Gelangensbestaetigung = "Gelangensbestaetigung"
    Shared Property QS_UeDok = "QS_UeDok"
    Shared Property SA_Gestellung = "SA_Gestellung"
    Shared Property Importaviso = "Importaviso"
    Shared Property Verbundenheit = "Verbundenheit"

    Shared Property Sendungsliste = "Sendungsliste"
    Shared Property Rechnungsbestaetigung = "Rechnungsbestaetigung"
    Shared Property Zollbeschau_Protokoll = "Zollbeschau Protokoll"

    Shared Property Qualitaetskontrolle = "Qualitätskontrolle"



End Class



Public Class FormularVorlagenGruppe
    ' Implements IReadOnlyCollection(Of String)
    Shared Property NeukundeAT = "NeukundeAT"
    Shared Property NeukundeDE = "NeukundeDE"
    Shared Property NeukundeATFiskal = "NeukundeATFiskal"
    Shared Property NeukundeDEFiskal = "NeukundeDEFiskal"


    Shared Property NeukundeAT_IMEX = "NeukundeAT_IMEX"
    Shared Property NeukundeDE_IMEX = "NeukundeDE_IMEX"
    Shared Property NeukundeATFiskal_IMEX = "NeukundeATFiskal_IMEX"
    Shared Property NeukundeDEFiskal_IMEX = "NeukundeDEFiskal_IMEX"
End Class

Public NotInheritable Class FormularManagerArten2
    Inherits System.Object

    Shared Property DE_Vollmacht = "DE_Vollmacht"

End Class


Public Class FormMangagerEmail
    Property Mail_To
    Property Mail_CC
    Property Mail_BCC
    Property Mail_Subject
    Property MailHTMLText
    Sub New(Mail_To, Mail_CC, Mail_BCC, Mail_Subject, MailHTMLText)
        Me.Mail_To = Mail_To
        Me.Mail_CC = Mail_CC
        Me.Mail_BCC = Mail_BCC
        Me.Mail_Subject = Mail_Subject
        Me.MailHTMLText = MailHTMLText
    End Sub
End Class
'Member von System.Windows.Forms
