272 lines
9.5 KiB
VB.net
272 lines
9.5 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtBEAMWALL.Core
|
|
Imports EgtBEAMWALL.Core.ConstBeam
|
|
Imports EgtBEAMWALL.DataLayer.DatabaseModels
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class ProdManagerVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private m_CurrProd As ProdFileVM
|
|
Friend Property CurrProd As ProdFileVM
|
|
Get
|
|
Return m_CurrProd
|
|
End Get
|
|
Set(value As ProdFileVM)
|
|
m_CurrProd = value
|
|
End Set
|
|
End Property
|
|
|
|
' indice ultimo progetto
|
|
Private m_nLastProdId As Integer
|
|
Friend ReadOnly Property nLastProdId As Integer
|
|
Get
|
|
Return m_nLastProdId
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdOpen As ICommand
|
|
Private m_cmdSave As ICommand
|
|
Private m_cmdGoToProj As ICommand
|
|
|
|
#Region "ToolTip"
|
|
|
|
'Proprietà ToolTip
|
|
Public ReadOnly Property OpenToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_TOPCOMMANDBAR + 2)
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property SaveToolTip As String
|
|
Get
|
|
Return EgtMsg(MSG_TOPCOMMANDBAR + 3)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' ToolTip
|
|
|
|
#End Region ' Fields & Properties
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in Map
|
|
Map.SetRefProdManagerVM(Me)
|
|
' Leggo ultimo indice di progetto
|
|
m_nLastProdId = GetMainPrivateProfileInt(S_GENERAL, K_PRODSINDEX, 1)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Function InitNewProject(ByRef nProjId As Integer, ByRef nProdId As Integer, ByRef sProjectDir As String) As Boolean
|
|
' richiedo indice nuovo progetto
|
|
nProdId = DbControllers.m_ProdController.GetNextIndex(nProjId)
|
|
If nProdId <= 0 Then Return False
|
|
sProjectDir = refMainWindowVM.MainWindowM.sProdsDir & "\" & nProdId.ToString("0000")
|
|
' creo cartella nuovo progetto
|
|
If Not Directory.Exists(sProjectDir) Then
|
|
Directory.CreateDirectory(sProjectDir)
|
|
Else
|
|
Dim di As System.IO.DirectoryInfo = New DirectoryInfo(sProjectDir)
|
|
For Each file As FileInfo In di.EnumerateFiles()
|
|
file.Delete()
|
|
Next
|
|
For Each dir As DirectoryInfo In di.EnumerateDirectories()
|
|
dir.Delete(True)
|
|
Next
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Public Function SetCurrProd(nProdId As Integer) As Boolean
|
|
Dim Currprod As ProdModel = DbControllers.m_ProdController.FindByProdId(nProdId)
|
|
If IsNothing(Currprod) Then Return False
|
|
Map.refProdManagerVM.CurrProd = New ProdFileVM(ProdFileM.CreateProdFileM(Currprod.ProdId, New List(Of Integer), Date.Now(), ""))
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "OpenCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Open.
|
|
''' </summary>
|
|
Public ReadOnly Property OpenCommand As ICommand
|
|
Get
|
|
If m_cmdOpen Is Nothing Then
|
|
m_cmdOpen = New Command(AddressOf Open)
|
|
End If
|
|
Return m_cmdOpen
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Open. This method is invoked by the OpenCommand.
|
|
''' </summary>
|
|
Friend Sub Open()
|
|
OpenProject()
|
|
End Sub
|
|
|
|
Friend Sub OpenProject()
|
|
' verifico se progetto modificato, e chiedo se salvare
|
|
ProdFileVM.VerifyProjectModification(CurrProd)
|
|
Dim sFilePath As String = ""
|
|
' se la string è vuota
|
|
Dim TempCurrProd As ProdFileVM
|
|
Dim OpenProjectFileDialogVM As OpenProjectFileDialogVM = Nothing
|
|
' apro dialogo di scelta file
|
|
OpenProjectFileDialogVM = New OpenProjectFileDialogVM
|
|
Dim OpenFile As New OpenProjectFileDialogV(Application.Current.MainWindow, OpenProjectFileDialogVM)
|
|
Dim DialogResult As Boolean? = OpenFile.EgtShowDialog(ProjectType.PROD)
|
|
If IsNothing(DialogResult) OrElse Not DialogResult Then Return
|
|
sFilePath = OpenProjectFileDialogVM.SelProject.sProdPath
|
|
TempCurrProd = OpenProjectFileDialogVM.SelProject
|
|
If File.Exists(sFilePath) Then
|
|
If Map.refSceneHostVM.MainController.OpenProject(sFilePath, False) Then
|
|
m_CurrProd = TempCurrProd
|
|
DbControllers.m_ProdController.LockByProdId(m_CurrProd.nProdId, True)
|
|
End If
|
|
Else
|
|
MessageBox.Show("File non trovato!!")
|
|
Map.refSceneHostVM.MainController.NewProject()
|
|
Map.refMainWindowVM.SetTitle("New - EgtBEAMWALL")
|
|
End If
|
|
' aggiorno titolo
|
|
Map.refMainWindowVM.UpdateTitle()
|
|
End Sub
|
|
|
|
#End Region ' OpenCommand
|
|
|
|
#Region "SaveCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Save.
|
|
''' </summary>
|
|
Public ReadOnly Property SaveCommand As ICommand
|
|
Get
|
|
If m_cmdSave Is Nothing Then
|
|
m_cmdSave = New Command(AddressOf Save)
|
|
End If
|
|
Return m_cmdSave
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Save. This method is invoked by the SaveCommand.
|
|
''' </summary>
|
|
Public Sub Save()
|
|
If IsNothing(m_CurrProd) Then Return
|
|
Map.refSceneHostVM.SaveProject()
|
|
Map.refMainWindowVM.UpdateTitle()
|
|
Dim MyMachGroupList As New List(Of MyMachGroupM)
|
|
For Each MachGroup In Map.refProjectVM.MachGroupPanelVM.m_MyMachGroupPanelM.MachGroupMList
|
|
MyMachGroupList.Add(MachGroup)
|
|
Next
|
|
'For Each MachGroup In Map.refProjectVM.MachGroupPanelVM.MachGroupVMList
|
|
' If Map.refMachinePanelVM.SelectedMachine.nType = MachineType.BEAM Then
|
|
' MyMachGroupList.Add(BeamMachGroupM.CreateBeamMachGroup(MachGroup.Id, MachGroup.Name, MachGroup.Machine))
|
|
' ElseIf Map.refMachinePanelVM.SelectedMachine.nType = MachineType.WALL Then
|
|
' MyMachGroupList.Add(New WallMachGroup(MachGroup.Id, MachGroup.Name, MachGroup.Machine))
|
|
' End If
|
|
'Next
|
|
'If Map.refMachinePanelVM.SelectedMachine.nType = MachineType.BEAM Then
|
|
' MyMachGroupList = Map.refProjectVM.MachGroupPanelVM.MachGroupList.Select(Function(x) New Core.BeamMachGroup(x.Id, x.Name, x.Machine)).ToList()
|
|
'ElseIf Map.refMachinePanelVM.SelectedMachine.nType = MachineType.wall Then
|
|
' MyMachGroupList = Map.refProjectVM.MachGroupPanelVM.MachGroupList.Select(Function(x) New Core.WallMachGroup(x.Id, x.Name, x.Machine))
|
|
'End If
|
|
' aggiorno pezzi su Db
|
|
DbControllers.m_ProdController.UpdateMachGroup(CurrProd.nProdId, MyMachGroupList)
|
|
' se nuovo progetto
|
|
If m_CurrProd.bIsNew Then
|
|
' resetto stato new
|
|
' DbControllers.m_ProdController.Reset(CurrProd.nProjId)
|
|
m_CurrProd.bIsNew = False
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' SaveCommand
|
|
|
|
#Region "GoToProj"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Open.
|
|
''' </summary>
|
|
Public ReadOnly Property GoToProj_Command As ICommand
|
|
Get
|
|
If m_cmdGoToProj Is Nothing Then
|
|
m_cmdGoToProj = New Command(AddressOf GoToProj)
|
|
End If
|
|
Return m_cmdGoToProj
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Open. This method is invoked by the OpenCommand.
|
|
''' </summary>
|
|
Friend Sub GoToProj()
|
|
' recupero Proj associato da Db
|
|
Dim DbProjList As List(Of DataLayer.DatabaseModels.ProjModel) = DbControllers.m_ProjController.GetByProdAsc(m_CurrProd.nProdId)
|
|
Dim nProjId As Integer = 0
|
|
Dim sBTLFileName As String = ""
|
|
If Not IsNothing(DbProjList) AndAlso DbProjList.Count > 0 AndAlso DbProjList(0).ProjId > 0 Then
|
|
nProjId = DbProjList(0).ProjId
|
|
End If
|
|
' verifico se salvare progetto corrente
|
|
ProdFileVM.VerifyProjectModification(Map.refProdManagerVM.CurrProd)
|
|
'' cerco proj associato
|
|
'Dim ProjList As New List(Of ProjectFile)
|
|
'Dim AllDirsInDir As IEnumerable(Of String) = IO.Directory.EnumerateDirectories(Map.refMainWindowVM.MainWindowM.sProjsDir)
|
|
'For Each Directory In AllDirsInDir
|
|
' Dim AllFilesInDir As IEnumerable(Of String) = IO.Directory.EnumerateFiles(Directory)
|
|
' For Each File In AllFilesInDir
|
|
' If Path.GetExtension(File).ToLower() = ".nge" Then
|
|
' If File.Contains(FILENAMESEPARATOR) Then
|
|
' Dim DataFromFileName As String() = File.Split(FILENAMESEPARATOR)
|
|
' If DataFromFileName.Count = 3 Then
|
|
' If Not String.IsNullOrEmpty(DataFromFileName(1)) Then
|
|
' Dim nTempProdId As Integer = 0
|
|
' Integer.TryParse(DataFromFileName(1), nTempProdId)
|
|
' If nTempProdId = CurrProd.nProdId Then
|
|
' ProjList.Add(New ProjectFile(ProjectType.PROJ, Path.GetFileNameWithoutExtension(File)))
|
|
' End If
|
|
' End If
|
|
' End If
|
|
' End If
|
|
' End If
|
|
' Next
|
|
'Next
|
|
'If ProjList.Count = 0 Then Return
|
|
'' se c'è più di un proj
|
|
'Dim Proj As ProjectFile
|
|
'If ProjList.Count > 1 Then
|
|
' ' apro dialogo di scelta file
|
|
' Dim OpenProjectFileDialogVM As New OpenProjectFileDialogVM
|
|
' Dim OpenFile As New OpenProjectFileDialogV(Application.Current.MainWindow, OpenProjectFileDialogVM)
|
|
' Dim DialogResult As Boolean? = OpenFile.EgtShowDialog(ProjectType.PROJ, ProjList)
|
|
' If IsNothing(DialogResult) OrElse Not DialogResult Then Return
|
|
' Proj = OpenProjectFileDialogVM.SelProject
|
|
'Else
|
|
' Proj = ProjList(0)
|
|
'End If
|
|
' apro progetto proj
|
|
Map.refProjManagerVM.SetCurrProj(nProjId)
|
|
' vado in pagina proj
|
|
Map.refMainMenuVM.SetSelPage(Pages.VIEW, False)
|
|
End Sub
|
|
|
|
#End Region ' GoToProj
|
|
|
|
#End Region ' Commands
|
|
|
|
End Class
|