Public Class Frmnat
Dim isupdate As Boolean
Dim minclass As New Class1
Dim dg As New DataGridView
'كودالكتابة بالعربية
Private Sub Txtorder_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Txtname.KeyPress
Select Case e.KeyChar
Case "ء" To "ي", ControlChars.Back, Chr(Keys.Space)
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub
Private Sub Btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
Txtname.Text = ""
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If Txtname.Text.Trim = "" Then
MsgBox("لم تقم بادخال بيانات يمكن حفظها", MsgBoxStyle.Critical, "تنبيه")
Exit Sub
End If
'................................................. ...........................................
'اذا كانت العملية تعديل
If isupdate = True Then
Dim updateok As Boolean = minclass.sqlexicute("update nat set NName='" & Txtname.Text & "' where NID='" & Txtid.Text & "' ")
If updateok = True Then
MsgBox("تمت عملية تعديل البانات بنجاح", MsgBoxStyle.Information, "تأكيد عملية التعديل")
Txtname.Enabled = True
Txtid.Text = ""
Txtname.Text = ""
Filldatagrid()
MsgBox("خطاء", MsgBoxStyle.Critical, "خطاء")
End If
Else
'................................................. .................................................. .........
'اذا كانت العملية حفظ
Dim saveok As Boolean = minclass.sqlexicute("insert into nat(NName)values('" & Txtname.Text & "' )")
If saveok = True Then
MsgBox("تمت عملية الحفظ بنجاح", MsgBoxStyle.Exclamation, " عملية الحفظ تأكيد")
Txtid.Text = ""
Txtname.Text = ""
Filldatagrid()
End If
End If
End Sub
' .................................................. ............................................
Private Sub Filldatagrid()
minclass.Filldatagrid(dg, "select *From nat")
dg.Columns(0).HeaderText = "الرقم"
dg.Columns(0).Visible = "false"
dg.Columns(1).HeaderText = "الاسم "
dg.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End Sub
Private Sub Frmnat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Filldatagrid()
End Sub
Private Sub Dg_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
isupdate = True
Txtname.Enabled = True
Txtid.Text = dg(0, e.RowIndex).Value
Txtname.Text = dg(0, e.RowIndex).Value
End Sub
Private Sub butdelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim deleteok As String = MsgBox("هل ترقب بحذف البيانات", MsgBoxStyle.Question, "تأكيد")
If deleteok = vbYes Then
Dim deleteconfrim As Boolean = minclass.sqlexicute("delete from orders where orderid=" & Txtid.Text & " ")
If deleteconfrim = True Then
MsgBox("تم عملية حذف البيانات المحدده", MsgBoxStyle.Exclamation, "عنوان الرسالة")
Txtname.Text = ""
Filldatagrid()
Else
MsgBox("خطا في عملية حذف الرسالة", MsgBoxStyle.Critical, "خطا")
End If
End If
End Sub