| 12
 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
 
 | Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class frmMain
    Private mImageFile As Image
    Private mImageFilePath As String
 
    Private conn As New SqlConnection("database=Mabase;" & _
                                   "server=;" & _
                                   "integrated security=sspi")
    Private cmd, cmd2, cmd3 As SqlCommand
    Private dr, dr3 As SqlDataReader
    '*****************************************************************
    Dim fs As FileStream
    Public img As Byte()
    '**************************************************************
    Dim I As Integer
    Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp&, ByVal wPixTypes&) As Long
    Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp&) As Long
 
    Public Function ByteArrayToImage(ByVal ByteArray As Byte()) As Image
        Dim stream As New MemoryStream(ByteArray, 0, ByteArray.Length)
        Return Image.FromStream(stream, True)
 
    End Function
 
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If codefamille = "" Then
            txtTitle.Text = codemodif
        ElseIf codemodif = "" Then
            txtTitle.Text = codefamille
        End If
 
        conn.Open()
        cmd3 = New SqlCommand("select * from insertImage where code='" & txtTitle.Text & "'", conn)
        dr = cmd3.ExecuteReader
        If dr.Read Then
            conn.Close()
            btnLoad.Visible = False
            Button3.Visible = True
            dr.Close()
            conn.Close()
            Try
                Dim k As Byte()
                conn.Open()
                cmd = New SqlCommand("select ImageContent from insertImage where ImageTitle='" & txtTitle.Text & "'", conn)
                dr = cmd.ExecuteReader
                If dr.Read Then
                    k = dr(0)
                    image1.Image = ByteArrayToImage(k)
                End If
                dr.Close()
                conn.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            dr.Close()
            conn.Close()
        Else
            MsgBox("Maquette introuvable SVP : Ajouter une Maquette ...... ")
            btnLoad.Visible = True
            Button3.Visible = False
        End If
        conn.Close()
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Set Pdf File"
        OpenFileDialog1.Filter = "Pdf Files|*.pdf"
        OpenFileDialog1.DefaultExt = "pdf"
        OpenFileDialog1.FilterIndex = 1
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.ShowDialog()
 
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Exit Sub
        End If
 
        Dim sFilePath As String
        sFilePath = OpenFileDialog1.FileName
        If sFilePath = "" Then Exit Sub
 
        If System.IO.File.Exists(sFilePath) = False Then
            Exit Sub
        Else
                 txtImageFile.Text = sFilePath
            mImageFilePath = sFilePath
       fs = New FileStream(mImageFilePath.ToString(), FileMode.Open)
            img = New Byte(fs.Length) {}
            fs.Read(img, 0, fs.Length)
            fs.Close()
            mImageFile = Image.FromFile(mImageFilePath.ToString())
            Dim imgLength As Integer = mImageFile.PropertyItems.Length
            mImageFile = Nothing
            image1.Image = ByteArrayToImage(img)
                    End If
    End Sub
 
       Private Sub Enregister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        Try
            If (Me.txtImageFile.Text = String.Empty Or Me.txtTitle.Text = String.Empty) Then
                MessageBox.Show("SVP    :   Choisir Une Image ................!! ", "Missing Values", _
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Sub
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "File Test Error")
        End Try
 
        ' mImageFilePath = txtImageFile.Text
        'Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open)
 
        Dim sSQL As String = "INSERT INTO insertImage VALUES('" & txtTitle.Text & "',@pic,'" & txtTitle.Text & "')"
 
        Dim cmd As SqlCommand = New SqlCommand(sSQL, conn)
        Dim pic As SqlParameter = New SqlParameter("@pic", SqlDbType.Image)
        pic.Value = img
        cmd.Parameters.Add(pic)
        Try
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
            MessageBox.Show("Image a été Ajoutée Avec succès....... !! ", "Image Load")
            image1.Image = ByteArrayToImage(img)
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Data Error")
            Exit Sub
        End Try
        conn.Close()
    End Sub
End Class |