يتم التعديل والامور تماام لكن اريد بعد التعديل ان يقف علة نفس السجل المعدل في الداتا جريد فيو
في كود اضافة يعمل تماام لوعندي 1000 سجل بعد الاضافة يقف على اخر سجل تمت اضافتة
استعملتة للتعديل
وبعد التعديل يتم تحميل كل البيانات ويقف على اول سجل
وظليت اعدل وابدل بالاكواد والان يقف على السجل الثاني او الثالث
فضلا لا امرا الاطلاع على الكود وشرح اين الخطا
هذا الكود المستخدم
كود :
Private Sub BtnEdit_Click(sender As Object, e As EventArgs) Handles BtnEdit.Click
If RadioBtnName.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
'..................كود تاكد من البيانات
myconn.ds = New DataSet
myconn.da = New SqlDataAdapter("Select name from Dalilak where name = '" & TxtNmae.Text & "'", myconn.conn)
myconn.da.Fill(myconn.ds, "Dalilak")
myconn.dv = New DataView(myconn.ds.Tables("Dalilak"))
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
If myconn.cur.Count <> 0 Then
MsgBox("hghsl موجود مسبقا", vbMsgBoxRtlReading + vbCritical, "خطا")
Exit Sub
End If
myconn.updata1(TxtNmae.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
24-09-18, 04:39 AM (آخر تعديل لهذه المشاركة : 24-09-18, 04:46 AM {2} بواسطة essawq.)
السلام عليكم ورحمة الله وبركاتة
هلا اخي
اوكي اخي
هذا كود FrmEdit.vb
كود :
Imports System.Data
Imports System.Data.SqlClient
Public Class FrmEdit
Dim myconn As New DBCoonnect
Private Sub FrmEdit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TxtSersh.Focus()
myconn.load_data()
DgvEdit.DataSource = myconn.dt
DgvEdit.DataSource = Nothing
Dim coluname() As String = {"الرقم", "الاسم", "هاتف 1", " هاتف 2", "العنوان", "ملاحظات"}
myconn.formatgrd(coluname, DgvEdit)
BinDataAdd()
myconn.FormatDgv(dgv:=DgvEdit)
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
myconn.showposition(lbl:=LblCount)
BtnEdit.Enabled = False
TxtNmae.Enabled = False
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
End Sub
Private Sub DgvDelet_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DgvEdit.CellClick
Try
Dim pos As Integer = Me.DgvEdit.CurrentRow.Index
Me.Textrecid.Text = DgvEdit.Rows(pos).Cells(0).Value
Me.TxtNmae.Text = DgvEdit.Rows(pos).Cells(1).Value
Me.TxtPhone1.Text = DgvEdit.Rows(pos).Cells(2).Value
Me.TxtPhone2.Text = DgvEdit.Rows(pos).Cells(3).Value
Me.TxtAdress.Text = DgvEdit.Rows(pos).Cells(4).Value
Me.TxtNotes.Text = DgvEdit.Rows(pos).Cells(5).Value
Catch ex As Exception
Exit Sub
End Try
myconn.showposition(lbl:=LblCount)
End Sub
Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub BtnMoveLast_Click(sender As Object, e As EventArgs) Handles BtnMoveLast.Click
myconn.cur.Position = 0
myconn.showposition(lbl:=LblCount)
End Sub
Private Sub BtnMoveNext_Click(sender As Object, e As EventArgs) Handles BtnMoveNext.Click
myconn.cur.Position -= 1
myconn.showposition(lbl:=LblCount)
End Sub
Private Sub BtnMovePre_Click(sender As Object, e As EventArgs) Handles BtnMovePre.Click
myconn.cur.Position += 1
myconn.showposition(lbl:=LblCount)
End Sub
Private Sub BtnMoveFirst_Click(sender As Object, e As EventArgs) Handles BtnMoveFirst.Click
myconn.cur.Position = myconn.cur.Count - 1
myconn.showposition(lbl:=LblCount)
End Sub
Private Sub TxtNotes_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtNotes.KeyPress
If Char.IsControl(e.KeyChar) = False Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
Private Sub TxtPhone1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtPhone1.KeyPress
Select Case e.KeyChar
Case "0"c To "9"c, Chr(Keys.Back)
'لن نفعل أي شيء.. هذا معناه قبول كتابة هذا الحرف
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub TxtPhone2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtPhone2.KeyPress
Select Case e.KeyChar
Case "0"c To "9"c, Chr(Keys.Back)
'لن نفعل أي شيء.. هذا معناه قبول كتابة هذا الحرف
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub TxtAdress_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtAdress.KeyPress
If Char.IsControl(e.KeyChar) = False Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
Private Sub BtnSershnew_Click(sender As Object, e As EventArgs) Handles BtnSershnew.Click
'myconn.ClereAllText(Me)
'myconn.load_data()
'myconn.FormatDgv(dgv:=DgvEdit)
'TxtNmae.Text = ""
'TxtPhone1.Enabled = True
'TxtPhone2.Enabled = True
'TxtAdress.Enabled = False
'TxtNotes.Enabled = False
'DgvEdit.DataSource = myconn.dv
'myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
'BtnSersh.Enabled = True
'myconn.showposition(lbl:=LblCount)
'BtnEdit.Enabled = False
TxtSersh.Focus()
BtnSersh.Enabled = True
'BtnEditName.Enabled = False
BtnEdit.Enabled = False
BtnEdit.Text = "تعديل "
End Sub
Private Sub BtnSersh_Click(sender As Object, e As EventArgs) Handles BtnSersh.Click
SrrshNameANdNUMBER()
End Sub
Private Sub SrrshNameANdNUMBER()
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
If RadioBtnName.Checked = True Then
If TxtSersh.Text.Trim = "" Then
MsgBox("ادخل قيمة البحث المطلوبة", vbMsgBoxRtlReading + vbCritical, "ادخال البيانات")
TxtSersh.Focus()
Exit Sub
End If
myconn.dt.Clear()
myconn.da = New SqlDataAdapter("Select * from Dalilak Where name= '" & TxtSersh.Text.Trim & "'", myconn.conn)
myconn.da.Fill(myconn.dt)
DgvEdit.DataSource = myconn.dv
If myconn.dt.Rows.Count() > 0 Then
myconn.ID = DgvEdit.CurrentRow.Cells(0).Value
TxtNmae.Text = myconn.dt.Rows(0)(1).ToString
TxtPhone1.Text = myconn.dt.Rows(0)(2).ToString
TxtPhone2.Text = myconn.dt.Rows(0)(3).ToString
TxtAdress.Text = myconn.dt.Rows(0)(4).ToString
TxtNotes.Text = myconn.dt.Rows(0)(5).ToString
DgvEdit.DataSource = myconn.dv
myconn.showposition(lbl:=LblCount)
BtnSersh.Enabled = False
BtnEdit.Enabled = True
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
TxtSersh.Text = ""
BtnEdit.Text = "تعديل الاسم"
Else
MsgBox("لايوجد بيانات", vbMsgBoxRtlReading + vbCritical, "خطا")
myconn.load_data()
DgvEdit.DataSource = myconn.dv
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
BtnEdit.Enabled = False
End If
ElseIf RadoBtnNumper.Checked = True Then
If TxtSersh11.Text = "" Then
MsgBox("ادخل قيمة البحث المطلوبة", vbMsgBoxRtlReading + vbCritical, "ادخال البيانات")
TxtSersh11.Focus()
Exit Sub
End If
myconn.dt.Clear()
myconn.da = New SqlDataAdapter("Select * from Dalilak Where phone1+phone2 like '%" & TxtSersh11.Text & "%'", myconn.conn)
myconn.da.Fill(myconn.dt)
DgvEdit.DataSource = myconn.dv
If myconn.dt.Rows.Count > 0 Then
myconn.ID = DgvEdit.CurrentRow.Cells(0).Value
TxtNmae.Text = myconn.dt.Rows(0)(1).ToString
TxtPhone1.Text = myconn.dt.Rows(0)(2).ToString
TxtPhone2.Text = myconn.dt.Rows(0)(3).ToString
TxtAdress.Text = myconn.dt.Rows(0)(4).ToString
TxtNotes.Text = myconn.dt.Rows(0)(5).ToString
DgvEdit.DataSource = myconn.dv
myconn.showposition(lbl:=LblCount)
BtnSersh.Enabled = False
BtnEdit.Enabled = True
TxtNmae.Enabled = False
TxtPhone1.Enabled = True
TxtPhone2.Enabled = True
TxtAdress.Enabled = True
TxtNotes.Enabled = True
TxtSersh11.Text = ""
BtnEdit.Text = "تعديل الارقام"
Else
MsgBox("لايوجد بيانات", vbMsgBoxRtlReading + vbCritical, "خطا")
myconn.load_data()
DgvEdit.DataSource = myconn.dv
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
myconn.showposition(lbl:=LblCount)
BtnEdit.Enabled = False
'BtnEditName.Enabled = False
End If
End If
End Sub
Private Sub RadioBtnName_Click(sender As Object, e As EventArgs) Handles RadioBtnName.Click
TxtSersh.Enabled = True
TxtSersh11.Enabled = False
TxtSersh.Focus()
TxtSersh11.Text = ""
End Sub
Private Sub RadoBtnNumper_Click(sender As Object, e As EventArgs) Handles RadoBtnNumper.Click
TxtSersh.Enabled = False
TxtSersh11.Enabled = True
TxtSersh11.Focus()
TxtSersh.Text = ""
End Sub
Private Sub BtnEdit_Click(sender As Object, e As EventArgs) Handles BtnEdit.Click
If RadioBtnName.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
'..................كود تاكد من البيانات
myconn.ds = New DataSet
myconn.da = New SqlDataAdapter("Select name from Dalilak where name = '" & TxtNmae.Text & "'", myconn.conn)
myconn.da.Fill(myconn.ds, "Dalilak")
myconn.dv = New DataView(myconn.ds.Tables("Dalilak"))
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
If myconn.cur.Count <> 0 Then
MsgBox("hghsl موجود مسبقا", vbMsgBoxRtlReading + vbCritical, "خطا")
Exit Sub
End If
myconn.updata1(TxtNmae.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
''myconn.dt.Clear()
''myconn.load_data()
'
''DgvEdit.DataSource = myconn.dt
''BindingContext(myconn.dv).Position = myconn.pos
'myconn.cur = CType(Me.BindingContext(myconn.dt), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
If RadoBtnNumper.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
myconn.updataNumper(TxtPhone1.Text, TxtPhone2.Text, TxtAdress.Text, TxtNotes.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
myconn.dt.Clear()
myconn.load_data()
DgvEdit.DataSource = myconn.dt
BindingContext(myconn.dt).Position = myconn.pos
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
End Sub
Private Sub TxtSersh_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtSersh.KeyPress
If Char.IsControl(e.KeyChar) = False Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
Private Sub TxtSersh11_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtSersh11.KeyPress
Select Case e.KeyChar
Case "0"c To "9"c, Chr(Keys.Back)
'لن نفعل أي شيء.. هذا معناه قبول كتابة هذا الحرف
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub BinDataAdd()
Textrecid.DataBindings.Clear()
TxtNmae.DataBindings.Clear()
TxtPhone1.DataBindings.Clear()
TxtPhone2.DataBindings.Clear()
TxtAdress.DataBindings.Clear()
TxtNotes.DataBindings.Clear()
Textrecid.DataBindings.Add("text", myconn.dv, "ID")
TxtNmae.DataBindings.Add("text", myconn.dv, "name")
TxtPhone1.DataBindings.Add("text", myconn.dv, "phone1")
TxtPhone2.DataBindings.Add("text", myconn.dv, "phone2")
TxtAdress.DataBindings.Add("text", myconn.dv, "adress")
TxtNotes.DataBindings.Add("text", myconn.dv, "notes")
End Sub
End Class
[b]هذا كود FrmEdit.Designer.vb[/b]
كود :
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class FrmEdit
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(FrmEdit))
Me.TxtAdress = New System.Windows.Forms.TextBox()
Me.Label5 = New System.Windows.Forms.Label()
Me.BtnSershnew = New System.Windows.Forms.Button()
Me.TxtSersh = New System.Windows.Forms.TextBox()
Me.BtnMoveLast = New System.Windows.Forms.Button()
Me.BtnMoveNext = New System.Windows.Forms.Button()
Me.BtnMovePre = New System.Windows.Forms.Button()
Me.BtnMoveFirst = New System.Windows.Forms.Button()
Me.BtnSersh = New System.Windows.Forms.Button()
Me.TxtNotes = New System.Windows.Forms.TextBox()
Me.TxtPhone2 = New System.Windows.Forms.TextBox()
Me.TxtPhone1 = New System.Windows.Forms.TextBox()
Me.TxtNmae = New System.Windows.Forms.TextBox()
Me.Label7 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.DgvEdit = New System.Windows.Forms.DataGridView()
Me.BtnExit = New System.Windows.Forms.Button()
Me.LblCount = New System.Windows.Forms.Label()
Me.BtnEdit = New System.Windows.Forms.Button()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Textrecid = New System.Windows.Forms.TextBox()
Me.TxtSersh11 = New System.Windows.Forms.TextBox()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.RadoBtnNumper = New System.Windows.Forms.RadioButton()
Me.RadioBtnName = New System.Windows.Forms.RadioButton()
CType(Me.DgvEdit, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TxtAdress
'
Me.TxtAdress.Location = New System.Drawing.Point(454, 43)
Me.TxtAdress.MaxLength = 10
Me.TxtAdress.Name = "TxtAdress"
Me.TxtAdress.ShortcutsEnabled = False
Me.TxtAdress.Size = New System.Drawing.Size(262, 20)
Me.TxtAdress.TabIndex = 3
Me.TxtAdress.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label5.ForeColor = System.Drawing.Color.Blue
Me.Label5.Location = New System.Drawing.Point(393, 42)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(60, 22)
Me.Label5.TabIndex = 157
Me.Label5.Text = "العنوان:"
'
'BtnSershnew
'
Me.BtnSershnew.Font = New System.Drawing.Font("Arial", 21.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnSershnew.ForeColor = System.Drawing.Color.Blue
Me.BtnSershnew.Image = Global.Dalilak2019.My.Resources.Resources.searchNew
Me.BtnSershnew.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.BtnSershnew.Location = New System.Drawing.Point(8, 26)
Me.BtnSershnew.Name = "BtnSershnew"
Me.BtnSershnew.Size = New System.Drawing.Size(178, 74)
Me.BtnSershnew.TabIndex = 6
Me.BtnSershnew.Text = "بحث جديد"
Me.BtnSershnew.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.BtnSershnew.UseVisualStyleBackColor = True
'
'TxtSersh
'
Me.TxtSersh.Location = New System.Drawing.Point(394, 30)
Me.TxtSersh.MaxLength = 30
Me.TxtSersh.Name = "TxtSersh"
Me.TxtSersh.Size = New System.Drawing.Size(284, 29)
Me.TxtSersh.TabIndex = 8
Me.TxtSersh.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'BtnMoveLast
'
Me.BtnMoveLast.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnMoveLast.ForeColor = System.Drawing.Color.Blue
Me.BtnMoveLast.Location = New System.Drawing.Point(657, 496)
Me.BtnMoveLast.Name = "BtnMoveLast"
Me.BtnMoveLast.Size = New System.Drawing.Size(75, 38)
Me.BtnMoveLast.TabIndex = 153
Me.BtnMoveLast.Text = ">|"
Me.BtnMoveLast.UseVisualStyleBackColor = True
'
'BtnMoveNext
'
Me.BtnMoveNext.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnMoveNext.ForeColor = System.Drawing.Color.Blue
Me.BtnMoveNext.Location = New System.Drawing.Point(576, 496)
Me.BtnMoveNext.Name = "BtnMoveNext"
Me.BtnMoveNext.Size = New System.Drawing.Size(75, 38)
Me.BtnMoveNext.TabIndex = 152
Me.BtnMoveNext.Text = ">"
Me.BtnMoveNext.UseVisualStyleBackColor = True
'
'BtnMovePre
'
Me.BtnMovePre.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnMovePre.ForeColor = System.Drawing.Color.Blue
Me.BtnMovePre.Location = New System.Drawing.Point(85, 496)
Me.BtnMovePre.Name = "BtnMovePre"
Me.BtnMovePre.Size = New System.Drawing.Size(75, 38)
Me.BtnMovePre.TabIndex = 151
Me.BtnMovePre.Text = "<"
Me.BtnMovePre.UseVisualStyleBackColor = True
'
'BtnMoveFirst
'
Me.BtnMoveFirst.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnMoveFirst.ForeColor = System.Drawing.Color.Blue
Me.BtnMoveFirst.Location = New System.Drawing.Point(4, 496)
Me.BtnMoveFirst.Name = "BtnMoveFirst"
Me.BtnMoveFirst.Size = New System.Drawing.Size(75, 38)
Me.BtnMoveFirst.TabIndex = 150
Me.BtnMoveFirst.Text = "|<"
Me.BtnMoveFirst.UseVisualStyleBackColor = True
'
'BtnSersh
'
Me.BtnSersh.Font = New System.Drawing.Font("Arial", 21.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnSersh.ForeColor = System.Drawing.Color.Blue
Me.BtnSersh.Image = Global.Dalilak2019.My.Resources.Resources.search
Me.BtnSersh.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.BtnSersh.Location = New System.Drawing.Point(192, 26)
Me.BtnSersh.Name = "BtnSersh"
Me.BtnSersh.Size = New System.Drawing.Size(178, 74)
Me.BtnSersh.TabIndex = 5
Me.BtnSersh.Text = "بحث"
Me.BtnSersh.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.BtnSersh.UseVisualStyleBackColor = True
'
'TxtNotes
'
Me.TxtNotes.Location = New System.Drawing.Point(454, 71)
Me.TxtNotes.MaxLength = 50
Me.TxtNotes.Multiline = True
Me.TxtNotes.Name = "TxtNotes"
Me.TxtNotes.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.TxtNotes.Size = New System.Drawing.Size(262, 65)
Me.TxtNotes.TabIndex = 4
Me.TxtNotes.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'TxtPhone2
'
Me.TxtPhone2.Location = New System.Drawing.Point(94, 43)
Me.TxtPhone2.MaxLength = 10
Me.TxtPhone2.Name = "TxtPhone2"
Me.TxtPhone2.ShortcutsEnabled = False
Me.TxtPhone2.Size = New System.Drawing.Size(283, 20)
Me.TxtPhone2.TabIndex = 2
Me.TxtPhone2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'TxtPhone1
'
Me.TxtPhone1.Location = New System.Drawing.Point(454, 15)
Me.TxtPhone1.MaxLength = 10
Me.TxtPhone1.Name = "TxtPhone1"
Me.TxtPhone1.ShortcutsEnabled = False
Me.TxtPhone1.Size = New System.Drawing.Size(262, 20)
Me.TxtPhone1.TabIndex = 1
Me.TxtPhone1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'TxtNmae
'
Me.TxtNmae.Enabled = False
Me.TxtNmae.Location = New System.Drawing.Point(93, 15)
Me.TxtNmae.MaxLength = 28
Me.TxtNmae.Name = "TxtNmae"
Me.TxtNmae.ShortcutsEnabled = False
Me.TxtNmae.Size = New System.Drawing.Size(283, 20)
Me.TxtNmae.TabIndex = 0
Me.TxtNmae.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'Label7
'
Me.Label7.AutoSize = True
Me.Label7.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label7.ForeColor = System.Drawing.Color.Blue
Me.Label7.Location = New System.Drawing.Point(378, 66)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(76, 22)
Me.Label7.TabIndex = 147
Me.Label7.Text = "ملاحظات :"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.ForeColor = System.Drawing.Color.Blue
Me.Label3.Location = New System.Drawing.Point(20, 39)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(70, 22)
Me.Label3.TabIndex = 146
Me.Label3.Text = "هاتف 2 :"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.ForeColor = System.Drawing.Color.Blue
Me.Label2.Location = New System.Drawing.Point(383, 13)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(70, 22)
Me.Label2.TabIndex = 145
Me.Label2.Text = "هاتف 1 :"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Blue
Me.Label1.Location = New System.Drawing.Point(34, 11)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(54, 22)
Me.Label1.TabIndex = 144
Me.Label1.Text = "الاسم :"
'
'DgvEdit
'
Me.DgvEdit.AllowUserToAddRows = False
Me.DgvEdit.AllowUserToDeleteRows = False
Me.DgvEdit.AllowUserToResizeColumns = False
Me.DgvEdit.AllowUserToResizeRows = False
Me.DgvEdit.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.DgvEdit.Location = New System.Drawing.Point(3, 263)
Me.DgvEdit.MultiSelect = False
Me.DgvEdit.Name = "DgvEdit"
Me.DgvEdit.ReadOnly = True
Me.DgvEdit.RowHeadersVisible = False
Me.DgvEdit.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
Me.DgvEdit.Size = New System.Drawing.Size(848, 227)
Me.DgvEdit.TabIndex = 139
'
'BtnExit
'
Me.BtnExit.Font = New System.Drawing.Font("Arial", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnExit.ForeColor = System.Drawing.Color.Blue
Me.BtnExit.Image = Global.Dalilak2019.My.Resources.Resources._Exit
Me.BtnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.BtnExit.Location = New System.Drawing.Point(735, 496)
Me.BtnExit.Name = "BtnExit"
Me.BtnExit.Size = New System.Drawing.Size(109, 38)
Me.BtnExit.TabIndex = 9
Me.BtnExit.Text = "خروج"
Me.BtnExit.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.BtnExit.UseVisualStyleBackColor = True
'
'LblCount
'
Me.LblCount.Font = New System.Drawing.Font("Tahoma", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.LblCount.ForeColor = System.Drawing.Color.Red
Me.LblCount.Location = New System.Drawing.Point(170, 496)
Me.LblCount.Name = "LblCount"
Me.LblCount.Size = New System.Drawing.Size(254, 38)
Me.LblCount.TabIndex = 137
Me.LblCount.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'BtnEdit
'
Me.BtnEdit.Font = New System.Drawing.Font("Arial", 21.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.BtnEdit.ForeColor = System.Drawing.Color.Blue
Me.BtnEdit.Image = Global.Dalilak2019.My.Resources.Resources.edit
Me.BtnEdit.ImageAlign = System.Drawing.ContentAlignment.MiddleRight
Me.BtnEdit.Location = New System.Drawing.Point(93, 66)
Me.BtnEdit.Name = "BtnEdit"
Me.BtnEdit.Size = New System.Drawing.Size(284, 70)
Me.BtnEdit.TabIndex = 7
Me.BtnEdit.Text = "تعديل"
Me.BtnEdit.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.BtnEdit.UseVisualStyleBackColor = True
'
'PictureBox1
'
Me.PictureBox1.Image = Global.Dalilak2019.My.Resources.Resources.iphone1
Me.PictureBox1.Location = New System.Drawing.Point(722, 7)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(128, 129)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.PictureBox1.TabIndex = 135
Me.PictureBox1.TabStop = False
'
'Textrecid
'
Me.Textrecid.Location = New System.Drawing.Point(499, 508)
Me.Textrecid.Name = "Textrecid"
Me.Textrecid.Size = New System.Drawing.Size(62, 20)
Me.Textrecid.TabIndex = 158
'
'TxtSersh11
'
Me.TxtSersh11.Location = New System.Drawing.Point(394, 65)
Me.TxtSersh11.MaxLength = 10
Me.TxtSersh11.Name = "TxtSersh11"
Me.TxtSersh11.Size = New System.Drawing.Size(284, 29)
Me.TxtSersh11.TabIndex = 159
Me.TxtSersh11.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadoBtnNumper)
Me.GroupBox1.Controls.Add(Me.RadioBtnName)
Me.GroupBox1.Controls.Add(Me.TxtSersh)
Me.GroupBox1.Controls.Add(Me.TxtSersh11)
Me.GroupBox1.Controls.Add(Me.BtnSershnew)
Me.GroupBox1.Controls.Add(Me.BtnSersh)
Me.GroupBox1.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.GroupBox1.ForeColor = System.Drawing.Color.Blue
Me.GroupBox1.Location = New System.Drawing.Point(24, 142)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes
Me.GroupBox1.Size = New System.Drawing.Size(805, 115)
Me.GroupBox1.TabIndex = 161
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "خيارات البخث"
'
'RadoBtnNumper
'
Me.RadoBtnNumper.AutoSize = True
Me.RadoBtnNumper.Location = New System.Drawing.Point(677, 65)
Me.RadoBtnNumper.Name = "RadoBtnNumper"
Me.RadoBtnNumper.Size = New System.Drawing.Size(111, 26)
Me.RadoBtnNumper.TabIndex = 161
Me.RadoBtnNumper.Text = "بحث بالرقم :"
Me.RadoBtnNumper.UseVisualStyleBackColor = True
'
'RadioBtnName
'
Me.RadioBtnName.AutoSize = True
Me.RadioBtnName.Checked = True
Me.RadioBtnName.Location = New System.Drawing.Point(677, 30)
Me.RadioBtnName.Name = "RadioBtnName"
Me.RadioBtnName.Size = New System.Drawing.Size(109, 26)
Me.RadioBtnName.TabIndex = 160
Me.RadioBtnName.TabStop = True
Me.RadioBtnName.Text = "بحث بالاسم :"
Me.RadioBtnName.UseVisualStyleBackColor = True
'
'FrmEdit1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.DarkSalmon
Me.ClientSize = New System.Drawing.Size(854, 540)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Textrecid)
Me.Controls.Add(Me.TxtAdress)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.BtnMoveLast)
Me.Controls.Add(Me.BtnMoveNext)
Me.Controls.Add(Me.BtnMovePre)
Me.Controls.Add(Me.BtnMoveFirst)
Me.Controls.Add(Me.BtnEdit)
Me.Controls.Add(Me.TxtNotes)
Me.Controls.Add(Me.TxtPhone2)
Me.Controls.Add(Me.TxtPhone1)
Me.Controls.Add(Me.TxtNmae)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.DgvEdit)
Me.Controls.Add(Me.BtnExit)
Me.Controls.Add(Me.LblCount)
Me.Controls.Add(Me.PictureBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "FrmEdit1"
Me.RightToLeft = System.Windows.Forms.RightToLeft.Yes
Me.RightToLeftLayout = True
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "شاشة البحث والتعديل"
CType(Me.DgvEdit, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TxtAdress As TextBox
Friend WithEvents Label5 As Label
Friend WithEvents BtnSershnew As Button
Friend WithEvents TxtSersh As TextBox
Friend WithEvents BtnMoveLast As Button
Friend WithEvents BtnMoveNext As Button
Friend WithEvents BtnMovePre As Button
Friend WithEvents BtnMoveFirst As Button
Friend WithEvents BtnSersh As Button
Friend WithEvents BtnEdit As Button
Friend WithEvents TxtNotes As TextBox
Friend WithEvents TxtPhone2 As TextBox
Friend WithEvents TxtPhone1 As TextBox
Friend WithEvents TxtNmae As TextBox
Friend WithEvents Label7 As Label
Friend WithEvents Label3 As Label
Friend WithEvents Label2 As Label
Friend WithEvents Label1 As Label
Friend WithEvents DgvEdit As DataGridView
Friend WithEvents BtnExit As Button
Friend WithEvents LblCount As Label
Friend WithEvents PictureBox1 As PictureBox
Friend WithEvents Textrecid As TextBox
Friend WithEvents TxtSersh11 As TextBox
Friend WithEvents GroupBox1 As GroupBox
Friend WithEvents RadoBtnNumper As RadioButton
Friend WithEvents RadioBtnName As RadioButton
End Class
الكلاس DBCoonnect غير موجود لدي , لكن إن شاء يعمل معك هذا الكود بعد التعديل
كود :
Private Sub BtnEdit_Click(sender As Object, e As EventArgs) Handles BtnEdit.Click
If RadioBtnName.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
'..................كود تاكد من البيانات
myconn.ds = New DataSet
myconn.da = New SqlDataAdapter("Select name from Dalilak where name = '" & TxtNmae.Text & "'", myconn.conn)
myconn.da.Fill(myconn.ds, "Dalilak")
myconn.dv = New DataView(myconn.ds.Tables("Dalilak"))
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
If myconn.cur.Count <> 0 Then
MsgBox("hghsl موجود مسبقا", vbMsgBoxRtlReading + vbCritical, "خطا")
Exit Sub
End If
myconn.updata1(TxtNmae.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
Dim CurrentPosition As Integer = BindingContext(myconn.dv).Position
''''''''''''''''''''myconn.pos = myconn.dt.Rows.Count
myconn.load_data()
DgvEdit.DataSource = myconn.dv
BindingContext(myconn.dv).Position = CurrentPosition
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
''myconn.dt.Clear()
''myconn.load_data()
'
''DgvEdit.DataSource = myconn.dt
''BindingContext(myconn.dv).Position = myconn.pos
'myconn.cur = CType(Me.BindingContext(myconn.dt), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
If RadoBtnNumper.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
myconn.updataNumper(TxtPhone1.Text, TxtPhone2.Text, TxtAdress.Text, TxtNotes.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
myconn.dt.Clear()
myconn.load_data()
DgvEdit.DataSource = myconn.dt
BindingContext(myconn.dt).Position = myconn.pos
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
End Sub
24-09-18, 11:25 AM (آخر تعديل لهذه المشاركة : 24-09-18, 11:26 AM {2} بواسطة essawq.)
(24-09-18, 05:17 AM)عبدالله الدوسري كتب : الكلاس DBCoonnect غير موجود لدي , لكن إن شاء يعمل معك هذا الكود بعد التعديل
كود :
Private Sub BtnEdit_Click(sender As Object, e As EventArgs) Handles BtnEdit.Click
If RadioBtnName.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
'..................كود تاكد من البيانات
myconn.ds = New DataSet
myconn.da = New SqlDataAdapter("Select name from Dalilak where name = '" & TxtNmae.Text & "'", myconn.conn)
myconn.da.Fill(myconn.ds, "Dalilak")
myconn.dv = New DataView(myconn.ds.Tables("Dalilak"))
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
If myconn.cur.Count <> 0 Then
MsgBox("hghsl موجود مسبقا", vbMsgBoxRtlReading + vbCritical, "خطا")
Exit Sub
End If
myconn.updata1(TxtNmae.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
Dim CurrentPosition As Integer = BindingContext(myconn.dv).Position
''''''''''''''''''''myconn.pos = myconn.dt.Rows.Count
myconn.load_data()
DgvEdit.DataSource = myconn.dv
BindingContext(myconn.dv).Position = CurrentPosition
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
''myconn.dt.Clear()
''myconn.load_data()
'
''DgvEdit.DataSource = myconn.dt
''BindingContext(myconn.dv).Position = myconn.pos
'myconn.cur = CType(Me.BindingContext(myconn.dt), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
If RadoBtnNumper.Checked = True Then
If myconn.conn.State = ConnectionState.Closed Then
myconn.conn.Open()
End If
myconn.updataNumper(TxtPhone1.Text, TxtPhone2.Text, TxtAdress.Text, TxtNotes.Text, myconn.ID)
MsgBox("تمت عملية تحديث البيانات بنجاح", vbMsgBoxRtlReading + vbInformation, "التحديث")
myconn.dt.Clear()
myconn.load_data()
DgvEdit.DataSource = myconn.dt
BindingContext(myconn.dt).Position = myconn.pos
myconn.cur = CType(Me.BindingContext(myconn.dv), CurrencyManager)
myconn.showposition(lbl:=LblCount)
myconn.conn.Open()
TxtSersh11.Text = ""
TxtSersh.Text = ""
BtnEdit.Enabled = False
TxtNmae.Enabled = True
TxtPhone1.Enabled = False
TxtPhone2.Enabled = False
TxtAdress.Enabled = False
TxtNotes.Enabled = False
BtnSersh.Enabled = False
BtnEdit.Text = "تعديل "
End If
End Sub
السلام عليكم ورحمة الله وبركاتة
مشكور اخي وبارك الله فيك
لا زالت نفس المشكلة يقف على اول صف
تفضل اخي ارفقت الكلاس