Attribute VB_Name = "Declarations"
' ========== Specific declarations for Word module ==========
Option Explicit

Public Const HELP_WORD_BOOKMARK = "HT03_WORD"
Public Const HELP_FILE_PATH = "\\fs1.concept.ru\Projects\10 Автоматизация деятельности\01 Высокие технологии\Концепт-НПА\!Руководство пользователя.docx"

Public Function AccessDatabase() As InfoDatabase
  Static s_AccessDatabase As InfoDatabase
  
  On Error GoTo CREATE_NEW
  Set AccessDatabase = s_AccessDatabase.Validate
  Exit Function
  
CREATE_NEW:
  Set s_AccessDatabase = New InfoDatabase
  Dim dbDoc As Excel.Workbook: Set dbDoc = GetDatabaseDocument(Word.ActiveDocument)
  If Not dbDoc Is Nothing Then _
    Call s_AccessDatabase.Init(dbDoc, GetDocumentsLocation(dbDoc))
    
  Set AccessDatabase = s_AccessDatabase
End Function

Public Function AccessWordDatabase() As InfoWordDatabase
  Static s_Database As InfoWordDatabase
  
  On Error GoTo CREATE_NEW
  Call s_Database.source_.Validate
  Set AccessWordDatabase = s_Database
  Exit Function
  
CREATE_NEW:
  Set s_Database = New InfoWordDatabase
  Call s_Database.Init(AccessDatabase)
  Set AccessWordDatabase = s_Database
End Function

Public Function GetDatabaseDocument(iReference As Word.Document) As Excel.Workbook
  Dim fso As New Scripting.FileSystemObject
  Dim sFile$: sFile = iReference.Path & "\" & HT03_DBNAME
  If Not fso.FileExists(sFile) Then _
    sFile = fso.GetParentFolderName(iReference.Path) & "\" & HT03_DBNAME
  
  Dim wrapper As New API_XLWrapper
  Set GetDatabaseDocument = wrapper.OpenDocument(sFile, bIgnoreFolder:=True)
End Function
