Imports DD_LIB_Standards
Public Class ClassLicense
    Private Shared lic_string As String
    Private Shared Sub Get_License(CLIENT_ID As Integer)
        Try
               Dim sql As String = String.Format("SELECT LICENSE FROM TBDD_MODULES WHERE SHORT_NAME = 'CW'")
            lic_string = Database.GetScalarValue(sql)
        Catch ex As Exception
            Try
                Dim sql As String = String.Format("SELECT LICENSE_DDCBSEARCHER FROM TBDD_CLIENT WHERE GUID = {0}", CLIENT_ID)
                lic_string = Database.GetScalarValue(sql)
            Catch ex1 As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in Get_License:")
            End Try
        End Try

    End Sub
    Public Shared Sub Refresh_Licence(CLIENT_ID As Integer)
        Try
            Dim _lizenzManager = New clsLicenseManager("#DigitalData35452!#", "")
            Get_License(CLIENT_ID)

            If lic_string = "" Then
                LICENSE_COUNT = 0
                LICENSE_DATE = "1900-01-01"
                ERROR_INIT = "NO LICENSE"
                Exit Sub
            End If

            Dim licString = _lizenzManager.DecodeLicenseKey(lic_string)
            Dim split() = licString.ToString.Split("#")

            If lic_string <> "" Then
                LICENSE_COUNT = split(0)
                LICENSE_DATE = CDate(split(1))
            End If

            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
                ERROR_INIT = "NO LICENSE"
            End If
        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
