f24dcd0bc5
Aggiunta gestione del passaggio da prod a proj con scelta di questultimo
360 lines
12 KiB
VB.net
360 lines
12 KiB
VB.net
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 EgtMsg(61815)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property BTLFileName_Msg As String
|
|
Get
|
|
Return EgtMsg(61819)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property ListName_Msg As String
|
|
Get
|
|
Return EgtMsg(61820)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property ExportDate_Msg As String
|
|
Get
|
|
Return EgtMsg(61821)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property CreateDate_Msg As String
|
|
Get
|
|
Return EgtMsg(61822)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property Name_Msg As String
|
|
Get
|
|
Return EgtMsg(61808)
|
|
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 EgtMsg(61823)
|
|
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 CurrProjectList As List(Of ProjectFileVM) = Nothing) As Boolean?
|
|
m_ProjectType = ProjectType
|
|
' carico colonne
|
|
LoadColumns(ProjectType)
|
|
' carico lista progetti
|
|
If IsNothing(CurrProjectList) OrElse CurrProjectList.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)(CurrProjectList)
|
|
NotifyPropertyChanged(NameOf(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("colBTLNAME")
|
|
ProjectColumns.Add("colCRTDATE")
|
|
End If
|
|
End Sub
|
|
|
|
Friend Function VerifySelected() As Boolean
|
|
If IsNothing( SelProject) Then Return False
|
|
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"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do New.
|
|
''' </summary>
|
|
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
|
|
|
|
''' <summary>
|
|
''' Execute the New. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Friend Sub ProjDoubleClick()
|
|
If VerifySelected() Then
|
|
RaiseEvent m_CloseWindow(True)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' ProjectDoubleClick
|
|
|
|
#Region "Delete"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do New.
|
|
''' </summary>
|
|
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
|
|
|
|
''' <summary>
|
|
''' Execute the New. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
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(EgtMsg(61872), EgtMsg(30009), MessageBoxButton.OK, MessageBoxImage.Warning)
|
|
Return
|
|
End If
|
|
' verifico se proj selezionato ha prod
|
|
If SelProject.nProdId > 0 Then
|
|
MessageBox.Show(EgtMsg(61873), EgtMsg(30009), 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(EgtMsg(61872), EgtMsg(30009), 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(EgtMsg(61874), EgtMsg(30009), MessageBoxButton.OK, MessageBoxImage.Warning)
|
|
Return
|
|
End If
|
|
' cancello progetto
|
|
DbControllers.m_ProdController.DeleteProd(SelProject.nProdId)
|
|
' riporto prod in proj
|
|
Dim nCurrCtx As Integer = EgtGetCurrentContext()
|
|
Dim nTempCtx As Integer = EgtInitContext()
|
|
If nTempCtx <> 0 Then
|
|
' inizializzo gestore lavorazioni
|
|
EgtInitMachMgr(Map.refMainWindowVM.MainWindowM.sMachinesRoot, Map.refMainWindowVM.MainWindowM.sToolMakersDir)
|
|
EgtOpenFile(SelProject.sProdPath)
|
|
' cancello tutti i gruppi di lavorazione
|
|
Dim nMachGroupId As Integer = EgtGetFirstMachGroup()
|
|
While nMachGroupId <> GDB_ID.NULL
|
|
EgtSetCurrMachGroup(nMachGroupId)
|
|
Dim nRawPartId As Integer = EgtGetFirstRawPart()
|
|
While nRawPartId <> GDB_ID.NULL
|
|
Dim nPartId As Integer = EgtGetFirstPartInRawPart(nRawPartId)
|
|
While nPartId <> GDB_ID.NULL
|
|
EgtRemovePartFromRawPart(nPartId)
|
|
' elimino pezzo copia
|
|
EgtErase(nPartId)
|
|
nPartId = EgtGetFirstPartInRawPart(nRawPartId)
|
|
End While
|
|
nRawPartId = EgtGetNextRawPart(nRawPartId)
|
|
End While
|
|
EgtRemoveMachGroup(nMachGroupId)
|
|
nMachGroupId = EgtGetFirstMachGroup()
|
|
End While
|
|
' lo salvo in tutti i proj correlati
|
|
Dim ProdFile As ProdFileVM = DirectCast(SelProject, ProdFileVM)
|
|
For Each nProjId In ProdFile.nProjIdList
|
|
EgtSaveFile(ProdFile.GetProjPath(nProjId), NGE.CMPTEXT)
|
|
Next
|
|
' torno sul contesto corrente
|
|
EgtSetCurrentContext(nCurrCtx)
|
|
EgtDeleteContext(nTempCtx)
|
|
End If
|
|
' se proj corrente era il prod cancellato, aggiorno proj corrente
|
|
If Not IsNothing(Map.refProjManagerVM.CurrProj) AndAlso Map.refProjManagerVM.CurrProj.nProdId = SelProject.nProdId Then
|
|
Map.refProjManagerVM.UpdateCurrProj()
|
|
End If
|
|
' 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
|