Public Class usrCntlATLAS_NCTS004_Positionen

    Dim NCTS As DAKOSY_Worker.cDakosyNCTSOut004 = Nothing
    Dim NCTS_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR = Nothing

    Dim POS As New List(Of usrCntlATLAS_NCTS004_Position)
    Dim sectionChangeBLOCK = False
    Dim gesRohmasse = 0
    Dim gesPackstuecke = 0

    Event RohmasseChanged(gesRohmasse As Double, gesPackstuecke As Double)
    Event PosAnzChanged(anzahlPos As Double)



    Sub New(NCTS As DAKOSY_Worker.cDakosyNCTSOut004)

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

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Me.NCTS = NCTS
    End Sub

    Sub New(NCTS_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR)

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

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Me.NCTS_TR = NCTS_TR
    End Sub
    Private Sub usrCntlATLAS_NCTS_Load(sender As Object, e As EventArgs) Handles Me.Load

        ' addItem() 'Auskommentiert!
        'setValues(NCTS.ncts_WARENPOS)
    End Sub

    Public Sub setValues(NCTS_POS As DAKOSY_Worker.cDakosyNCTSOut004)
        If NCTS_POS Is Nothing Then Exit Sub
        POS.Clear()

        If NCTS_POS.ncts_HOUSE_CONSIGNMENT IsNot Nothing AndAlso NCTS_POS.ncts_HOUSE_CONSIGNMENT.Count > 0 Then
            If NCTS_POS.ncts_HOUSE_CONSIGNMENT(0).nctsWP_CONSIGNMENT_ITEM IsNot Nothing Then
                For Each p In NCTS_POS.ncts_HOUSE_CONSIGNMENT(0).nctsWP_CONSIGNMENT_ITEM
                    addItem(p) 'MyPanel2.Controls.Add()
                Next
            End If
        End If
        MyPanel2.Controls.Clear()
        MyListBox1_SelectedIndexChanged(dgvPositionen, New EventArgs)
    End Sub


    Public Sub setValues_TR(NCTS_POS As VERAG_PROG_ALLGEMEIN.cNCTS_TR)
        If NCTS_POS Is Nothing Then Exit Sub
        POS.Clear()

        For Each p In NCTS_POS.ncts_WARENPOS
            addItem_TR(p) 'MyPanel2.Controls.Add()
        Next
        MyPanel2.Controls.Clear()
        MyListBox1_SelectedIndexChanged(dgvPositionen, New EventArgs)
    End Sub


    Sub initListBox(Optional selectedIndex = -1)
        If dgvPositionen.ColumnCount <= 0 Then Exit Sub
        If selectedIndex >= 0 Then sectionChangeBLOCK = True
        Dim cnt As Integer = 1
        dgvPositionen.Rows.Clear()
        For Each p In POS
            p.lblPosNr.Text = cnt
            dgvPositionen.Rows.Add(POS.IndexOf(p), cnt, p.txtWarenbezeichnung.Text)
            cnt += 1
        Next
        If selectedIndex >= 0 Then
            '   MyListBox1.SetSelected(selectedIndex, True)
            '  sectionChangeBLOCK = False
        End If
    End Sub

    Private Sub dgvPositionen_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvPositionen.KeyDown
        If e.KeyCode = Keys.Delete Then
            removeItem(dgvPositionen.SelectedRows(0).Cells("index").Value)
        End If
    End Sub


    Private Sub MyListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles dgvPositionen.SelectionChanged
        Try

            If sectionChangeBLOCK Then Exit Sub
            MyPanel2.Controls.Clear()
            If dgvPositionen.SelectedRows.Count > 0 Then
                MyPanel2.Controls.Add(POS(dgvPositionen.SelectedRows(0).Cells("index").Value))
                POS(dgvPositionen.SelectedRows(0).Cells("index").Value).txtWarenbezeichnung.Focus()
                '   Try : DirectCast(MyPanel2.Controls(0), usrCntlATLAS_NCTS004_Position).txtWarenbezeichnung.Focus() : Catch : End Try
                ' initListBox(MyListBox1.SelectedIndex())
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub usrCntlATLAS_NCTS004_Position_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        If e.Control = True Then
            If e.KeyCode = Keys.Oemplus Then addItem()
            If e.KeyCode = Keys.OemMinus Then
                If dgvPositionen.SelectedRows.Count > 0 Then
                    removeItem(dgvPositionen.SelectedRows(0).Cells("index").Value)
                End If
            End If

        End If
    End Sub



    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Try
            If keyData = (Keys.Control Or Keys.Add) Then
                'RaiseEvent a() : Return True
                addItem()
                Return True
            ElseIf keyData = (Keys.Control Or Keys.Subtract) Then
                'RaiseEvent REMOVE(ID) : Return True
                removeItem(dgvPositionen.SelectedRows(0).Cells("index").Value)
                Return True
            ElseIf keyData = Keys.PageUp Then
                'RaiseEvent PREV_POS() : Return True
                PREV_POS()
                Return True
            ElseIf keyData = Keys.PageDown Then
                'RaiseEvent NEXT_POS() : Return True
                NEXT_POS()
                Return True
            End If
        Catch ex As Exception
        End Try
        Return False
    End Function


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

    Function duplicateItem(Optional POSTMP As DAKOSY_Worker.cDakosy_NCTSOut_Warenposition = Nothing) As usrCntlATLAS_NCTS004_Position
        If dgvPositionen.SelectedRows.Count > 0 Then
            'GET
            'Dim d = getValues()
            '??????????????????????????


            MyPanel2.Controls.Add(POS(dgvPositionen.SelectedRows(0).Cells("index").Value))

            Dim u As usrCntlATLAS_NCTS004_Position = POS(dgvPositionen.SelectedRows(0).Cells("index").Value) '.CreateCopy(New usrCntlATLAS_NCTS004_Position))


            AddHandler u.RohmasseChanged, Sub(r, pk)
                                              gesRohmasse = 0
                                              gesPackstuecke = 0
                                              For Each p As usrCntlATLAS_NCTS004_Position In POS
                                                  gesRohmasse += If(IsNumeric(p.txtRohmasse.Text), p.txtRohmasse.Text, 0)
                                                  For Each row As DataGridViewRow In p.dgvPackstuecke.Rows
                                                      gesPackstuecke += If(IsNumeric(row.Cells("Anzahl").Value), row.Cells("Anzahl").Value, 0)
                                                  Next
                                              Next
                                              RaiseEvent RohmasseChanged(gesRohmasse, gesPackstuecke)
                                          End Sub
            u.Dock = DockStyle.Fill
            u.cboVpTyp.changeItem("OHNE")
            '  AddHandler u.ADD, AddressOf addItem
            ' AddHandler u.REMOVE, AddressOf removeItem
            ' AddHandler u.NEXT_POS, AddressOf NEXT_POS
            ' AddHandler u.PREV_POS, AddressOf PREV_POS
            POS.Add(u)
            initListBox()
            dgvPositionen.ClearSelection()
            If dgvPositionen.RowCount > 0 Then dgvPositionen.Rows(dgvPositionen.RowCount - 1).Selected = True
            RaiseEvent PosAnzChanged(POS.Count)
            Return u
        End If
    End Function

    Function addItem(Optional POSTMP As DAKOSY_Worker.cDakosy_NCTSOut004_HouseConsignment_ConsignmentItem = Nothing) As usrCntlATLAS_NCTS004_Position '
        Dim u = New usrCntlATLAS_NCTS004_Position(POS.Count, POSTMP)

        AddHandler u.RohmasseChanged, Sub(r, pk)
                                          gesRohmasse = 0
                                          gesPackstuecke = 0
                                          For Each p As usrCntlATLAS_NCTS004_Position In POS
                                              gesRohmasse += If(IsNumeric(p.txtRohmasse.Text), p.txtRohmasse.Text, 0)
                                              For Each row As DataGridViewRow In p.dgvPackstuecke.Rows
                                                  gesPackstuecke += If(IsNumeric(row.Cells("Anzahl").Value), row.Cells("Anzahl").Value, 0)
                                              Next
                                          Next
                                          RaiseEvent RohmasseChanged(gesRohmasse, gesPackstuecke)
                                      End Sub
        u.Dock = DockStyle.Fill
        u.cboVpTyp.changeItem("OHNE")
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "ATILLA"
                u.cbxEmport.Checked = True
        End Select
        '  AddHandler u.ADD, AddressOf addItem
        ' AddHandler u.REMOVE, AddressOf removeItem
        ' AddHandler u.NEXT_POS, AddressOf NEXT_POS
        ' AddHandler u.PREV_POS, AddressOf PREV_POS
        POS.Add(u)
        initListBox()
        dgvPositionen.ClearSelection()
        If dgvPositionen.RowCount > 0 Then dgvPositionen.Rows(dgvPositionen.RowCount - 1).Selected = True
        RaiseEvent PosAnzChanged(POS.Count)
        Return u
    End Function

    Function addItem_TR(Optional POSTMP As VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition = Nothing) As usrCntlATLAS_NCTS004_Position '
        Dim u = New usrCntlATLAS_NCTS004_Position(POS.Count, POSTMP)

        AddHandler u.RohmasseChanged, Sub(r, pk)
                                          gesRohmasse = 0
                                          gesPackstuecke = 0
                                          For Each p As usrCntlATLAS_NCTS004_Position In POS
                                              gesRohmasse += If(IsNumeric(p.txtRohmasse.Text), p.txtRohmasse.Text, 0)
                                              For Each row As DataGridViewRow In p.dgvPackstuecke.Rows
                                                  gesPackstuecke += If(IsNumeric(row.Cells("Anzahl").Value), row.Cells("Anzahl").Value, 0)
                                              Next
                                          Next
                                          RaiseEvent RohmasseChanged(gesRohmasse, gesPackstuecke)
                                      End Sub
        u.Dock = DockStyle.Fill
        u.cboVpTyp.changeItem("OHNE")
        Select Case VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
            Case "ATILLA"
                u.cbxEmport.Checked = True
        End Select
        '  AddHandler u.ADD, AddressOf addItem
        ' AddHandler u.REMOVE, AddressOf removeItem
        ' AddHandler u.NEXT_POS, AddressOf NEXT_POS
        ' AddHandler u.PREV_POS, AddressOf PREV_POS
        POS.Add(u)
        initListBox()
        dgvPositionen.ClearSelection()
        If dgvPositionen.RowCount > 0 Then dgvPositionen.Rows(dgvPositionen.RowCount - 1).Selected = True
        RaiseEvent PosAnzChanged(POS.Count)
        Return u
    End Function


    Sub removeItem(index)
        If index < 0 Then Exit Sub
        'If index < 0 Then Exit Sub
        If dgvPositionen.Rows.Count > index Then
            If vbYes = MsgBox("Möchten Sie die Position wirklich löschen?", vbYesNoCancel) Then
                dgvPositionen.ClearSelection()
                If POS.Count > index Then POS.RemoveAt(index)
                initListBox()
                If dgvPositionen.Rows.Count > index Then
                    dgvPositionen.Rows(index).Selected = True 'SetSelected(index, True)
                ElseIf dgvPositionen.Rows.Count > 0 Then
                    dgvPositionen.Rows(0).Selected = True
                End If
            End If
        End If
        RaiseEvent PosAnzChanged(POS.Count)
    End Sub

    Sub NEXT_POS()
        If dgvPositionen.SelectedRows.Count > 0 Then
            If dgvPositionen.RowCount > dgvPositionen.SelectedRows(0).Index + 1 Then
                Dim i = dgvPositionen.SelectedRows(0).Index
                dgvPositionen.ClearSelection()
                dgvPositionen.Rows(i + 1).Selected = True
                '  POS(dgvPositionen.SelectedRows(0).Cells("index").Value).txtWarenbezeichnung.Focus()
            End If
        End If
    End Sub
    Sub PREV_POS()
        If dgvPositionen.SelectedRows.Count > 0 Then
            If dgvPositionen.SelectedRows(0).Index > 0 Then
                Dim i = dgvPositionen.SelectedRows(0).Index
                dgvPositionen.ClearSelection()
                dgvPositionen.Rows(i - 1).Selected = True
                ' POS(dgvPositionen.SelectedRows(0).Cells("index").Value).txtWarenbezeichnung.Focus()
            End If
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If dgvPositionen.SelectedRows.Count > 0 Then
            removeItem(dgvPositionen.SelectedRows(0).Cells("index").Value)
        End If
    End Sub

    Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
        refreshDGV()
    End Sub


    Public Sub refreshDGV()
        With dgvPositionen
            If dgvPositionen.ColumnCount = 0 Then Exit Sub
            For Each r As DataGridViewRow In .Rows
                Dim index = r.Cells("index").Value
                'r.Cells("ID").Value = POS(index)..Text
                If POS.Count > index Then
                    r.Cells("Ware").Value = POS(index).txtWarenbezeichnung.Text
                End If
            Next
        End With
    End Sub


    Public Sub getValues(ByRef NCTS As DAKOSY_Worker.cDakosyNCTSOut004)
        '   Dim POSITIONEN As List(Of DAKOSY_Worker.cDakosy_NCTSOut_Warenposition)
        NCTS.ncts_HOUSE_CONSIGNMENT.Clear()

        Dim cnt As Integer = 1
        For Each P In POS
            Dim HC As New DAKOSY_Worker.cDakosy_NCTSOut004_HouseConsignment
            Dim POSITION As New DAKOSY_Worker.cDakosy_NCTSOut004_HouseConsignment_ConsignmentItem

            'POSITION.nctsWP_Id As Integer
            '  POSITION.nctsWP_NctsId = NCTS.ncts_Id
            POSITION.nctsHCCI_GoodsItemNumber = cnt
            POSITION.nctsHCCI_CommodityCode = cProgramFunctions.isLeerNothing(P.txtWarennummer.Text)
            ' POSITION.nctsWP_ArtAnmeldungPositionCode = cProgramFunctions.isLeerNothing(P.cboArtAnmeldung._value)
            POSITION.nctsHCCI_DescriptionOfGoods = P.txtWarenbezeichnung.Text
            POSITION.nctsHCCI_GoodsValue = cProgramFunctions.isLeerNothingDbl(P.txtWarenwert._value)
            ' POSITION.nctsWP_WarenwertProzent = cProgramFunctions.isLeerNothingDbl(P.txtSiBetragProzent._value)
            POSITION.nctsHCCI_CurrencyOfGoodsValue = cProgramFunctions.isLeerNothing(P.cboWaehrung._value)
            'POSITION.nctsWP_WarenwertWaehrung = P.XXXXXXXXXXXX.Text
            'POSITION.nctsWP_SchaetzKz = P.XXXXXXXXXXXX.Text
            'POSITION.nctsWP_WarenwertProzent = P.XXXXXXXXXXXX.Text 
            POSITION.nctsHCCI_GrossMass = cProgramFunctions.isLeerNothingDbl(P.txtRohmasse.Text)
            POSITION.nctsHCCI_NetMass = cProgramFunctions.isLeerNothingDbl(P.txtEigenmasse.Text)
            '
            '           POSITION.nctsWP_VorpapierTyp = cProgramFunctions.isLeerNothing(P.cboVpTyp._value)


            'POSITION.nctsWP_BesondereVermeke_Export = P.cbxEmport.Checked
            'POSITION.nctsWP_BesondereVermeke_ExportAbgaben = P.cbxEmportAbgaben.Checked
            'POSITION.nctsWP_BesondereVermeke_ExportBeschraenkung = P.cbxEmportBeschraernkung.Checked
            'POSITION.nctsWP_BesondereVermeke_ExportAusEU = P.cbxExportAusEU.Checked
            POSITION.nctsHCCI_CountryOfDispatch = cProgramFunctions.isLeerNothing(P.sbVersendungsLand._value)
            POSITION.nctsHCCI_CountryOfDestination = cProgramFunctions.isLeerNothing(P.sbBestimmungsland._value)

            'If P.cbxExportAusEU.CheckState = CheckState.Checked Then
            '    POSITION.nctsWP_BesondereVermeke_ExportAusEU = True
            'ElseIf P.cbxExportAusEU.CheckState = CheckState.Unchecked Then
            '    POSITION.nctsWP_BesondereVermeke_ExportAusEU = False
            'Else
            '    POSITION.nctsWP_BesondereVermeke_ExportAusEU = Nothing
            'End If

            'If P.cbxEmportAusLand.Checked = CheckState.Checked Then
            '    POSITION.nctsWP_BesondereVermeke_ExportAusLand = cProgramFunctions.isLeerNothing(P.sbExportAusLand._value)
            'Else
            '    POSITION.nctsWP_BesondereVermeke_ExportAusLand = Nothing
            'End If

            'POSITION.nctsWP_BesondereVermeke_Vermerk = P.cbxVermerk.Text
            'POSITION.nctsWP_BesondereVermeke_Kz10600 = P.cbxVermerk10600.Checked


            POSITION.nctsHCCI_PreviousDocument_1_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_1_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_2_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_2_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_3_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_3_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_4_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_4_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_5_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_5_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_6_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_6_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_7_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_7_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_8_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_8_ComplementOfInformation = Nothing
            POSITION.nctsHCCI_PreviousDocument_9_ReferenceNumber = Nothing
            POSITION.nctsHCCI_PreviousDocument_9_ComplementOfInformation = Nothing
            If P.dgvVorpapier.Rows.Count > 0 Then
                POSITION.nctsHCCI_PreviousDocument_1_ReferenceNumber = P.dgvVorpapier.Rows(0).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_1_ComplementOfInformation = P.dgvVorpapier.Rows(0).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 1 Then
                POSITION.nctsHCCI_PreviousDocument_2_ReferenceNumber = P.dgvVorpapier.Rows(1).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_2_ComplementOfInformation = P.dgvVorpapier.Rows(1).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 2 Then
                POSITION.nctsHCCI_PreviousDocument_3_ReferenceNumber = P.dgvVorpapier.Rows(2).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_3_ComplementOfInformation = P.dgvVorpapier.Rows(2).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 3 Then
                POSITION.nctsHCCI_PreviousDocument_4_ReferenceNumber = P.dgvVorpapier.Rows(3).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_4_ComplementOfInformation = P.dgvVorpapier.Rows(3).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 4 Then
                POSITION.nctsHCCI_PreviousDocument_5_ReferenceNumber = P.dgvVorpapier.Rows(4).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_5_ComplementOfInformation = P.dgvVorpapier.Rows(4).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 5 Then
                POSITION.nctsHCCI_PreviousDocument_6_ReferenceNumber = P.dgvVorpapier.Rows(5).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_6_ComplementOfInformation = P.dgvVorpapier.Rows(5).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 6 Then
                POSITION.nctsHCCI_PreviousDocument_7_ReferenceNumber = P.dgvVorpapier.Rows(6).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_7_ComplementOfInformation = P.dgvVorpapier.Rows(6).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 7 Then
                POSITION.nctsHCCI_PreviousDocument_8_ReferenceNumber = P.dgvVorpapier.Rows(7).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_8_ComplementOfInformation = P.dgvVorpapier.Rows(7).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 8 Then
                POSITION.nctsHCCI_PreviousDocument_9_ReferenceNumber = P.dgvVorpapier.Rows(8).Cells("VpReferenz").Value
                POSITION.nctsHCCI_PreviousDocument_9_ComplementOfInformation = P.dgvVorpapier.Rows(8).Cells("VpZusatz").Value
            End If

            POSITION.nctsHCCI_PACKAGING = New List(Of DAKOSY_Worker.cDakosy_NCTSOut004_HouseConsignment_ConsignmentItem_Packaging)
            For Each r As DataGridViewRow In P.dgvPackstuecke.Rows
                Dim Pk As New DAKOSY_Worker.cDakosy_NCTSOut004_HouseConsignment_ConsignmentItem_Packaging
                Pk.nctsHCCIPK_TypeOfPackages = r.Cells("PkCode").Value
                Pk.nctsHCCIPK_NumberOfPackages = r.Cells("Anzahl").Value
                Pk.nctsHCCIPK_GoodsItemNumber = r.Cells("Marke").Value
                POSITION.nctsHCCI_PACKAGING.Add(Pk)
            Next

            'POSITION.nctsWP_UNTERLAGEN = New List(Of DAKOSY_Worker.cDakosy_NCTSOut_WarenpositionVorgelegteUnterlagen)
            'For Each r As DataGridViewRow In P.dgvUnterlage.Rows
            '    Dim Ul As New DAKOSY_Worker.cDakosy_NCTSOut_WarenpositionVorgelegteUnterlagen
            '    Ul.nctsWpUl_Typ = r.Cells("UlCode").Value
            '    Ul.nctsWpUl_Referenz = r.Cells("UlReferenz").Value
            '    Ul.nctsWpUl_Zusatz = r.Cells("UlZusatz").Value
            '    POSITION.nctsWP_UNTERLAGEN.Add(Ul)
            'Next

            'POSITION.nctsWP_KdRefNr = P.txtKdRefNr.Text

            'POSITION.nctsWP_Versender_Name = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.kdFirma.Text)
            'POSITION.nctsWP_Versender_StrasseHausnummer = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtStrasse.Text)
            'POSITION.nctsWP_Versender_PLZ = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtPlz.Text)
            'POSITION.nctsWP_Versender_Ort = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtOrt.Text)
            'POSITION.nctsWP_Versender_Land = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.sbLand._value)
            'POSITION.nctsWP_Versender_EORI = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtEORI.Text)
            'POSITION.nctsWP_Versender_NLNR = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtEORINL.Text)

            POSITION.nctsHCCI_Consignor_Name = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.kdFirma.Text)
            POSITION.nctsHCCI_Consignor_StreetNumber = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtStrasse.Text)
            POSITION.nctsHCCI_Consignor_Postcode = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtPlz.Text)
            POSITION.nctsHCCI_Consignor_City = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtOrt.Text)
            POSITION.nctsHCCI_Consignor_Country = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.sbLand._value)
            POSITION.nctsHCCI_Consignor_IdentificationNumber = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtEORI.Text)
            POSITION.nctsHCCI_Consignor_SubsidiaryNumber = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtEORINL.Text)



            HC.nctsWP_CONSIGNMENT_ITEM.Add(POSITION)
            NCTS.ncts_HOUSE_CONSIGNMENT.Add(HC)
            cnt += 1
        Next
        '    NCTS.ncts_WARENPOS


    End Sub



    Public Sub getValues_TR(ByRef NCTS As VERAG_PROG_ALLGEMEIN.cNCTS_TR)
        '   Dim POSITIONEN As List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition)
        NCTS.ncts_WARENPOS.Clear()

        Dim cnt As Integer = 1
        For Each P In POS
            Dim POSITION As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition

            'POSITION.nctsWP_Id As Integer
            '  POSITION.nctsWP_NctsId = NCTS.ncts_Id
            POSITION.nctsWP_PositionsNummer = cnt
            POSITION.nctsWP_Warennummer = cProgramFunctions.isLeerNothing(P.txtWarennummer.Text)
            POSITION.nctsWP_ArtAnmeldungPositionCode = cProgramFunctions.isLeerNothing(P.cboArtAnmeldung._value)
            POSITION.nctsWP_Warenbezeichnung = P.txtWarenbezeichnung.Text
            POSITION.nctsWP_Warenwert = cProgramFunctions.isLeerNothingDbl(P.txtWarenwert._value)
            POSITION.nctsWP_WarenwertProzent = cProgramFunctions.isLeerNothingDbl(P.txtSiBetragProzent._value)
            POSITION.nctsWP_WarenwertWaehrung = cProgramFunctions.isLeerNothing(P.cboWaehrung._value)
            'POSITION.nctsWP_WarenwertWaehrung = P.XXXXXXXXXXXX.Text
            'POSITION.nctsWP_SchaetzKz = P.XXXXXXXXXXXX.Text
            'POSITION.nctsWP_WarenwertProzent = P.XXXXXXXXXXXX.Text 
            POSITION.nctsWP_Rohmasse = cProgramFunctions.isLeerNothingDbl(P.txtRohmasse.Text)
            POSITION.nctsWP_Eigenmasse = cProgramFunctions.isLeerNothingDbl(P.txtEigenmasse.Text)

            POSITION.nctsWP_VorpapierTyp = cProgramFunctions.isLeerNothing(P.cboVpTyp._value)


            POSITION.nctsWP_BesondereVermeke_Export = P.cbxEmport.Checked
            POSITION.nctsWP_BesondereVermeke_ExportAbgaben = P.cbxEmportAbgaben.Checked
            POSITION.nctsWP_BesondereVermeke_ExportBeschraenkung = P.cbxEmportBeschraernkung.Checked
            POSITION.nctsWP_BesondereVermeke_ExportAusEU = P.cbxExportAusEU.Checked
            POSITION.nctsWP_VersendungslandPositionCode = cProgramFunctions.isLeerNothing(P.sbVersendungsLand._value)
            POSITION.nctsWP_BestimmungslandPositionCode = cProgramFunctions.isLeerNothing(P.sbBestimmungsland._value)

            If P.cbxExportAusEU.CheckState = CheckState.Checked Then
                POSITION.nctsWP_BesondereVermeke_ExportAusEU = True
            ElseIf P.cbxExportAusEU.CheckState = CheckState.Unchecked Then
                POSITION.nctsWP_BesondereVermeke_ExportAusEU = False
            Else
                POSITION.nctsWP_BesondereVermeke_ExportAusEU = Nothing
            End If

            If P.cbxEmportAusLand.Checked = CheckState.Checked Then
                POSITION.nctsWP_BesondereVermeke_ExportAusLand = cProgramFunctions.isLeerNothing(P.sbExportAusLand._value)
            Else
                POSITION.nctsWP_BesondereVermeke_ExportAusLand = Nothing
            End If

            POSITION.nctsWP_BesondereVermeke_Vermerk = P.cbxVermerk.Text
            POSITION.nctsWP_BesondereVermeke_Kz10600 = P.cbxVermerk10600.Checked


            POSITION.nctsWP_VorpapierReferenz1 = Nothing
            POSITION.nctsWP_VorpapierZusatz1 = Nothing
            POSITION.nctsWP_VorpapierReferenz2 = Nothing
            POSITION.nctsWP_VorpapierZusatz2 = Nothing
            POSITION.nctsWP_VorpapierReferenz3 = Nothing
            POSITION.nctsWP_VorpapierZusatz3 = Nothing
            POSITION.nctsWP_VorpapierReferenz4 = Nothing
            POSITION.nctsWP_VorpapierZusatz4 = Nothing
            POSITION.nctsWP_VorpapierReferenz5 = Nothing
            POSITION.nctsWP_VorpapierZusatz5 = Nothing
            POSITION.nctsWP_VorpapierReferenz6 = Nothing
            POSITION.nctsWP_VorpapierZusatz6 = Nothing
            POSITION.nctsWP_VorpapierReferenz7 = Nothing
            POSITION.nctsWP_VorpapierZusatz7 = Nothing
            POSITION.nctsWP_VorpapierReferenz8 = Nothing
            POSITION.nctsWP_VorpapierZusatz8 = Nothing
            POSITION.nctsWP_VorpapierReferenz9 = Nothing
            POSITION.nctsWP_VorpapierZusatz9 = Nothing
            If P.dgvVorpapier.Rows.Count > 0 Then
                POSITION.nctsWP_VorpapierReferenz1 = P.dgvVorpapier.Rows(0).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz1 = P.dgvVorpapier.Rows(0).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 1 Then
                POSITION.nctsWP_VorpapierReferenz2 = P.dgvVorpapier.Rows(1).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz2 = P.dgvVorpapier.Rows(1).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 2 Then
                POSITION.nctsWP_VorpapierReferenz3 = P.dgvVorpapier.Rows(2).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz3 = P.dgvVorpapier.Rows(2).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 3 Then
                POSITION.nctsWP_VorpapierReferenz4 = P.dgvVorpapier.Rows(3).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz4 = P.dgvVorpapier.Rows(3).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 4 Then
                POSITION.nctsWP_VorpapierReferenz5 = P.dgvVorpapier.Rows(4).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz5 = P.dgvVorpapier.Rows(4).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 5 Then
                POSITION.nctsWP_VorpapierReferenz6 = P.dgvVorpapier.Rows(5).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz6 = P.dgvVorpapier.Rows(5).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 6 Then
                POSITION.nctsWP_VorpapierReferenz7 = P.dgvVorpapier.Rows(6).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz7 = P.dgvVorpapier.Rows(6).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 7 Then
                POSITION.nctsWP_VorpapierReferenz8 = P.dgvVorpapier.Rows(7).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz8 = P.dgvVorpapier.Rows(7).Cells("VpZusatz").Value
            End If
            If P.dgvVorpapier.Rows.Count > 8 Then
                POSITION.nctsWP_VorpapierReferenz9 = P.dgvVorpapier.Rows(8).Cells("VpReferenz").Value
                POSITION.nctsWP_VorpapierZusatz9 = P.dgvVorpapier.Rows(8).Cells("VpZusatz").Value
            End If

            POSITION.nctsWP_PACKSTUECKE = New List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_WarenpositionPackstuecke)
            For Each r As DataGridViewRow In P.dgvPackstuecke.Rows
                Dim Pk As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_WarenpositionPackstuecke
                Pk.nctsWpPk_Verpackungsart = r.Cells("PkCode").Value
                Pk.nctsWpPk_PackstueckeAnzahl = r.Cells("Anzahl").Value
                Pk.nctsWpPk_ZeichenNummern = r.Cells("Marke").Value
                POSITION.nctsWP_PACKSTUECKE.Add(Pk)
            Next

            POSITION.nctsWP_UNTERLAGEN = New List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_WarenpositionVorgelegteUnterlagen)
            For Each r As DataGridViewRow In P.dgvUnterlage.Rows
                Dim Ul As New VERAG_PROG_ALLGEMEIN.cNCTS_TR_WarenpositionVorgelegteUnterlagen
                Ul.nctsWpUl_Typ = r.Cells("UlCode").Value
                Ul.nctsWpUl_Referenz = r.Cells("UlReferenz").Value
                Ul.nctsWpUl_Zusatz = r.Cells("UlZusatz").Value
                POSITION.nctsWP_UNTERLAGEN.Add(Ul)
            Next

            POSITION.nctsWP_KdRefNr = P.txtKdRefNr.Text

            POSITION.nctsWP_Versender_Name = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.kdFirma.Text)
            POSITION.nctsWP_Versender_StrasseHausnummer = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtStrasse.Text)
            POSITION.nctsWP_Versender_PLZ = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtPlz.Text)
            POSITION.nctsWP_Versender_Ort = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtOrt.Text)
            POSITION.nctsWP_Versender_Land = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.sbLand._value)
            POSITION.nctsWP_Versender_EORI = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtEORI.Text)
            POSITION.nctsWP_Versender_NLNR = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtEORINL.Text)

            POSITION.nctsWP_Empfaenger_Name = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.kdFirma.Text)
            POSITION.nctsWP_Empfaenger_StrasseHausnummer = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtStrasse.Text)
            POSITION.nctsWP_Empfaenger_PLZ = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtPlz.Text)
            POSITION.nctsWP_Empfaenger_Ort = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtOrt.Text)
            POSITION.nctsWP_Empfaenger_Land = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.sbLand._value)
            POSITION.nctsWP_Empfaenger_EORI = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtEORI.Text)
            POSITION.nctsWP_Empfaenger_NLNR = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtEORINL.Text)

            POSITION.nctsWP_SumAVersender_Name = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.kdFirma.Text)
            POSITION.nctsWP_SumAVersender_StrasseHausnummer = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.txtStrasse.Text)
            POSITION.nctsWP_SumAVersender_PLZ = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.txtPlz.Text)
            POSITION.nctsWP_SumAVersender_Ort = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.txtOrt.Text)
            POSITION.nctsWP_SumAVersender_Land = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.sbLand._value)
            POSITION.nctsWP_SumAVersender_EORI = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.txtEORI.Text)
            POSITION.nctsWP_SumAVersender_NLNR = cProgramFunctions.isLeerNothing(P.usrcntlSumAVersedner.txtEORINL.Text)

            POSITION.nctsWP_SumAEmpfaenger_Name = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.kdFirma.Text)
            POSITION.nctsWP_SumAEmpfaenger_StrasseHausnummer = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.txtStrasse.Text)
            POSITION.nctsWP_SumAEmpfaenger_PLZ = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.txtPlz.Text)
            POSITION.nctsWP_SumAEmpfaenger_Ort = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.txtOrt.Text)
            POSITION.nctsWP_SumAEmpfaenger_Land = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.sbLand._value)
            POSITION.nctsWP_SumAEmpfaenger_EORI = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.txtEORI.Text)
            POSITION.nctsWP_SumAEmpfaenger_NLNR = cProgramFunctions.isLeerNothing(P.usrcntlSumAEmpfaenger.txtEORINL.Text)


            NCTS.ncts_WARENPOS.Add(POSITION)
            cnt += 1
        Next
        '    NCTS.ncts_WARENPOS


    End Sub


    Private Sub MyPanel2_ControlAdded(sender As Object, e As ControlEventArgs) Handles MyPanel2.ControlAdded
        Try : DirectCast(e.Control, usrCntlATLAS_NCTS004_Position).txtWarenbezeichnung.Focus() : Catch : End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        duplicateItem()
    End Sub
End Class


