Imports System.Collections.ObjectModel Imports EgtUILib Public Class ImportExportToolWindowVM Inherits VMBase ' Modalita' di apertura della finestra Public Enum WindowModeEnum As Integer IMPORT EXPORT End Enum Private m_WindowMode As WindowModeEnum Public ReadOnly Property WindowMode As WindowModeEnum Get Return m_WindowMode End Get End Property ' Lista degli utensili Private m_FamilyList As New ObservableCollection(Of ImpExpToolFamily) Public Property FamilyList As ObservableCollection(Of ImpExpToolFamily) Get Return m_FamilyList End Get Set(value As ObservableCollection(Of ImpExpToolFamily)) m_FamilyList = value End Set End Property ' Percorso del file da cui importare gli utensili Private m_ImportFilePath As String Public ReadOnly Property ImportFilePath As String Get Return m_ImportFilePath End Get End Property ' Lista degli utensili presenti nel file da cui importare Private m_ImportFileToolNameList As String() Public ReadOnly Property ImportFileToolNameList As String() Get Return m_ImportFileToolNameList End Get End Property ' Lista degli utensili importati con successo Private m_vsImported As String() Public ReadOnly Property vsImported As String() Get Return m_vsImported End Get End Property Public ReadOnly Property IsEnabledOkBtn As Boolean Get For Each Family In FamilyList For Each Tool In Family.ToolList If Tool.Active Then Return True Next Next Return False End Get End Property Friend Event m_CloseWindow(bDialogResult As Boolean) #Region "MESSAGES" Public ReadOnly Property OkMsg As String Get If WindowMode = WindowModeEnum.IMPORT Then Return EgtMsg(31161) ' Importa Else Return EgtMsg(31162) ' Esporta End If End Get End Property #End Region ' Messages #Region "CONSTRUCTOR" Sub New(FamilyList As ObservableCollection(Of ImpExpToolFamily), bExport As Boolean, Optional sImportFilePath As String = Nothing, Optional vsImportFileToolNameList As String() = Nothing) If bExport Then m_WindowMode = WindowModeEnum.EXPORT Else m_WindowMode = WindowModeEnum.IMPORT m_ImportFilePath = sImportFilePath m_ImportFileToolNameList = vsImportFileToolNameList End If ' carico lista Me.FamilyList = FamilyList ImpExpToolItem.m_delEnableOkBtn = AddressOf EnableOkBtn End Sub #End Region ' Constructor #Region "METHODS" Private Sub EnableOkBtn() NotifyPropertyChanged(NameOf(IsEnabledOkBtn)) End Sub #End Region ' Methods #Region "COMMANDS" ' Definizione comandi Private m_cmdOk As ICommand #Region "OkCommand" ''' ''' Returns a command that remove the current selected machining. ''' Public ReadOnly Property OkCommand() As ICommand Get If m_cmdOk Is Nothing Then m_cmdOk = New Command(AddressOf ConfirmImpExpTools) End If Return m_cmdOk End Get End Property ''' ''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand. ''' Public Sub ConfirmImpExpTools(param As Object) Select Case WindowMode Case WindowModeEnum.IMPORT Dim FinalNameList As New List(Of String) Dim ImportToolNameList As New List(Of String)(ImportFileToolNameList) For Each Family In FamilyList For Each Tool In Family.ToolList If Tool.Active Then FinalNameList.Add(Tool.Name) Else ImportToolNameList.Remove(Tool.Name) End If Next Next Dim vsFinalName = FinalNameList.ToArray() Dim vsImportToolName = ImportToolNameList.ToArray() ' Eseguo importazione EgtTdbImport(ImportFilePath, vsImportToolName, vsFinalName, m_vsImported) ' Report Dim ImportedToolList As New List(Of String)(vsImported) MessageBox.Show(EgtMsg(31166) & " " & vbCrLf & String.Join(vbCrLf, ImportedToolList.ToArray()), "", MessageBoxButton.OK) 'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31166) & " " & vbCrLf & String.Join(vbCrLf, ImportedToolList.ToArray()), "", MessageBoxButton.OK) ' I seguenti Utensili sono stati importati correttamente: Case WindowModeEnum.EXPORT ' recupero gli utensili checkati Dim FinalNameList As New List(Of String) For Each Family In FamilyList For Each Tool In Family.ToolList If Tool.Active Then FinalNameList.Add(Tool.Name) End If Next Next If FinalNameList.Count() = 0 Then Return Dim FinalNameArray = FinalNameList.ToArray() ' chiedo il nome con cui salvare il file .data Dim SaveFileDlg As New System.Windows.Forms.SaveFileDialog() With { .Title = EgtMsg(31162) & " " & EgtMsg(31163), .Filter = "File data (*.data)|*.data|Tutti i file (*.*)|*.*", .FileName = String.Empty } 'Dim SaveFileDlg As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With { ' .Title = EgtMsg(31162) & " " & EgtMsg(31163), ' Esporta Utensili ' .Filter = "File data (*.data)|*.data|Tutti i file (*.*)|*.*", ' .FileName = String.Empty '} If SaveFileDlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return Dim sFilePath As String = String.Empty sFilePath = SaveFileDlg.FileName ' Eseguo esportazione EgtTdbExport(FinalNameArray, sFilePath) End Select ' Chiusura finestra RaiseEvent m_CloseWindow(True) End Sub #End Region ' OkCommand #End Region ' Commands End Class Public Class ImpExpToolFamily Inherits VMBase Private m_Name As String Public Property Name As String Get Return m_Name End Get Set(value As String) m_Name = value End Set End Property Private m_FamilyType As Integer ''' ''' Property that determines the tool type of the family ''' Public Property FamilyType As Integer Get Return m_FamilyType End Get Set(value As Integer) m_FamilyType = value End Set End Property Private m_ToolList As New ObservableCollection(Of ImpExpToolItem) Public Property ToolList As ObservableCollection(Of ImpExpToolItem) Get Return m_ToolList End Get Set(value As ObservableCollection(Of ImpExpToolItem)) m_ToolList = value End Set End Property Private m_sPictureString As String Public Property PictureString As String Get Return m_sPictureString End Get Set(value As String) If value <> m_sPictureString Then m_sPictureString = value End If End Set End Property Sub New(Name As String, FamilyType As Integer) m_Name = Name m_FamilyType = FamilyType m_sPictureString = "/Resources/TreeView/Folder.png" End Sub End Class Public Class ImpExpToolItem Inherits VMBase ' Actions Friend Shared m_delEnableOkBtn As Action Private m_Name As String Public Property Name As String Get If m_ChangeName Then Return m_Name & "_imp" Else Return m_Name End If End Get Set(value As String) m_Name = value End Set End Property Private m_Active As Boolean Public Property Active As Boolean Get Return m_Active End Get Set(value As Boolean) ' se esiste gia' chiedo se sovrascriverlo If value Then If m_AlreadyExist Then Select Case System.Windows.MessageBox.Show(EgtMsg(31164), "", MessageBoxButton.YesNoCancel) 'Select Case EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31164), "", MessageBoxButton.YesNoCancel) ' L'utensile esiste già, sovrascriverlo? Case MessageBoxResult.Yes m_ChangeName = False m_Active = True Case MessageBoxResult.No System.Windows.MessageBox.Show(EgtMsg(31165), "", MessageBoxButton.OK) 'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31165), "", MessageBoxButton.OK) ' L'utensile verrà importato col nome seguito da "_imp" m_ChangeName = True m_Active = True Case Else m_Active = False End Select NotifyPropertyChanged(NameOf(Active)) Else m_Active = True End If Else m_ChangeName = False m_Active = False End If If Not IsNothing(m_delEnableOkBtn) Then m_delEnableOkBtn() End Set End Property ' Parametro che indica se questo item da importare esiste gia' Private m_AlreadyExist As Boolean Friend ReadOnly Property AlreadyExist As Boolean Get Return m_AlreadyExist End Get End Property ' Parametro che indica se cambiare il nome di un item che esiste gia' o sovrascriverlo Private m_ChangeName As Boolean Friend Property ChangeName As Boolean Get Return m_ChangeName End Get Set(value As Boolean) m_ChangeName = value NotifyPropertyChanged(NameOf(Name)) End Set End Property Sub New(Name As String, AlreadyExist As Boolean) m_Name = Name m_AlreadyExist = AlreadyExist End Sub End Class