|
Персоны, должности и предприятия
#35809792
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
|
Я сделал формиррование дерева для дерева организации через шейпы, но потом пришел к выводу, что через циклы с обычныим рекордсетами удобнее.
Посему код формы дерева с организациями не буду приводить, но многие формы у меня работают аналогично. Заполняется дерево в левой части, при клике по узлу передергивается форма в правой части.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297.
Option Compare Database
Option Explicit
Public SourceObject
Public NodeKey
Public Function LoadTree()
Dim rs1 As ADODB.Recordset, rs2 As ADODB.Recordset, rs3 As ADODB.Recordset
Dim nodeFirst As node, node1 As node, node2 As node, node3 As node
Me.treeCtl.Nodes.Clear
Set nodeFirst = Me.treeCtl.Nodes.Add( _
Key:="ROOT", _
Text:="Все типы вложений" _
)
Set rs1 = CurrentProject.Connection.Execute( _
"SELECT * " & _
"FROM TBD_AttachmentType " & _
"ORDER BY iAttachmentTypeNomer ")
Do While Not rs1.EOF
Set node1 = Me.treeCtl.Nodes.Add( _
relative:=nodeFirst.index, relationship:=tvwChild, _
Key:="L1" & rs1!sAttachmentTypeCode, Text:=rs1!sAttachmentTypeCode & " " & rs1!sAttachmentTypeName _
)
Set rs2 = CurrentProject.Connection.Execute( _
"SELECT * " & _
"FROM TBD_AttachmentDocType " & _
"WHERE sAttachmentTypeCode='" & rs1!sAttachmentTypeCode & "'" & _
"ORDER BY iAttachmentDocTypeNomer ")
Do While Not rs2.EOF
Set node2 = Me.treeCtl.Nodes.Add( _
relative:=node1.index, relationship:=tvwChild, _
Key:="L2" & rs2!sAttachmentDocTypeCode, Text:=rs2!sAttachmentDocTypeCode & " " & rs2!sAttachmentDocTypeName _
)
Set rs3 = CurrentProject.Connection.Execute( _
"SELECT * " & _
"FROM qrAttachmentDocBase " & _
"WHERE sAttachmentDocTypeCode='" & rs2!sAttachmentDocTypeCode & "'" & _
"ORDER BY dtAttachmentDocDate, iAttachmentDocID ")
Do While Not rs3.EOF
Set node3 = Me.treeCtl.Nodes.Add( _
relative:=node2.index, relationship:=tvwChild, _
Key:="L3" & rs3!iAttachmentDocID, Text:=rs3!sDataSourceIDFieldValue & " " & rs3!sDataSourceAliasFieldValue _
)
rs3.MoveNext
Loop
rs2.MoveNext
Loop
rs1.MoveNext
Loop
End Function
Private Sub form_Load()
SourceObject = ""
NodeKey = ""
Call Me.LoadTree
With Me.treeCtl
.style = 7
.Indentation = 300
.LineStyle = 1
.Visible = True
.SetFocus
.OLEDragMode = 1 ' ccOLEDragAutomatic
.OLEDropMode = 1 ' ccOLEDropManual
End With
Dim n As node
Set n = Me.treeCtl.Nodes("ROOT")
n.Expanded = True
n.Selected = True
NodeClick n, True
End Sub
Private Sub treeCtl_NodeClick(ByVal oNode As Object)
NodeClick oNode, True
End Sub
Public Function SubOnOff(bVisible As Boolean)
Me.subForm.Visible = bVisible: Me.boxSub.Visible = (Not bVisible)
Me.Repaint: Me.Painting = bVisible
DoCmd.Hourglass (Not bVisible)
End Function
Public Function NodeClick(n As node, Optional bVisualEffect As Boolean = True)
SubOnOff False
If Not n Is Nothing Then
NodeKey = n.Key
Dim s As String, ss() As String
s = n.FullPath
ss = Split(s, "\")
Select Case UBound(ss)
Case 0
If n.Key = "ROOT" Then
If SourceObject <> "subForm0" Then
SourceObject = "subForm0"
Me.subForm.SourceObject = Me.Name & "_subForm0"
With Me.lblSub
.Visible = True
.Caption = "Все типы вложений"
End With
End If
Me.subForm.Form.RecordSource = _
"SELECT * " & _
"FROM TBD_AttachmentType " & _
"ORDER BY iAttachmentTypeNomer "
End If
Case 1
If SourceObject <> "subForm1" Then
SourceObject = "subForm1"
Me.subForm.SourceObject = Me.Name & "_subForm1"
With Me.lblSub
.Visible = True
.Caption = "Данные типа вложений"
End With
End If
Me.subForm.Form.RecordSource = _
"SELECT * " & _
"FROM TBD_AttachmentType " & _
"WHERE sAttachmentTypeCode='" & Mid(n.Key, 3) & "' " & _
"ORDER BY iAttachmentTypeNomer "
Me.subForm.Form.ResizeForm Me.subForm.Height - 30 , Me.subForm.Width - 30
Case 2
If SourceObject <> "subForm2" Then
SourceObject = "subForm2"
Me.subForm.SourceObject = Me.Name & "_subForm2"
With Me.lblSub
.Visible = True
.Caption = "Данные типа вложенных документов"
End With
End If
Me.subForm.Form.RecordSource = _
"SELECT * " & _
"FROM TBD_AttachmentDocType " & _
"WHERE sAttachmentDocTypeCode='" & Mid(n.Key, 3) & "' " & _
"ORDER BY iAttachmentDocTypeNomer"
Me.subForm.Form.ResizeForm Me.subForm.Height - 30 , Me.subForm.Width - 30
Case 3
Me.iAttachmentDocID = Mid(n.Key, 3 )
If SourceObject <> "subForm3" Then
SourceObject = "subForm3"
Me.subForm.SourceObject = "frmAttachmentDoc"
With Me.lblSub
.Visible = True
.Caption = "Данные вложенного документа"
End With
End If
Me.subForm.Form.RecordSource = _
"SELECT * " & _
"FROM qrAttachmentDoc " & _
"WHERE iAttachmentDocID=" & Mid(n.Key, 3 ) & " " & _
"ORDER BY iAttachmentDocTypeNomer"
Me.subForm.Form.ResizeForm Me.subForm.Height - 30 , Me.subForm.Width - 30
End Select
Else
NodeKey = ""
End If
If Me.subForm.SourceObject <> "" Then
Dim b As Boolean: b = modUser.IsSuperUser()
With Me.subForm.Form
.AllowAdditions = b
.AllowDeletions = b
.AllowEdits = b
End With
End If
SubOnOff True
End Function
Private Sub btnExpandAll_Click()
Dim n As node
For Each n In Me.treeCtl.Nodes
n.Expanded = True
Next n
Me.treeCtl.SetFocus
End Sub
Private Sub btnCollapseAll_Click()
Dim n As node
For Each n In Me.treeCtl.Nodes
If Left(n.Key, 4 ) = "ROOT" Then
n.Expanded = True
Else
n.Expanded = False
End If
Next n
Me.treeCtl.SetFocus
End Sub
Private Sub btnRequery_Click()
If Me.NodeKey <> "" Then
LoadTree
Dim n As node
Set n = Me.treeCtl.Nodes(NodeKey)
n.EnsureVisible
n.Selected = True
NodeClick Me.treeCtl.Nodes(NodeKey)
Me.treeCtl.SetFocus
End If
End Sub
Private Sub btnOpenDocClassForm_Click()
DoCmd.OpenForm "frmDocClass", acNormal, , , acFormEdit, acWindowNormal
Me.treeCtl.SetFocus
End Sub
Private Sub btnOpenDatasourceForm_Click()
DoCmd.OpenForm "frmMETA_Datasource", acNormal, , , acFormEdit, acWindowNormal
Me.treeCtl.SetFocus
End Sub
Private Sub Form_Resize()
On Error Resume Next
Me.Painting = False
Dim w
With Me!btnExpandAll
.Left = 100 : .Top = 100
End With
With Me!btnCollapseAll
.Left = Me!btnExpandAll.Left + Me!btnExpandAll.Width
.Top = Me!btnExpandAll.Top
End With
With Me!btnRequery
.Left = Me!btnCollapseAll.Left + Me!btnCollapseAll.Width + 100
.Top = Me!btnCollapseAll.Top
End With
With Me.btnOpenDocClassForm
.Left = Me!btnRequery.Left + Me!btnRequery.Width + 100
.Top = Me!btnRequery.Top
End With
With Me.btnOpenDatasourceForm
.Left = Me!btnOpenDocClassForm.Left + Me!btnOpenDocClassForm.Width + 100
.Top = Me!btnOpenDocClassForm.Top
End With
With Me.lblTree
.Left = Me!btnExpandAll.Left
.Top = Me!btnExpandAll.Top + Me!btnExpandAll.Height + 100
w = Me.InsideWidth * 0 . 35
If w > 5000 Then w = 5000
If w < 2000 Then w = 2000
.Width = w
End With
With Me.treeCtl
.Left = Me.lblTree.Left
.Top = Me.lblTree.Top + Me.lblTree.Height
.Width = Me.lblTree.Width + 15
Dim h: h = Me.InsideHeight - .Top - 60
If h < 1000 Then h = 1000
.Height = h
End With
With Me.lblSub
.Left = Me.lblTree.Left + Me.lblTree.Width + 100
.Top = Me.lblTree.Top
w = Me.InsideWidth - .Left - 60
If w < 1000 Then w = 1000
.Width = w
End With
With Me.subForm
.Left = Me.lblSub.Left
.Top = Me.lblSub.Top + Me.lblSub.Height
.Width = Me.lblSub.Width
.Height = Me.treeCtl.Height - 15
End With
On Error Resume Next
Me.subForm.Form.ResizeForm Me.subForm.Height - 30 , Me.subForm.Width - 30
On Error GoTo 0
With Me.treeCtl
Me.boxTree.Move .Left, .Top, .Width, .Height
End With
With Me.subForm
Me.boxSub.Move .Left, .Top, .Width, .Height
End With
Me.Painting = True
End Sub
|
|
|