Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtUILib

Public Class ProdFileVM
   Inherits ProjectFileVM

   Public ReadOnly Property ProdFileM As ProdFileM
      Get
         Return m_ProjectFileM
      End Get
   End Property

   Public ReadOnly Property nProjIdList As List(Of Integer)
      Get
         Return ProdFileM.nProjIdList
      End Get
   End Property

   Public Overrides ReadOnly Property nProdId As Integer
      Get
         Return ProdFileM.nProdId
      End Get
   End Property

   Public Overrides ReadOnly Property sProdDirPath As String
      Get
         Dim sPath As String = String.Empty
         If IsNothing(ProdFileM.nProdId) OrElse ProdFileM.nProdId = 0 Then Return String.Empty
         Return m_sProdsDir & "\" & nProdId.ToString("0000")
      End Get
   End Property
   Public Overrides ReadOnly Property sProdPath As String
      Get
         Dim sPath As String = String.Empty
         If IsNothing(ProdFileM.nProdId) OrElse ProdFileM.nProdId = 0 Then Return String.Empty
         Return m_sProdsDir & "\" & nProdId.ToString("0000") & "\" & nProdId.ToString("0000") & ".nge"
      End Get
   End Property

   Public Overrides Property bIsNew As Boolean
      Get
         Return ProdFileM.bIsNew
      End Get
      Set(value As Boolean)
         ProdFileM.bIsNew = value
      End Set
   End Property

   Public Property sName As String
      Get
         Return ProdFileM.sName
      End Get
      Set(value As String)
         ProdFileM.sName = value
      End Set
   End Property

   Private m_sBTLFileName As String
   Public ReadOnly Property sBTLFileName As String
      Get
         Return m_sBTLFileName
      End Get
   End Property
   Protected Sub SetBTLFileName(value As String)
      m_sBTLFileName = value
   End Sub

   Public ReadOnly Property bIsProduced As Boolean
      Get
         Return ProdFileM.bIsProduced
      End Get
   End Property

#Region "CONSTRUCTORS"

   Sub New(ProdFileM As ProdFileM)
      m_ProjectFileM = ProdFileM
   End Sub

#End Region    ' CONSTRUCTORS

   Friend Function GetProjPath(nProjId As Integer)
      Dim sPath As String = String.Empty
      If nProjId = 0 Then Return String.Empty
      Return m_sProjsDir & "\" & nProjId.ToString("0000") & "\" & nProjId.ToString("0000") & ".nge"
   End Function

   ' funzione che restituisce le parti di nome file
   Friend Shared Function VerifyProjectFile(nProjectType As ProjectType, ProjectFileName As String, ByRef nProjId As Integer, ByRef nProdId As Integer, ByRef sBTLFileName As String) As Boolean
      If nProjectType = ProjectType.PROJ Then
         Dim DataFromFileName As String() = ProjectFileName.Split(FILENAMESEPARATOR)
         If DataFromFileName.Count = 3 Then
            If Not String.IsNullOrEmpty(DataFromFileName(0)) Then
               Integer.TryParse(DataFromFileName(0), nProjId)
            Else Return False
            End If
            If Not String.IsNullOrEmpty(DataFromFileName(1)) Then
               Integer.TryParse(DataFromFileName(1), nProdId)
            Else
               nProdId = 0
            End If
            If Not String.IsNullOrEmpty(DataFromFileName(2)) Then
               sBTLFileName = DataFromFileName(2)
            End If
            Return True
         Else Return False
         End If
      ElseIf nProjectType = ProjectType.PROD Then
         Return Integer.TryParse(ProjectFileName, nProdId)
      Else Return False
      End If
   End Function

End Class