Imports EgtUILib Imports System.ComponentModel Imports System.IO Imports EgtWPFLib5 Public Class MainWindowVM Implements INotifyPropertyChanged ' Modello del MainWindow (classe vera e propria) Private m_MainWindowModel As New MainWindowModel Private m_VisibilityAssemblyManager As Visibility = Visibility.Visible Public Property VisibilityAssemblyManager As Visibility Get Return m_VisibilityAssemblyManager End Get Set(value As Visibility) m_VisibilityAssemblyManager = value NotifyPropertyChanged("VisibilityAssemblyManager") End Set End Property Private m_ProjectNameMsg As String Public Property ProjectNameMsg As String Get Return m_ProjectNameMsg End Get Set(value As String) m_ProjectNameMsg = "EgtDOORCreator - " & value NotifyPropertyChanged("ProjectNameMsg") End Set End Property Private m_Launcher As LauncherV Public ReadOnly Property Launcher As LauncherV Get If IsNothing(m_Launcher) Then m_Launcher = New LauncherV m_Launcher.DataContext = New LauncherVM(Me) End If Return m_Launcher End Get End Property Private m_OptionPage As OptionsVM Public ReadOnly Property OptionPage As OptionsVM Get If IsNothing(m_OptionPage) Then m_OptionPage = New OptionsVM End If Return m_OptionPage End Get End Property Enum ListPageEnum As Integer nNothingSelected nAssemblyPage nDDFPage nHardwarePage End Enum Private m_SelectedPage As ListPageEnum Public Property SelectedPage As ListPageEnum Get Return m_SelectedPage End Get Set(value As ListPageEnum) m_SelectedPage = value NotifyPropertyChanged("PageControl") End Set End Property Private m_ProjectManagerHardware As ProjectManagerHardwareV Private m_ProjectManager As ProjectManagerV Private m_AssemblyManager As AssemblyManagerV Private m_PartPage As PartPageV Private m_AssemblyPage As AssemblyPageV Private m_HardwarePage As HardwarePageV Public ReadOnly Property PageControl As ContentControl Get If m_SelectedPage = ListPageEnum.nDDFPage Then VisibilityAssemblyManager = Visibility.Visible NotifyPropertyChanged("AssemblyManagerControl") NotifyPropertyChanged("ProjectManagerControl") Return m_PartPage ElseIf m_SelectedPage = ListPageEnum.nAssemblyPage Then VisibilityAssemblyManager = Visibility.Visible NotifyPropertyChanged("AssemblyManagerControl") NotifyPropertyChanged("ProjectManagerControl") Return m_AssemblyPage ElseIf m_SelectedPage = ListPageEnum.nHardwarePage Then VisibilityAssemblyManager = Visibility.Collapsed NotifyPropertyChanged("AssemblyManagerControl") NotifyPropertyChanged("ProjectManagerControl") Return m_HardwarePage Else VisibilityAssemblyManager = Visibility.Visible NotifyPropertyChanged("AssemblyManagerControl") NotifyPropertyChanged("ProjectManagerControl") Return Nothing End If End Get End Property Public ReadOnly Property AssemblyManagerControl As ContentControl Get If VisibilityAssemblyManager = Visibility.Visible Then Return m_AssemblyManager Else Return Nothing End If End Get End Property Public ReadOnly Property ProjectManagerControl As ContentControl Get If VisibilityAssemblyManager = Visibility.Visible Then Return m_ProjectManager Else ProjectNameMsg = "HardwareManager" Return m_ProjectManagerHardware End If End Get End Property Sub New() Map.SetRefMainWindowVM(Me) m_AssemblyPage = New AssemblyPageV m_AssemblyPage.DataContext = New AssemblyPageVM m_ProjectManagerHardware = New ProjectManagerHardwareV m_ProjectManagerHardware.DataContext = New ProjectManagerHardwareVM m_ProjectManager = New ProjectManagerV m_ProjectManager.DataContext = New ProjectManagerVM m_PartPage = New PartPageV m_PartPage.DataContext = New PartPageVM m_HardwarePage = New HardwarePageV m_HardwarePage.DataContext = New HardwarePageVM m_AssemblyManager = New AssemblyManagerV m_AssemblyManager.DataContext = New AssemblyManagerVM Dim OptionsPage As OptionsVM = OptionPage End Sub ' Comandi Private m_cmdAboutBox As ICommand Private m_cmdClose As ICommand Public Sub SetLauncher() Dim nLauncher As Integer = If(OptionModule.m_bLauncherOpenOnce, LauncherOpt.Open_last_project, OptionModule.m_SelectedOptionLauncher) Select Case nLauncher Case LauncherOpt.Open_window ' apre la finestra Dim Launcher As New LauncherV Launcher.Height = 200 Launcher.Width = 250 LauncherModule.InitLauncherModule() Launcher.DataContext = New LauncherVM(Me) Launcher.Owner = Application.Current.MainWindow Launcher.ShowDialog() Case LauncherOpt.Open_last_project ' se definito ultimo progetto, lo apro If GetMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, "", m_sLastProject) > 0 Then Map.refProjectManagerVM.OpenLastProject() End If Case Else ' non fa assolutamente nulla End Select End Sub #Region "AboutBoxCommand" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property AboutBoxCommand() 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 "CloseApplicationCommand" Public ReadOnly Property CloseApplicationCommand() As ICommand Get If m_cmdClose Is Nothing Then m_cmdClose = New Command(AddressOf CloseApplication) End If Return m_cmdClose End Get End Property 'Public Sub CloseApplication(ByVal param As Object) Public Sub CloseApplication() ' verifico se selezionato esiste e modificato Select Case SelectedPage Case ListPageEnum.nHardwarePage If Not IsNothing(Map.refHardwarePageVM) And Not IsNothing(Map.refHardwarePageVM.CurrHardware) Then If Map.refHardwarePageVM.CurrHardware.SaveControl() = Hardware.SaveResult.nCancel Then Return ElseIf Map.refHardwarePageVM.CurrHardware.SaveControl() = Hardware.SaveResult.nYes Then Map.refHardwarePageVM.CurrHardware.Save() End If End If Case Else If Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified Then Dim sText As String = String.Format(EgtMsg(50109), Path.GetFileNameWithoutExtension(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)) Select Case MessageBox.Show(sText, "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) Case MessageBoxResult.Yes Map.refAssemblyManagerVM.Save(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) If Not DdfFile.DDFIsCorrect Then Return ' se il ddf non è corretto non permetto il salvataggio Case MessageBoxResult.No ' Non faccio alcunchè Case MessageBoxResult.Cancel Return End Select End If End Select '' scrivo il nome dell'ultimo file aperto 'If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso ' Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.Name) Then ' WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name) 'End If If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Then If File.Exists(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Then WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Else WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name) End If ElseIf Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso Not String.IsNullOrWhiteSpace(Map.refAssemblyManagerVM.CurrProject.Name) Then WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name) End If EgtExit() Application.Current.MainWindow.Close() 'End If End Sub #End Region ' CloseApplicationCommand Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Public Sub NotifyPropertyChanged(propName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub End Class