23-04-25, 09:13 PM
الصفحات : 1 2
23-04-25, 09:13 PM
23-04-25, 09:42 PM
جرب الطريقة التالية
PHP كود :
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.ColumnIndex = 0 Then ' نفترض أن العمود 0 يحتوي على كود الصنف
Dim currentRow As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
Dim currentCode As String = currentRow.Cells(0).Value.ToString()
For i = 0 To DataGridView1.RowCount - 1
If i <> e.RowIndex Then
Dim row As DataGridViewRow = DataGridView1.Rows(i)
If row.Cells(0).Value IsNot Nothing AndAlso row.Cells(0).Value.ToString() = currentCode Then
' صنف مكرر
Dim existingQty As Integer = Val(row.Cells(2).Value) ' نفترض العمود 2 هو الكمية
Dim newQty As Integer = Val(currentRow.Cells(2).Value)
row.Cells(2).Value = existingQty + newQty
' حذف الصف الجديد بأمان
Me.BeginInvoke(New MethodInvoker(Sub()
DataGridView1.Rows.Remove(currentRow)
End Sub))
Exit For
End If
End If
Next
End If
End Sub
23-04-25, 10:32 PM
الف شكر على تعبك ولكن لا يا صديقى لم ينجح الكود
23-04-25, 11:36 PM
وعليكم السلام ورحمة الله وبركاته
الكود التالي سيعمل معك
بإذن الله تعالى
الكود التالي سيعمل معك
بإذن الله تعالى
كود :
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim pro_code As String = DataGridView1.CurrentRow.Cells(0).Value
Dim pro_name As String = DataGridView1.CurrentRow.Cells(1).Value
Dim QTY As String = DataGridView1.CurrentRow.Cells(2).Value
Dim prise As Decimal = DataGridView1.CurrentRow.Cells(3).Value
If pro_code = "" Then
MsgBox("الرجاء عدم ترك خانه رقم الصنف فارغة")
Return
End If
If part_no_Ex(pro_code) = False Then
If MessageBox.Show("هذا الصنف غير موجود بقاعده البيانات هل تريد تسجيلة ؟؟", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
Return
End If
add_pro.TextBox1.Text = pro_code
add_pro.ShowDialog()
Return
End If
If e.ColumnIndex = 0 Then
For i As Integer = 0 To DataGridView1.RowCount - 1
If i <> DataGridView1.CurrentRow.Index AndAlso DataGridView1.Rows(i).Cells(0).Value = pro_code Then
Dim existingQty As Integer = Val(DataGridView1.Rows(i).Cells(2).Value)
DataGridView1.Rows(i).Cells(2).Value = existingQty + 1
DataGridView1.Rows(i).Cells(4).Value = (existingQty + 1) * Val(DataGridView1.Rows(i).Cells(3).Value)
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
GoTo UpdateTotal
End If
Next
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
Dim cmd As New OleDbCommand()
cmd.Connection = con
cmd.CommandText = "select * from product where pro_code =@pro_code"
cmd.Parameters.AddWithValue("@pro_code", pro_code)
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read
pro_name = dr.Item(1)
prise = dr.Item(5)
DataGridView1.CurrentRow.Cells(1).Value = pro_name
DataGridView1.CurrentRow.Cells(2).Value = 1
DataGridView1.CurrentRow.Cells(3).Value = prise
DataGridView1.CurrentRow.Cells(4).Value = prise
End While
dr.Close()
con.Close()
ElseIf e.ColumnIndex = 2 Then
Dim total As Decimal
total = QTY * prise
DataGridView1.CurrentRow.Cells(4).Value = total
End If
UpdateTotal:
Dim sum_total As Decimal = 0
For i As Integer = 0 To DataGridView1.RowCount - 1
sum_total += Val(DataGridView1.Rows(i).Cells(4).Value)
Next
TextBox3.Text = sum_total
End Sub24-04-25, 12:54 PM
صديقى واخى princelovelorn عامل ايه يرب تكون فى نعمه
ساجرب الكود ان شاء الله
ساجرب الكود ان شاء الله
24-05-25, 01:14 AM
24-05-25, 04:48 PM
الكود يعمل جيداً أخي
24-05-25, 07:59 PM
طب تسمحلى تبعتلى السورس اللى شغال ده
24-05-25, 10:49 PM
يا ريت الفورمة علشان نتعلم منها
وتبقيكسبت ثواب في الجميع
وتبقيكسبت ثواب في الجميع
24-05-25, 10:49 PM
الصفحات : 1 2