الله يعطيك العافية أخ زهير
هذا كود الإضافة
هذا كود التعديل
وهذا كود الحذف
هذا كود الإضافة
كود :
Public Sub Insert_Car_Arshef(ByVal ID As Long, ByVal Car_Number As String, ByVal Enwan_Ketab As String, ByVal Date_Ketab As String, Car_Doc As PictureBox)
Dim folderPath As String = Application.StartupPath & "\Images\"
If Not Directory.Exists(folderPath & "\" & ID.ToString) Then
Directory.CreateDirectory(folderPath & "\" & ID.ToString)
End If
Dim mname As String = ID.ToString
Dim imagePath As String = folderPath & ID.ToString() & "\" & mname & ".jpg"
Dim ms As New MemoryStream
Car_Doc.Image.Save(ms, Car_Doc.Image.RawFormat)
IO.File.WriteAllBytes(imagePath, ms.ToArray())
Dim Cmd As New OleDbCommand
With Cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "Insert Into Car_Arshef ( ID,Car_Number,Enwan_Ketab,Date_Ketab,Car_Doc)values(@ID,@Car_Number,@Enwan_Ketab,@Date_Ketab,@Car_Doc)"
.Parameters.Clear()
.Parameters.AddWithValue("@ID", OleDbType.Integer).Value = ID
.Parameters.AddWithValue("@Car_Number", OleDbType.VarChar).Value = Car_Number
.Parameters.AddWithValue("@Enwan_Ketab", OleDbType.VarChar).Value = Enwan_Ketab
.Parameters.AddWithValue("@Date_Ketab", OleDbType.VarChar).Value = Date_Ketab
.Parameters.AddWithValue("@Car_Doc", OleDbType.VarChar).Value = "images\" & ID.ToString() & "\" & mname & ".jpg"
End With
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Cmd.ExecuteNonQuery()
con.Close()
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
Cmd = Nothing
End Subهذا كود التعديل
كود :
Public Sub Update_Car_Arshef(ByVal Car_Number As String, ByVal Enwan_Ketab As String, ByVal Date_Ketab As String, ByVal Car_Doc As PictureBox, ByVal IDW As Long)
Try
Dim folderPath As String = Path.Combine(Application.StartupPath, "Images")
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Dim imagePath As String = Path.Combine(folderPath, IDW.ToString() & ".jpg")
If File.Exists(imagePath) Then
File.Delete(imagePath)
End If
Using bmpCopy As New Bitmap(Car_Doc.Image)
bmpCopy.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
End Using
Dim Cmd As New OleDbCommand
With Cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "Update Car_Arshef Set Car_Number = @Car_Number,Enwan_Ketab = @Enwan_Ketab,Date_Ketab = @Date_Ketab,Car_Doc = @Car_Doc Where ID = @ID"
.Parameters.Clear()
.Parameters.AddWithValue("@Car_Number", OleDbType.VarWChar).Value = Car_Number
.Parameters.AddWithValue("@Enwan_Ketab", OleDbType.VarWChar).Value = Enwan_Ketab
.Parameters.AddWithValue("@Date_Ketab", OleDbType.VarWChar).Value = Date_Ketab
.Parameters.AddWithValue("@Car_Doc", "images\" & IDW.ToString() & ".jpg")
.Parameters.AddWithValue("@ID", IDW)
End With
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Cmd.ExecuteNonQuery()
con.Close()
MsgBox("تم تعديل السجل بنجاح", MsgBoxStyle.Information, "تعديل")
Catch ex As Exception
MsgBox("حدث خطأ أثناء محاولة تعديل السجل" & ex.Message, MsgBoxStyle.Critical)
End Try
End Subوهذا كود الحذف
كود :
Public Sub Delete_Car_Arshef(ByVal dgv_Car_Arshef As DataGridView)
Dim Position As Integer = dgv_Car_Arshef.CurrentRow.Index
Dim ID_Position As Integer = dgv_Car_Arshef.Rows(Position).Cells("ID").Value
Dim Cmd As New OleDbCommand
With Cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "Delete From Car_Arshef Where ID = @ID"
.Parameters.Clear()
.Parameters.AddWithValue("@ID", OleDbType.Integer).Value = ID_Position
End With
If con.State = 1 Then con.Close()
con.Open()
Cmd.ExecuteNonQuery()
con.Close()
MsgBox("تم حذف السجل.", MsgBoxStyle.Information, "حذف")
Cmd = Nothing
End Sub