Imports System.Collections.ObjectModel Imports System.IO Imports EgtBEAMWALL.Core Imports EgtBEAMWALL.Core.ConstBeam Imports EgtUILib Public Class OpenProjectFileDialogVM Inherits VMBase Friend Event m_CloseWindow(bDialogResult As Boolean) Private m_ProjectColumns As New ObservableCollection(Of String) Public Property ProjectColumns As ObservableCollection(Of String) Get Return m_ProjectColumns End Get Set(value As ObservableCollection(Of String)) m_ProjectColumns = value End Set End Property Private m_ProjectType As ProjectType Private m_FileNameTxBl As TextBlock Private m_sDirectory As String Public Property Directory As String Get Return m_sDirectory End Get Set(value As String) m_sDirectory = value End Set End Property Private m_sFilter As String Public Property Filter As String Get Return m_sFilter End Get Set(value As String) m_sFilter = value End Set End Property Private m_sFileNameFilter As Predicate(Of String) Public Property FileNameFilter As Predicate(Of String) Get Return m_sFileNameFilter End Get Set(value As Predicate(Of String)) m_sFileNameFilter = value End Set End Property Private m_sExtensions As New List(Of String) Public ReadOnly Property Extensions As List(Of String) Get Return m_sExtensions End Get End Property Private m_ProjectList As New ObservableCollection(Of ProjectFileVM) Public ReadOnly Property ProjectList As ObservableCollection(Of ProjectFileVM) Get Return m_ProjectList End Get 'Set(value As List(Of ProjFile)) ' m_ProjList = value ' NotifyPropertyChanged("ProjList") 'End Set End Property Private m_SelProject As ProjectFileVM Public Property SelProject As ProjectFileVM Get Return m_SelProject End Get Set(value As ProjectFileVM) m_SelProject = value End Set End Property Private m_FileName As String Public Property FileName As String Get Return m_FileName End Get Set(value As String) m_FileName = value End Set End Property #Region "Messages" Public ReadOnly Property Id_Msg As String Get Return "ID" End Get End Property Public ReadOnly Property BTLFileName_Msg As String Get Return "BTL File Name" End Get End Property Public ReadOnly Property ListName_Msg As String Get Return "List Name" End Get End Property Public ReadOnly Property ExportDate_Msg As String Get Return "Export Date" End Get End Property Public ReadOnly Property CreateDate_Msg As String Get Return "Creation Date" End Get End Property Public ReadOnly Property Name_Msg As String Get Return "Name" End Get End Property Public ReadOnly Property Open_Msg As String Get Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 6) End Get End Property Public ReadOnly Property Delete_Msg As String Get Return "Delete" End Get End Property Public ReadOnly Property Cancel_Msg As String Get Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 2) End Get End Property #End Region ' Definizione comandi Private m_cmdProjectDoubleClick As ICommand Private m_cmdDelete As ICommand Public Function Init(ProjectType As ProjectType, Optional ProjectList As List(Of ProjectFileVM) = Nothing) As Boolean? m_ProjectType = ProjectType ' carico colonne LoadColumns(ProjectType) ' carico lista progetti If IsNothing(ProjectList) OrElse ProjectList.Count = 0 Then ' leggo da db If ProjectType = ProjectType.PROJ Then Dim DbProjectList As New List(Of ProjFileM) DbProjectList = DbControllers.m_ProjController.GetLastDesc(50) For Each Project In DbProjectList m_ProjectList.Add(New ProjFileVM(Project)) Next ElseIf ProjectType = ProjectType.PROD Then Dim DbProjectList As New List(Of ProdFileM) DbProjectList = DbControllers.m_ProdController.GetLastDesc(50) For Each Project In DbProjectList m_ProjectList.Add(New ProdFileVM(Project)) Next End If Else m_ProjectList = New ObservableCollection(Of ProjectFileVM)(ProjectList) End If End Function Private Sub LoadColumns(ProjectType As ProjectType) If ProjectType = ProjectType.PROJ Then ProjectColumns.Add("colPROJID") ProjectColumns.Add("colBTLNAME") ProjectColumns.Add("colLISTNAME") ProjectColumns.Add("colEXPDATE") ProjectColumns.Add("colCRTDATE") ElseIf ProjectType = ProjectType.PROD Then ProjectColumns.Add("colPRODID") ProjectColumns.Add("colCRTDATE") End If End Sub Friend Function VerifySelected() As Boolean Dim AllFilesInDir As IEnumerable(Of String) If m_ProjectType = Core.ConstBeam.ProjectType.PROJ Then ' verifico se esiste ProdId AllFilesInDir = IO.Directory.EnumerateFiles(SelProject.sProjDirPath) ElseIf m_ProjectType = Core.ConstBeam.ProjectType.PROD Then AllFilesInDir = IO.Directory.EnumerateFiles(SelProject.sProdDirPath) End If For Each File In AllFilesInDir If Path.GetExtension(File).ToLower() = ".nge" Then Return True End If Next Return False End Function 'Private Sub m_FileNameTxBl_MouseDown(sender As Object, e As Windows.Input.MouseButtonEventArgs) Handles FileNameList.MouseDoubleClick ' Dim src As DependencyObject = VisualTreeHelper.GetParent(DirectCast(e.OriginalSource, DependencyObject)) ' ' verifico che venga clickato un item, non lo spazio vuoto o la scrollbar ' If Not TypeOf src Is ListBoxItem Then ' src = Utility.FindAncestor(Of ListBoxItem)(src) ' End If ' If IsNothing(src) OrElse src.[GetType]() <> GetType(ListBoxItem) Then ' e.Handled = True ' Else ' If Not IsNothing(m_SelectedFile) Then ' m_FileName = SelectedFile ' DialogResult = True ' End If ' End If 'End Sub 'Private Sub OpenBtn_Click(sender As Object, e As RoutedEventArgs) Handles OpenBtn.Click ' If Not IsNothing(m_SelectedFile) Then ' m_FileName = SelectedFile ' DialogResult = True ' End If 'End Sub #Region "COMMANDS" #Region "ProjectDoubleClick" ''' ''' Returns a command that do New. ''' Public ReadOnly Property ProjectDoubleClick_Command As ICommand Get If m_cmdProjectDoubleClick Is Nothing Then m_cmdProjectDoubleClick = New Command(AddressOf ProjDoubleClick) End If Return m_cmdProjectDoubleClick End Get End Property ''' ''' Execute the New. This method is invoked by the NewCommand. ''' Friend Sub ProjDoubleClick() If VerifySelected() Then RaiseEvent m_CloseWindow(True) End If End Sub #End Region ' ProjectDoubleClick #Region "Delete" ''' ''' Returns a command that do New. ''' Public ReadOnly Property Delete_Command As ICommand Get If m_cmdDelete Is Nothing Then m_cmdDelete = New Command(AddressOf Delete) End If Return m_cmdDelete End Get End Property ''' ''' Execute the New. This method is invoked by the NewCommand. ''' Friend Sub Delete() If IsNothing(SelProject) Then Return If m_ProjectType = ProjectType.PROJ Then ' verifico se proj selezionato e' il corrente If Not IsNothing(Map.refProjManagerVM.CurrProj) AndAlso SelProject.nProjId = Map.refProjManagerVM.CurrProj.nProjId Then MessageBox.Show("Impossibile cancellare il progetto correntemente aperto", "Avviso", MessageBoxButton.OK, MessageBoxImage.Warning) Return End If ' verifico se proj selezionato ha prod If SelProject.nProdId > 0 Then MessageBox.Show("Impossibile cancellare il progetto perche' gia' collegato ad una produzione", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning) Return End If ' cancello progetto DbControllers.m_ProjController.DeleteProj(SelProject.nProjId) ' aggiorno lista progetti m_ProjectList.Clear() Dim DbProjectList As New List(Of ProjFileM) DbProjectList = DbControllers.m_ProjController.GetLastDesc(50) For Each Project In DbProjectList m_ProjectList.Add(New ProjFileVM(Project)) Next ElseIf m_ProjectType = ProjectType.PROD Then ' verifico se prod selezionato e' il corrente If Not IsNothing(Map.refProdManagerVM.CurrProd) AndAlso SelProject.nProdId = Map.refProdManagerVM.CurrProd.nProdId Then MessageBox.Show("Impossibile cancellare il progetto correntemente aperto", "Avviso", MessageBoxButton.OK, MessageBoxImage.Warning) Return End If ' verifico se ci sono grezzi mandati al supervisore If DbControllers.m_ProdController.IsAnyInSupervisor(SelProject.nProdId) Then MessageBox.Show("Impossibile cancellare il progetto perche' alcuni grezzi sono gia' stati mandati in produzione.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning) Return End If ' cancello progetto DbControllers.m_ProdController.DeleteProd(SelProject.nProdId) ' aggiorno lista progetti m_ProjectList.Clear() Dim DbProjectList As New List(Of ProdFileM) DbProjectList = DbControllers.m_ProdController.GetLastDesc(50) For Each Project In DbProjectList m_ProjectList.Add(New ProdFileVM(Project)) Next End If End Sub #End Region ' Delete #End Region ' Commands End Class