Files
egtbeamwall/EgtBEAMWALL.Supervisor/MainWindow/MainWindowVM.vb
T
Emmanuele Sassi d611f66d43 Modifiche comunicazione tra Opt e Sup
Correzioni e migliorie
2021-08-02 15:32:39 +02:00

160 lines
5.1 KiB
VB.net

Imports System.Threading
Imports EgtBEAMWALL.Core
Public Class MainWindowVM
Inherits VMBase
Private m_ViewerOptimizerCommThread As Thread
' 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
' proprietà che seleziona la giusta pagina del TabControl
Public Property nSelTabPage As Integer
Get
Return If(IsNothing(Map.refMainMenuVM.SelPage) OrElse Map.refMainMenuVM.SelPage = -1 OrElse Map.refMainMenuVM.SelPage = Pages.SUPERVISOR, 0, 1)
End Get
Set(value As Integer)
End Set
End Property
' Definizione comandi
Private m_cmdAboutBox As ICommand
Private m_cmdCloseApplication 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
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 = Map.refSupervisorManagerVM.CurrProd.nProdId.ToString("0000") & " - EgtBEAMWALL"
NotifyPropertyChanged(NameOf(Title))
End Sub
Friend Sub ContentRendered()
'' chiamata a caso su Db per inizializzarlo
DbControllers.m_ProdController.FindByProdDbId(0)
' Verifico che l'inizializzazione di tutte le parti del programma sia andata a buon fine
' If Map.EndInit() Then
' m_bInitStatus = True
' altrimenti chiudo il programma
' Else
' m_bInitStatus = False
' End If
' Aggiorno visualizzazione unità di misura
' Map.refStatusBarVM.SetMeasureUnit(If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH))
' Se istanza oltre la prima, chiedo cosa aprire
' If Not m_MainWindowM.bFirstInstance Then
' Map.refProjectManagerVM.Open()
' ' altrimenti verifico se richiesto ultimo progetto
' ElseIf GetMainPrivateProfileInt(S_GENERAL, K_AUTOLOADLASTPROJ, 0) = 1 Then
' Dim sLastProjectPath As String = String.Empty
' GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, String.Empty, sLastProjectPath)
' If Not String.IsNullOrWhiteSpace(sLastProjectPath) AndAlso File.Exists(sLastProjectPath) Then
' Map.refProjectManagerVM.OpenProject(sLastProjectPath)
' Else
' Map.refProjectManagerVM.NewCmd()
' End If
' ' altrimenti nuovo progetto
' Else
' Map.refProjectManagerVM.NewCmd()
' End If
' apro in modalita' VIEW
' Map.refMainMenuVM.SelPage = Pages.VIEW
' 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()
' Chiudo la finestra principale del programma
Application.Current.MainWindow.Close()
End Sub
#End Region ' CloseApplication
#End Region ' COMMANDS
End Class