Imports DLLLicenseManager
Public Class ClassLicence

    Private Shared _lizenzManager As ClassLicenseManager
    Public Shared Sub Refresh_Licence(CLIENT_ID As Integer)
        Try
            _lizenzManager = New ClassLicenseManager("#DigitalData35452!#", "")
            Dim sql As String = String.Format("SELECT LICENSE_PMO FROM TBDD_CLIENT WHERE GUID = {0}", CLIENT_ID)

            Dim lic As String = ClassDatabase.Execute_Scalar(sql, False)
            If lic = "" Then
                LICENSE_COUNT = 0
                LICENSE_DATE = "1900-01-01"
                LICENSE_DOSSIER_COUNT = 0
                Exit Sub
            End If
            Dim licString = _lizenzManager.DecodeLicenseKey(lic)
            Dim split() = licString.ToString.Split("#")

            If lic <> "" Then
                LICENSE_COUNT = split(0)
            Else
                LICENSE_COUNT = 0
            End If
            LICENSE_DATE = CDate(split(1))
            If CDate(split(1)) < CDate(Now.ToShortDateString) Then
                MsgBox("Your license evaluated!" & vbNewLine & "Last valid date: " & split(1) & vbNewLine & "Please contact Digital Data.", MsgBoxStyle.Exclamation)
                LICENSE_EXPIRED = True
                LICENSE_COUNT = 0
            End If

            ''Die Anzahl der Userlizenzen
            'LICENSE_COUNT = split(1)

            Try
                LICENSE_DOSSIER_COUNT = split(2)
            Catch ex As Exception
                ClassLogger.Add(">> Could not read License for LICENSE_DOSSIER_COUNT: " & ex.Message, False)
                LICENSE_DOSSIER_COUNT = 0
            End Try
            Try
                LICENSE_SAP_Connect = CBool(split(3))
            Catch ex As Exception
                ClassLogger.Add(">> Could not read License for LICENSE_SAP_Connect: " & ex.Message, False)
                LICENSE_SAP_Connect = False
            End Try
            Try
                LICENSE_SITE_PROXY = CBool(split(4))
            Catch ex As Exception
                ClassLogger.Add(">> Could not read License for LICENSE_SITE_Proxy: " & ex.Message, False)
                LICENSE_SITE_PROXY = False
            End Try
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in licensemanager:")
        End Try
    End Sub

    Public Shared Function license_is_Valid()
        If LICENSE_EXPIRED Then
            MsgBox("Your license has expired!" & vbNewLine & "Last valid date: " & License_Date & vbNewLine & "Please contact Digital Data!", MsgBoxStyle.Exclamation)
            Return False
        Else : Return True

        End If
    End Function

End Class
