Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.IO Imports System.Windows.Forms Imports EgtWPFLib5 Imports EgtUILib Public Class EgtManageFileDialogVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Enum VisualizationContainerType As Integer LISTBOX = 0 DATAGRID = 1 End Enum Public Enum VisualizationType As Integer SCHEDULETEMPLATE = 0 DETAILSTEMPLATE = 1 BOXINGTEMPLATE = 2 CONTENTTEMPLATE = 3 End Enum Public Enum ModeTypes As Integer FILE = 1 FOLDER = 2 End Enum Private m_sTitle As String Public Property sTitle As String Get Return m_sTitle End Get Set(value As String) m_sTitle = value End Set End Property Private m_sFilter As String Public Property sFilter As String Get Return m_sFilter End Get Set(value As String) m_sFilter = value If Not IsNothing(sFilter) Then Dim FilterListSplit As String() = sFilter.Split("|"c) For i As Integer = 0 To FilterListSplit.Count - 1 If i Mod 2 = 0 Then Dim strExstension As New EgtExstension() With {.sNameExstension = FilterListSplit(i) & FilterListSplit(i + 1), .sExstension = FilterListSplit(i + 1)} m_ListFilter.Add(strExstension) m_SelExstension.sNameExstension = m_ListFilter(0).sNameExstension m_SelExstension.sExstension = m_ListFilter(0).sExstension End If Next End If End Set End Property Private m_sInitialDirectory As String Public Property sInitialDirectory As String Get Return m_sInitialDirectory End Get Set(value As String) m_sInitialDirectory = value m_sSaveFileName = "New.icrs" m_sUrl_Msg = m_sInitialDirectory m_sFileNameMsg = FileName_Msg Dim DirectoryStart As String() = m_sInitialDirectory.Split("\"c) For i As Integer = 0 To m_RootList.Count - 1 m_RootList(i).sIconSource = "\Resources\EgtDialog\Root.png" If m_RootList(i).sName.Trim("\") = DirectoryStart(0) Then m_RootList(i).IsExpanded = True Dim CurrItem As EgtFolder = TryCast(m_RootList(i), EgtFolder) If Not IsNothing(CurrItem) Then For j As Integer = 0 To CurrItem.FolderList.Count - 1 If CurrItem.FolderList(j).sName = DirectoryStart(1) Then CurrItem.FolderList(j).IsExpanded = True Dim ItemFolder As EgtFolder = TryCast(CurrItem.FolderList(j), EgtFolder) If Not IsNothing(ItemFolder) Then For y As Integer = 0 To ItemFolder.FolderList.Count - 1 If ItemFolder.FolderList(y).sName = DirectoryStart(2) Then ItemFolder.FolderList(y).IsExpanded = True ItemFolder.FolderList(y).IsSelected = True End If Next End If End If Next End If End If Next End Set End Property Private m_sFileName As String Public Property sFileName As String Get Return m_sFileName End Get Set(value As String) m_sFileName = value m_sSaveFileName = m_sFileName End Set End Property Private m_sUrl_Msg As String Public Overloads Property sUrl_Msg As String Get Return m_sUrl_Msg End Get Set(value As String) m_sUrl_Msg = value NotifyPropertyChanged(NameOf(sUrl_Msg)) End Set End Property Private m_sSaveFileName As String Public Property sSaveFileName As String Get Return m_sSaveFileName End Get Set(value As String) m_sSaveFileName = value NotifyPropertyChanged(NameOf(sSaveFileName)) End Set End Property Private m_sFileNameMsg As String Public Property sFileNameMsg As String Get Return m_sFileNameMsg End Get Set(value As String) m_sFileNameMsg = value NotifyPropertyChanged(NameOf(sFileNameMsg)) End Set End Property Private m_nTaskStatus As Integer Public Property nTaskStatus As String Get Return m_nTaskStatus End Get Set(value As String) m_nTaskStatus = value NotifyPropertyChanged(NameOf(nTaskStatus)) End Set End Property Private m_nFilterIndex As Integer Public Property nFilterIndex As Integer Get Return m_nFilterIndex End Get Set(value As Integer) m_nFilterIndex = value End Set End Property Private m_nMode As Integer Public Property nMode As Integer Get Return m_nMode End Get Set(value As Integer) m_nMode = value End Set End Property Private m_nSelectView As Integer Public Property nSelectView As Integer Get Return m_nSelectView End Get Set(value As Integer) m_nSelectView = value End Set End Property Private m_ListFilter As ObservableCollection(Of EgtExstension) Public Property ListFilter As ObservableCollection(Of EgtExstension) Get Return m_ListFilter End Get Set(value As ObservableCollection(Of EgtExstension)) m_ListFilter = value End Set End Property Private m_RootList As New ObservableCollection(Of EgtDirectory) Public Property RootList As ObservableCollection(Of EgtDirectory) Get Return m_RootList End Get Set(value As ObservableCollection(Of EgtDirectory)) m_RootList = value End Set End Property Private m_VisualizationList As ObservableCollection(Of IdNameStruct) Public Property VisualizationList As ObservableCollection(Of IdNameStruct) Get Return m_VisualizationList End Get Set(value As ObservableCollection(Of IdNameStruct)) m_VisualizationList = value End Set End Property Private m_SelVisualization As IdNameStruct Public Property SelVisualization As IdNameStruct Get Return m_SelVisualization End Get Set(value As IdNameStruct) m_SelVisualization = value Select Case m_SelVisualization.Id Case VisualizationType.SCHEDULETEMPLATE m_nSelectView = VisualizationContainerType.LISTBOX nTaskStatus = 0 m_UVision_Visibility = Visibility.Visible Case VisualizationType.DETAILSTEMPLATE m_nSelectView = VisualizationContainerType.DATAGRID m_UVision_Visibility = Visibility.Collapsed Case VisualizationType.BOXINGTEMPLATE m_nSelectView = VisualizationContainerType.LISTBOX nTaskStatus = 1 m_UVision_Visibility = Visibility.Collapsed Case VisualizationType.CONTENTTEMPLATE m_nSelectView = VisualizationContainerType.LISTBOX nTaskStatus = 2 m_UVision_Visibility = Visibility.Collapsed End Select NotifyPropertyChanged(NameOf(nSelectView)) NotifyPropertyChanged(NameOf(UVision_Visibility)) End Set End Property Private m_UVision_Visibility As Visibility Public Property UVision_Visibility As Visibility Get Return m_UVision_Visibility End Get Set(value As Visibility) m_UVision_Visibility = value End Set End Property Private m_SelExstension As EgtExstension Public Property SelExstension As EgtExstension Get Return m_SelExstension End Get Set(value As EgtExstension) m_SelExstension = value Dim CurrItem As EgtFolder = TryCast(m_SelTreeItem, EgtFolder) If Not IsNothing(CurrItem) Then CollectionViewSource.GetDefaultView(CurrItem.FolderList).Refresh() End If End Set End Property Public m_SelTreeItem As EgtDirectory Public Property SelTreeItem As EgtDirectory Get Return m_SelTreeItem End Get Set(value As EgtDirectory) m_SelTreeItem = value NotifyPropertyChanged(NameOf(SelTreeItem)) End Set End Property Friend Sub UpdateSelRoot(Item As EgtDirectory) m_SelTreeItem = Item NotifyPropertyChanged(NameOf(SelTreeItem)) End Sub 'Comandi Private m_cmdCancel As ICommand Private m_cmdOk As ICommand Private m_cmdGoBack As ICommand Private m_cmdDoubleClick As ICommand Friend Event m_CloseWindow(bDialogResult As MessageBoxResult) #End Region ' FIELDS & PROPERTIES #Region "CONTRUCTORS" Sub New() m_RootList.Clear() EgtDirectory.refUpdateSelRoot = AddressOf UpdateSelRoot Dim drives As DriveInfo() = DriveInfo.GetDrives().Where(Function(d) d.IsReady).ToArray() m_ListFilter = New ObservableCollection(Of EgtExstension) For i As Integer = 0 To drives.Count() - 1 Dim directory As New EgtFolder(drives(i).RootDirectory, Nothing, Me) 'AddHandler directory.PropertyChanged, AddressOf Directory_PropertyChanged m_RootList.Add(directory) Next m_SelExstension = New EgtExstension() SetVisualizzationList() m_SelVisualization.Id = VisualizationType.SCHEDULETEMPLATE m_nSelectView = VisualizationContainerType.LISTBOX nTaskStatus = 0 m_UVision_Visibility = Visibility.Visible NotifyPropertyChanged(NameOf(RootList)) NotifyPropertyChanged(NameOf(ListFilter)) NotifyPropertyChanged(NameOf(VisualizationList)) End Sub #End Region ' CONTRUCTORS #Region "Messages" Public ReadOnly Property Name_Msg As String Get Return EgtMsg(15060) End Get End Property Public ReadOnly Property LastModify_Msg As String Get Return EgtMsg(15061) End Get End Property Public ReadOnly Property Type_Msg As String Get Return EgtMsg(15062) End Get End Property Public ReadOnly Property Dimension_Msg As String Get Return EgtMsg(15063) End Get End Property Public ReadOnly Property Folder_Msg As String Get Return EgtMsg(15064) End Get End Property Public ReadOnly Property FileName_Msg As String Get Return EgtMsg(15065) End Get End Property Public ReadOnly Property FolderName_Msg As String Get Return EgtMsg(15066) End Get End Property Public ReadOnly Property Schedule_Msg As String Get Return EgtMsg(15067) End Get End Property Public ReadOnly Property Details_Msg As String Get Return EgtMsg(15068) End Get End Property Public ReadOnly Property Boxing_Msg As String Get Return EgtMsg(15069) End Get End Property Public ReadOnly Property Content_Msg As String Get Return EgtMsg(15070) End Get End Property Public ReadOnly Property DataFolder_Msg As String Get Return EgtMsg(15071) End Get End Property #End Region #Region "METHODS" ''' ''' Inizializza la ComboBox per la scelta dei template ''' Private Sub SetVisualizzationList() m_VisualizationList = New ObservableCollection(Of IdNameStruct) Dim ItemVisualization As New IdNameStruct With { .Id = 0, .Name = Schedule_Msg } m_VisualizationList.Add(ItemVisualization) ItemVisualization.Id = 1 ItemVisualization.Name = Details_Msg m_VisualizationList.Add(ItemVisualization) ItemVisualization.Id = 2 ItemVisualization.Name = Boxing_Msg m_VisualizationList.Add(ItemVisualization) ItemVisualization.Id = 3 ItemVisualization.Name = Content_Msg m_VisualizationList.Add(ItemVisualization) End Sub Private Sub Directory_PropertyChanged(sender As Object, e As PropertyChangedEventArgs) If e.PropertyName = "IsSelected" Then 'UpdateSelRoot() End If End Sub Public Sub MouseDoubleClick() m_SelTreeItem.m_ItemSelected.IsExpanded = True m_SelTreeItem.m_ItemSelected.IsSelected = True End Sub #End Region #Region "COMMANDS" #Region "Command Ok" Public ReadOnly Property Ok_Command As ICommand Get If m_cmdOk Is Nothing Then m_cmdOk = New Command(AddressOf Ok) End If Return m_cmdOk End Get End Property Public Sub Ok() Dim CurrItem As EgtItem = TryCast(m_SelTreeItem.m_ItemSelected, EgtItem) If nMode = ModeTypes.FILE Then If Not IsNothing(CurrItem) Then m_sFileName = m_SelTreeItem.InfoDir.FullName & "\" & CurrItem.sName Else m_sFileName = m_SelTreeItem.InfoDir.FullName & "\" & m_sSaveFileName End If ElseIf nMode = ModeTypes.FOLDER Then m_sFileName = m_SelTreeItem.InfoDir.FullName End If RaiseEvent m_CloseWindow(DialogResult.OK) End Sub #End Region 'Command Ok #Region "Command GoBack" Public ReadOnly Property GoBack_Command As ICommand Get If m_cmdGoBack Is Nothing Then m_cmdGoBack = New Command(AddressOf GoBack) End If Return m_cmdGoBack End Get End Property Public Sub GoBack() If Not IsNothing(m_SelTreeItem.m_ParentFolder) Then m_SelTreeItem = m_SelTreeItem.m_ParentFolder m_SelTreeItem.IsSelected = True m_sUrl_Msg = m_SelTreeItem.InfoDir.FullName NotifyPropertyChanged(NameOf(sUrl_Msg)) End If End Sub #End Region 'Command GoBack #Region "Command Cancel" Public ReadOnly Property Cancel_Command As ICommand Get If m_cmdCancel Is Nothing Then m_cmdCancel = New Command(AddressOf Cancel) End If Return m_cmdCancel End Get End Property Public Sub Cancel() RaiseEvent m_CloseWindow(DialogResult.Cancel) End Sub #End Region 'Command Cancel #Region "Command DoubleClick" Public ReadOnly Property DoubleClick_Command As ICommand Get If m_cmdDoubleClick Is Nothing Then m_cmdDoubleClick = New Command(AddressOf MouseDoubleClick) End If Return m_cmdDoubleClick End Get End Property #End Region 'Command DoubleClick #End Region ' COMMANDS End Class Public Class EgtExstension Inherits VMBase Public m_sNameExstension As String Public Property sNameExstension As String Get Return m_sNameExstension End Get Set(value As String) m_sNameExstension = value NotifyPropertyChanged(NameOf(sNameExstension)) End Set End Property Public m_sExstension As String Public Property sExstension As String Get Return m_sExstension End Get Set(value As String) m_sExstension = value NotifyPropertyChanged(NameOf(sExstension)) End Set End Property End Class Public Class EgtDirectory Inherits VMBase #Region "FIELDS & PROPERTIES" Friend Shared refUpdateSelRoot As Action(Of EgtDirectory) Friend Shared m_refEgtManageFileDialogVM As EgtManageFileDialogVM Private m_bIsSelected As Boolean Public Overridable Property IsSelected As Boolean Get Return m_bIsSelected End Get Set(value As Boolean) m_bIsSelected = value refUpdateSelRoot(Me) End Set End Property Private m_bIsExpanded As Boolean Public Overridable Property IsExpanded As Boolean Get Return m_bIsExpanded End Get Set(value As Boolean) m_bIsExpanded = value End Set End Property Protected m_InfoDir As DirectoryInfo Public Property InfoDir As DirectoryInfo Get Return m_InfoDir End Get Set(value As DirectoryInfo) m_InfoDir = value End Set End Property Public ReadOnly Property sName As String Get Try Return If(Not IsNothing(m_InfoDir), m_InfoDir.Name, "") Catch ex As Exception Return "" End Try End Get End Property Public m_sIconSource As String Public Property sIconSource As String Get Return m_sIconSource End Get Set(value As String) m_sIconSource = value End Set End Property Public ReadOnly Property sTypeItem As String Get Try Return If(Not IsNothing(m_InfoDir), m_InfoDir.Extension, "") Catch ex As Exception Return "" End Try End Get End Property Public ReadOnly Property dLastModifyDate As Date Get Try Return If(Not IsNothing(m_InfoDir), m_InfoDir.LastAccessTime.ToString("dd/MM/yyyy HH:mm:ss"), Date.UtcNow.ToString("dd/MM/yyyy HH:mm:ss")) Catch ex As Exception Return Date.UtcNow.ToString("dd/MM/yyyy HH:mm:ss") End Try End Get End Property Public ReadOnly Property sDimension As String Get Try Return If(Not IsNothing(m_InfoDir), "", "") Catch ex As Exception Return "" End Try End Get End Property Public m_ParentFolder As EgtFolder Public Property ParentFolder As EgtFolder Get Return m_ParentFolder End Get Set(value As EgtFolder) m_ParentFolder = value End Set End Property Public m_ItemSelected As EgtDirectory Public Property ItemSelected As EgtDirectory Get Return m_ItemSelected End Get Set(value As EgtDirectory) m_ItemSelected = value Dim Item As EgtItem = TryCast(m_ItemSelected, EgtItem) If Not IsNothing(Item) Then m_refEgtManageFileDialogVM.sSaveFileName = Item.sName m_refEgtManageFileDialogVM.sFileNameMsg = m_refEgtManageFileDialogVM.FileName_Msg Else Dim Folder As EgtFolder = TryCast(m_ItemSelected, EgtFolder) If Not IsNothing(Folder) Then m_refEgtManageFileDialogVM.sSaveFileName = Folder.sName m_refEgtManageFileDialogVM.sFileNameMsg = m_refEgtManageFileDialogVM.FolderName_Msg End If End If End Set End Property #End Region ' FIELDS & PROPERTIES End Class Public Class EgtFolder Inherits EgtDirectory #Region "FIELDS & PROPERTIES" Public m_ItemList_View As CollectionView = Nothing Friend Sub SetEgtManageFileDialogVM(EgtManageFileDialogVM As EgtManageFileDialogVM) m_refEgtManageFileDialogVM = EgtManageFileDialogVM End Sub Private m_FolderList As New ObservableCollection(Of EgtDirectory) Public Property FolderList As ObservableCollection(Of EgtDirectory) Get Return m_FolderList End Get Set(value As ObservableCollection(Of EgtDirectory)) m_FolderList = value End Set End Property Private m_sName As String Public Overloads Property sName As String Get Return m_sName End Get Set(value As String) m_sName = value End Set End Property Private m_sTypeItem As String Public Overloads Property sTypeItem As String Get Return m_sTypeItem End Get Set(value As String) m_sTypeItem = value End Set End Property Private m_dLastModifyDate As Date Public Overloads Property dLastModifyDate As String Get Return m_dLastModifyDate End Get Set(value As String) m_dLastModifyDate = value End Set End Property Private m_bIsExpanded As Boolean Public Overrides Property IsExpanded As Boolean Get Return m_bIsExpanded End Get Set(value As Boolean) m_bIsExpanded = value NotifyPropertyChanged(NameOf(IsExpanded)) SetFolderList() End Set End Property Private m_bIsSelected As Boolean Public Overrides Property IsSelected As Boolean Get Return m_bIsSelected End Get Set(value As Boolean) m_bIsSelected = value refUpdateSelRoot(Me) m_refEgtManageFileDialogVM.sUrl_Msg = m_InfoDir.FullName If m_bIsSelected = True Then SetFolderList() End If End Set End Property #End Region ' FIELDS & PROPERTIES #Region "CONTRUCTORS" Sub New(InfoDir As DirectoryInfo, Folder As EgtDirectory, EgtManageFileDialogVM As EgtManageFileDialogVM) SetEgtManageFileDialogVM(EgtManageFileDialogVM) m_InfoDir = InfoDir m_sName = InfoDir.Name m_dLastModifyDate = InfoDir.LastWriteTime.ToString("dd/MM/yyyy HH:mm:ss") If InfoDir.Extension <> "" AndAlso InfoDir.Attributes <> FileAttributes.Directory AndAlso InfoDir.Attributes = FileAttributes.ReadOnly Then m_sTypeItem = "File " & InfoDir.Extension.ToUpper() m_sIconSource = "\Resources\EgtDialog\New.png" Else m_sTypeItem = m_refEgtManageFileDialogVM.Folder_Msg m_sIconSource = "\Resources\EgtDialog\Folder.png" End If m_FolderList.Add(New EgtDirectory()) m_ParentFolder = Folder m_ItemSelected = New EgtDirectory() m_ItemList_View = CollectionViewSource.GetDefaultView(m_FolderList) m_ItemList_View.Filter = AddressOf ItemFilter NotifyPropertyChanged(NameOf(sName)) NotifyPropertyChanged(NameOf(dLastModifyDate)) NotifyPropertyChanged(NameOf(sTypeItem)) NotifyPropertyChanged(NameOf(sIconSource)) NotifyPropertyChanged(NameOf(FolderList)) NotifyPropertyChanged(NameOf(ParentFolder)) End Sub #End Region ' CONTRUCTORS #Region "METHODS" Private Function ItemFilter(Item As Object) As Boolean Dim CurrItem As EgtItem = TryCast(Item, EgtItem) Dim MyChar() As Char = {"F", "i", "l", "e", " "} If Not IsNothing(CurrItem) AndAlso Not IsNothing(m_refEgtManageFileDialogVM.SelExstension.m_sExstension) Then If CurrItem.sTypeItem.Trim(MyChar).ToLower() = m_refEgtManageFileDialogVM.SelExstension.m_sExstension.TrimStart("*") Then Return True Else Return False End If End If Return True End Function Private Sub SetFolderList() Dim DirectoryList() As DirectoryInfo Dim FileList() As FileInfo Try DirectoryList = m_InfoDir.GetDirectories().Where(Function(file) (file.Attributes And FileAttributes.Hidden And file.Name <> m_refEgtManageFileDialogVM.DataFolder_Msg) = 0).ToArray() FileList = m_InfoDir.GetFiles().Where(Function(file) (file.Attributes And FileAttributes.Hidden) = 0).ToArray() Catch ex As Exception DirectoryList = Nothing FileList = Nothing End Try m_FolderList.Clear() If Not IsNothing(DirectoryList) AndAlso m_FolderList.Count = 0 Then For Each subDir As DirectoryInfo In DirectoryList Dim directory As New EgtFolder(subDir, Me, m_refEgtManageFileDialogVM) m_FolderList.Add(directory) Next End If If Not IsNothing(FileList) Then For Each files As FileInfo In FileList Dim file As New EgtItem(files) Dim MyChar() As Char = {"F", "i", "l", "e", " "} If file.sTypeItem.Trim(MyChar).ToLower() = m_refEgtManageFileDialogVM.SelExstension.sExstension.TrimStart("*") Then m_FolderList.Add(file) Else m_FolderList.Add(file) End If Next End If End Sub #End Region End Class Public Class EgtItem Inherits EgtDirectory #Region "FIELDS & PROPERTIES" Private m_sName As String Public Overloads Property sName As String Get Return m_sName End Get Set(value As String) m_sName = value End Set End Property Private m_sTypeItem As String Public Overloads Property sTypeItem As String Get Return m_sTypeItem End Get Set(value As String) m_sTypeItem = value End Set End Property Private m_sDimension As String Public Overloads Property sDimension As String Get Return m_sDimension End Get Set(value As String) m_sDimension = value End Set End Property Private m_dLastModifyDate As Date Public Overloads Property dLastModifyDate As String Get Return m_dLastModifyDate End Get Set(value As String) m_dLastModifyDate = value End Set End Property #End Region ' FIELDS & PROPERTIES #Region "CONTRUCTORS" Sub New(InfoDir As FileInfo) m_sName = InfoDir.Name m_sDimension = String.Format("{0:#,##0.00}", InfoDir.Length / 1024) & " Kb" m_dLastModifyDate = InfoDir.LastWriteTime.ToString("dd/MM/yyyy HH:mm:ss") If InfoDir.Extension <> "" Then m_sTypeItem = "File " & InfoDir.Extension.ToUpper() m_sIconSource = "\Resources\EgtDialog\New.png" Else m_sTypeItem = "" End If NotifyPropertyChanged(NameOf(sName)) NotifyPropertyChanged(NameOf(sDimension)) NotifyPropertyChanged(NameOf(dLastModifyDate)) NotifyPropertyChanged(NameOf(sTypeItem)) NotifyPropertyChanged(NameOf(sIconSource)) End Sub #End Region ' CONTRUCTORS End Class