17-09-18, 10:22 PM
(17-09-18, 09:38 PM)aljzazy كتب :يا ريت توضيح اكثر ويفضل وضع جميع الاكواد لان المشكلة التي ذكرتها اغلب اسبابهاكود :
Imports System.Data.SqlClient
Public Class WatchList
Dim sqlcon As New SqlConnection("server=desktop-8ao3o4k\mssqlserver2017; database=DB_WatchList; Integrated security=true")
'تنفيذ
Dim Adapter As SqlDataAdapter
'تخزين
Dim DT As New DataTable
Dim cmdb As SqlCommandBuilder
Private Sub WatchList_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DGV.BackgroundColor = Me.BackColor
Dim query As String = "select ID, Name ,Eps ,TimeTike ,DateStr, DateEnd from TBL_WatchList"
Adapter = New SqlDataAdapter("select * from TBL_WatchList", sqlcon)
Adapter.Fill(DT)
Me.DGV.DataSource = DT
DGV.Columns(0).HeaderText = "رقم العمل"
DGV.Columns(1).HeaderText = "اسم العمل"
DGV.Columns(2).HeaderText = "عدد الحلقات"
DGV.Columns(3).HeaderText = "الوقت المستغرق"
DGV.Columns(4).HeaderText = "وقت البدايه"
DGV.Columns(5).HeaderText = "وقت الانتهاء"
DGV.Columns(0).Width = 80
DGV.Columns(1).Width = 330
DGV.Columns(2).Width = 80
DGV.Columns(3).Width = 100
DGV.Columns(4).Width = 100
DGV.Columns(5).Width = 100
'ID.Value = 0
'txtName.Clear()
'NumEps.Value = 1
'NumTime.Value = 20
'DateStr.Value = Now.Date
'DateEnd.Value = Now.Date
' نخليه الممنوع التكرر
DT.Constraints.Add("primary", DT.Columns("ID"), True)
End Sub
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
' add()
Try
Dim row As DataRow = DT.NewRow
row(0) = ID.Value
row(1) = txtName.Text
row(2) = NumEps.Value
row(3) = NumTime.Value
row(4) = DateStr.Value
row(5) = DateEnd.Value
DT.Rows.Add(row)
cmdb = New SqlCommandBuilder(Adapter)
Adapter.Update(DT)
MsgBox("تمت الاضافة بنجاح", MsgBoxStyle.Information, "الاضافة")
txtName.Clear()
ID.Value = ID.Value + 1
NumEps.Value = 1
NumTime.Value = 20
DateStr.Value = Now.Date
DateEnd.Value = Now.Date
txtName.Focus()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Dim oldID As Integer
Private Sub btndel_Click(sender As System.Object, e As System.EventArgs) Handles btndel.Click
Try
Dim row As DataRow = DT.Rows.Find(ID.Value)
If row Is Nothing Then
MsgBox("هذا العمل غير موجود", MsgBoxStyle.Exclamation, "الحذف")
Else
row.Delete()
cmdb = New SqlCommandBuilder(Adapter)
Adapter.Update(DT)
MsgBox("تمت عملية الحذف بنجاح", MsgBoxStyle.Information, "الحذف")
txtName.Clear()
NumEps.Value = 1
NumTime.Value = 20
DateStr.Value = Now.Date
DateEnd.Value = Now.Date
txtName.Focus()
End If
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Exclamation,"خطأ")
End Try
End Sub
' Sub add()
' End Sub
Private Sub ID_ValueChanged(sender As System.Object, e As System.EventArgs) Handles ID.ValueChanged
Try
If ID.Value = Nothing Then
ID.Value = 1
Else
Dim row As DataRow = DT.Rows.Find(ID.Value)
If row IsNot Nothing Then
oldID = row(0)
txtName.Text = row(1)
NumEps.Value = row(2)
NumTime.Value = row(3)
DateStr.Value = row(4)
DateEnd.Value = row(5)
ElseIf (ID.Value <> oldID) Then
txtName.Clear()
NumEps.Value = 1
NumTime.Value = 20
DateStr.Value = Now.Date
DateEnd.Value = Now.Date
End If
End If
Catch ex As Exception
'MsgBox(ex.Message)
End Try
End Sub
Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
Try
Dim row As DataRow = DT.Rows.Find(oldID)
row(0) = ID.Value
row(1) = txtName.Text
row(2) = NumEps.Value
row(3) = NumTime.Value
row(4) = DateStr.Value
row(5) = DateEnd.Value
cmdb = New SqlCommandBuilder(Adapter)
Adapter.Update(DT)
MsgBox("تمت عملية التحديث", MsgBoxStyle.Information, "التحديث")
ID.Value = +1
txtName.Clear()
NumEps.Value = 1
NumTime.Value = 20
DateStr.Value = Now.Date
DateEnd.Value = Now.Date
txtName.Focus()
Catch ex As Exception
End Try
End Sub
End Class
هو المفتاح الرئيسي بالجدول الذي من خلاله تتم عمليات النحديث والحذف
مو فاهم قصدك بالتوضيح لكن ذا الاكواد كلها
