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
| Imports System.Data
Imports System.Data.SqlClient
Module Module1
Public conx As SqlConnection
Public Sub chaine_connection()
conx = New SqlConnection("")
Try
conx.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Function ByteArray2Image(ByVal BArray As Byte()) As Image
Try
Dim mstImage As MemoryStream = New MemoryStream(BArray)
Dim img As Image = Image.FromStream(mstImage)
Return img
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
Public Function Image2ByteArray(ByVal img As Image) As Byte()
Try
Dim mstimage As MemoryStream = New MemoryStream
img.Save(mstimage, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim BytImage As Byte() = mstimage.GetBuffer
Return BytImage
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
End module
'**************************************************************************************************************'
' PROCEDURE AFFICHAGE client dans un datagridview
'**************************************************************************************************************'
Public Sub affiche_client()
chaine_connection()
Dim cmd As New SqlCommand("select NUM_CL as Numero,PRENOM_CL as Prénom, NOM_CL as Nom ,AGE_CL as Age, GENRE_CL as Genre, ADRESSE_CL as Adresse, TEL_CL as Téléphone, PHOTO_CL as Photo,EMAIL_CL as EMail from CLIENT ")
cmd.Connection = conx
Dim da = New SqlDataAdapter(cmd)
Dim ds As New DataTable
da.Fill(ds)
Form2_menu_principal.UserControl1_client1.dgvclients.DataSource = ds
End Sub
'**************************************************************************************************************'
' transmission de l'element selectionné dans le datagridview pour le mettre dans les labelles
'**************************************************************************************************************'
Private Sub dgvclients_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvclients.CellContentClick
If dgvclients.CurrentRow.Cells(0).Value.ToString <> "" Then
lbl_num_client.Text = dgvclients.CurrentRow.Cells(0).Value.ToString
lbl_prenom_client.Text = dgvclients.CurrentRow.Cells(1).Value.ToString
lbl_nom_client.Text = dgvclients.CurrentRow.Cells(2).Value.ToString
lbl_age_client.Text = dgvclients.CurrentRow.Cells(3).Value.ToString
lbl_genre_client.Text = dgvclients.CurrentRow.Cells(4).Value.ToString
lbl_adresse_client.Text = dgvclients.CurrentRow.Cells(5).Value.ToString
lbl_tel_client.Text = dgvclients.CurrentRow.Cells(6).Value.ToString
If Pict_img__client.Visible = True Then
Dim img As Image
Dim t() As Byte
t = dgvclients.CurrentRow.Cells(7).Value
img = ByteArray2Image(t)
Pict_img__client.Image = img
Else
Pict_img__client.Image = My.Resources.default_avatar1
End If
lbl_email_client.Text = dgvclients.CurrentRow.Cells(8).Value.ToString
End If
End Sub |
Partager