Files
LicenceManager/UpdateKeyPage/UpdateKeyPageVM.vb
T

374 lines
10 KiB
VB.net

Imports EgtWPFLib5
Public Class UpdateKeyPageVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_Key As Key
Public Property Key As Key
Get
Return m_Key
End Get
Set(value As Key)
m_Key = value
End Set
End Property
Private m_KeyNumber As Integer
Public Property KeyNumber As Integer
Get
Return m_KeyNumber
End Get
Set(value As Integer)
m_KeyNumber = value
End Set
End Property
Private m_IsDongleList As New List(Of String)({"Hardware", "Software", "---ANY---"})
Public ReadOnly Property IsDongleList As List(Of String)
Get
Return m_IsDongleList
End Get
End Property
Private m_SelIsDongle As Integer
Public Property SelIsDongle As String
Get
If (m_SelIsDongle = 1) Then
Return "Hardware"
End If
If (m_SelIsDongle = 0) Then
Return "Software"
Else
Return "---ANY---"
End If
End Get
Set(value As String)
End Set
End Property
Private m_NameList As List(Of Client)
Public ReadOnly Property NameList As List(Of Client)
Get
Return m_NameList
End Get
End Property
Private m_SelName As Client
Public Property SelName As Client
Get
Return m_SelName
End Get
Set(value As Client)
m_SelName = value
NotifyPropertyChanged("SelName")
End Set
End Property
Private m_ClientID As Integer
Public Property ClientID As Integer
Get
Return m_ClientID
End Get
Set(value As Integer)
m_ClientID = value
NotifyPropertyChanged("ClientID")
End Set
End Property
Private m_StateList As List(Of Key.KeyState)
Public ReadOnly Property StateList As List(Of Key.KeyState)
Get
Return m_StateList
End Get
End Property
Private m_SelState As Key.KeyState
Public Property SelState As Key.KeyState
Get
Return m_SelState
End Get
Set(value As Key.KeyState)
m_SelState = value
NotifyPropertyChanged("SelState")
End Set
End Property
Private m_State As Key.KeyState
Public Property State As Key.KeyState
Get
Return m_State
End Get
Set(value As Key.KeyState)
m_State = value
NotifyPropertyChanged("State")
End Set
End Property
Private m_KeyDate As Nullable(Of Date)
Public Property KeyDate As Nullable(Of Date)
Get
Return m_KeyDate
End Get
Set(value As Nullable(Of Date))
m_KeyDate = value
End Set
End Property
Private m_Note As String
Public Property Note As String
Get
Return m_Note
End Get
Set(value As String)
m_Note = value
NotifyPropertyChanged("Note")
End Set
End Property
Private m_Seriale As String
Public Property Seriale As String
Get
Return m_Seriale
End Get
Set(value As String)
m_Seriale = value
NotifyPropertyChanged("Seriale")
End Set
End Property
' Definizione comandi
Private m_cmdUpdate As Command
Private m_cmdCancel As Command
#Region "Messages"
Public ReadOnly Property UpdateKeyMsg As String
Get
Return "Update key"
End Get
End Property
Public ReadOnly Property NumberMsg As String
Get
Return "Number"
End Get
End Property
Public ReadOnly Property IsDongleMsg As String
Get
Return "Is dongle"
End Get
End Property
Public ReadOnly Property NameMsg As String
Get
Return "Name client"
End Get
End Property
Public ReadOnly Property KeyDateMsg As String
Get
Return "Key date"
End Get
End Property
Public ReadOnly Property StateMsg As String
Get
Return "State"
End Get
End Property
Public ReadOnly Property NoteMsg As String
Get
Return "Note"
End Get
End Property
Public ReadOnly Property SerialeMsg As String
Get
Return "Seriale"
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 "Close"
End Get
End Property
#End Region ' Messages
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Imposto riferimento nella mappa
Map.SetRefUpdateKeyPageVM(Me)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub InitUpdateKeyPage()
m_KeyNumber = Key.Number
NotifyPropertyChanged("KeyNumber")
m_SelIsDongle = Key.IsDongle
NotifyPropertyChanged("SelIsDongle")
' Carico lista Name
Dim Query As String = "SELECT * FROM " & DB_CLIENT
m_NameList = ManageDb.ExecuteClientQuery(Query)
NotifyPropertyChanged("NameList")
Dim nQuery As String = "SELECT * FROM " & DB_CLIENT & " WHERE " & DB_CLIENTID & " = '" & Key.ClientID & "'"
If ManageDb.ExecuteClientQuery(nQuery).Count <> 0 Then
Dim sName As String = ManageDb.ExecuteClientQuery(nQuery)(0).Name
m_SelName = m_NameList.FirstOrDefault(Function(namel) namel.Name.Equals(sName)) 'ManageDb.ExecuteClientQuery(nQuery)(0)
Else
m_SelName = Nothing
End If
NotifyPropertyChanged("SelName")
' Carico lista State
Dim sList As New List(Of Key.KeyState)
sList.Add(Key.KeyState.Consegnata)
sList.Add(Key.KeyState.InDeposito)
sList.Add(Key.KeyState.InDepositoEgt)
sList.Add(Key.KeyState.Guasta)
sList.Add(Key.KeyState.Interna)
sList.Add(Key.KeyState.InternaEgt)
sList.Add(Key.KeyState.InDepositoTrial)
m_StateList = sList
NotifyPropertyChanged("StateList")
'Dim sQuery As String = "SELECT * FROM " & DB_KEY & " WHERE " & DB_LOCKID & " = '" & Key.LockID & "'"
'm_SelState = m_StateList.ElementAt(2) ' m_StateList.FirstOrDefault(Function(statel) statel.Equals(ManageDb.ExecuteKeyQuery(sQuery)(0).State))
'Dim item As Key.KeyState = m_StateList(2)
'm_StateList.RemoveAt(2)
''If (newIndex > oldIndex) Then newIndex--;
'' the actual index could have shifted due to the removal
'm_StateList.Insert(0, item)
m_SelState = m_StateList(Key.State)
NotifyPropertyChanged("SelState")
m_KeyDate = Key.KeyDate
NotifyPropertyChanged("KeyDate")
m_Note = Key.Note
NotifyPropertyChanged("Note")
m_Seriale = Key.Seriale
NotifyPropertyChanged("Seriale")
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "Update"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property UpdateKey_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)
If Not IsNothing(Key) Then
If Not IsNothing(SelName) Then
''Cerco IDClient associato a Name
'Dim Query As String = "SELECT " & DB_CLIENTID & " FROM " & DB_CLIENT & " WHERE " & DB_NAME & " = '" & SelName.Name & "'"
'ClientID = ManageDb.ExecuteIntegerQuery(Query, DB_CLIENTID)(0)
ClientID = SelName.ClientID
' Aggiorno tabella Key col Client scelto
Dim Query As String = "UPDATE " & DB_KEY & " SET " & DB_CLIENTID & " = '" & m_ClientID & "' WHERE " & DB_LOCKID & " = '" & Key.LockID & "' "
Query = Query.TrimEnd(","c, " "c)
ManageDb.ExecuteQuery(Query)
End If
If Not IsNothing(SelState) Then
' Aggiorno tabella Key con lo State scelto
Dim Query As String = "UPDATE " & DB_KEY & " SET " & DB_STATE & " = '" & m_SelState.ToString() & "' WHERE " & DB_LOCKID & " = '" & Key.LockID & "' "
Query = Query.TrimEnd(","c, " "c)
ManageDb.ExecuteQuery(Query)
End If
If Not IsNothing(SelState) Then
' Aggiorno tabella Key con KeyDate scelto
Dim Query As String = "UPDATE " & DB_KEY & " SET " & DB_DATE & " = '" & Format(m_KeyDate, "yyyy-MM-dd") & "' WHERE " & DB_LOCKID & " = '" & Key.LockID & "' "
Query = Query.TrimEnd(","c, " "c)
ManageDb.ExecuteQuery(Query)
End If
If Not IsNothing(Note) Then
' Aggiorno tabella Key con KeyDate scelto
Dim Query As String = "UPDATE " & DB_KEY & " SET " & DB_NOTE & " = '" & m_Note & "' WHERE " & DB_LOCKID & " = '" & Key.LockID & "' "
Query = Query.TrimEnd(","c, " "c)
ManageDb.ExecuteQuery(Query)
End If
If Not IsNothing(Seriale) Then
' Aggiorno tabella Key con KeyDate scelto
Dim Query As String = "UPDATE " & DB_KEY & " SET " & DB_SERIALE & " = '" & m_Seriale & "' WHERE " & DB_LOCKID & " = '" & Key.LockID & "' "
Query = Query.TrimEnd(","c, " "c)
ManageDb.ExecuteQuery(Query)
End If
Else
MessageBox.Show("Non è stata selezionata nessuna chiave")
End If
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.SEARCHKEY
' Else
' MessageBox.Show("Completare il campo presente")
'End If
End Sub
#End Region ' Update
#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.SEARCHKEY
End Sub
#End Region ' Cancel
#End Region 'COMMANDS
End Class