Public Class frmKundeTeamZuordnung

    Dim TEAMS As New VERAG_PROG_ALLGEMEIN.cQSTeams

    Public SEL_TEAM As VERAG_PROG_ALLGEMEIN.cQSTeam = Nothing
    Public SEL_MA As VERAG_PROG_ALLGEMEIN.cQSTeamMA = Nothing



    Sub New(qsId, maId)

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

        AddHandler Me.Shown, Sub()
                                 If qsId IsNot Nothing Then cboTeams.changeItem(qsId)
                                 If maId IsNot Nothing Then
                                     For Each b As Button In MyFlowLayoutPanel1.Controls
                                         If b.Tag = maId Then
                                             b.BackColor = Color.LightBlue
                                         End If
                                     Next
                                 End If
                             End Sub


        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    Private Sub frmKundeTeamZuordnung_Load(sender As Object, e As EventArgs) Handles Me.Load

        cboTeams.Items.Clear()
        cboTeams.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem("", ""))
        For Each T In TEAMS.LIST
            cboTeams.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem(T.qstm_bezeichnung, T.qstm_Id)) ', TEAMS.LIST.IndexOf(T)))
        Next

    End Sub



    Private Sub cboTeams_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTeams.SelectedIndexChanged
        initTeam()
    End Sub

    Sub initTeam()
        MyFlowLayoutPanel1.Controls.Clear()
        SEL_TEAM = Nothing
        SEL_MA = Nothing
        If IsNumeric(DirectCast(cboTeams.SelectedItem, VERAG_PROG_ALLGEMEIN.MyListItem).Value) Then
            SEL_TEAM = TEAMS.getTeamById(DirectCast(cboTeams.SelectedItem, VERAG_PROG_ALLGEMEIN.MyListItem).Value)
            Dim btn As New Button
            btn.Size = New Size(MyFlowLayoutPanel1.Width - 10, 30)
            btn.Text = "alle"
            btn.Tag = "0"

            MyFlowLayoutPanel1.Controls.Add(btn)
            AddHandler btn.Click, Sub()
                                      SEL_MA = Nothing
                                      Me.DialogResult = Windows.Forms.DialogResult.OK
                                      Me.Close()
                                  End Sub


            If SEL_TEAM Is Nothing Then Exit Sub
            For Each M In SEL_TEAM.MEMBER
                btn = New Button
                btn.Size = New Size(MyFlowLayoutPanel1.Width - 10, 30)
                btn.Text = M.qtma_name
                btn.Tag = M.qtma_MaId

                MyFlowLayoutPanel1.Controls.Add(btn)
                AddHandler btn.Click, Sub()
                                          SEL_MA = M
                                          Me.DialogResult = Windows.Forms.DialogResult.OK
                                          Me.Close()
                                      End Sub

            Next
        End If
    End Sub

    Private Sub btnZuordnungAufheben_Click(sender As Object, e As EventArgs) Handles btnZuordnungAufheben.Click
        SEL_MA = Nothing
        SEL_TEAM = Nothing
    End Sub
End Class