Public Class usrCntlATLAS_NCTS_Position
    ''  Public Event ADD()
    ' Public Event REMOVE(id)

    ' Public Event NEXT_POS()
    ' Public Event PREV_POS()
    Dim WARE As DAKOSY_Worker.cDakosy_NCTSOut_Warenposition = Nothing
    Dim WARE_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition = Nothing
    Event RohmasseChanged(rohmasse As Double, packstuecke As Double)
    Dim id As Integer = -1

    Dim PK_EDIT = -1
    Dim UL_EDIT = -1
    Dim VP_EDIT = -1

    Sub New(id)
        InitializeComponent()
        Me.id = id
    End Sub


    Sub New(id As Integer, WARE As DAKOSY_Worker.cDakosy_NCTSOut_Warenposition)
        InitializeComponent()
        Me.id = id
        Me.WARE = WARE
    End Sub


    Sub New(id As Integer, WARE_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition)
        InitializeComponent()
        Me.id = id
        Me.WARE_TR = WARE_TR
    End Sub



    Function getPackstuecke() As Integer

        getPackstuecke = 0

        For Each row As DataGridViewRow In dgvPackstuecke.Rows
            getPackstuecke += If(IsNumeric(row.Cells("Anzahl").Value), row.Cells("Anzahl").Value, 0)
        Next

    End Function
    Private Sub usrCntlATLAS_NCTS_Position_Load(sender As Object, e As EventArgs) Handles Me.Load
        ' cboColliMenge.Items.Clear()
        '  cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VQ", "VQ"))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VG", "VG"))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VL", "VL"))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VR", "VR"))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VY", "VY"))
        ' cboColliMenge.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("VO", "VO"))


        '   Me.Parent.KeyDown += New KeyEventHandler(usrCntlATLAS_NCTS_Position_KeyDown)

        'sbPkTyp.initSearchBox(Me.FindForm, " [Code] ,[Description] as Verpackungsart, Code + ' ' +  Description as display FROM tbl_DY_ZollDE_C0017_PackstueckeVerpackungsarten", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "display", "FMZOLL", , 400, 200)
        ' sbUlArten.initSearchBox(Me.FindForm, " [Code] ,[Description] as Art,Code + ' ' +  Description as display FROM tbl_DY_ZollDE_C0013_UnterlagenArten", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "display", "FMZOLL", , 400, 200)
        sbPkTyp.initSearchBox(Me.FindForm, " [Code] ,[Description] as Verpackungsart FROM tbl_DY_ZollDE_C0017_PackstueckeVerpackungsarten", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", , "FMZOLL", , 400, 200)
        sbUlArten.initSearchBox(Me.FindForm, " [Code] ,[Description] as Art FROM tbl_DY_ZollDE_C0013_UnterlagenArten", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", , "FMZOLL", , 400, 200)
        sbExportAusLand.initSearchBox(Me.FindForm, " [Code] ,[Description] as Land FROM tbl_DY_ZollDE_C0008_LaenderFull", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "Code", "FMZOLL", , 400, 200)
        sbBestimmungsland.initSearchBox(Me.FindForm, " [Code] ,[Description] as Land FROM tbl_DY_ZollDE_C0008_LaenderFull", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "Code", "FMZOLL", , 400, 200)
        sbVersendungsLand.initSearchBox(Me.FindForm, " [Code] ,[Description] as Land FROM tbl_DY_ZollDE_C0008_LaenderFull", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "Code", "FMZOLL", , 400, 200)

        cboWaehrung.initSearchBox(Me.FindForm, " [Code] ,[Description] as Land FROM [tbl_DY_ZollDE_I0400_Waehrungsliste]", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "Code", "FMZOLL", , 400, 200)



        cboArtAnmeldung.Items.Clear()
        cboArtAnmeldung.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
        cboArtAnmeldung.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("T1 - Versandanmeldung T1 Waren, die im externen gemeinschaftlichen/gemeinsamen Versandverfahren befördert werden sollen.", "T1"))
        cboArtAnmeldung.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("T2 - Versandanmeldung T2 Waren, die - soweit nicht das T2F-Verfahren vorgeschrieben ist - im internen gemeinschaftlichen Versandverfahren befördert werden sollen", "T2"))
        cboArtAnmeldung.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("T2F - Versandanmeldung T2F Waren, die im Linienverkehr zwischen Teilen des Zollgebiets der Gemeinschaft, in denen die Richtlinie 77/388/EWG (6. Mehrwertsteuerrichtlinie) Anwendung findet und den Teilen des Zollgebiets der Gemeinschaft, in denen diese Richtlinie nicht gilt (siehe Titel I, Absatz 3) im internen gemeinschaftlichen Versandverfahren befördert werden sollen.", "T2F"))

        cboVpTyp.Items.Clear()
        For Each v In (New cVorpapierTypen).LIST
            cboVpTyp.Items.Add(v)
        Next
        ' cboVpTyp.changeItem("OHNE")
        cboVpTyp.changeItem("OHNE")


        If WARE IsNot Nothing Then  setvalue(WARE)
        If WARE_TR IsNot Nothing Then setvalue_TR(WARE_TR)

    End Sub

    Sub setvalue(WARE As DAKOSY_Worker.cDakosy_NCTSOut_Warenposition)
        If WARE IsNot Nothing Then
            Me.txtWarenbezeichnung.Text = If(WARE.nctsWP_Warenbezeichnung, "")
            Me.txtRohmasse.Text = If(WARE.nctsWP_Rohmasse, "")
            Me.txtEigenmasse.Text = If(WARE.nctsWP_Eigenmasse, "")
            Me.txtWarennummer.Text = If(WARE.nctsWP_Warennummer, "")
            Me.txtWarenwert._value = If(WARE.nctsWP_Warenwert, "")

            Me.txtSiBetragProzent._value = If(WARE.nctsWP_WarenwertProzent, 0.25)
            Me.cboVpTyp.changeItem(If(WARE.nctsWP_VorpapierTyp, ""))
            Me.cboWaehrung.SET_VALUE(If(WARE.nctsWP_WarenwertWaehrung, ""))

            Dim packstuecke = 0
            dgvPackstuecke.Rows.Clear()
            If WARE.nctsWP_PACKSTUECKE IsNot Nothing Then
                For Each PK In WARE.nctsWP_PACKSTUECKE

                    Dim VerpackArtTxt = sbPkTyp.GET_VALUE_OnlyReturn(PK.nctsWpPk_Verpackungsart)
                    dgvPackstuecke.Rows.Add(PK.nctsWpPk_Verpackungsart, PK.nctsWpPk_PackstueckeAnzahl, VerpackArtTxt, PK.nctsWpPk_ZeichenNummern)
                Next
            End If
            RaiseEvent RohmasseChanged(If(IsNumeric(txtRohmasse.Text), CDbl(txtRohmasse.Text), 0), getPackstuecke)

            dgvUnterlage.Rows.Clear()
            If WARE.nctsWP_UNTERLAGEN IsNot Nothing Then
                For Each Ul In WARE.nctsWP_UNTERLAGEN
                    Dim UlTxt = sbUlArten.GET_VALUE_OnlyReturn(Ul.nctsWpUl_Typ)
                    dgvUnterlage.Rows.Add(Ul.nctsWpUl_Typ, UlTxt, Ul.nctsWpUl_Referenz, Ul.nctsWpUl_Zusatz)
                Next
            End If


            dgvVorpapier.Rows.Clear()
            If WARE.nctsWP_VorpapierReferenz1 IsNot Nothing And WARE.nctsWP_VorpapierReferenz1 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz1, If(WARE.nctsWP_VorpapierZusatz1, ""))
            If WARE.nctsWP_VorpapierReferenz2 IsNot Nothing And WARE.nctsWP_VorpapierReferenz2 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz2, If(WARE.nctsWP_VorpapierZusatz2, ""))
            If WARE.nctsWP_VorpapierReferenz3 IsNot Nothing And WARE.nctsWP_VorpapierReferenz3 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz3, If(WARE.nctsWP_VorpapierZusatz3, ""))
            If WARE.nctsWP_VorpapierReferenz4 IsNot Nothing And WARE.nctsWP_VorpapierReferenz4 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz4, If(WARE.nctsWP_VorpapierZusatz4, ""))
            If WARE.nctsWP_VorpapierReferenz5 IsNot Nothing And WARE.nctsWP_VorpapierReferenz5 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz5, If(WARE.nctsWP_VorpapierZusatz5, ""))
            If WARE.nctsWP_VorpapierReferenz6 IsNot Nothing And WARE.nctsWP_VorpapierReferenz6 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz6, If(WARE.nctsWP_VorpapierZusatz6, ""))
            If WARE.nctsWP_VorpapierReferenz7 IsNot Nothing And WARE.nctsWP_VorpapierReferenz7 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz7, If(WARE.nctsWP_VorpapierZusatz7, ""))
            If WARE.nctsWP_VorpapierReferenz8 IsNot Nothing And WARE.nctsWP_VorpapierReferenz8 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz8, If(WARE.nctsWP_VorpapierZusatz8, ""))
            If WARE.nctsWP_VorpapierReferenz9 IsNot Nothing And WARE.nctsWP_VorpapierReferenz9 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz9, If(WARE.nctsWP_VorpapierZusatz9, ""))

            Me.cbxEmport.Checked = If(WARE.nctsWP_BesondereVermeke_Export, False)
            Me.cbxEmportAbgaben.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAbgaben, False)
            Me.cbxEmportBeschraernkung.Checked = If(WARE.nctsWP_BesondereVermeke_ExportBeschraenkung, False)
            '    Me.cbxExportAusEU.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAusEU, False)

            If WARE.nctsWP_BesondereVermeke_ExportAusEU IsNot Nothing Then
                Me.cbxExportAusEU.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAusEU, False)
            Else
                Me.cbxExportAusEU.CheckState = CheckState.Indeterminate
            End If

            If WARE.nctsWP_BesondereVermeke_ExportAusLand IsNot Nothing AndAlso WARE.nctsWP_BesondereVermeke_ExportAusLand <> "" Then
                Me.cbxEmportAusLand.Checked = True
                sbExportAusLand.SET_VALUE(WARE.nctsWP_BesondereVermeke_ExportAusLand)
            Else
                sbExportAusLand.SET_VALUE("")
                Me.cbxEmportAusLand.Checked = False
            End If

            txtKdRefNr.Text = If(WARE.nctsWP_KdRefNr, "")

            usrcntlVersedner.kdFirma.Text = WARE.nctsWP_Versender_Name
            usrcntlVersedner.txtStrasse.Text = WARE.nctsWP_Versender_StrasseHausnummer
            usrcntlVersedner.txtPlz.Text = WARE.nctsWP_Versender_PLZ
            usrcntlVersedner.txtOrt.Text = WARE.nctsWP_Versender_Ort
            usrcntlVersedner.txtEORI.Text = WARE.nctsWP_Versender_EORI
            usrcntlVersedner.txtEORINL.Text = WARE.nctsWP_Versender_NLNR
            usrcntlVersedner.sbLand.SET_VALUE(WARE.nctsWP_Versender_Land)

            usrcntlEmpfaenger.kdFirma.Text = WARE.nctsWP_Empfaenger_Name
            usrcntlEmpfaenger.txtStrasse.Text = WARE.nctsWP_Empfaenger_StrasseHausnummer
            usrcntlEmpfaenger.txtPlz.Text = WARE.nctsWP_Empfaenger_PLZ
            usrcntlEmpfaenger.txtOrt.Text = WARE.nctsWP_Empfaenger_Ort
            usrcntlEmpfaenger.txtEORI.Text = WARE.nctsWP_Empfaenger_EORI
            usrcntlEmpfaenger.txtEORINL.Text = WARE.nctsWP_Empfaenger_NLNR
            usrcntlEmpfaenger.sbLand.SET_VALUE(WARE.nctsWP_Empfaenger_Land)


            usrcntlSumAVersedner.kdFirma.Text = WARE.nctsWP_SumAVersender_Name
            usrcntlSumAVersedner.txtStrasse.Text = WARE.nctsWP_SumAVersender_StrasseHausnummer
            usrcntlSumAVersedner.txtPlz.Text = WARE.nctsWP_SumAVersender_PLZ
            usrcntlSumAVersedner.txtOrt.Text = WARE.nctsWP_SumAVersender_Ort
            usrcntlSumAVersedner.txtEORI.Text = WARE.nctsWP_SumAVersender_EORI
            usrcntlSumAVersedner.txtEORINL.Text = WARE.nctsWP_SumAVersender_NLNR
            usrcntlSumAVersedner.sbLand.SET_VALUE(WARE.nctsWP_SumAVersender_Land)

            usrcntlSumAEmpfaenger.kdFirma.Text = WARE.nctsWP_SumAEmpfaenger_Name
            usrcntlSumAEmpfaenger.txtStrasse.Text = WARE.nctsWP_SumAEmpfaenger_StrasseHausnummer
            usrcntlSumAEmpfaenger.txtPlz.Text = WARE.nctsWP_SumAEmpfaenger_PLZ
            usrcntlSumAEmpfaenger.txtOrt.Text = WARE.nctsWP_SumAEmpfaenger_Ort
            usrcntlSumAEmpfaenger.txtEORI.Text = WARE.nctsWP_SumAEmpfaenger_EORI
            usrcntlSumAEmpfaenger.txtEORINL.Text = WARE.nctsWP_SumAEmpfaenger_NLNR
            usrcntlSumAEmpfaenger.sbLand.SET_VALUE(WARE.nctsWP_SumAEmpfaenger_Land)


        End If
    End Sub


    Sub setvalue_TR(WARE As VERAG_PROG_ALLGEMEIN.cNCTS_TR_Warenposition)
        If WARE IsNot Nothing Then
            Me.txtWarenbezeichnung.Text = If(WARE.nctsWP_Warenbezeichnung, "")
            Me.txtRohmasse.Text = If(WARE.nctsWP_Rohmasse, "")
            Me.txtEigenmasse.Text = If(WARE.nctsWP_Eigenmasse, "")
            Me.txtWarennummer.Text = If(WARE.nctsWP_Warennummer, "")
            Me.txtWarenwert._value = If(WARE.nctsWP_Warenwert, "")

            Me.txtSiBetragProzent._value = If(WARE.nctsWP_WarenwertProzent, 0.25)
            Me.cboVpTyp.changeItem(If(WARE.nctsWP_VorpapierTyp, ""))
            Me.cboWaehrung.SET_VALUE(If(WARE.nctsWP_WarenwertWaehrung, ""))

            Dim packstuecke = 0
            dgvPackstuecke.Rows.Clear()
            If WARE.nctsWP_PACKSTUECKE IsNot Nothing Then
                For Each PK In WARE.nctsWP_PACKSTUECKE

                    Dim VerpackArtTxt = sbPkTyp.GET_VALUE_OnlyReturn(PK.nctsWpPk_Verpackungsart)
                    dgvPackstuecke.Rows.Add(PK.nctsWpPk_Verpackungsart, PK.nctsWpPk_PackstueckeAnzahl, VerpackArtTxt, PK.nctsWpPk_ZeichenNummern)
                Next
            End If
            RaiseEvent RohmasseChanged(If(IsNumeric(txtRohmasse.Text), CDbl(txtRohmasse.Text), 0), getPackstuecke)

            dgvUnterlage.Rows.Clear()
            If WARE.nctsWP_UNTERLAGEN IsNot Nothing Then
                For Each Ul In WARE.nctsWP_UNTERLAGEN
                    Dim UlTxt = sbUlArten.GET_VALUE_OnlyReturn(Ul.nctsWpUl_Typ)
                    dgvUnterlage.Rows.Add(Ul.nctsWpUl_Typ, UlTxt, Ul.nctsWpUl_Referenz, Ul.nctsWpUl_Zusatz)
                Next
            End If


            dgvVorpapier.Rows.Clear()
            If WARE.nctsWP_VorpapierReferenz1 IsNot Nothing And WARE.nctsWP_VorpapierReferenz1 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz1, If(WARE.nctsWP_VorpapierZusatz1, ""))
            If WARE.nctsWP_VorpapierReferenz2 IsNot Nothing And WARE.nctsWP_VorpapierReferenz2 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz2, If(WARE.nctsWP_VorpapierZusatz2, ""))
            If WARE.nctsWP_VorpapierReferenz3 IsNot Nothing And WARE.nctsWP_VorpapierReferenz3 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz3, If(WARE.nctsWP_VorpapierZusatz3, ""))
            If WARE.nctsWP_VorpapierReferenz4 IsNot Nothing And WARE.nctsWP_VorpapierReferenz4 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz4, If(WARE.nctsWP_VorpapierZusatz4, ""))
            If WARE.nctsWP_VorpapierReferenz5 IsNot Nothing And WARE.nctsWP_VorpapierReferenz5 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz5, If(WARE.nctsWP_VorpapierZusatz5, ""))
            If WARE.nctsWP_VorpapierReferenz6 IsNot Nothing And WARE.nctsWP_VorpapierReferenz6 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz6, If(WARE.nctsWP_VorpapierZusatz6, ""))
            If WARE.nctsWP_VorpapierReferenz7 IsNot Nothing And WARE.nctsWP_VorpapierReferenz7 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz7, If(WARE.nctsWP_VorpapierZusatz7, ""))
            If WARE.nctsWP_VorpapierReferenz8 IsNot Nothing And WARE.nctsWP_VorpapierReferenz8 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz8, If(WARE.nctsWP_VorpapierZusatz8, ""))
            If WARE.nctsWP_VorpapierReferenz9 IsNot Nothing And WARE.nctsWP_VorpapierReferenz9 <> "" Then dgvVorpapier.Rows.Add(WARE.nctsWP_VorpapierReferenz9, If(WARE.nctsWP_VorpapierZusatz9, ""))

            Me.cbxEmport.Checked = If(WARE.nctsWP_BesondereVermeke_Export, False)
            Me.cbxEmportAbgaben.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAbgaben, False)
            Me.cbxEmportBeschraernkung.Checked = If(WARE.nctsWP_BesondereVermeke_ExportBeschraenkung, False)
            '    Me.cbxExportAusEU.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAusEU, False)

            If WARE.nctsWP_BesondereVermeke_ExportAusEU IsNot Nothing Then
                Me.cbxExportAusEU.Checked = If(WARE.nctsWP_BesondereVermeke_ExportAusEU, False)
            Else
                Me.cbxExportAusEU.CheckState = CheckState.Indeterminate
            End If

            If WARE.nctsWP_BesondereVermeke_ExportAusLand IsNot Nothing AndAlso WARE.nctsWP_BesondereVermeke_ExportAusLand <> "" Then
                Me.cbxEmportAusLand.Checked = True
                sbExportAusLand.SET_VALUE(WARE.nctsWP_BesondereVermeke_ExportAusLand)
            Else
                sbExportAusLand.SET_VALUE("")
                Me.cbxEmportAusLand.Checked = False
            End If

            txtKdRefNr.Text = If(WARE.nctsWP_KdRefNr, "")

            usrcntlVersedner.kdFirma.Text = WARE.nctsWP_Versender_Name
            usrcntlVersedner.txtStrasse.Text = WARE.nctsWP_Versender_StrasseHausnummer
            usrcntlVersedner.txtPlz.Text = WARE.nctsWP_Versender_PLZ
            usrcntlVersedner.txtOrt.Text = WARE.nctsWP_Versender_Ort
            usrcntlVersedner.txtEORI.Text = WARE.nctsWP_Versender_EORI
            usrcntlVersedner.txtEORINL.Text = WARE.nctsWP_Versender_NLNR
            usrcntlVersedner.sbLand.SET_VALUE(WARE.nctsWP_Versender_Land)

            usrcntlEmpfaenger.kdFirma.Text = WARE.nctsWP_Empfaenger_Name
            usrcntlEmpfaenger.txtStrasse.Text = WARE.nctsWP_Empfaenger_StrasseHausnummer
            usrcntlEmpfaenger.txtPlz.Text = WARE.nctsWP_Empfaenger_PLZ
            usrcntlEmpfaenger.txtOrt.Text = WARE.nctsWP_Empfaenger_Ort
            usrcntlEmpfaenger.txtEORI.Text = WARE.nctsWP_Empfaenger_EORI
            usrcntlEmpfaenger.txtEORINL.Text = WARE.nctsWP_Empfaenger_NLNR
            usrcntlEmpfaenger.sbLand.SET_VALUE(WARE.nctsWP_Empfaenger_Land)


            usrcntlSumAVersedner.kdFirma.Text = WARE.nctsWP_SumAVersender_Name
            usrcntlSumAVersedner.txtStrasse.Text = WARE.nctsWP_SumAVersender_StrasseHausnummer
            usrcntlSumAVersedner.txtPlz.Text = WARE.nctsWP_SumAVersender_PLZ
            usrcntlSumAVersedner.txtOrt.Text = WARE.nctsWP_SumAVersender_Ort
            usrcntlSumAVersedner.txtEORI.Text = WARE.nctsWP_SumAVersender_EORI
            usrcntlSumAVersedner.txtEORINL.Text = WARE.nctsWP_SumAVersender_NLNR
            usrcntlSumAVersedner.sbLand.SET_VALUE(WARE.nctsWP_SumAVersender_Land)

            usrcntlSumAEmpfaenger.kdFirma.Text = WARE.nctsWP_SumAEmpfaenger_Name
            usrcntlSumAEmpfaenger.txtStrasse.Text = WARE.nctsWP_SumAEmpfaenger_StrasseHausnummer
            usrcntlSumAEmpfaenger.txtPlz.Text = WARE.nctsWP_SumAEmpfaenger_PLZ
            usrcntlSumAEmpfaenger.txtOrt.Text = WARE.nctsWP_SumAEmpfaenger_Ort
            usrcntlSumAEmpfaenger.txtEORI.Text = WARE.nctsWP_SumAEmpfaenger_EORI
            usrcntlSumAEmpfaenger.txtEORINL.Text = WARE.nctsWP_SumAEmpfaenger_NLNR
            usrcntlSumAEmpfaenger.sbLand.SET_VALUE(WARE.nctsWP_SumAEmpfaenger_Land)


        End If
    End Sub

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

    Sub addPackstuecke()
        Label23.Visible = False
        Label24.Visible = False
        If sbPkTyp._value = "" Then Label24.Visible = True : sbPkTyp.Focus() : Exit Sub
        If txtPkAnzahl.Text = "" Then Label23.Visible = True : txtPkAnzahl.Focus() : Exit Sub

        If PK_EDIT >= 0 Then
            dgvPackstuecke.Rows.RemoveAt(PK_EDIT)
            dgvPackstuecke.Rows.Insert(PK_EDIT, sbPkTyp._value, txtPkAnzahl.Text, sbPkTyp.Text, txtPkMarke.Text)
            PK_EDIT = -1
            btn.BackgroundImage = My.Resources.plus
            lklBearbeitungAbbrechenPK.Visible = False
        Else
            dgvPackstuecke.Rows.Add(sbPkTyp._value, txtPkAnzahl.Text, sbPkTyp.Text, txtPkMarke.Text)
        End If
        sbPkTyp.SET_VALUE("") : txtPkAnzahl.Text = "" : txtPkMarke.Text = "ohne"
        dgvPackstuecke.FirstDisplayedScrollingRowIndex = dgvPackstuecke.RowCount - 1
        dgvPackstuecke.ClearSelection()
        txtPkAnzahl.Focus()

        RaiseEvent RohmasseChanged(If(IsNumeric(txtRohmasse.Text), CDbl(txtRohmasse.Text), 0), getPackstuecke)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        addUnterlage()
    End Sub

    Sub addUnterlage()
        Label22.Visible = False
        If sbUlArten._value = "" Then Label22.Visible = True : sbUlArten.Focus() : Exit Sub

        If UL_EDIT >= 0 Then
            dgvUnterlage.Rows.RemoveAt(UL_EDIT)
            dgvUnterlage.Rows.Insert(UL_EDIT, sbUlArten._value, sbUlArten.Text, txtUlReferenz.Text, txtUlZusatz.Text)
            UL_EDIT = -1
            Button1.BackgroundImage = My.Resources.plus
            lklBearbeitungAbbrechenUl.Visible = False
        Else
            dgvUnterlage.Rows.Add(sbUlArten._value, sbUlArten.Text, txtUlReferenz.Text, txtUlZusatz.Text)
        End If

        txtUlZusatz.Text = "" : txtUlReferenz.Text = "" : sbUlArten.SET_VALUE("")
        dgvUnterlage.FirstDisplayedScrollingRowIndex = dgvUnterlage.RowCount - 1
        dgvUnterlage.ClearSelection()
        sbUlArten.Focus()
    End Sub


    Private Sub PackstueckeKeyDown(sender As Object, e As KeyEventArgs) Handles sbPkTyp.KeyDown, txtPkAnzahl.KeyDown, txtPkMarke.KeyDown
        If e.KeyCode = Keys.Return Then addPackstuecke() : e.Handled = True
    End Sub

    Private Sub UnterlageKeyDown(sender As Object, e As KeyEventArgs) Handles txtUlZusatz.KeyDown, txtUlReferenz.KeyDown, sbUlArten.KeyDown
        If e.KeyCode = Keys.Return Then addUnterlage() : e.Handled = True
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If dgvPackstuecke.SelectedRows.Count > 0 Then
            If MsgBox("Möchten Sie den Eintrag in 'Packstücke' wirklich löschen?", vbYesNoCancel) = vbYes Then
                dgvPackstuecke.Rows.Remove(dgvPackstuecke.SelectedRows(0))
            End If
        End If
        dgvPackstuecke.ClearSelection()

        RaiseEvent RohmasseChanged(If(IsNumeric(txtRohmasse.Text), CDbl(txtRohmasse.Text), 0), getPackstuecke)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If dgvUnterlage.SelectedRows.Count > 0 Then
            If MsgBox("Möchten Sie den Eintrag in 'Unterlagen' wirklich löschen?", vbYesNoCancel) = vbYes Then
                dgvUnterlage.Rows.Remove(dgvUnterlage.SelectedRows(0))
            End If
        End If
        dgvUnterlage.ClearSelection()
    End Sub

    Private Sub MyTextBox2_TextChanged(sender As Object, e As EventArgs) Handles txtWarenwert.TextChanged, txtSiBetragProzent.TextChanged, txtWarenwert.Leave, txtSiBetragProzent.Leave, cboWaehrung.Leave
        If IsNumeric(txtWarenwert._value) And IsNumeric(txtSiBetragProzent._value) Then
            Label5.Text = CDbl(txtSiBetragProzent._value * txtWarenwert._value).ToString("N2") & " " & cboWaehrung._value
        Else
            Label5.Text = CDbl(0).ToString("N2") & " " & cboWaehrung._value
        End If
    End Sub



    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        addVorpapier()
    End Sub
    Sub addVorpapier()
        Label38.Visible = False
        If txtVpReferenz.Text = "" Then Label38.Visible = True : txtVpReferenz.Focus() : Exit Sub

        If VP_EDIT >= 0 Then
            dgvVorpapier.Rows.RemoveAt(VP_EDIT)
            dgvVorpapier.Rows.Insert(VP_EDIT, txtVpReferenz.Text, txtVpZusatz.Text)
            VP_EDIT = -1
            Button5.BackgroundImage = My.Resources.plus
            lklBearbeitungAbbrechenVP.Visible = False
        Else
            dgvVorpapier.Rows.Add(txtVpReferenz.Text, txtVpZusatz.Text)
        End If

        txtVpReferenz.Text = "" : txtVpZusatz.Text = ""
        dgvVorpapier.FirstDisplayedScrollingRowIndex = dgvVorpapier.RowCount - 1
        dgvVorpapier.ClearSelection()
        txtVpReferenz.Focus()
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If dgvVorpapier.SelectedRows.Count > 0 Then
            If MsgBox("Möchten Sie den Eintrag in 'Vorpapiere' wirklich löschen?", vbYesNoCancel) = vbYes Then
                dgvVorpapier.Rows.Remove(dgvVorpapier.SelectedRows(0))
            End If
        End If
        dgvVorpapier.ClearSelection()
    End Sub

    Private Sub txtVpReferenz_KeyDown(sender As Object, e As KeyEventArgs) Handles txtVpReferenz.KeyDown, txtVpZusatz.KeyDown
        If e.KeyCode = Keys.Return Then addVorpapier() : e.Handled = True
    End Sub

    Private Sub txtRohmasse_TextChanged(sender As Object, e As EventArgs) Handles txtRohmasse.TextChanged
        RaiseEvent RohmasseChanged(If(IsNumeric(txtRohmasse.Text), CDbl(txtRohmasse.Text), 0), getPackstuecke)
    End Sub

    Private Sub dgvPackstuecke_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPackstuecke.CellDoubleClick
        If e.RowIndex < 0 Then Exit Sub
        editableRowPK(e.RowIndex)
    End Sub


    Sub editableRowPK(index As Integer)
        txtPkAnzahl.Text = dgvPackstuecke.Rows(index).Cells("Anzahl").Value
        sbPkTyp.SET_VALUE(dgvPackstuecke.Rows(index).Cells("PkCode").Value)
        txtPkMarke.Text = dgvPackstuecke.Rows(index).Cells("Marke").Value
        PK_EDIT = index
        btn.BackgroundImage = My.Resources.stift
        lklBearbeitungAbbrechenPK.Visible = True
    End Sub

    Private Sub lklBearbeitungAbbrechenPK_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lklBearbeitungAbbrechenPK.LinkClicked
        PK_EDIT = -1
        txtPkAnzahl.Text = ""
        sbPkTyp.SET_VALUE("")
        txtPkMarke.Text = ""
        btn.BackgroundImage = My.Resources.plus
        lklBearbeitungAbbrechenPK.Visible = False
    End Sub



    Private Sub dgvUnterlage_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUnterlage.CellDoubleClick
        If e.RowIndex < 0 Then Exit Sub
        editableRowUL(e.RowIndex)
    End Sub


    Sub editableRowUL(index As Integer)
        txtUlReferenz.Text = dgvUnterlage.Rows(index).Cells("UlReferenz").Value
        sbUlArten.SET_VALUE(dgvUnterlage.Rows(index).Cells("UlCode").Value)
        txtUlZusatz.Text = dgvUnterlage.Rows(index).Cells("UlZusatz").Value
        UL_EDIT = index
        Button1.BackgroundImage = My.Resources.stift
        lklBearbeitungAbbrechenUl.Visible = True
    End Sub

    Private Sub lklBearbeitungAbbrechenUl_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lklBearbeitungAbbrechenUl.LinkClicked
        UL_EDIT = -1
        txtUlReferenz.Text = ""
        sbUlArten.SET_VALUE("")
        txtUlZusatz.Text = ""
        Button1.BackgroundImage = My.Resources.plus
        lklBearbeitungAbbrechenUl.Visible = False
    End Sub


    Private Sub dgvVorpapier_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvVorpapier.CellDoubleClick
        If e.RowIndex < 0 Then Exit Sub
        editableRowVP(e.RowIndex)
    End Sub


    Sub editableRowVP(index As Integer)
        txtVpReferenz.Text = dgvVorpapier.Rows(index).Cells("VpReferenz").Value
        txtVpZusatz.Text = dgvVorpapier.Rows(index).Cells("VpZusatz").Value

        VP_EDIT = index
        Button5.BackgroundImage = My.Resources.stift
        lklBearbeitungAbbrechenVP.Visible = True
    End Sub

    Private Sub lklBearbeitungAbbrechenVP_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lklBearbeitungAbbrechenVP.LinkClicked
        VP_EDIT = -1
        txtVpReferenz.Text = ""
        txtVpZusatz.Text = ""
        Button5.BackgroundImage = My.Resources.plus
        lklBearbeitungAbbrechenVP.Visible = False
    End Sub

    Private Sub dgvPackstuecke_CellContentClick(sender As Object, e As EventArgs) Handles dgvPackstuecke.LostFocus
        dgvPackstuecke.ClearSelection()
    End Sub

    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles cbxEmportAusLand.CheckedChanged
        sbExportAusLand.Enabled = cbxEmportAusLand.Checked
    End Sub

    Private Sub txtEigenmasse_TextChanged() Handles txtEigenmasse.ValueChanged, txtRohmasse.ValueChanged
        Label7.Visible = False
        If IsNumeric(txtRohmasse._value) And IsNumeric(txtEigenmasse._value) Then
            If CDbl(txtRohmasse._value) < CDbl(txtEigenmasse._value) Then
                Label7.Visible = True
            End If
        End If
    End Sub


End Class




