Imports VERAG_PROG_ALLGEMEIN Public Class usrCntlModaltrans_NCTS_Positionen Dim NCTS_TR As VERAG_PROG_ALLGEMEIN.cOregonNCTs_DeclarationData = Nothing Dim POS As New List(Of usrCntlModaltrans_NCTS_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_TR As VERAG_PROG_ALLGEMEIN.cOregonNCTs_DeclarationData) InitializeComponent() Me.NCTS_TR = NCTS_TR End Sub Public Sub setValues_TR(NCTS_POS As VERAG_PROG_ALLGEMEIN.cOregonNCTs_DeclarationData) If NCTS_POS Is Nothing Then Exit Sub POS.Clear() For Each p In NCTS_POS.goods addItem_TR(p) 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() End If Catch ex As Exception End Try End Sub Private Sub usrCntlATLAS_NCTS_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() As usrCntlModaltrans_NCTS_Position If dgvPositionen.SelectedRows.Count > 0 Then MyPanel2.Controls.Add(POS(dgvPositionen.SelectedRows(0).Cells("index").Value)) Dim u As usrCntlModaltrans_NCTS_Position = POS(dgvPositionen.SelectedRows(0).Cells("index").Value) '.CreateCopy(New usrCntlATLAS_NCTS_Position)) AddHandler u.RohmasseChanged, Sub(r, pk) gesRohmasse = 0 gesPackstuecke = 0 For Each p As usrCntlModaltrans_NCTS_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 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 cOregonNCTs_GoodsAttribute = Nothing) As usrCntlModaltrans_NCTS_Position Dim u = New usrCntlModaltrans_NCTS_Position(POS.Count, POSTMP) AddHandler u.RohmasseChanged, Sub(r, pk) gesRohmasse = 0 gesPackstuecke = 0 For Each p As usrCntlModaltrans_NCTS_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 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 cOregonNCTs_GoodsAttribute = Nothing) As usrCntlModaltrans_NCTS_Position ' Dim u = New usrCntlModaltrans_NCTS_Position(POS.Count, POSTMP) AddHandler u.RohmasseChanged, Sub(r, pk) gesRohmasse = 0 gesPackstuecke = 0 For Each p As usrCntlModaltrans_NCTS_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 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 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 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 If POS.Count > index Then r.Cells("Ware").Value = POS(index).txtWarenbezeichnung.Text End If Next End With End Sub Public Sub getValues_TR(ByRef NCTS As VERAG_PROG_ALLGEMEIN.cOregonNCTs_DeclarationData) NCTS.goods.Clear() Dim cnt As Integer = 1 For Each P In POS Dim POSITION As New VERAG_PROG_ALLGEMEIN.cOregonNCTs_GoodsAttribute 'POSITION.nctsWP_Id As Integer ' POSITION.nctsWP_NctsId = NCTS.ncts_Id POSITION.line_no = cnt POSITION.commodity = P.txtWarenbezeichnung.Text POSITION.invoice_amount = cProgramFunctions.isLeerNothingDbl(P.txtWarenwert._value) POSITION.invoice_curr = cProgramFunctions.isLeerNothing(P.cboWaehrung._value) POSITION.net_wg = cProgramFunctions.isLeerNothingDbl(P.txtRohmasse.Text) POSITION.brut_wg = cProgramFunctions.isLeerNothingDbl(P.txtEigenmasse.Text) POSITION.origin_country_id = cProgramFunctions.isLeerNothing(P.sbVersendungsLand._value) POSITION.preferential_country_id = cProgramFunctions.isLeerNothing(P.sbBestimmungsland._value) POSITION.decl_PAckattributes = New List(Of VERAG_PROG_ALLGEMEIN.cOregonNCTs_PacksAttribute) For Each r As DataGridViewRow In P.dgvPackstuecke.Rows Dim Pk As New VERAG_PROG_ALLGEMEIN.cOregonNCTs_PacksAttribute Pk.pack_type = r.Cells("PkCode").Value Pk.pack_count = r.Cells("Anzahl").Value Pk.notes = r.Cells("Marke").Value POSITION.decl_PAckattributes.Add(Pk) Next POSITION.sender_name = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.kdFirma.Text) POSITION.sender_address = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtStrasse.Text) POSITION.sender_postcode = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtPlz.Text) POSITION.sender_city_name = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtOrt.Text) POSITION.sender_country_id = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.sbLand._value) POSITION.sender_eori_code = cProgramFunctions.isLeerNothing(P.usrcntlVersedner.txtEORI.Text) POSITION.consignee_name = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.kdFirma.Text) POSITION.consignee_address = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtStrasse.Text) POSITION.consignee_postcode = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtPlz.Text) POSITION.consignee_city_name = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtOrt.Text) POSITION.consignee_country_id = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.sbLand._value) POSITION.consignee_country_id = cProgramFunctions.isLeerNothing(P.usrcntlEmpfaenger.txtEORI.Text) NCTS.goods.Add(POSITION) cnt += 1 Next End Sub Private Sub MyPanel2_ControlAdded(sender As Object, e As ControlEventArgs) Handles MyPanel2.ControlAdded Try : DirectCast(e.Control, usrCntlATLAS_NCTS_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