Imports EgtBEAMWALL.Core

Module ProjectManagerVM

   Private m_CurrProj As ProjFileVM
   Friend Property CurrProj As ProjFileVM
      Get
         Return m_CurrProj
      End Get
      Set(value As ProjFileVM)
         m_CurrProj = value
      End Set
   End Property

   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 progetto in caricamento
   Private m_nLoadingProjId As Integer = 0
   Friend Property nLoadingProjId As Integer
      Get
         Return m_nLoadingProjId
      End Get
      Set(value As Integer)
         m_nLoadingProjId = value
      End Set
   End Property

   Public Function SetCurrProj(nProjId As Integer) As Boolean
      Dim CurrProjM As ProjFileM = DbControllers.m_ProjController.FindByProjIdConv(nProjId)
      If IsNothing(CurrProjM) Then Return False
      m_CurrProj = New ProjFileVM(CurrProjM)
      If Map.refMainWindowVM.MainWindowM.bOnlyProd AndAlso CurrProjM.nProdId > 0 AndAlso IsNothing(CurrProd) Then
         SetCurrProd(m_CurrProj.nProdId)
      End If
      Return True
   End Function

   Public Function SetCurrProd(nProdId As Integer) As Boolean
      Dim CurrProdM As ProdFileM = DbControllers.m_ProdController.FindCoreByProdId(nProdId)
      If IsNothing(CurrProdM) Then Return False
      m_CurrProd = New ProdFileVM(CurrProdM)
      If Map.refMainWindowVM.MainWindowM.bOnlyProd AndAlso CurrProdM.nProjIdList.Count > 0 AndAlso IsNothing(CurrProj) Then
         SetCurrProj(m_CurrProd.nProjIdList(0))
      End If
      Return True
   End Function

End Module
