Public Class frmLicense_User
    Dim CLIENT_ID As Integer = -1


    Private Sub frmLicense_User_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        

        Try
            cmbClients.DataSource = DT_CLIENT_USER
            cmbClients.DisplayMember = "CLIENT_NAME"
            cmbClients.ValueMember = "CLIENT_ID"
        Catch ex As Exception
            MsgBox("Unexpected Error in Loading Clients: " & ex.Message, MsgBoxStyle.Critical)
        End Try

        If DT_CLIENT_USER.Rows.Count = 1 Then
            cmbClients.Enabled = False
        End If

        Dim ClientId = cmbClients.SelectedValue
        RefreshLicense(ClientId)
    End Sub

    Private Sub cmbClients_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbClients.SelectedIndexChanged
        If cmbClients.SelectedIndex <> -1 Then
            Try
                Dim ClientId = cmbClients.SelectedValue
                RefreshLicense(ClientId)
            Catch ex As Exception
                CLIENT_ID = 99
            End Try
        End If
    End Sub

    Private Sub RefreshLicense(clientId As Integer)
        ClassLicence.Refresh_Licence(clientId)

        lbLicenceCount.Text = LICENSE_COUNT.ToString
        lbDossierCount.Text = LICENSE_DOSSIER_COUNT.ToString

        If USER_LANGUAGE = "de-DE" Then
            lbValidUntil.Text = LICENSE_DATE.ToString("dd.MM.yyyy")
        Else
            lbValidUntil.Text = LICENSE_DATE.ToString("MM-dd-yyyy")
        End If
        DataGridViewAddOns.DataSource = DT_LICENSE_ADDONS
        DataGridViewAddOns.Columns(0).Width = 200
        DataGridViewAddOns.Columns(1).Visible = False
        DataGridViewAddOns.Columns(2).Width = 100
        GridColor()

    End Sub
    Sub GridColor()
        Try
            For i = 0 To DataGridViewAddOns.RowCount - 1
                If DataGridViewAddOns.Rows(i).Cells(2).Value.ToString = "Valid" Then
                    DataGridViewAddOns.Rows(i).DefaultCellStyle.BackColor = Color.LimeGreen
                Else
                    DataGridViewAddOns.Rows(i).DefaultCellStyle.BackColor = Color.Red
                End If
            Next
        Catch ex As Exception

        End Try


    End Sub

End Class