Attribute VB_Name = "ex_ConceptOrganization"
' ======== Concept organization specific functionality ============
' Shared module version: 20221031
' Tested in:
' Depends on:
' Required reference: Scripting
Option Private Module
Option Explicit

Public Enum TProjectType
  T_PRJ_LEAD_ACTIVE = 1
  T_PRJ_LEAD_TENTATIVE = 2
  T_PRJ_OUTCOME = 3
  T_PRJ_INCOME = 4
End Enum

Public Enum TProjectCategory
  T_PCAT_ERR = 0
  T_PCAT_MISC = 1
  T_PCAT_OUTCOME = 2
  T_PCAT_INCOME = 3
End Enum

Public Const SERVER_PATH_INCOME = "\\fs1.concept.ru\projects\01 Income-проекты"
Public Const SERVER_PATH_OUTCOME = "\\fs1.concept.ru\projects\02 Outcome-проекты"
Public Const SERVER_PATH_LEAD_ACTIVE = "\\fs1.concept.ru\projects\03 Переговоры Активные"
Public Const SERVER_PATH_LEAD_TENTATIVE = "\\fs1.concept.ru\projects\03 1 Переговоры возможные"

Public Function CCListProjects(nType As TProjectType) As Scripting.Dictionary
  Dim iProjects As New Scripting.Dictionary
  Set CCListProjects = iProjects
  
  Dim sFolder$: sFolder = GetProjectsFolder(nType)
  Dim fso As New Scripting.FileSystemObject
  If Not fso.FolderExists(sFolder) Then _
    Exit Function
  
  Dim iSubFolder As Scripting.Folder
  For Each iSubFolder In fso.GetFolder(sFolder).SubFolders
    If CCTestProjectName(iSubFolder.Name) Then _
      Call iProjects.Add(iSubFolder.Name, ProjectTypeToCategory(nType))
  Next iSubFolder
End Function

Public Function CCTestProjectName(sProject$) As Boolean
  CCTestProjectName = sProject Like "####*"
End Function

Public Function CCCategoryToString(nType As TProjectCategory) As String
  Select Case nType
  Case T_PCAT_ERR: CCCategoryToString = "ERR"
  Case T_PCAT_INCOME: CCCategoryToString = "I"
  Case T_PCAT_OUTCOME: CCCategoryToString = "O"
  Case T_PCAT_MISC: CCCategoryToString = "-"
  End Select
End Function

Public Function CCStringToCategory(sType$) As TProjectCategory
  Select Case sType
  Case "I": CCStringToCategory = T_PCAT_INCOME
  Case "O": CCStringToCategory = T_PCAT_OUTCOME
  Case "-": CCStringToCategory = T_PCAT_MISC
  Case Else: CCStringToCategory = T_PCAT_ERR
  End Select
End Function

' ============
Private Function GetProjectsFolder(nType As TProjectType) As String
  Select Case nType
  Case T_PRJ_INCOME: GetProjectsFolder = SERVER_PATH_INCOME
  Case T_PRJ_OUTCOME: GetProjectsFolder = SERVER_PATH_OUTCOME
  Case T_PRJ_LEAD_ACTIVE: GetProjectsFolder = SERVER_PATH_LEAD_ACTIVE
  Case T_PRJ_LEAD_TENTATIVE: GetProjectsFolder = SERVER_PATH_LEAD_TENTATIVE
  End Select
End Function

Private Function ProjectTypeToCategory(nType As TProjectCategory) As TProjectCategory
  Select Case nType
  Case T_PRJ_INCOME: ProjectTypeToCategory = T_PCAT_INCOME
  Case T_PRJ_OUTCOME: ProjectTypeToCategory = T_PCAT_OUTCOME
  Case T_PRJ_LEAD_ACTIVE: ProjectTypeToCategory = T_PCAT_OUTCOME
  Case T_PRJ_LEAD_TENTATIVE: ProjectTypeToCategory = T_PCAT_OUTCOME
  End Select
End Function
