10-11-17, 12:53 AM
اعتزر لك اخي جميل علي
لا استخدم هذة الطريقة لتعامل مع قاعدة البيانات ولم اقد ر علي استخلاص ما احتاج ببرنامجي
انا بستخدم الطريقة دية لحفظ الصور ومسحها ووضعت امتداد لكل الملفات ولكن لاتحفظ بقاعدة البيانات وتحفظ الصور فقط وذالك لان الكود يصف الصور كاملا ليست اكواد حفظ الصور متشابة مع اكواد حفظ html ,pdf ,doc
Private Sub savimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savimage.Click
' save
If BindingSource1.Count = 0 Then Beep() : Exit Sub
Try
If PictureBox1.Image IsNot Nothing Then
If MsgBox(" هل تريد استبدال الصورة الحالية " & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "استبدال صورة") = MsgBoxResult.Cancel Then Exit Sub
Else
If MsgBox(" استمرار اضافة صورة جديدة للسجل رقم " & Label2.Text & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "ادراج صورة") = MsgBoxResult.Cancel Then Exit Sub
End If
Application.DoEvents()
Dim OFG As New OpenFileDialog
OFG.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.GIF)|*.bmp;*.jpg;*.jpeg;*.GIF|" + _
"PNG files (*.png)|*.png|text files (*.text)|*.txt|doc files (*.doc)|*.doc|pdf files (*.pdf)|*.pdf" '"Files(*.jpg)|*.jpg|Files(*.gif)|*.gif|Files(*.bmp)|*.bmp|Files(*.png)|*.png"
OFG.Title = "ادراج صورة"
OFG.FileName = ""
If OFG.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fs As IO.FileStream = New IO.FileStream(OFG.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim LoadImage As Image = Image.FromStream(fs)
fs.Close()
Dim Stream As New IO.MemoryStream()
Dim NewBitmap As New Bitmap(LoadImage, 200, 225)
NewBitmap.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
Application.DoEvents()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
DataSet1.Tables("purch_tb").Rows(BindingSource1.Position).Item("pic_prod") = Stream.ToArray
Stream.Close()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
Application.DoEvents()
MsgBox("تم حفظ الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub deletimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deletimage.Click
Try
If PictureBox1.Image Is Nothing Then Beep() : MsgBox("لايوجد صورة ليتم حذفها") : Exit Sub
If MsgBox(" استمرار حذف الصورة الحالية" & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "حذف صورة") = MsgBoxResult.Cancel Then Exit Sub
PictureBox1.Image = Nothing
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
MsgBox("تم حذف الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
لا استخدم هذة الطريقة لتعامل مع قاعدة البيانات ولم اقد ر علي استخلاص ما احتاج ببرنامجي
انا بستخدم الطريقة دية لحفظ الصور ومسحها ووضعت امتداد لكل الملفات ولكن لاتحفظ بقاعدة البيانات وتحفظ الصور فقط وذالك لان الكود يصف الصور كاملا ليست اكواد حفظ الصور متشابة مع اكواد حفظ html ,pdf ,doc
Private Sub savimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savimage.Click
' save
If BindingSource1.Count = 0 Then Beep() : Exit Sub
Try
If PictureBox1.Image IsNot Nothing Then
If MsgBox(" هل تريد استبدال الصورة الحالية " & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "استبدال صورة") = MsgBoxResult.Cancel Then Exit Sub
Else
If MsgBox(" استمرار اضافة صورة جديدة للسجل رقم " & Label2.Text & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "ادراج صورة") = MsgBoxResult.Cancel Then Exit Sub
End If
Application.DoEvents()
Dim OFG As New OpenFileDialog
OFG.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.GIF)|*.bmp;*.jpg;*.jpeg;*.GIF|" + _
"PNG files (*.png)|*.png|text files (*.text)|*.txt|doc files (*.doc)|*.doc|pdf files (*.pdf)|*.pdf" '"Files(*.jpg)|*.jpg|Files(*.gif)|*.gif|Files(*.bmp)|*.bmp|Files(*.png)|*.png"
OFG.Title = "ادراج صورة"
OFG.FileName = ""
If OFG.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fs As IO.FileStream = New IO.FileStream(OFG.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim LoadImage As Image = Image.FromStream(fs)
fs.Close()
Dim Stream As New IO.MemoryStream()
Dim NewBitmap As New Bitmap(LoadImage, 200, 225)
NewBitmap.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
Application.DoEvents()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
DataSet1.Tables("purch_tb").Rows(BindingSource1.Position).Item("pic_prod") = Stream.ToArray
Stream.Close()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
Application.DoEvents()
MsgBox("تم حفظ الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub deletimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deletimage.Click
Try
If PictureBox1.Image Is Nothing Then Beep() : MsgBox("لايوجد صورة ليتم حذفها") : Exit Sub
If MsgBox(" استمرار حذف الصورة الحالية" & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "حذف صورة") = MsgBoxResult.Cancel Then Exit Sub
PictureBox1.Image = Nothing
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
MsgBox("تم حذف الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

