Public Class Form1
Dim con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=db.accdb")
Dim dt As DataTable
Dim da As OleDb.OleDbDataAdapter
Dim cmdb As OleDb.OleDbCommandBuilder
Private Sub oncon()
Try
con.Open()
Catch ex As Exception
End Try
End Sub
Private Sub ofcon()
Try
con.Close()
Catch ex As Exception
End Try
End Sub
Private Sub gd()
PictureBox1.DataBindings.Clear()
PictureBox1.Image = Nothing
dt = New DataTable
da = New OleDb.OleDbDataAdapter("select * from tb", con)
cmdb = New OleDb.OleDbCommandBuilder(da)
da.Fill(dt)
PictureBox1.DataBindings.Add("image", dt, "pic", True)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "picname"
ofcon()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
gd()
End Sub
Private Function addpic(ByVal b() As Byte, ByVal t As String) As Boolean
' Try
Dim row As DataRow = dt.NewRow
row(1) = b
row(2) = t
dt.Rows.Add(row)
da.Update(dt)
Return True
gd()
' Catch ex As Exception
'Return False
' End Try
End Function
Private Function edpic(ByVal b() As Byte) As Boolean
' Try
Dim row As DataRow = dt.Rows(Me.BindingContext(dt).Position)
row.BeginEdit()
row(1) = b
row.EndEdit()
da.Update(dt)
Return True
gd()
' Catch ex As Exception
'Return False
' End Try
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.BindingContext(dt).Position -= 1
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.BindingContext(dt).Position += 1
End Sub
Private Sub cmdnew_Click(sender As Object, e As EventArgs) Handles cmdnew.Click
Dim o As New OpenFileDialog
If o.ShowDialog = Windows.Forms.DialogResult.OK Then
If addpic(My.Computer.FileSystem.ReadAllBytes(o.FileName), IO.Path.GetFileNameWithoutExtension(o.FileName)) Then
MsgBox("تم حفظ الصورة بنجاح")
Else
MsgBox("حدث خطا", MsgBoxStyle.Critical, "")
End If
End If
End Sub
Private Sub cmdedit_Click(sender As Object, e As EventArgs) Handles cmdedit.Click
Dim o As New OpenFileDialog
If o.ShowDialog = Windows.Forms.DialogResult.OK Then
If edpic(My.Computer.FileSystem.ReadAllBytes(o.FileName)) Then
MsgBox("تم التعديل بنجاح")
Else
MsgBox("حدث خطا", MsgBoxStyle.Critical, "")
End If
End If
End Sub
Private Sub cmddel_Click(sender As Object, e As EventArgs) Handles cmddel.Click
dt.Rows(Me.BindingContext(dt).Position).Delete()
da.Update(dt)
gd()
MsgBox("تم الحذف بنجاح")
End Sub
Private Sub cmdAll_Click(sender As Object, e As EventArgs) Handles cmdAll.Click
For Each row As DataRow In dt.Rows
row.Delete()
Next
da.Update(dt)
MsgBox("تم حذف الكل")
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyData = Keys.Enter Then
If TextBox1.Text.Trim = "" Then Exit Sub
' ComboBox1.SelectedText = TextBox1.Text
ComboBox1.SelectedIndex = ComboBox1.FindString(TextBox1.Text)
TextBox1.Clear()
TextBox1.Select()
TextBox1.Focus()
End If
End Sub
Private Sub TextBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseClick
If e.Button = Windows.Forms.MouseButtons.Left Then
TextBox1.Clear()
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
End Class