Files
LicenceManager/NewKeyPage/NewKeyPageVM.vb
T
Renzo Lanza 2ff390d577 LicenceManager 2.1b1 :
- Primo commit.
2019-02-20 09:46:20 +00:00

196 lines
6.3 KiB
VB.net

Imports EgtWPFLib5
Public Class NewKeyPageVM
Inherits KeyPageVM
#Region "FIELDS & PROPERTIES"
Private Shadows m_Number As Integer
Public Overloads Property Number As String
Get
Return m_Number.ToString()
End Get
Set(value As String)
If Not String.IsNullOrWhiteSpace(value) AndAlso Not Integer.TryParse(value, m_Number) Then m_Number = 0
End Set
End Property
Private m_LockID As String
Public Shadows Property LockID As String
Get
Return m_LockID
End Get
Set(value As String)
' Se chiave software
If (GetSelIsDongle() = 0) And Not String.IsNullOrWhiteSpace(value) Then
' Verifico se valore inserito già esistente
Dim Query As String = "SELECT COUNT(" & DB_LOCKID & ") AS " & DB_MAXNUMBER & " FROM " & DB_KEY & " WHERE " & DB_LOCKID & " = '" & value & "'"
Dim MaxLockID As Integer = ExecuteNumberQuery(Query)
If ExecuteNumberQuery(Query) = 0 Then
m_LockID = value
Else
MessageBox.Show("Il numero di chiave inserito esiste già!!")
m_LockID = ""
MyBase.NotifyPropertyChanged("LockID")
End If
End If
NotifyPropertyChanged("LockID")
End Set
End Property
' Definizione comandi
Private m_cmdAddKey As Command
Private m_cmdCancel As Command
#Region "Messages"
Public ReadOnly Property NewKeyMsg As String
Get
Return "New key"
End Get
End Property
Public ReadOnly Property AddMsg As String
Get
Return "Add"
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return "Cancel"
End Get
End Property
#End Region ' Messages
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Imposto riferimento nella mappa
Map.SetRefNewKeyPageVM(Me)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub InitNewKeyPage()
' Svuoto campi
Number = Nothing
NotifyPropertyChanged("Number")
m_LockID = String.Empty
NotifyPropertyChanged("LockID")
' Carico valore di default IsDongle
SelIsDongle = 0
' Carico lista Client
Dim Query As String = "SELECT * FROM " & DB_CLIENT
SetClientList(ManageDb.ExecuteClientQuery(Query))
NotifyPropertyChanged("ClientList")
' Carico valore di default State (InDeposito)
SelState = 1
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "AddKey"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property AddKey_Command As ICommand
Get
If m_cmdAddKey Is Nothing Then
m_cmdAddKey = New Command(AddressOf AddKey)
End If
Return m_cmdAddKey
End Get
End Property
Public Sub AddKey(ByVal param As Object)
Dim Query As String = String.Empty
' Se chiave hardware
If (GetSelIsDongle() = 1) Then
' Costruisco lockId
Dim sCompleteNumber As String = m_Number.ToString("D6")
Dim sCompleteChar As String = sCompleteNumber
sCompleteChar = sCompleteChar.Replace("0"c, "o"c)
sCompleteChar = sCompleteChar.Replace("1"c, "a"c)
sCompleteChar = sCompleteChar.Replace("2"c, "b"c)
sCompleteChar = sCompleteChar.Replace("3"c, "c"c)
sCompleteChar = sCompleteChar.Replace("4"c, "d"c)
sCompleteChar = sCompleteChar.Replace("5"c, "e"c)
sCompleteChar = sCompleteChar.Replace("6"c, "f"c)
sCompleteChar = sCompleteChar.Replace("7"c, "g"c)
sCompleteChar = sCompleteChar.Replace("8"c, "h"c)
sCompleteChar = sCompleteChar.Replace("9"c, "i"c)
Dim CompleteChar() As Char = sCompleteChar.ToCharArray()
For I = 0 To sCompleteChar.Count - 1
If I Mod 2 = 1 Then
CompleteChar(I) = Char.ToUpper(CompleteChar(I))
Else
CompleteChar(I) = Char.ToLower(CompleteChar(I))
End If
Next
m_LockID = "EGTECH-" & sCompleteNumber & "-" & CompleteChar
' Se chiave software
Else
' Recupero ultimo Number di chiave software usato
Query = "SELECT MAX(" & DB_NUMBER & ") AS " & DB_MAXNUMBER & " FROM " & DB_KEY & " WHERE " & DB_ISDONGLE & " = 0"
m_Number = ExecuteNumberQuery(Query)
' Setto number
m_Number += 1
End If
'Verifico che valore LockID si a valido
If Not String.IsNullOrWhiteSpace(m_LockID) And
Not IsNothing(SelClient) Then
' Aggiungo un rivenditore al Db
Dim dongleValue As Integer = 0
If (GetSelIsDongle() = 0) Then dongleValue = 0
If (GetSelIsDongle() = 1) Then dongleValue = 1
Query = "INSERT INTO " & DB_KEY & " (" & DB_NUMBER & ", " & DB_CLIENTID & ", " & DB_ISDONGLE & ", " & DB_LOCKID & ", " & DB_STATE & ")" &
" VALUES ('" & Number & "', " &
" '" & SelClient.ClientID & "', " &
" '" & dongleValue & "', " &
" '" & m_LockID & "', " &
" '" & SelState.ToString() & "')"
ManageDb.ExecuteQuery(Query)
Else
MessageBox.Show("Completare i campi presenti")
End If
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.MAINMENU
End Sub
#End Region ' AddKey
#Region "Cancel"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property Cancel_Command As ICommand
Get
If m_cmdCancel Is Nothing Then
m_cmdCancel = New Command(AddressOf Cancel)
End If
Return m_cmdCancel
End Get
End Property
Public Sub Cancel(ByVal param As Object)
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.MAINMENU
End Sub
#End Region ' Cancel
#End Region ' COMMANDS
End Class