'Static code module
Sub Process_Globals
Private fx As JFX
Private frm As Form
Public LicenseID As Int
Public UserID As Int
Public Fullname As String
Public CustomerID As Int
Public ProductID As Int
Public ProductName As String
Private Firstname As String
Private LastName As String
Private CompanyName As String
'User Information
'Private cbxUser As ComboBox
Private lblUserName As Label
Private lblUserEmail As Label
Private lblCompanyName As Label
'License Information
Private lblLicenseID As Label
Private txtLicenseKey As TextField
Private cbxProduct As ComboBox
Private txtProductDescription As TextArea
Private lblProductVersion As Label
Private cbxStatus As ComboBox
Private txtToken As TextField
Private txtIssuedDate As TextField
Private txtActivatedDate As TextField
Private txtInactivatedDate As TextField
Private txtHTMLFilename As TextField
Private lblEmailSentDate As Label
End Sub
Public Sub Show
If frm.IsInitialized = False Then
frm.Initialize("frm", 900,845)
frm.RootPane.LoadLayout("License_Edit")
End If
frm.SetWindowSizeLimits(900,845,1200,1000)
frm.WindowLeft = (fx.PrimaryScreen.MaxX - frm.Width) / 2
frm.WindowTop = (fx.PrimaryScreen.MaxY - frm.Height) / 2
ClearForm
LoadcbxProduct
LoadcbxStatus
SetTextColor
If LicenseID <> 0 Then
frm.Title = "Edit User License"
LoadLicenseRecord
Else
frm.Title = "New User License"
Get_User_Info
End If
frm.ShowAndWait
End Sub
#Region LOAD DATA
Sub ClearForm
'User Info
lblUserEmail.Text = ""
lblCompanyName.Text = ""
'License Info
lblLicenseID.Text = "0"
cbxProduct.SelectedIndex = -1
txtLicenseKey.Text = ""
cbxStatus.SelectedIndex = 0
txtToken.Text = ""
txtIssuedDate.Text = ""
txtActivatedDate.Text = ""
txtInactivatedDate.Text = ""
txtHTMLFilename.Text = ""
lblEmailSentDate.Text = ""
End Sub
Sub LoadcbxProduct
cbxProduct.Items.Clear
Dim data As List = DBProducts.Products_GetProductNames
cbxProduct.Items.AddAll(data)
End Sub
Sub LoadcbxStatus
cbxStatus.Items.Clear
cbxStatus.Items.AddAll(Array As String("Issued","Activated","Inactivated"))
End Sub
Sub SetTextColor
Utils.Set_TextField_TextColor(txtLicenseKey)
Utils.Set_TextField_TextColor(txtToken)
Utils.Set_TextField_TextColor(txtIssuedDate)
Utils.Set_TextField_TextColor(txtActivatedDate)
Utils.Set_TextField_TextColor(txtInactivatedDate)
Utils.Set_TextField_TextColor(txtHTMLFilename)
Utils.Set_TextArea_TextColor(txtProductDescription)
End Sub
Sub LoadLicenseRecord
Dim l As LicenseView = DBLicenses.License_GetByLicenseID(LicenseID)
If Not(l.IsInitialized) Then
fx.Msgbox(frm,"Record not Found!","Warning")
Return
End If
lblUserName.Text = l.Fullname
cbxProduct.SelectedIndex = cbxProduct.Items.IndexOf(l.ProductName)
cbxStatus.SelectedIndex = cbxStatus.Items.IndexOf(l.Status)
'User Information
Firstname = l.Firstname
LastName = l.Lastname
lblUserEmail.Text = l.UserEmail
lblCompanyName.Text = l.CompanyName
CompanyName = l.CompanyName
'License Information
lblLicenseID.Text = LicenseID
txtProductDescription.Text = l.ProductDescription
lblProductVersion.Text = l.ProductVersion
txtLicenseKey.Text = l.LicenseKey
txtToken.Text = l.Token
txtIssuedDate.Text = l.IssuedDate
txtActivatedDate.Text = l.ActivatedDate
txtInactivatedDate.Text = l.InactivatedDate
txtHTMLFilename.Text = l.HTMLFilename
lblEmailSentDate.Text = l.EmailSentDate
End Sub
Sub Get_User_Info
Dim u As UserView = DBUsers.User_GetByUserID(UserID)
lblUserName.Text = u.Firstname.Trim & " " & u.Lastname
lblUserEmail.Text = u.UserEmail
lblCompanyName.Text = u.CompanyName
cbxStatus.SelectedIndex = 0
End Sub
Private Sub cbxProduct_SelectedIndexChanged(Index As Int, Value As Object)
ProductName = Value
ProductID = DBProducts.Products_GetProductIDByName(ProductName)
txtProductDescription.Text = DBProducts.Product_GetDescription(ProductID)
End Sub
'Private Sub cbxUser_SelectedIndexChanged(Index As Int, Value As Object)
'
'End Sub
'Sub LoadcbxUsers
' cbxUser.Items.Clear
' Dim data As List = DBUsers.Users_GetUserNames(CustomerID)
' data.RemoveAt(0)
' cbxUser.Items.AddAll(data)
' cbxUser.SelectedIndex = cbxUser.Items.IndexOf(Fullname)
'End Sub
#End Region
#Region BUTTONS
Private Sub btnSave_Click
Dim l As License
l.Initialize
l.LicenseID = LicenseID
l.UserID = UserID
l.ProductID = ProductID
l.LicenseKey = txtLicenseKey.Text
l.Status = cbxStatus.Value
l.IssuedDate = txtIssuedDate.Text
l.ActivatedDate = txtActivatedDate.Text
l.InactivatedDate = txtInactivatedDate.Text
l.Token = txtToken.Text
l.HTMLFilename = txtHTMLFilename.Text
l.EmailSentDate = lblEmailSentDate.Text
'save data
DBLicenses.License_Save(l)
CallSubDelayed(Licenses,"LoadLicenses")
fx.Msgbox(frm,"License saved. Now create the HTML file","Attention")
End Sub
Private Sub btnGenerateLicenseKey_Click
Dim lk As String = LicenseUtils.Generate_LicenseKey
If lk = "" Then
fx.Msgbox(frm,"License Key was unable to be generated!","Warning")
Return
End If
txtLicenseKey.Text = lk
End Sub
Private Sub btnGenerateToken_Click
Dim tk As String = LicenseUtils.Generate_EmailToken
If tk = "" Then
fx.Msgbox(frm,"Token was unable to be generated!","Warning")
Return
End If
txtToken.Text = tk
End Sub
Private Sub btnCreateHTML_Click
Dim email As String = lblUserEmail.Text
Dim description As String = txtProductDescription.Text
Dim version As String = lblProductVersion.Text
Dim licensekey As String = txtLicenseKey.Text
Dim token As String = txtToken.Text
Dim issued As String = txtIssuedDate.Text
Dim download_url As String = AppInfo.GetURL
Dim folder As String = File.DirApp & "\licenses\"
Dim filename As String = "softwarelicense_" & ProductName.ToLowerCase & "_" & Firstname.ToLowerCase & "_" & LastName.ToLowerCase & ".html"
Dim htmlfilename As String = folder & filename
Dim html As String = Get_HTML_Template
html = html.Replace("{firstname}",Firstname)
html = html.Replace("{lastname}",LastName)
html = html.Replace("{companyname}",CompanyName)
html = html.Replace("{useremail}",email)
html = html.Replace("{productname}",ProductName)
html = html.Replace("{productdescription}",description)
html = html.Replace("{productversion}",version)
html = html.Replace("{licensekey}",licensekey)
html = html.Replace("{issueddate}",issued)
html = html.Replace("{year}",DateTime.GetYear(DateTime.Now))
html = html.Replace("{download_url}",download_url)
html = html.Replace("{token}",token)
File.WriteString(folder,filename,html)
txtHTMLFilename.Text = htmlfilename
Log(htmlfilename)
DBLicenses.License_Save_HTMLFilename(htmlfilename,LicenseID)
End Sub
Private Sub btnIssuedDate_Click
txtIssuedDate.Text = Utils.GetDate
End Sub
Private Sub btnActivate_Click
txtActivatedDate.Text = Utils.GetDate
End Sub
Private Sub btnInactivated_Click
txtInactivatedDate.Text = Utils.GetDate
End Sub
Private Sub btnOpenHTML_Click
Dim fn As String = txtHTMLFilename.Text
If Not(File.Exists("",fn)) Then
fx.Msgbox(frm,"HTML file not found!","Warning")
Return
End If
fx.ShowExternalDocument(File.GetUri("",txtHTMLFilename.Text))
End Sub
Private Sub btnEmailSent_Click
lblEmailSentDate.Text = Utils.GetDate
DBLicenses.License_Save_SentEmailDate(lblEmailSentDate.Text,LicenseID)
fx.Msgbox(frm,"Email Sent Date saved.","Attention")
End Sub
Sub Get_HTML_Template As String
Dim html As String = File.ReadString(File.DirAssets,"request-apk-template.html")
Return html
End Sub
#End Region