29-04-17, 01:42 AM
ارجو مساعدتي حيث اني عملت كلاس وكتبت به مجموعه من الدوال لكن هذه الدوال لا تعمل جميعها
'داله بناء أوامر الحفظ والحذف والتعديل
Public Function SQLExicute(ByVal SQLStatment As String) As Boolean
Try
Dim Cmd As New SqlCommand
Cmd.CommandText = SQLStatment
sqlcon.Open()
Cmd.Connection = sqlcon
Cmd.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
End Function
بعد ان كتبت لكم الداله التي وضعتها في الكلاس سوف اكتب لكم البرمجه التي كتبتها في الفورمه لكن هذه الداله في الجزء التعديل للبيانات لم تعمل ارجو مساعدتي
Imports System.Data.SqlClient
Public Class FrmPlaneType
Dim ISUpdate As Boolean
Dim Winclass As New Class1
Private Sub BtnNew1_Click(sender As Object, e As EventArgs) Handles BtnNew1.Click
TxtTypeAdd.Enabled = True
TxtTypeAdd.Text = ""
ISUpdate = False
End Sub
Private Sub BtnSave1_Click(sender As Object, e As EventArgs) Handles BtnSave1.Click
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
'اذا كان حقل أدخال نوع الطائره فارغ يظهر رساله
If TxtTypeAdd.Text.Trim = "" Then
MsgBox("لم تقم بأدخال بيانات لكي يتم حفظها ", MsgBoxStyle.Critical, "تنبية")
Exit Sub
End If
'------------------------------------------------------------------------------------------------------------------------------------------
' اذا كانت العمليه تعديل ما أدخلته سابقآ
If ISUpdate = True Then
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Dim UpdateOk As Boolean = Winclass.SQLExicute("Update PlaneType SET TYPE= '" & TxtTypeAdd.Text & ", WHERE TID=" & TxtID.Text & "")
If UpdateOk = True Then
MsgBox("تمت عملية تعديل البيانات بنجاح ", MsgBoxStyle.Information, "تأكيد عملية التعديل ")
TxtTypeAdd.Enabled = False
'تفريغ حقول الأدخال بعد التعديل
TxtID.Text = ""
TxtTypeAdd.Text = ""
FillDataGrid()
Else
MsgBox("Error", MsgBoxStyle.Critical, "Error")
End If
Else
'------------------------------------------------------------------------------------------------------------------------------------
'أجراء عملية الحفظ
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Dim Saveok As Boolean = Winclass.SQLExicute("insert into PlaneType(TYPE) values ('" & TxtTypeAdd.Text & "')")
If Saveok = True Then
MsgBox("تمت عملية الحفظ بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
TxtID.Text = ""
TxtTypeAdd.Text = ""
FillDataGrid()
End If
End If
End Sub
Private Sub FrmPlaneType_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FillDataGrid()
End Sub
Private Sub FillDataGrid()
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Winclass.fillDataGrid(DG, " SELECT TID AS الرقم, TYPE AS النوع FROM PlaneType")
DG.Columns(0).HeaderText = "الرقم"
DG.Columns(0).Visible = False
DG.Columns(1).HeaderText = "النوع"
DG.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End Sub
Private Sub DG_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DG.CellClick
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
'عندما أضغط على نوع طائره يضهرها لي في ال text
ISUpdate = True
TxtTypeAdd.Enabled = True
TxtID.Text = DG(0, e.RowIndex).Value
TxtTypeAdd.Text = DG(1, e.RowIndex).Value
End Sub
Private Sub BtnDelete1_Click(sender As Object, e As EventArgs) Handles BtnDelete1.Click
Dim DeleteOk As String = MsgBox("هل فعلآ تريد حذف البيانات المحدده ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, " تأكيد الحذف ")
If DeleteOk = vbYes Then
Dim DeleteConfirm As Boolean = Winclass.SQLExicute("Delete FROM PlaneType WHERE TID=" & TxtID.Text)
If DeleteConfirm = True Then
MsgBox("تمت عملية حذف البيانات بنجاح", MsgBoxStyle.Exclamation, "الحذف")
TxtTypeAdd.Text = ""
FillDataGrid()
Else
MsgBox("خطأ في عملية الحذف ", MsgBoxStyle.Critical, "Error")
End If
End If
End Sub
Private Sub BtnExit1_Click(sender As Object, e As EventArgs) Handles BtnExit1.Click
End Sub
End Class
Public Class FrmPlaneType
Dim ISUpdate As Boolean
Dim Winclass As New Class1
Private Sub BtnNew1_Click(sender As Object, e As EventArgs) Handles BtnNew1.Click
TxtTypeAdd.Enabled = True
TxtTypeAdd.Text = ""
ISUpdate = False
End Sub
Private Sub BtnSave1_Click(sender As Object, e As EventArgs) Handles BtnSave1.Click
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
'اذا كان حقل أدخال نوع الطائره فارغ يظهر رساله
If TxtTypeAdd.Text.Trim = "" Then
MsgBox("لم تقم بأدخال بيانات لكي يتم حفظها ", MsgBoxStyle.Critical, "تنبية")
Exit Sub
End If
'------------------------------------------------------------------------------------------------------------------------------------------
' اذا كانت العمليه تعديل ما أدخلته سابقآ
If ISUpdate = True Then
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Dim UpdateOk As Boolean = Winclass.SQLExicute("Update PlaneType SET TYPE= '" & TxtTypeAdd.Text & ", WHERE TID=" & TxtID.Text & "")
If UpdateOk = True Then
MsgBox("تمت عملية تعديل البيانات بنجاح ", MsgBoxStyle.Information, "تأكيد عملية التعديل ")
TxtTypeAdd.Enabled = False
'تفريغ حقول الأدخال بعد التعديل
TxtID.Text = ""
TxtTypeAdd.Text = ""
FillDataGrid()
Else
MsgBox("Error", MsgBoxStyle.Critical, "Error")
End If
Else
'------------------------------------------------------------------------------------------------------------------------------------
'أجراء عملية الحفظ
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Dim Saveok As Boolean = Winclass.SQLExicute("insert into PlaneType(TYPE) values ('" & TxtTypeAdd.Text & "')")
If Saveok = True Then
MsgBox("تمت عملية الحفظ بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
TxtID.Text = ""
TxtTypeAdd.Text = ""
FillDataGrid()
End If
End If
End Sub
Private Sub FrmPlaneType_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FillDataGrid()
End Sub
Private Sub FillDataGrid()
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
Winclass.fillDataGrid(DG, " SELECT TID AS الرقم, TYPE AS النوع FROM PlaneType")
DG.Columns(0).HeaderText = "الرقم"
DG.Columns(0).Visible = False
DG.Columns(1).HeaderText = "النوع"
DG.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End Sub
Private Sub DG_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DG.CellClick
Class1.sqlcon.ConnectionString = "data source=DESKTOP-SDJV93N; initial catalog = Test; integrated security = true "
'عندما أضغط على نوع طائره يضهرها لي في ال text
ISUpdate = True
TxtTypeAdd.Enabled = True
TxtID.Text = DG(0, e.RowIndex).Value
TxtTypeAdd.Text = DG(1, e.RowIndex).Value
End Sub
Private Sub BtnDelete1_Click(sender As Object, e As EventArgs) Handles BtnDelete1.Click
Dim DeleteOk As String = MsgBox("هل فعلآ تريد حذف البيانات المحدده ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, " تأكيد الحذف ")
If DeleteOk = vbYes Then
Dim DeleteConfirm As Boolean = Winclass.SQLExicute("Delete FROM PlaneType WHERE TID=" & TxtID.Text)
If DeleteConfirm = True Then
MsgBox("تمت عملية حذف البيانات بنجاح", MsgBoxStyle.Exclamation, "الحذف")
TxtTypeAdd.Text = ""
FillDataGrid()
Else
MsgBox("خطأ في عملية الحذف ", MsgBoxStyle.Critical, "Error")
End If
End If
End Sub
Private Sub BtnExit1_Click(sender As Object, e As EventArgs) Handles BtnExit1.Click
End Sub
End Class