Imports System.Windows.Forms

Public Class frmMessenger_Members

    Dim SQL As New SQL
    Dim CHAT As New cMessenger.cMessenger_Chat

    Dim loaded = False
    Public chat_id As Integer = -1

    Sub New(CHAT)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.CHAT = CHAT
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    Sub initDGV()
        With dgvChatMembers
            .Rows.Clear()

            For Each MB In CHAT.CHAT_MEMBERS
                Dim MA As New cMitarbeiter(MB.chatMb_maId)
                .Rows.Add({MB.chatMb_maId, MA.Fullname, If(MA.mit_firma = "ALL", MA.mit_FirmaHaupt, MA.mit_firma)})
            Next
            .ClearSelection()
        End With
    End Sub

    Private Sub frmMessenger_Members_Load(sender As Object, e As EventArgs) Handles Me.Load
        initDGV()
        If CHAT.chat_erstelltMaId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Or VERAG_PROG_ALLGEMEIN.cAllgemein.USRID = 4 Then
            Button1.Visible = True
            Button2.Visible = True
        End If
    End Sub

    Private Sub dgvChatMembers_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvChatMembers.CellDoubleClick, dgvChatMembers.CellContentDoubleClick
        If dgvChatMembers.SelectedRows.Count > 0 Then
            Dim mit_id = dgvChatMembers.SelectedRows(0).Cells("clmnMaId").Value
            Dim f As New frmMitarbeitersuche(mit_id)
            f.ShowDialog(Me)
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim f As New frmMessenger_NeuerChat(CHAT)
        f.ShowDialog()
        initDGV()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If dgvChatMembers.SelectedRows.Count > 1 Then
            Dim ol As New List(Of Object)
            For Each r As DataGridViewRow In dgvChatMembers.SelectedRows
                If r.Cells("clmnMaId").Value <> VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                    For Each MB In CHAT.CHAT_MEMBERS
                        If r.Cells("clmnMaId").Value = MB.chatMb_maId Then
                            ol.Add(MB)
                        End If
                    Next
                End If
            Next
            For Each o In ol
                CHAT.CHAT_MEMBERS.Remove(o)
                If CHAT.SAVE_MEMBERS() Then
                    initDGV()
                End If
            Next
        End If
    End Sub
End Class