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
| Public Sub remplissageTreeView(oT As Object, odb As DAO.Database, Optional intRessource As Integer = 0, Optional intRang As Integer = 0)
Dim Aaffiche As Boolean
Dim strSQL As String
Dim strSQLtestSurN2 As String
Dim strSQLConditionCaseACocher As String
Dim oRst As DAO.Recordset
Dim oRstTestSurN2 As DAO.Recordset
Dim strLibelle As String
Dim IndexCount As Integer 'numero d'index du noeud en cours
Dim NumCocheN1 As Integer 'nombre de fils qui ont une case à cocher d'activée
Dim NumCocheN2 As Integer
Dim NumCocheN0 As Integer 'pour verif si la ressouce en cours est à afficher
Dim DejaUnTruc As Boolean
Dim NumImage As Integer
'vérification que il y a au moins une case à cochée de cochée
If (Me.Coch_NonUtilise.Value = False And Me.Coch_Accessoires.Value = False And Me.Coch_SuivContrat.Value = False And Me.Coch_SuiviSecu.Value = False And Me.Coch_SuiviQ.Value = False And Me.Coch_MachineProd.Value = False) Then Me.Coch_MachineProd.Value = True
'###on determine le filtre à utiliser pour les tests d'affichage des ressources
strSQLConditionCaseACocher = "AND (" 'initialisation du filtre
DejaUnTruc = False 'on initialise le flag qui sert à la creation de ce filtre
If Me.Coch_MachineProd.Value = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & "[C_MachineProd]= True OR [C_SuiviQ]= True"
DejaUnTruc = True
End If
If Me.Coch_SuiviQ.Value = True Then
If DejaUnTruc = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " OR [C_SuiviQ]= True"
Else
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " [C_SuiviQ]= True"
DejaUnTruc = True
End If
End If
If Me.Coch_SuiviSecu.Value = True Then
If DejaUnTruc = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " OR [C_SuiviSecu]= True"
Else
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " [C_SuiviSecu]= True"
DejaUnTruc = True
End If
End If
If Me.Coch_SuivContrat.Value = True Then
If DejaUnTruc = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " OR [C_suiviContrat]= True"
Else
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " [C_suiviContrat]= True"
DejaUnTruc = True
End If
End If
If Me.Coch_Accessoires.Value = True Then
If DejaUnTruc = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " OR [C_Accessoires]= True"
Else
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " [C_Accessoires]= True"
DejaUnTruc = True
End If
End If
If Me.Coch_NonUtilise.Value = True Then
If DejaUnTruc = True Then
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " OR [C_NonUtilise]= True"
Else
strSQLConditionCaseACocher = strSQLConditionCaseACocher & " [C_NonUtilise]= True"
DejaUnTruc = True
End If
End If
strSQLConditionCaseACocher = strSQLConditionCaseACocher & ")" 'fin du filtre
'###FIN on determine le filtre à utiliser pour les tests d'affichage des ressources
strSQL = "SELECT NumRessource,CODERESS,NumImage,NumImageSelected,OrdreAffichage,C_MachineProd,C_SuiviQ,C_SuiviSecu,C_suiviContrat,C_Accessoires,C_NonUtilise FROM Ress WHERE NumParent=" & intRessource & " ORDER BY OrdreAffichage"
Set oRst = odb.OpenRecordset(strSQL)
With oRst
While Not oRst.EOF
IndexCount = oT.Nodes.Count
strLibelle = .Fields(1).Value
' ##### test s'il faut afficher
Aaffiche = False 'par défaut il ne faut pas afficher
' si NumCocheN0 N1 ou N2 >0 alors il faut afficher car presence d'une ressource à afficher dans l'arborescence inférieure
'on regarde s'il y a des cases à cocher pour cette ressource
NumCocheN0 = DCount("*", "Ress", "[NumRessource]= " & oRst.Fields(0).Value & strSQLConditionCaseACocher)
If NumCocheN0 > 0 Then
Aaffiche = True
NumImage = oRst.Fields(2).Value
GoTo fin1
End If
'on regarde s'il y a des cases à cocher dans les n-1 de cette ressource
NumCocheN1 = DCount("*", "Ress", "[NumParent]= " & oRst.Fields(0).Value & strSQLConditionCaseACocher)
If NumCocheN1 > 0 Then
Aaffiche = True
NumImage = 2
GoTo fin1
End If
'on regarde pour le niveau n-2 de tous les niveaux n-1 de l'objet
strSQLtestSurN2 = "SELECT NumRessource FROM Ress WHERE NumParent=" & oRst.Fields(0).Value
Set oRstTestSurN2 = odb.OpenRecordset(strSQLtestSurN2) ' dans ce recorset on va voir s'il y a une case à cocher d'active
While Not oRstTestSurN2.EOF
NumCocheN2 = DCount("*", "Ress", "[NumParent]= " & oRstTestSurN2.Fields(0).Value & strSQLConditionCaseACocher)
If NumCocheN2 > 0 Then
Aaffiche = True
NumImage = 2
GoTo fin2
End If
oRstTestSurN2.MoveNext 'Passe à l'enregistrement suivant
Wend
fin2:
oRstTestSurN2.Close: Set oRstTestSurN2 = Nothing 'fermeture du recorset et libération mémoire
fin1:
' ##### FIN test s'il faut afficher
If Aaffiche = True Then
If intRessource = 0 Then
oT.Nodes.Add , , "Atel_" & oRst.Fields(0).Value, strLibelle, NumImage, oRst.Fields(3).Value
' test si on déploie ou pas le treeview pour les noeuds de premier niveau (la racine)
If Me.ExpandN1.Value = True Then
oT.Nodes("Atel_" & oRst.Fields(0).Value).Expanded = True
End If
remplissageTreeView oT, odb, oRst.Fields(0).Value, 1
Else
If intRang = 1 Then
oT.Nodes.Add "Atel_" & intRessource, tvwChild, "Ress_" & oRst.Fields(0).Value, strLibelle, NumImage, oRst.Fields(3).Value
'test si on déploie ou pas le treeview pour les noeuds de niveau 2 et plus
If Me.ExpandN2.Value = True Then
oT.Nodes("Ress_" & oRst.Fields(0).Value).Expanded = True
End If
remplissageTreeView oT, odb, oRst.Fields(0).Value, 2
Else
oT.Nodes.Add "Ress_" & intRessource, tvwChild, "Part_" & oRst.Fields(0).Value, strLibelle, NumImage, oRst.Fields(3).Value
End If
End If
End If
oRst.MoveNext 'Passe à l'enregistrement suivant
Wend
End With
oRst.Close: Set oRst = Nothing 'Ferme le recordset
End Sub |
Partager