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
| Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Cursor = Cursors.WaitCursor
For i = 0 To Me.ListBox1.Items.Count - 1
ProgressBar1.Maximum = Me.ListBox1.Items.Count - 1
Me.ListBox1.SetSelected(i, True)
Dim cmd As New MySqlCommand
Dim SQL As String
'Dim FileSize As UInt32
Dim rawData() As Byte = IO.File.ReadAllBytes(ListBox1.SelectedItem)
Dim mstream As New System.IO.MemoryStream()
Dim arrImage() As Byte = mstream.GetBuffer()
mstream.Close()
'Save Image in Folder
Dim strBasePath As String
Dim strFileName As String
strFileName = TextBox3.Text
strBasePath = Application.StartupPath & "\Images" & ComboBox1.Text & "\"
' >> Check if Folder Exists
If Directory.Exists(strBasePath) = False Then
Call Directory.CreateDirectory(strBasePath)
End If
' >> Save Picture
If TextBox1.Text = ".jpg" Then
Call PictureBox1.Image.Save(strBasePath & "\" & strFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
ElseIf TextBox1.Text = ".png" Then
Call PictureBox1.Image.Save(strBasePath & "\" & strFileName, System.Drawing.Imaging.ImageFormat.Png)
ElseIf TextBox1.Text = ".bmp" Then
Call PictureBox1.Image.Save(strBasePath & "\" & strFileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
'Save Image in Folder
MysqlConn.Close()
MysqlConn.Open()
SQL = "INSERT INTO xcollectibles.foto (id_product,name,path) VALUES ((Select id from xcollectibles.product where product.name='" & ComboBox1.Text & "'), @name, @path) "
ProgressBar1.Value = i
cmd.Connection = MysqlConn
cmd.CommandText = SQL
cmd.Parameters.AddWithValue("@name", TextBox3.Text)
cmd.Parameters.AddWithValue("@path", strBasePath)
cmd.ExecuteNonQuery()
Next
MessageBox.Show("File Inserted into database successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
MysqlConn.Dispose()
ProgressBar1.Value = 0
Me.Cursor = Cursors.Default
End Sub |
Partager