Imports System.Collections.ObjectModel Imports System.IO Imports EgtWPFLib5 ' la finestra associata a queta classe serve per gestire la creazione di una copia (ivocata dal bottone Duplica) Public Class NewHardwareVM Inherits VMBase Friend Enum CommandList As Integer nDuplicate nNew End Enum Private m_Command As Integer Public ReadOnly Property Command As Integer Get Return m_Command End Get End Property Public ReadOnly Property Title As String Get Return "New Hardware" End Get End Property Public ReadOnly Property BrandMsg As String Get Return "Brand" End Get End Property Public ReadOnly Property TemplateMsg As String Get Return "Template" End Get End Property Public ReadOnly Property TypeMsg As String Get Return "Type" End Get End Property ' Comandi Private m_cmdSave As ICommand Private m_cmdCancel As ICommand Private m_CmdCloseNewHardware As ICommand Private m_HardwareGeneral As CompoType Private m_ForceToQuit As Boolean = False Public Property ForceToQuit As Boolean Get Return m_ForceToQuit End Get Set(value As Boolean) m_ForceToQuit = value End Set End Property Private m_BrandList As New ObservableCollection(Of String) Public ReadOnly Property BrandList As ObservableCollection(Of String) Get Return m_BrandList End Get End Property Private m_SelBrand As String Public Property SelBrand As String Get Return m_SelBrand End Get Set(value As String) m_SelBrand = value NotifyPropertyChanged("SelBrand") End Set End Property Private m_Template As String Public Property Template As String Get Return m_Template End Get Set(value As String) m_Template = value NotifyPropertyChanged("Template") End Set End Property Private m_TypeList As New List(Of TypeHardware) Public ReadOnly Property TypeList As List(Of TypeHardware) Get Return m_TypeList End Get End Property Private m_Type As TypeHardware Public Property SelType As TypeHardware Get Return m_Type End Get Set(value As TypeHardware) m_Type = value NotifyPropertyChanged("SelType") End Set End Property Private m_TypeVisibility As Visibility = Visibility.Collapsed Public Property TypeVisibility As Visibility Get Return m_TypeVisibility End Get Set(value As Visibility) m_TypeVisibility = value End Set End Property Sub New(HardwareGeneral As CompoType, nCommand As Integer) m_Command = nCommand m_HardwareGeneral = HardwareGeneral Dim ModelList As New ObservableCollection(Of CompoBrandDir) 'GetDirectoryCompoModel(HardwareGeneral.Path, ModelList) If m_HardwareGeneral.HardwareFolderList.Count > 0 Then For Each Folder In m_HardwareGeneral.HardwareFolderList m_BrandList.Add(Folder.ModelDirGraphic) Next NotifyPropertyChanged("BrandList") Dim SelItemindex As Integer = 0 While Path.HasExtension(m_BrandList(SelItemindex)) And SelItemindex < m_BrandList.Count - 1 SelItemindex += 1 End While SelBrand = m_BrandList(SelItemindex) Template = "File Name" If Map.refHardwarePageVM.CurrHardware.TypeList.Count > 0 Then TypeVisibility = Visibility.Visible m_TypeList = Map.refHardwarePageVM.CurrHardware.TypeList NotifyPropertyChanged("TypeList") SelType = TypeList(0) End If End If End Sub ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property SaveCmd() As ICommand Get If m_cmdSave Is Nothing Then m_cmdSave = New Command(AddressOf Save) End If Return m_cmdSave End Get End Property Public Sub Save(ByVal param As Object) If m_Command = CommandList.nDuplicate Then If Map.refHardwarePageVM.CurrHardware.Duplicate(Trim(m_SelBrand), Trim(m_Template)) Then CloseNewHardware() ElseIf m_Command = CommandList.nNew Then Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False Map.refHardwarePageVM.CurrHardware.ClearGroupChapters() ' Creo un nuovo hardware Map.refHardwarePageVM.CurrHardware.NewHardware(m_SelBrand, m_Template, m_Type) Map.refSceneManagerVM.RefreshBtn() Map.refHardwarePageVM.CurrHardware.IsEnableType = False CloseNewHardware() End If End Sub ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property CancelCmd() As ICommand Get If m_cmdCancel Is Nothing Then m_cmdCancel = New Command(AddressOf Cancel) End If Return m_cmdCancel End Get End Property ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Public Sub Cancel(ByVal param As Object) ForceToQuit = True CloseNewHardware() End Sub #Region "CloseNewHardwareCommand" ''' ''' Returns a command that remove the current selected machining. ''' Public ReadOnly Property CloseNewHardwareCmd() As ICommand Get If m_CmdCloseNewHardware Is Nothing Then m_CmdCloseNewHardware = New Command(AddressOf CloseNewHardware) End If Return m_CmdCloseNewHardware End Get End Property ''' ''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand. ''' Public Function CloseNewHardware() As Boolean ' Chiusura finestra For Each Window In Application.Current.Windows If TypeOf Window Is NewHardwareV Then Dim NewHardwareWindow As NewHardwareV = DirectCast(Window, NewHardwareV) NewHardwareWindow.Close() End If Next Return True End Function #End Region ' CloseOptionsCommand End Class