Files
Emmanuele Sassi 6e4645875b - Primo commit
- Tpa funzionante
2021-09-29 11:35:42 +02:00

344 lines
10 KiB
VB.net

Imports System.Threading
Imports EgtCOMMTest.Core
Imports EgtCOMMTest.MachCommandMessagePanelVM
Imports EgtWPFLib5
Public Class MainWindowVM
Inherits VMBase
Public Enum NCTypes As Integer
NULL = 0
TPA = 1
NUM_FLEXIUM = 2
End Enum
' Riferimento al Model della MainWindow
Private m_MainWindowM As MainWindowM
Friend ReadOnly Property MainWindowM As MainWindowM
Get
Return m_MainWindowM
End Get
End Property
' Titolo
Private m_Title As String
Public ReadOnly Property Title As String
Get
Return m_Title
End Get
End Property
Public Property Num_Flexium_IsChecked As Boolean
Get
Return m_SelNCType = NCTypes.NUM_FLEXIUM
End Get
Set(value As Boolean)
If value Then m_SelNCType = NCTypes.NUM_FLEXIUM
End Set
End Property
Public Property Tpa_IsChecked As Boolean
Get
Return m_SelNCType = NCTypes.TPA
End Get
Set(value As Boolean)
If value Then m_SelNCType = NCTypes.TPA
End Set
End Property
Private m_SelNCType As NCTypes = NCTypes.NULL
Public Property SelNCType As Integer
Get
Return m_SelNCType
End Get
Set(value As Integer)
m_SelNCType = value
NotifyPropertyChanged(NameOf(Tpa_IsChecked))
NotifyPropertyChanged(NameOf(Num_Flexium_IsChecked))
End Set
End Property
Private m_CurrMachineName As String
Private m_ProgramPath As String
Public ReadOnly Property ProgramPath As String
Get
Return m_ProgramPath
End Get
End Property
Private m_ProgramIndex As Integer = 0
Public Property ProgramIndex As Integer
Get
Return m_ProgramIndex
End Get
Set(ByVal value As Integer)
m_ProgramIndex = value
End Set
End Property
Private m_VarName As String
Public Property VarName As String
Get
Return m_VarName
End Get
Set(ByVal value As String)
m_VarName = value
End Set
End Property
Private m_VarValue As String = ""
Public Property VarValue As String
Get
Return m_VarValue
End Get
Set(ByVal value As String)
m_VarValue = value
End Set
End Property
Public Sub SetVarValue(ByVal value As Object)
m_VarValue = CStr(value)
NotifyPropertyChanged(NameOf(VarValue))
End Sub
'Private m_OPState As MachineOperatingState
'Public ReadOnly Property OPState As MachineOperatingState
' Get
' Return m_OPState
' End Get
'End Property
'Public ReadOnly Property sOPState As String
' Get
' Select Case m_OPState
' Case MachineOperatingState.Start
' Return "START"
' Case MachineOperatingState.Stop
' Return "STOP"
' Case MachineOperatingState.End
' Return "RESET"
' Case MachineOperatingState.SetPoint
' Return "SETPOINT"
' Case MachineOperatingState.Pending
' Return "PENDING"
' Case Else
' Return "UNSPECIFIED"
' End Select
' End Get
'End Property
'Public Sub SetOPState(value As MachineOperatingState)
' m_OPState = value
' NotifyPropertyChanged(NameOf(OPState))
' NotifyPropertyChanged(NameOf(sOPState))
'End Sub
Private _OPStateList As List(Of MachineOperatingState)
Public Property OPStateList As List(Of MachineOperatingState)
Get
Return _OPStateList
End Get
Set(ByVal value As List(Of MachineOperatingState))
_OPStateList = value
End Set
End Property
Private _SelOPState As MachineOperatingState
Public Property SelOPState As MachineOperatingState
Get
Return _SelOPState
End Get
Set(ByVal value As MachineOperatingState)
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.SETOP, value))
_SelOPState = value
End Set
End Property
Friend Sub SetOPState(value As MachineOperatingState)
_SelOPState = value
NotifyPropertyChanged(NameOf(SelOPState))
End Sub
' Definizione comandi
Private m_cmdAboutBox As ICommand
Private m_cmdCloseApplication As ICommand
Private m_cmdSearchFilePath As ICommand
Private m_cmdAddProgram As ICommand
Private m_cmdRemoveProgram As ICommand
Private m_cmdReadVar As ICommand
Private m_cmdWriteVar As ICommand
#Region "CONSTRUCTOR"
Sub New()
' Avvio l'inizializzazione della mappa passandogli il riferimento al MainWindowVM
Map.BeginInit(Me)
' Creo Model della MainWindow
m_MainWindowM = New MainWindowM
' leggo macchina corrente
GetMainPrivateProfileString(S_MACH, K_CURRMACH, "", m_CurrMachineName)
' Impostazione path MachIni file
MainWindowM.SetMachIniFile(MainWindowM.sMachinesRoot & "\" & m_CurrMachineName & "\" & m_CurrMachineName & ".ini")
' recupero tipo di controllo
SelNCType = GetMainPrivateProfileInt(S_GENERAL, K_NCTYPE, 0)
' carico stati della macchina
_OPStateList = New List(Of MachineOperatingState) From {
MachineOperatingState.Start,
MachineOperatingState.[Stop],
MachineOperatingState.[End],
MachineOperatingState.SetPoint,
MachineOperatingState.Pending,
MachineOperatingState.Unspecified
}
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub SetTitle(sTitle As String)
m_Title = sTitle
NotifyPropertyChanged(NameOf(Title))
End Sub
Public Sub UpdateTitle()
m_Title = "EgtCOMMTest"
NotifyPropertyChanged(NameOf(Title))
End Sub
Friend Sub ContentRendered()
'' inizializzo thread di aggiornamento e comunicazione con DB
'' creo thread gestione macchina
'm_ViewerOptimizerCommThread = New Thread(Sub()
' ViewerOptimizerCommThread.ViewerOptimizerCommThreadFunction()
' End Sub)
'm_ViewerOptimizerCommThread.SetApartmentState(ApartmentState.STA)
'' avvio thread di gestione della macchina che avvia la connessione
'm_ViewerOptimizerCommThread.Start()
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "AboutBoxCommand"
' Returns a command that manage the MainWindow_Unloaded command
Public ReadOnly Property AboutBox_Command As ICommand
Get
If m_cmdAboutBox Is Nothing Then
m_cmdAboutBox = New Command(AddressOf AboutBox)
End If
Return m_cmdAboutBox
End Get
End Property
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
Public Sub AboutBox(ByVal param As Object)
'Dim AboutBoxWindow As New AboutBoxV
'AboutBoxWindow.Owner = Application.Current.MainWindow
'AboutBoxWindow.ShowDialog()
End Sub
#End Region ' AboutBoxCommand
#Region "CloseApplication"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property CloseApplication_Command As ICommand
Get
If m_cmdCloseApplication Is Nothing Then
m_cmdCloseApplication = New Command(AddressOf CloseApplication)
End If
Return m_cmdCloseApplication
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub CloseApplication()
' disconnetto comunicazione con macchina
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.DISCONNECT))
'' termino thread di comunicazione con Db ed altri programmi
'ViewerOptimizerCommThread.StopThread()
'' Verifico modifica parametri in Configurazione e chiedo il salvataggio
'If Map.refMainMenuVM.SelPage = Pages.CONFIG Then Map.refConfigurationPageVM.VerifyConfigPageModification()
' Chiudo la finestra principale del programma
Application.Current.MainWindow.Close()
End Sub
#End Region ' CloseApplication
Public ReadOnly Property SearchFilePath_Command As ICommand
Get
If m_cmdSearchFilePath Is Nothing Then m_cmdSearchFilePath = New Command(AddressOf SearchFilePath)
Return m_cmdSearchFilePath
End Get
End Property
Public Sub SearchFilePath(ByVal param As Object)
Dim OpenFileDialog As Microsoft.Win32.OpenFileDialog = New Microsoft.Win32.OpenFileDialog()
If OpenFileDialog.ShowDialog() = True Then m_ProgramPath = OpenFileDialog.FileName
NotifyPropertyChanged(NameOf(ProgramPath))
End Sub
Public ReadOnly Property AddProgram_Command As ICommand
Get
If m_cmdAddProgram Is Nothing Then m_cmdAddProgram = New Command(AddressOf AddProgram)
Return m_cmdAddProgram
End Get
End Property
Public Sub AddProgram(ByVal param As Object)
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.SENDPROG, m_ProgramPath))
End Sub
Public ReadOnly Property RemoveProgram_Command As ICommand
Get
If m_cmdRemoveProgram Is Nothing Then m_cmdRemoveProgram = New Command(AddressOf RemoveProgram)
Return m_cmdRemoveProgram
End Get
End Property
Public Sub RemoveProgram(ByVal param As Object)
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.REMOVEPROG))
End Sub
Public ReadOnly Property ReadVar_Command As ICommand
Get
If m_cmdReadVar Is Nothing Then m_cmdReadVar = New Command(AddressOf ReadVar)
Return m_cmdReadVar
End Get
End Property
Public Sub ReadVar(ByVal param As Object)
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.READ))
End Sub
Public ReadOnly Property WriteVar_Command As ICommand
Get
If m_cmdWriteVar Is Nothing Then m_cmdWriteVar = New Command(AddressOf WriteVar)
Return m_cmdWriteVar
End Get
End Property
Public Sub WriteVar(ByVal param As Object)
MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.WRITE))
End Sub
#End Region ' COMMANDS
End Class