Imports System.Globalization
Imports DLLLicenseManager
Imports DigitalData.Modules.License

Public Class ClassLicence
    Public Shared LicenseDate As Date
    Public Shared LicenseManager As LicenseManagerLegacy
    Public Shared Sub Refresh_Licence()
        Try
            LicenseManager = New LicenseManagerLegacy(LOGCONFIG, "#DigitalData35452!#", "")
            Dim sql As String = "SELECT LICENSEKEY FROM TBGI_CONFIGURATION WHERE GUID = 1"

            Dim licEncoded As String = DATABASE_ECM.GetScalarValue(sql)
            Dim licString As String = LicenseManager.DecodeLicenseKey(licEncoded)
            Dim licArray() As String = licString.ToString.Split("#")

            If licEncoded <> "" Then
                LICENSE_COUNT = licArray(0)
            Else
                LICENSE_COUNT = 0
            End If

            LOGGER.Debug("License Date is {0}", licArray(1))

            LicenseDate = Date.ParseExact(licArray(1), "dd.MM.yyyy", CultureInfo.InvariantCulture)
            'License_Date = CDate(split(1))

            If LicenseDate < Now Then
                If USER_LANGUAGE = "de-DE" Then
                    MsgBox("Ihre Lizenz ist abgelaufen!" & vbNewLine & "Letztes Gültigkeitsdatum: " & licArray(1) & vbNewLine & "Bitte setzen Sie sich mit Digital Data in Verbindung", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("Your license has expired!" & vbNewLine & "Last Valid Date: " & licArray(1) & vbNewLine & "Please contact Digital Data", MsgBoxStyle.Exclamation)
                End If
                START_INCOMPLETE = True
                LICENSE_EXPIRED = True
                LICENSE_COUNT = 0
            End If

            'tslblLicenses.Text = "Anzahl Lizenzen: " & licenseanzahl
            LICENSE_DOCTYPE_COUNT = licArray(2)
            Try
                LicenseHotKey = licArray(3)
            Catch ex As Exception
                LicenseHotKey = 0
            End Try
        Catch ex As Exception
            LOGGER.Error(ex)
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Unexpected error in Licensemanager:")
            START_INCOMPLETE = True
        End Try
    End Sub

    Public Shared Function license_is_Valid()
        If LICENSE_EXPIRED Then
            If USER_LANGUAGE = "de-DE" Then
                MsgBox("Ihre Lizenz ist abgelaufen!" & vbNewLine & "Letztes Gültigkeitsdatum: " & LicenseDate & vbNewLine & "Bitte setzen Sie sich mit Digital Data in Verbindung", MsgBoxStyle.Exclamation)
            Else
                MsgBox("Your license has expired!" & vbNewLine & "Last Valid Date: " & LicenseDate & vbNewLine & "Please contact Digital Data", MsgBoxStyle.Exclamation)
            End If

            Return False
        Else : Return True

        End If
    End Function

End Class
