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
   |  
'Je vérifie lors de la sélection des clients, si on applique un filtre ou si on charge simplement tous les clients
If UBound(filtres) > 0 Then
            'Je vérifie si ma recherche est global ou sélective (ce n'est pas important, j'ai juste un système de recherche global ou on recherche une partie d'un mot dans tous les champs, ou un système de recherche par champ que je n'ai pas encore implanté)
            If filtres(UBound(filtres)) = False Then
                'Là je sélectionne toutes les colonnes de ma table client afin de rechercher dans tous mes champs n'importe quel valeur entrée
                DA1.SelectCommand = cmd1
                DA1.SelectCommand.Connection = cn
                DA1.SelectCommand.CommandText = "SELECT column_name FROM information_schema.columns where table_name='client' and (data_type='character' or data_type='text');"
                DS1 = New DataSet("data")
                DA1.Fill(DS1)
 
                'Là je fais un select en générant une requête à partir des champs se trouvant dans ma base client
                DA.SelectCommand = cmd
                DA.SelectCommand.Connection = cn
                DA.SelectCommand.CommandText = "SELECT * from client WHERE"
                splitedFiltre = Split(filtres(0), " ")
                For j = 0 To DS1.Tables(0).Rows.Count - 1
                    For i = 0 To UBound(splitedFiltre)
                        If i <> 0 Or j <> 0 Then DA.SelectCommand.CommandText = DA.SelectCommand.CommandText & " OR"
                        DA.SelectCommand.CommandText = DA.SelectCommand.CommandText & " UPPER(" & DS1.Tables(0).Rows.Item(j).ItemArray(0).ToString & ") LIKE"
                        DA.SelectCommand.CommandText = DA.SelectCommand.CommandText & " UPPER('%" & splitedFiltre(i) & "%')"
                    Next i
                Next j
                DA.SelectCommand.CommandText = DA.SelectCommand.CommandText & " ORDER BY nom;"
                DS = New DataSet("data")
                DA.Fill(DS)
                If DS.Tables(0).Rows.Count = 0 Then
                    MsgBox("Votre recherche n'a retournée aucun résultat")
                    loadClients()
                    bt_retablir.Enabled = False
                Else
                    Filtre.Close()
                    bt_retablir.Enabled = True
                End If
            'Pour implémenter le système de filtre plus tard
            ElseIf filtres(UBound(filtres)) = True Then
            End If
        Else
            'La commande exécutée au démarrage de l'appli ou lorsqu'on annule un filtre. Un simple select de toute ma base
            DA.SelectCommand = cmd
            DA.SelectCommand.Connection = cn
            DA.SelectCommand.CommandText = "SELECT * from client WHERE nom <> '' ORDER BY nom;"
            DS = New DataSet("data")
            DA.Fill(DS)
            bt_retablir.Enabled = False
        End If
 
        lb_Clients.DataSource = DS.Tables(0)
        lb_Clients.DisplayMember = "Nom" | 
Partager