Bonjour à tous,

Tout d'abord, un grand merci à ceux qui se pencheront sur mon problème car je suis un pur autodidacte....

Je réalise un programme qui permet de configurer des boutons (12 boutons au total) (image, image Mouse Hover, Image Mouse Leave...).

J'utilise pour cela une table dédiée dans une base de données où je ''stocke'' les chemins des fichiers image et d'autres informations utiles pour mon application.

J'ai développé le programme pour que lorsque l'utilisateur clique sur le bouton qu'il veut configurer, l'interface affiche les informations actuelles du bouton ainsi que les diverses informations. Tout ceci bien-sûr en interrogeant la table de la base de données.

Pensant qu'une fonction serait plus judicieuse que de faire un copier-coller dans chaque clic de bouton, je rencontre un problème que je ne m'explique pas.
Quand je fais un test du programme, lorsque je clique sur le bouton numéro 1, les informations s'affichent correctement dans le Usercontrol. Ainsi de suite pour tous les boutons, si je respecte bien l'ordre des boutons cliques (bouton 1 puis bouton 2 puis bouton 3.... jusqu'au bouton 12). Mais lorsque mon premier clic se fait sur un bouton autre que le bouton 1 (par exemple, l'utilisateur souhaite modifier la configuration du bouton 6), le programme m'indique une erreur disant qu'il n'y a pas de ligne à la position 6. Hors la table que j'interroge contient bien 12 lignes, et chaque ligne à ses champs renseignés (la preuve puisque ça marche quand je respecte l'ordre croissant des boutons). C'est dans la recherche de la variable Acronyme_prestation que cela plante.

De plus, je dois aujouter une information de prix issu d'une autre table. cela fonctionne pour le bouton1 mais pas pour les autres....

Version utilisée : Visual Studio Communauty 2017

Encore une fois, je suis autodidacte et donc mon code risque de provoquer quelques brûlures oculaires aux puristes... D'avance merci de votre mansuétude!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Imports System
Imports System.Windows
Imports System.Windows.Forms
Imports System.Data.OleDb
Public Class Usr_Conf_Btn_Prestas_Co
    Public btn_cliqué As Integer
    Public Shared catégorie As String
    Public Shared Btn_Catégorie As String
    Dim catégorieclick As Infos_Conf_View
    Public acronyme_prestation As String
    Public Shared acronyme_presta As String
    Public numéro_btn_prestation As Integer
    Public num_btn_presta As String
    Public target_table_conf, target_table_prix As String
 
 
    Public Shared cn_Phb As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Documents\Visual Studio 2017\Projects\WindowsApp7\WindowsApp7\PH.mdb")
    Public Shared ds, dsp As New DataSet
 
    Public Shared provider As String
    Public Shared dataFile As String
    Public Shared connString As String
    Public Shared myConnection As OleDbConnection = New OleDbConnection
    Public Shared nom_presta As New OleDbDataAdapter
    Public Shared cmd_presta As New OleDbCommand
    Public Shared cmd_prestation As New OleDbCommand
    Public Shared table_item As String
 
    Private Sub Btn_Conf_Catégorie_1_MouseHover(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_1.MouseHover
        Btn_Conf_Catégorie_1.Image = My.Resources.Btn_F_cc_On
    End Sub
 
    Private Sub Btn_Conf_Catégorie_1_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_1.MouseLeave
        If btn_cliqué <> 1 Then
            Btn_Conf_Catégorie_1.Image = My.Resources.Btn_F_cc_Off
        End If
    End Sub
 
    Private Sub Btn_Conf_Catégorie_2_MouseHover(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_2.MouseHover
        Btn_Conf_Catégorie_2.Image = My.Resources.Btn_F_CL_On
    End Sub
 
    Private Sub Btn_Conf_Catégorie_2_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_2.MouseLeave
        Btn_Conf_Catégorie_2.Image = My.Resources.Btn_F_CL_Off
    End Sub
 
    Private Sub Btn_Conf_Catégorie_3_MouseHover(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_3.MouseHover
        Btn_Conf_Catégorie_3.Image = My.Resources.Btn_H_On
    End Sub
 
    Private Sub Btn_Conf_Catégorie_3_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_3.MouseLeave
        Btn_Conf_Catégorie_3.Image = My.Resources.Btn_H_Off
    End Sub
 
    Private Sub Btn_Conf_Catégorie_4_MouseHover(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_4.MouseHover
        Btn_Conf_Catégorie_4.Image = My.Resources.Btn_E_On
    End Sub
 
    Private Sub Btn_Conf_Catégorie_4_MouseLeave(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_4.MouseLeave
        Btn_Conf_Catégorie_4.Image = My.Resources.Btn__Off
    End Sub
 
    Private Sub Btn_Conf_Catégorie_1_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_1.Click
        btn_cliqué = 1
        Btn_Catégorie = "F CC"
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").ForeColor = Color.RoyalBlue
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").Text = "Catégorie : " & Btn_Catégorie
 
 
 
    End Sub
 
    Private Sub Btn_Conf_Catégorie_2_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_2.Click
        btn_cliqué = 2
        Btn_Catégorie = "F CL"
        VarExchange = Btn_Catégorie
 
        catégorieclick = New Infos_Conf_View(Btn_Catégorie)
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").ForeColor = Color.RoyalBlue
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").Text = "Catégorie : " & catégorieclick.catégoriebtn
 
    End Sub
 
    Private Sub Btn_Conf_Catégorie_3_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_3.Click
        btn_cliqué = 3
        Btn_Catégorie = "H"
        VarExchange = Btn_Catégorie
 
        catégorieclick = New Infos_Conf_View(Btn_Catégorie)
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").ForeColor = Color.RoyalBlue
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").Text = "Catégorie : " & catégorieclick.catégoriebtn
 
    End Sub
 
    Private Sub Btn_Conf_Catégorie_4_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Catégorie_4.Click
        btn_cliqué = 4
        Btn_Catégorie = "E"
        VarExchange = Btn_Catégorie
 
        catégorieclick = New Infos_Conf_View(Btn_Catégorie)
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").ForeColor = Color.RoyalBlue
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Rubrique_presta").Text = "Catégorie : " & catégorieclick.catégoriebtn
 
    End Sub
    Public Function Connexion_BD_PH()
 
        provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
        dataFile = "C:\Users\Documents\Visual Studio 2017\Projects\WindowsApp7\WindowsApp7\PH.mdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString
 
 
        'Test état de connexion à la base de données. si la connexion est ouverte alors on l'ouvre
        If Not cn_Perfecthairdb.State = ConnectionState.Open Then
            cn_Perfecthairdb.Open()
        End If
        myConnection.Close()
    End Function
 
    Public Function Affich_Prix()
 
        If Not cn_Perfecthairdb.State = ConnectionState.Open Then
            cn_Perfecthairdb.Open()
        End If
 
        cmd_presta.CommandText = "SELECT * FROM " & target_table_prix & " where Nom_Presta= '" & acronyme_prestation & "' "
        nom_presta = New OleDbDataAdapter(cmd_presta.CommandText, myConnection)
        cmd_prestation = New OleDbCommand(cmd_presta.CommandText)
        nom_presta.Fill(dsp, target_table_prix)
        ' Id_Num = Val(dsp.Tables(target_table_prix).Rows(Id_Num)(1).ToString)
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Prix_TTC_presta").Text = "Tarif TTC : " & dsp.Tables(target_table_prix).Rows(0)(6).ToString & ",00 €"
 
        myConnection.Close()
 
    End Function
 
    Private Sub Btn_Conf_Tarif_C_1_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_1.Click
 
        numéro_btn_prestation = 1
        Conf_btn_BD()
        Affich_Prix()
    End Sub
 
    Public Function Conf_btn_BD()
 
        If btn_cliqué = 1 Then
            target_table_conf = "Config_boutons_C_F_CC"
            target_table_prix = "Tarifs_prestas_c_f_CC"
        End If
 
        If btn_cliqué = 2 Then
            target_table_conf = "Config_boutons_C_F_CL"
            target_table_prix = "Tarifs_prestas_c_f_CL"
        End If
 
        Connexion_BD_PH()
 
        If Not cn_Perfecthairdb.State = ConnectionState.Open Then
            cn_Perfecthairdb.Open()
        End If
 
        'Recherche Acronyme prestation dans la table Config_boutons_coiffure
        num_btn_presta = "Btn_Conf_Tarif_C_" & numéro_btn_prestation
 
        myConnection.Open()
 
        cmd_presta.CommandText = "SELECT * FROM " & target_table_conf & " where Num_bouton= '" & num_btn_presta & "' "
        nom_presta = New OleDbDataAdapter(cmd_presta.CommandText, myConnection)
        cmd_prestation = New OleDbCommand(cmd_presta.CommandText)
        nom_presta.Fill(ds, target_table_conf)
 
 
        acronyme_prestation = ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(8).ToString
 
        cmd_presta.CommandText = "SELECT * FROM " & target_table_conf & " where Nom_Presta= '" & acronyme_prestation & "' "
        nom_presta = New OleDbDataAdapter(cmd_presta.CommandText, myConnection)
        cmd_prestation = New OleDbCommand(cmd_presta.CommandText)
        nom_presta.Fill(ds, target_table_conf)
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Acronyme_presta").Text = "Acronyme : " & ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(8).ToString
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Nom_presta").Text = "Nom prestation : " & ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(3).ToString
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Désignation_presta").Text = "Désignation : " & ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(3).ToString
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Btn_off").BackgroundImage = Image.FromFile(ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(2).ToString & ".png")
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Btn_on").BackgroundImage = Image.FromFile(ds.Tables(target_table_conf).Rows(numéro_btn_prestation - 1)(1).ToString & ".png")
 
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Btn_off").BackgroundImageLayout = ImageLayout.Stretch
        Général.Pnl_View.Controls("Usr_conf_view").Controls("Grp_Actual_conf").Controls("Actual_Btn_on").BackgroundImageLayout = ImageLayout.Stretch
 
               myConnection.Close()
 
    End Function
 
 
    Private Sub Btn_Conf_Tarif_C_2_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_2.Click
        numéro_btn_prestation = 2
        Conf_btn_BD()
        Affich_Prix()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_3_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_3.Click
        numéro_btn_prestation = 3
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_4_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_4.Click
        numéro_btn_prestation = 4
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_5_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_5.Click
        numéro_btn_prestation = 5
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_6_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_6.Click
        numéro_btn_prestation = 6
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_7_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_7.Click
        numéro_btn_prestation = 7
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_8_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_8.Click
        numéro_btn_prestation = 8
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_9_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_9.Click
        numéro_btn_prestation = 9
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_10_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_10.Click
        numéro_btn_prestation = 10
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_11_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_11.Click
        numéro_btn_prestation = 11
        Conf_btn_BD()
    End Sub
 
    Private Sub Btn_Conf_Tarif_C_12_Click(sender As Object, e As EventArgs) Handles Btn_Conf_Tarif_C_12.Click
        numéro_btn_prestation = 12
        Conf_btn_BD()
    End Sub
End Class