Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtUILib

Public Class ProjFileVM
   Inherits ProjectFileVM

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

   Public Overrides ReadOnly Property nProjId As Integer
      Get
         Return ProjFileM.nProjId
      End Get
   End Property

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

   Public Overrides ReadOnly Property sProjDirPath As String
      Get
         If IsNothing(ProjFileM.nProjId) OrElse ProjFileM.nProjId = 0 Then Return String.Empty
         Return m_sProjsDir & "\" & nProjId.ToString("0000")
      End Get
   End Property
   Public Overrides ReadOnly Property sProjPath As String
      Get
         Dim sPath As String = String.Empty
         If IsNothing(ProjFileM.nProjId) OrElse ProjFileM.nProjId = 0 Then Return String.Empty
         sPath = m_sProjsDir & "\" & nProjId.ToString("0000") & "\" & nProjId.ToString("0000") & ".nge"
         Return sPath
      End Get
   End Property

   Public Overrides ReadOnly Property sProdDirPath As String
      Get
         Dim sPath As String = String.Empty
         If IsNothing(ProjFileM.nProdId) OrElse ProjFileM.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(ProjFileM.nProdId) OrElse ProjFileM.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 ProjFileM.bIsNew
      End Get
      Set(value As Boolean)
         ProjFileM.bIsNew = value
      End Set
   End Property

   Public ReadOnly Property sBTLFileName As String
      Get
         Return ProjFileM.sBTLFileName
      End Get
   End Property

   Public ReadOnly Property sDescription As String
      Get
         Return ProjFileM.sDescription
      End Get
   End Property

   Public ReadOnly Property sListName As String
      Get
         Return ProjFileM.sListName
      End Get
   End Property

   Public ReadOnly Property dtExportDate As DateTime
      Get
         Return ProjFileM.dtExportDate
      End Get
   End Property

#Region "CONSTRUCTORS"

   Sub New(ProjectFileM As ProjFileM)
      m_ProjectFileM = ProjectFileM
   End Sub

#End Region    ' CONSTRUCTORS

#Region "METHODS"

   Public Sub SetBTLFileName(BTLFileName As String)
      ProjFileM.sBTLFileName = BTLFileName
   End Sub

   ' 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 Region    ' METHODS

End Class