-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrmProduit.vb
More file actions
570 lines (483 loc) · 21.6 KB
/
Copy pathFrmProduit.vb
File metadata and controls
570 lines (483 loc) · 21.6 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
Imports System.Data.SqlClient
Imports MONIN_CONTACT.dbconnect
Public Class FrmProduit
Dim idGa As Integer
Dim RS As String
Dim dgRecetteIndex As DataGridViewRow
Dim nomPhoto As String
Private Sub Form_Produit_Load(sender As Object, e As EventArgs) Handles Me.Load
''' DataGridView Produit '''
dgProduit.ColumnCount = 6
dgProduit.ColumnHeadersVisible = True
dgProduit.Columns(0).Visible = False
dgProduit.Columns(3).Visible = False
dgProduit.Columns(1).Name = "Libellé"
dgProduit.Columns(2).Name = "Description"
dgProduit.Columns(3).Name = "Photo"
dgProduit.Columns(4).Name = "Prix unitaire"
dgProduit.Columns(5).Name = "Gamme"
'''End DataGridView Produit '''
''' DataGridView Recette '''
dgRecette.ColumnCount = 3
dgRecette.ColumnHeadersVisible = True
dgRecette.Columns(0).Visible = False
dgRecette.Columns(1).Name = "Libellé"
dgRecette.Columns(2).Name = "Description"
'''End DataGridView Recette '''
''' DataGridView Composition '''
dgCompo.ColumnCount = 2
dgCompo.ColumnHeadersVisible = True
dgCompo.Columns(0).Visible = False
dgCompo.Columns(1).Name = "Nom du produit"
'''End DataGridView Composition '''
RefreshProduit()
''' CboGamme load content '''
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT libGamme FROM GAMME"
reader = cmd.ExecuteReader()
While (reader.Read)
cboGamme.Items.Add(reader.GetValue(0))
End While
reader.Close()
cnn.Close()
'''END CboGamme load content '''
'''LoadRecette '''
If (cnn.State = ConnectionState.Closed) Then
dgRecette.Rows.Clear()
dgRecette.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libRecette, descRecette FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND P.idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgRecette.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2))
End While
dgRecette.AutoResizeColumns()
reader.Close()
cnn.Close()
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
End If
'''END LoadRecette '''
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed And dgRecette.RowCount > 0) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadRecette '''
End Sub
''' Filtre combobox Gamme '''
Private Sub cboGamme_SelectedIndexChanged(sender As Object, e As EventArgs)
End Sub
'''End Filtre combobox Gamme '''
''' Sub refresh datagridview '''
Public Sub RefreshProduit()
cnn = New SqlConnection(connectionString)
dgProduit.Rows.Clear()
dgProduit.Refresh()
dgRecette.Rows.Clear()
dgRecette.Refresh()
dgCompo.Rows.Clear()
dgCompo.Refresh()
tbProduit.Text = ""
cnn.Close()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT idProduit, libProduit, descProduit, photo, PUProduit, libGamme FROM PRODUIT P, GAMME G WHERE P.idGamme = G.idGamme"
reader = cmd.ExecuteReader()
While reader.Read
dgProduit.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
reader.Close()
cnn.Close()
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
End Sub
''' End Sub refresh datagridview '''
''' Search txtBox Produit '''
Private Sub tbProduit_TextChanged(sender As Object, e As EventArgs) Handles tbProduit.TextChanged
If tbProduit.Text = "" Then
RefreshProduit()
Else
dgProduit.Rows.Clear()
dgProduit.Refresh()
dgRecette.Rows.Clear()
dgRecette.Refresh()
dgCompo.Rows.Clear()
dgCompo.Refresh()
cboGamme.Text = ""
If (cnn.State = ConnectionState.Closed) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT idProduit, libProduit, descProduit, photo, PUProduit, libGamme FROM PRODUIT P, GAMME G WHERE P.idGamme = G.idGamme AND libProduit like '" & tbProduit.Text & "%'"
reader = cmd.ExecuteReader()
While reader.Read
dgProduit.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
reader.Close()
cnn.Close()
End If
If (cnn.State = ConnectionState.Closed And dgProduit.RowCount > 0) Then
dgRecette.Rows.Clear()
dgRecette.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libRecette, descRecette FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgRecette.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2))
End While
dgRecette.AutoResizeColumns()
reader.Close()
cnn.Close()
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
End If
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed And dgRecette.RowCount > 0) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadRecette '''
End If
End Sub
''' End Search txtBox Produit '''
''' Remove Filtre Entreprise '''
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
cboGamme.Text = ""
RefreshProduit()
End Sub
'''End Remove Filte Gamme '''
''' On select row on datagridview contact '''
Private Sub dgProduit_SelectionChanged(sender As Object, e As EventArgs) Handles dgProduit.SelectionChanged
If (cnn.State = ConnectionState.Closed) Then
dgRecette.Rows.Clear()
dgRecette.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libRecette, descRecette FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgRecette.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2))
End While
dgRecette.AutoResizeColumns()
reader.Close()
cnn.Close()
Try
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
Catch ex As Exception
End Try
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
If dgRecette.RowCount > 0 Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
End If
'''END LoadCompo '''
End If
End Sub
''' End On select row on datagridview Produit '''
''' Btn Add Produit '''
Private Sub btnAddProduit_Click(sender As Object, e As EventArgs) Handles btnAddProduit.Click
FrmAddProduit.Show()
End Sub
''' End Btn Add Produit '''
''' Btn Update Produit '''
Private Sub btnEditProduit_Click(sender As Object, e As EventArgs) Handles btnEditProduit.Click
If dgProduit.RowCount > 0 Then
FrmUpdateProduit.Show()
Else
MsgBox("Veuillez sélectionner un produit", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Update Produit '''
''' Btn Del Produit '''
Private Sub btnDelProduit_Click(sender As Object, e As EventArgs) Handles btnDelProduit.Click
If dgProduit.RowCount > 0 Then
Dim response = MsgBox("Voulez-vous vraiment supprimer le produit ?", vbCritical + vbYesNo, "Attention /!\")
If (response = vbYes) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
cmd.ExecuteNonQuery()
cnn.Close()
If (cnn.State = ConnectionState.Closed) Then
RefreshProduit()
End If
End If
Else
MsgBox("Veuillez sélectionner un produit", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Del Produit '''
'''Btn Add Recette '''
Private Sub btnAddRecette_Click(sender As Object, e As EventArgs)
'' Form_Add_Recette.Show()
End Sub
''' End Btn Add Recette '''
''' Btn Del Recette'''
Private Sub BtnDelRecette_Click(sender As Object, e As EventArgs)
If dgRecette.RowCount > 0 Then
Dim response = MsgBox("Voulez-vous vraiment supprimer la recette sélectionnée ?", vbCritical + vbYesNo, "Attention /!\")
If (response = vbYes) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM RECETTE WHERE idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
cmd.ExecuteNonQuery()
cnn.Close()
dgRecetteIndex = dgRecette.CurrentRow
dgRecette.Rows.Remove(dgRecetteIndex)
End If
Else
MsgBox("Veuillez sélectionner une recette", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Del Recette '''
Private Sub dgProduit_Click(sender As Object, e As EventArgs) Handles dgProduit.Click
If (cnn.State = ConnectionState.Closed) Then
dgRecette.Rows.Clear()
dgRecette.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libRecette, descRecette FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgRecette.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2))
End While
dgRecette.AutoResizeColumns()
reader.Close()
cnn.Close()
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
End If
End Sub
''' Btn Update Recette '''
Private Sub btnEditRecette_Click(sender As Object, e As EventArgs)
If dgRecette.RowCount > 0 Then
'' Form_Update_Recette.Show()
Else
MsgBox("Veuillez sélectionner une recette", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Update Recette '''
'''
Private Sub dgRecette_SelectionChanged(sender As Object, e As EventArgs) Handles dgRecette.SelectionChanged
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed And dgRecette.RowCount > 0) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadCompo '''
End Sub
Private Sub dgRecette_Click(sender As Object, e As EventArgs) Handles dgRecette.Click
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed And dgRecette.RowCount > 0) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadCompo '''
End Sub
Private Sub cboGamme_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles cboGamme.SelectedIndexChanged
dgProduit.Rows.Clear()
dgProduit.Refresh()
dgRecette.Rows.Clear()
dgRecette.Refresh()
dgCompo.Rows.Clear()
dgCompo.Refresh()
tbProduit.Text = ""
'''SELECT IdGa '''
Try
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT idGamme FROM GAMME WHERE libGamme = '" & cboGamme.Text & "'"
reader = cmd.ExecuteReader()
reader.Read()
idGa = reader.GetValue(0)
reader.Close()
cnn.Close()
Catch ex As Exception
End Try
'''END SELECT IdGa '''
'''Content datagridview Produit '''
If (cnn.State = ConnectionState.Closed) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT idProduit, libProduit, descProduit, photo, PUProduit, libGamme FROM PRODUIT P, GAMME G WHERE P.idGamme = G.idGamme AND P.idGamme = '" & idGa & "'"
reader = cmd.ExecuteReader()
While (reader.Read)
dgProduit.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
reader.Close()
cnn.Close()
End If
'''END Content datagridview Produit '''
'''Content datagridview Recette '''
If (cnn.State = ConnectionState.Closed) Then
dgRecette.Rows.Clear()
dgRecette.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libRecette, descRecette FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgRecette.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2))
End While
dgRecette.AutoResizeColumns()
reader.Close()
cnn.Close()
'Load Picture'
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT photo FROM PRODUIT WHERE idProduit = '" & dgProduit.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
nomPhoto = reader.GetValue(0)
reader.Close()
cnn.Close()
PictureBox1.ImageLocation = path & nomPhoto
'End Load Picture'
End If
'''END Content datagridview Recette '''
'''LoadCompo '''
If (cnn.State = ConnectionState.Closed And dgRecette.RowCount > 0) Then
dgCompo.Rows.Clear()
dgCompo.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT R.idRecette, libProduit FROM RECETTE R, PRODUIT P, COMPOSITION C WHERE C.idProduit = P.idProduit AND C.idRecette = R.idRecette AND C.idRecette = '" & dgRecette.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgCompo.Rows.Add(reader.GetValue(0), reader.GetValue(1))
End While
dgCompo.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadRecette '''
End Sub
Private Sub BtnGamme_Click(sender As Object, e As EventArgs) Handles BtnGamme.Click
FrmGammes.Show()
End Sub
End Class