OA_Import.bas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. Option Compare Database
  2. Option Explicit
  3. Public Sub ImportAll()
  4. Dim db As DAO.Database
  5. Dim FSO As Object
  6. logger "ImportAll", "INFO", "Begin 'Import all sources'"
  7. Set FSO = CreateObject("Scripting.FileSystemObject")
  8. Set db = CurrentDb
  9. If Not FSO.FolderExists(source_dir()) Then
  10. logger "ImportAll", "CRITICAL", "No source found at:" & source_dir
  11. End If
  12. ' close any opened form or report, except OpenAccess's form
  13. Call CloseFormsReports
  14. ' import database properties
  15. Call ImportProperties(CurrentDb, joinpaths(source_dir, "database.properties"))
  16. Call ImportAllQueries
  17. Call ImportAllTblDefs
  18. Call ImportAllTableDatas
  19. Call ImportAllDataMacros
  20. Call ImportAllDocs(acForm)
  21. Call ImportAllDocs(acReport)
  22. Call ImportAllPrintVars
  23. Call ImportAllDocs(acMacro)
  24. Call ImportReferences
  25. Call ImportAllDocs(acModule)
  26. Call ImportAllRelations
  27. SaveProject
  28. logger "ImportAll", "INFO", "Import done"
  29. End Sub
  30. Public Sub ImportAllQueries()
  31. Dim dirpath, obj_name As String
  32. Dim filename As Variant
  33. Dim count, total As Integer
  34. dirpath = joinpaths(source_dir(), "queries\")
  35. logger "ImportAllQueries", "INFO", "Import queries"
  36. logger "ImportAllQueries", "DEBUG", "> import from: " & dirpath
  37. count = 0
  38. total = 0
  39. Dim to_import As String
  40. to_import = list_files_in(dirpath, "*.bas")
  41. total = UBound(Split(to_import, "|")) + 1
  42. If Len(to_import) > 0 Then
  43. For Each filename In Split(to_import, "|")
  44. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  45. obj_name = to_accessname(obj_name)
  46. ImportDocument acQuery, obj_name, joinpaths(dirpath, filename)
  47. count = count + 1
  48. Call SysCmd(acSysCmdSetStatus, "Import query: " & count & " on " & total)
  49. filename = dir$()
  50. Next filename
  51. logger "ImportAllQueries", "INFO", "> " & count & " queries imported"
  52. Else
  53. logger "ImportAllQueries", "INFO", "> No query to import"
  54. End If
  55. Call SysCmd(acSysCmdClearStatus)
  56. End Sub
  57. Public Sub ImportAllTblDefs()
  58. Dim dirpath, obj_name As String
  59. Dim filename As Variant
  60. Dim count, total As Integer
  61. dirpath = joinpaths(source_dir(), "tbldefs\")
  62. logger "ImportAllTblDefs", "INFO", "Import table defs"
  63. logger "ImportAllTblDefs", "DEBUG", "> import from: " & dirpath
  64. count = 0
  65. total = 0
  66. Dim to_import As String
  67. to_import = list_files_in(dirpath, "*.sql")
  68. total = UBound(Split(to_import, "|")) + 1
  69. If Len(to_import) > 0 Then
  70. For Each filename In Split(to_import, "|")
  71. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  72. obj_name = to_accessname(obj_name)
  73. ImportTableDef CStr(obj_name), dirpath
  74. count = count + 1
  75. Call SysCmd(acSysCmdSetStatus, "Import tabledef: " & count & " on " & total)
  76. Next filename
  77. logger "ImportAllTblDefs", "INFO", "> " & count & " TblDefs imported"
  78. Else
  79. logger "ImportAllTblDefs", "INFO", "> No tabledef to import"
  80. End If
  81. Call SysCmd(acSysCmdClearStatus)
  82. End Sub
  83. Public Sub ImportAllLinkedTables()
  84. Dim dirpath, obj_name As String
  85. Dim filename As Variant
  86. Dim count, total As Integer
  87. dirpath = joinpaths(source_dir(), "tbldef\")
  88. logger "ImportAllLinkedTables", "INFO", "Import linked tables"
  89. logger "ImportAllLinkedTables", "DEBUG", "> import from: " & dirpath
  90. count = 0
  91. total = 0
  92. Dim to_import As String
  93. to_import = list_files_in(dirpath, "*.LNKD")
  94. total = UBound(Split(to_import, "|")) + 1
  95. If Len(to_import) > 0 Then
  96. For Each filename In Split(to_import, "|")
  97. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  98. obj_name = to_accessname(obj_name)
  99. ImportLinkedTable CStr(obj_name), dirpath
  100. count = count + 1
  101. Call SysCmd(acSysCmdSetStatus, "Import linked table: " & count & " on " & total)
  102. Next filename
  103. logger "ImportAllLinkedTables", "INFO", "> " & count & " Linked TblDefs imported"
  104. Else
  105. logger "ImportAllLinkedTables", "INFO", "> No linked table to import"
  106. End If
  107. Call SysCmd(acSysCmdClearStatus)
  108. End Sub
  109. Public Sub ImportAllTableDatas()
  110. Dim dirpath, obj_name As String
  111. Dim filename As Variant
  112. Dim count, total As Integer
  113. dirpath = joinpaths(source_dir(), "tables\")
  114. logger "ImportAllTableDatas", "INFO", "Import table datas"
  115. logger "ImportAllTableDatas", "DEBUG", "> import from: " & dirpath
  116. count = 0
  117. total = 0
  118. Dim to_import As String
  119. to_import = list_files_in(dirpath, "*.txt")
  120. total = UBound(Split(to_import, "|")) + 1
  121. If Len(to_import) > 0 Then
  122. For Each filename In Split(to_import, "|")
  123. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  124. obj_name = to_accessname(obj_name)
  125. ImportTableData CStr(obj_name), dirpath
  126. count = count + 1
  127. Call SysCmd(acSysCmdSetStatus, "Import table data: " & count & " on " & total)
  128. Next filename
  129. logger "ImportAllTableDatas", "INFO", "> " & count & " table's data imported"
  130. Else
  131. logger "ImportAllTableDatas", "INFO", "> " & count & " table's data imported"
  132. End If
  133. Call SysCmd(acSysCmdClearStatus)
  134. End Sub
  135. Public Sub ImportAllDataMacros()
  136. Dim dirpath, obj_name As String
  137. Dim filename As Variant
  138. Dim count, total As Integer
  139. dirpath = joinpaths(source_dir(), "tbldef\")
  140. logger "ImportAllDataMacros", "INFO", "Import DataMacros"
  141. logger "ImportAllDataMacros", "DEBUG", "> import from: " & dirpath
  142. count = 0
  143. total = 0
  144. Dim to_import As String
  145. to_import = list_files_in(dirpath, "*.xml")
  146. total = UBound(Split(to_import, "|")) + 1
  147. If Len(to_import) > 0 Then
  148. For Each filename In Split(to_import, "|")
  149. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  150. obj_name = to_accessname(obj_name)
  151. ImportDataMacros obj_name, dirpath
  152. Call SysCmd(acSysCmdSetStatus, "Import DataMacro: " & count & " on " & total)
  153. count = count + 1
  154. Next filename
  155. logger "ImportAllDataMacros", "INFO", "> " & count & " DataMacros imported"
  156. Else
  157. logger "ImportAllDataMacros", "INFO", "> " & count & " DataMacros imported"
  158. End If
  159. Call SysCmd(acSysCmdClearStatus)
  160. End Sub
  161. Public Sub ImportAllDocs(ByVal acType As Integer, Optional ByVal encoding = "utf-8")
  162. Dim doc_label As String
  163. Dim dirpath, obj_name As String
  164. Dim filename As Variant
  165. Dim count, total As Integer
  166. 'get the document's container's name from it's type
  167. doc_label = get_container_name(acType)
  168. If Len(doc_label) = 0 Then
  169. logger "ImportAllDocs", "CRITICAL", "acType " & acType & " is not recognized!"
  170. Exit Sub
  171. End If
  172. dirpath = joinpaths(source_dir(), doc_label & "\")
  173. logger "ImportAllDocs", "INFO", "# Import " & doc_label
  174. logger "ImportAllDocs", "DEBUG", "> import from: " & dirpath
  175. count = 0
  176. total = 0
  177. Dim to_import As String
  178. to_import = list_files_in(dirpath, "*.bas")
  179. total = UBound(Split(to_import, "|")) + 1
  180. If Len(to_import) > 0 Then
  181. For Each filename In Split(to_import, "|")
  182. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  183. obj_name = to_accessname(obj_name)
  184. If IsNotVCS(obj_name) Then
  185. ImportDocument acType, obj_name, joinpaths(dirpath, filename)
  186. Else
  187. logger "ImportAllDocs", "WARNING", "Module " & obj_name & " could not be updated while running. Ensure latest version is included!"
  188. End If
  189. count = count + 1
  190. Call SysCmd(acSysCmdSetStatus, "Import " & doc_label & ": " & count & " on " & total)
  191. Next filename
  192. logger "ImportAllDocs", "INFO", "> " & count & " " & doc_label & " imported"
  193. Else
  194. logger "ImportAllDocs", "INFO", "> No " & doc_label & " to import"
  195. End If
  196. Call SysCmd(acSysCmdClearStatus)
  197. End Sub
  198. Public Sub ImportAllPrintVars()
  199. Dim dirpath, obj_name As String
  200. Dim filename As Variant
  201. Dim count, total As Integer
  202. dirpath = joinpaths(source_dir(), "reports\")
  203. logger "ImportAllPrintVars", "INFO", "Import Print Vars"
  204. logger "ImportAllPrintVars", "DEBUG", "> import from: " & dirpath
  205. count = 0
  206. total = 0
  207. Dim to_import As String
  208. to_import = list_files_in(dirpath, "*.pv")
  209. total = UBound(Split(to_import, "|")) + 1
  210. If Len(to_import) > 0 Then
  211. For Each filename In Split(to_import, "|")
  212. obj_name = Mid$(filename, 1, InStrRev(filename, ".") - 1)
  213. obj_name = to_accessname(obj_name)
  214. ImportPrintVars obj_name, joinpaths(dirpath, filename)
  215. count = count + 1
  216. Call SysCmd(acSysCmdSetStatus, "Import Print Vars: " & count & " on " & total)
  217. Next filename
  218. logger "ImportAllPrintVars", "INFO", "> " & count & " Print Vars imported"
  219. Else
  220. logger "ImportAllPrintVars", "INFO", "> No Print Vars to import"
  221. End If
  222. Call SysCmd(acSysCmdClearStatus)
  223. End Sub
  224. Public Sub ImportAllRelations()
  225. Dim dirpath As String
  226. Dim filename As Variant
  227. Dim count, total As Integer
  228. dirpath = joinpaths(source_dir(), "relations\")
  229. logger "ImportAllRelations", "INFO", "Import Relations"
  230. logger "ImportAllRelations", "DEBUG", "> import from: " & dirpath
  231. count = 0
  232. total = 0
  233. Dim to_import As String
  234. to_import = list_files_in(dirpath, "*.txt")
  235. total = UBound(Split(to_import, "|")) + 1
  236. If Len(to_import) > 0 Then
  237. For Each filename In Split(to_import, "|")
  238. ImportRelation joinpaths(dirpath, filename)
  239. count = count + 1
  240. Call SysCmd(acSysCmdSetStatus, "Import relation: " & count & " on " & total)
  241. Next filename
  242. logger "ImportAllRelations", "INFO", "> " & count & " Relations imported"
  243. Else
  244. logger "ImportAllRelations", "INFO", "> No relation to import"
  245. End If
  246. Call SysCmd(acSysCmdClearStatus)
  247. End Sub