Imports System.Threading Imports EgtCOMMTest.MachCommandMessagePanelVM Imports EgtWPFLib5 Imports EgtUILib 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_ChannelList As List(Of String) Public ReadOnly Property ChannelList As List(Of String) Get Return m_ChannelList End Get End Property Private m_SelChannel As String Public Property SelChannel As String Get Return m_SelChannel End Get Set(value As String) m_SelChannel = value 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_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 OPState) Public Property OPStateList As List(Of OPState) Get Return _OPStateList End Get Set(ByVal value As List(Of OPState)) _OPStateList = value End Set End Property Private _SelOPState As OPState Public Property SelOPState As OPState Get Return _SelOPState End Get Set(ByVal value As OPState) MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.SETOP, value.Id)) _SelOPState = value End Set End Property Friend Sub SetOPState(value As OPState) _SelOPState = value NotifyPropertyChanged(NameOf(SelOPState)) End Sub Private m_MDI_Text As String Public Property MDI_Text As String Get Return m_MDI_Text End Get Set(value As String) m_MDI_Text = value End Set End Property ' 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 Private m_cmdMDI 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 = GetPrivateProfileInt(S_GENERAL, K_NCTYPE, 0, Map.refMainWindowVM.MainWindowM.sMachIniFile) ' carico stati della macchina Select Case SelNCType Case NCTypes.TPA _OPStateList = New List(Of OPState) From { New OPState("Start", 1), New OPState("Stop", 2), New OPState("End", 3), New OPState("SetPoint", 4), New OPState("Pending", 5), New OPState("Unspecified", 100) } Case NCTypes.NUM_FLEXIUM _OPStateList = New List(Of OPState) From { New OPState("Auto", 0), New OPState("Single", 1), New OPState("Mdi", 2), New OPState("Manual", 7), New OPState("Home", 8) } End Select 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" ''' ''' Returns a command that do Exec. ''' 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 ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' 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, "%770"})) 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_TPA)) 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 Public ReadOnly Property MDI_Command As ICommand Get If m_cmdMDI Is Nothing Then m_cmdMDI = New Command(AddressOf MDI) Return m_cmdMDI End Get End Property Public Sub MDI(ByVal param As Object) MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.MDI, m_MDI_Text)) End Sub #End Region ' COMMANDS End Class Public Class OPState Private m_Name As String Public ReadOnly Property Name As String Get Return m_Name End Get End Property Private m_Id As Integer Public ReadOnly Property Id As Integer Get Return m_Id End Get End Property Sub New(Name As String, Id As Integer) m_Name = Name m_Id = Id End Sub End Class