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

    ' Public Event NEXT_POS()
    ' Public Event PREV_POS()
    Dim WARE As DAKOSY_Worker.cDakosy_AES_Warenposition = Nothing
    Event RohmasseChanged(rohmasse 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_AES_Warenposition)
        InitializeComponent()
        Me.id = id
        Me.WARE = WARE
    End Sub




    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_C0014_VorpapierArten", {"Code", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", "Code", "Code", "display", "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)



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


        setvalue(WARE)

    End Sub

    Sub setvalue(WARE As DAKOSY_Worker.cDakosy_AES_Warenposition)
        If WARE IsNot Nothing Then
         

        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()
    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()

    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
        If IsNumeric(txtWarenwert._value) Then
            Label5.Text = CDbl(txtWarenwert._value).ToString("C2")
        Else
            Label5.Text = CDbl(0).ToString("C2")
        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))
    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




