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

358 lines
10 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtWPFLib5
Public Class UpdateLicencePageVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_Licence As Licence
Public Property Licence As Licence
Get
Return m_Licence
End Get
Set(value As Licence)
m_Licence = value
End Set
End Property
Private m_ProductName As String
Public Property ProductName As String
Get
Return m_ProductName
End Get
Set(value As String)
m_ProductName = value
NotifyPropertyChanged("ProductName")
End Set
End Property
Private m_VersionList As List(Of Version)
Public ReadOnly Property VersionList As List(Of Version)
Get
Return m_VersionList
End Get
End Property
Private m_SelVersion As Version
Public Property SelVersion As Version
Get
Return m_SelVersion
End Get
Set(value As Version)
m_SelVersion = value
NotifyPropertyChanged("SelVersion")
End Set
End Property
Private m_ProductLevelList As List(Of String)
Public ReadOnly Property ProductLevelList As List(Of String)
Get
Return m_ProductLevelList
End Get
End Property
Private m_SelProductLevel As String
Public Property SelProductLevel As String
Get
Return m_SelProductLevel
End Get
Set(value As String)
m_SelProductLevel = value
NotifyPropertyChanged("SelProductLevel")
End Set
End Property
Private m_ProductDeadline As Nullable(Of Date)
Public Property ProductDeadline As Nullable(Of Date)
Get
Return m_ProductDeadline
End Get
Set(value As Nullable(Of Date))
m_ProductDeadline = value
End Set
End Property
Private m_OptionDeadline As Nullable(Of Date)
Public Property OptionDeadline As Nullable(Of Date)
Get
Return m_OptionDeadline
End Get
Set(value As Nullable(Of Date))
m_OptionDeadline = value
End Set
End Property
Private m_ClientName As String
Public Property ClientName As String
Get
Return m_ClientName
End Get
Set(value As String)
m_ClientName = value
NotifyPropertyChanged("ClientName")
End Set
End Property
Private m_Option1 As New ObservableCollection(Of KeyOption)
Public ReadOnly Property Option1 As ObservableCollection(Of KeyOption)
Get
Return m_Option1
End Get
End Property
Private m_Option2 As New ObservableCollection(Of KeyOption)
Public ReadOnly Property Option2 As ObservableCollection(Of KeyOption)
Get
Return m_Option2
End Get
End Property
' Definizione comandi
Private m_cmdUpdate As Command
Private m_cmdCancel As Command
#End Region
#Region "Messages"
Public ReadOnly Property UpdateLicenceMsg As String
Get
Return "Update licence"
End Get
End Property
Public ReadOnly Property ProductVersionMsg As String
Get
Return "Product version"
End Get
End Property
Public ReadOnly Property ProductLevelMsg As String
Get
Return "Product level"
End Get
End Property
Public ReadOnly Property ProductDeadlineMsg As String
Get
Return "Product deadline"
End Get
End Property
Public ReadOnly Property Option1Msg As String
Get
Return "Option 1"
End Get
End Property
Public ReadOnly Property Option2Msg As String
Get
Return "Option 2"
End Get
End Property
Public ReadOnly Property OptionDeadlineMsg As String
Get
Return "Option deadline"
End Get
End Property
Public ReadOnly Property ClientNameMsg As String
Get
Return "Client name"
End Get
End Property
Public ReadOnly Property UpdateMsg As String
Get
Return "Update"
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return "Cancel"
End Get
End Property
#End Region ' Messages
#Region "CONSTRUCTOR"
Sub New()
' Imposto riferimento nella mappa
Map.SetRefUpdateLicencePageVM(Me)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub InitUpdateLicencePage()
' Svuoto campi
SelVersion = Nothing
NotifyPropertyChanged("SelVersion")
SelProductLevel = String.Empty
NotifyPropertyChanged("SelProductLevel")
ClientName = String.Empty
NotifyPropertyChanged("File")
' Carico lista ProductVersion
Dim Query As String = "SELECT * FROM " & DB_VERSION
m_VersionList = ManageDb.ExecuteVersionQuery(Query)
NotifyPropertyChanged("VersionList")
' Carico lista ProductLevel
Query = "SELECT " & DB_PRODUCTLEVEL & " FROM " & DB_LICENCE
m_ProductLevelList = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTLEVEL)
NotifyPropertyChanged("ProductLevelList")
' Inizializzo liste opzioni
LoadOptions(1, m_Option1)
LoadOptions(2, m_Option2)
End Sub
Private Sub LoadOptions(nIndex As Integer, OptionList As ObservableCollection(Of KeyOption))
'Cerco ProductName associat a ProductID
Dim Query As String = "SELECT " & DB_PRODUCTNAME & " FROM " & DB_PRODUCT & " WHERE " & DB_PRODUCTID & " = " & Licence.ProductID
m_ProductName = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTNAME)(0)
' Cancello opzioni
OptionList.Clear()
' Carico opzioni
Dim OptionIndex As Integer = 1
Dim OptionName As String = String.Empty
GetMainPrivateProfileString(m_ProductName & " - Option" & nIndex, "Option" & OptionIndex, "", OptionName)
While Not String.IsNullOrWhiteSpace(OptionName)
OptionList.Add(New KeyOption(False, True, OptionName))
OptionIndex += 1
GetMainPrivateProfileString(m_ProductName & " - Option" & nIndex, "Option" & OptionIndex, "", OptionName)
End While
' Se ho caricato delle opzioni
If OptionList.Count > 0 Then
' Verifico se ci sono opzioni del prodotto
Dim ProductOption As Integer = If(nIndex = 1, Licence.Option1, Licence.Option2)
Dim nBinaryIndex As Integer = 1
For I = 0 To 15
If (ProductOption And nBinaryIndex) <> 0 Then
OptionList(I).IsChecked = True
OptionList(I).IsEnabled = True
End If
nBinaryIndex *= 2
Next
End If
End Sub
Private Function CalcOptionDec(OptionList As ObservableCollection(Of KeyOption)) As Integer
Dim nDecOption As Integer = 0
Dim nBinaryIndex As Integer = 1
For I As Integer = 0 To OptionList.Count() - 1
If OptionList(I).IsChecked Then
nDecOption += nBinaryIndex
End If
nBinaryIndex *= 2
Next
Return nDecOption
End Function
#End Region ' METHODS
#Region "Update"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property Update_Command As ICommand
Get
If m_cmdUpdate Is Nothing Then
m_cmdUpdate = New Command(AddressOf Update)
End If
Return m_cmdUpdate
End Get
End Property
Public Sub Update(ByVal param As Object)
' Calcolo valore decimale opzione1
Dim nDecOption1 As Integer = CalcOptionDec(m_Option1)
Dim nDecOption2 As Integer = CalcOptionDec(m_Option2)
' Cerco nella tabella Licence
Dim Query As String = "UPDATE " & DB_LICENCE
Dim bFirstWhere As Boolean = True
If Not IsNothing(m_SelVersion) OrElse
Not String.IsNullOrWhiteSpace(m_SelProductLevel) OrElse
Not IsNothing(ProductDeadline) OrElse
Not nDecOption1 = 0 OrElse
Not nDecOption2 = 0 OrElse
Not IsNothing(OptionDeadline) OrElse
Not String.IsNullOrWhiteSpace(ClientName) Then ' (File)
Query &= " SET "
If Not IsNothing(m_SelVersion) Then
EvalWhere(bFirstWhere, Query)
Query &= DB_PRODUCTVERSION & " = '" & m_SelVersion.VersionID & "' "
End If
If Not String.IsNullOrWhiteSpace(m_SelProductLevel) Then
EvalWhere(bFirstWhere, Query)
Query &= DB_PRODUCTLEVEL & " = '" & m_SelProductLevel & "' "
End If
If Not IsNothing(ProductDeadline) Then
EvalWhere(bFirstWhere, Query)
Query &= DB_PRODUCTDEADLINE & " = '" & ProductDeadline & "' "
End If
If Not nDecOption1 = 0 Then
EvalWhere(bFirstWhere, Query)
Query &= DB_OPTION1 & " = '" & nDecOption1 & "' "
End If
If Not nDecOption2 = 0 Then
EvalWhere(bFirstWhere, Query)
Query &= DB_OPTION2 & " = '" & nDecOption2 & "' "
End If
If Not IsNothing(OptionDeadline) Then
EvalWhere(bFirstWhere, Query)
Query &= DB_OPTIONDEADLINE & " = '" & OptionDeadline & "' "
End If
'If Not String.IsNullOrWhiteSpace(File) Then
' EvalWhere(bFirstWhere, Query)
' Query &= DB_FILE & " = '" & File & "' "
'End If
Query &= "WHERE " & DB_LICENCEID & " = " & Licence.LicenceID
Query = Query.TrimEnd(","c, " "c)
End If
ManageDb.ExecuteQuery(Query)
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.MAINMENU
End Sub
Private Sub EvalWhere(ByRef bFirst As Boolean, ByRef Query As String)
If bFirst Then
bFirst = False
Else
Query &= ", "
End If
End Sub
#End Region ' Search
#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 Class