Public Class usrCntlATLAS_NCTS004_Sicherheit


    Public LIST As New List(Of usrCntlATLAS_NCTS004_SicherheitPos)
    '   Public NCTS As DAKOSY_Worker.cDakosyNCTSOut = Nothing
    ' Dim AKT_POS As Integer = -1
    Dim NCTS As DAKOSY_Worker.cDakosyNCTSOut004 = Nothing
    Dim NCTS_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR = Nothing

    Dim FIRMA_DY = VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA

    Sub New(NCTS As DAKOSY_Worker.cDakosyNCTSOut004, FIRMA_DY As String) 'NCTS As DAKOSY_Worker.cDakosyNCTSOut)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.NCTS = NCTS
        Me.FIRMA_DY = FIRMA_DY
        ' loadValues()
        '  ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        'If NCTS.ncts_SICHERHEITSANGABEN.Count = 0 Then
        'NCTS.ncts_SICHERHEITSANGABEN.Add(New DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee)
        'End If
        ' For Each s In NCTS.ncts_SICHERHEITSANGABEN
        'Dim u As New usrCntlATLAS_NCTS004_SicherheitPos
        '   u.loadBrg(s)
        '  LIST.Add(u)
        '  Next

    End Sub
    Sub New(NCTS_TR As VERAG_PROG_ALLGEMEIN.cNCTS_TR, FIRMA_DY As String) 'NCTS As DAKOSY_Worker.cDakosyNCTSOut)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.NCTS_TR = NCTS_TR
        Me.FIRMA_DY = FIRMA_DY
        ' loadValues()
        '  ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        'If NCTS.ncts_SICHERHEITSANGABEN.Count = 0 Then
        'NCTS.ncts_SICHERHEITSANGABEN.Add(New DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee)
        'End If
        ' For Each s In NCTS.ncts_SICHERHEITSANGABEN
        'Dim u As New usrCntlATLAS_NCTS004_SicherheitPos
        '   u.loadBrg(s)
        '  LIST.Add(u)
        '  Next

    End Sub



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

        '  NCTS.ncts_SICHERHEITSANGABEN.Add(New DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee)
        addPos()
    End Sub

    Sub addPos(Optional sa As DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee = Nothing)
        Dim u As New usrCntlATLAS_NCTS004_SicherheitPos(FIRMA_DY)
        LIST.Add(u)
        If sa IsNot Nothing Then
            u.setValues(sa)
        End If

        loadDGVListValues()

    End Sub

    Sub addPos_TR(Optional sa As VERAG_PROG_ALLGEMEIN.cNCTS_TR_Sicherheitsangaben = Nothing)
        Dim u As New usrCntlATLAS_NCTS004_SicherheitPos(FIRMA_DY)
        LIST.Add(u)
        If sa IsNot Nothing Then
            u.setValues_TR(sa)
        End If

        loadDGVListValues()

    End Sub

    Private Sub MyDatagridview1_SelectionChanged(sender As Object, e As EventArgs) Handles MyDatagridview1.SelectionChanged
        initPosAnzeige()
    End Sub

    Sub initPosAnzeige()
        ' MsgBox("anz")
        Panel1.Controls.Clear()
        If MyDatagridview1.SelectedRows.Count > 0 Then
            Panel1.Enabled = True
            '  loadBrg(NCTS.ncts_SICHERHEITSANGABEN(MyDatagridview1.SelectedRows(0).Cells("index").Value))
            Panel1.Controls.Add(LIST(MyDatagridview1.SelectedRows(0).Cells("index").Value))
        Else
            Panel1.Enabled = False
            Panel1.Controls.Add(New usrCntlATLAS_NCTS004_SicherheitPos(FIRMA_DY)) ' Pseudo-Object, damit Platz besetzt
        End If
    End Sub
    Public Sub loadDGVListValues()

        With MyDatagridview1
            If .Columns.Count <= 0 Then Exit Sub
            ' Dim selIndex = -1
            ' If .SelectedRows.Count > 0 Then selIndex()
            .Rows.Clear()
            Dim cnt = 1
            For Each SA As usrCntlATLAS_NCTS004_SicherheitPos In LIST
                Dim art = ""
                'For Each l In (New cDakosy_Sicherheitsarten).LIST
                '            If SA.cboArtSicherheit = l.Value Then art = l.Text
                'Next
                'LIST.IndexOf(SA)
                .Rows.Add(LIST.IndexOf(SA), cnt, SA.cboArtSicherheit.Text, SA.txtAbgabenbetrag.Text, SA.txtGRN.Text, SA.txtEORI_TIN.Text, SA.txtBezeichnung.Text)
                '  index += 1
                cnt += 1
                '.loadBrg()
                '   LIST.Add(SA)
            Next
        End With
    End Sub

    Public Sub refreshDGV()
        With MyDatagridview1

            For Each r As DataGridViewRow In .Rows
                Dim index = r.Cells("index").Value
                r.Cells("Art").Value = LIST(index).cboArtSicherheit.Text
                r.Cells("Abgabenbetrag").Value = LIST(index).txtAbgabenbetrag.Text
                r.Cells("GRN").Value = LIST(index).txtGRN.Text
                r.Cells("TIN_EORI").Value = LIST(index).txtEORI_TIN.Text
                r.Cells("Bezeichnung").Value = LIST(index).txtBezeichnung.Text
            Next
        End With
    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        LIST.RemoveAt(MyDatagridview1.SelectedRows(0).Cells("index").Value)
        loadDGVListValues()
    End Sub

    Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
        'alle 1 Sekunden wird die Ansicht aktualisiert
        refreshDGV()
    End Sub



    Private Sub usrCntlATLAS_NCTS_Sicherheit_Load(sender As Object, e As EventArgs) Handles Me.Load
        '   setValues(NCTS.ncts_SICHERHEITSANGABEN)
        loadDGVListValues()
    End Sub



    Public Function getValues() As List(Of DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee)
        Dim SA As New List(Of DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee)
        For Each s As usrCntlATLAS_NCTS004_SicherheitPos In LIST
            SA.Add(s.getValues)
        Next
        Return SA
    End Function


    Public Sub setValues(ByRef SA As List(Of DAKOSY_Worker.cDakosy_NCTSOut004_Guarantee))
        Panel1.Controls.Clear()
        If SA Is Nothing Then Exit Sub
        LIST.Clear()
        For Each s In SA
            addPos(s)
        Next
        If LIST.Count = 0 Then addPos() 'leere Laden
        loadDGVListValues()
        initPosAnzeige()
    End Sub



    Public Function getValues_TR() As List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_Sicherheitsangaben)
        Dim SA As New List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_Sicherheitsangaben)
        For Each s As usrCntlATLAS_NCTS004_SicherheitPos In LIST
            SA.Add(s.getValues_TR)
        Next
        Return SA
    End Function


    Public Sub setValues_TR(ByRef SA As List(Of VERAG_PROG_ALLGEMEIN.cNCTS_TR_Sicherheitsangaben))
        Panel1.Controls.Clear()
        If SA Is Nothing Then Exit Sub
        LIST.Clear()
        For Each s In SA
            addPos_TR(s)
        Next
        If LIST.Count = 0 Then addPos() 'leere Laden
        loadDGVListValues()
        initPosAnzeige()
    End Sub

End Class
