02-11-17, 08:55 PM
الكود
مثال
قيمة الخصم : 44 جنيه
قبل الخصم
بعد الخصم
للاستفسار
https://goo.gl/Kbu4Mc
كود :
Dim dis As Double = Val(TXT_DISCOUNT.Text)
For i As Integer = 0 To DGV.Rows.Count - 1
Dim def As Double = Val(DGV(2, DGV.Rows(i).Index).Value) - Val(DGV(8, DGV.Rows(i).Index).Value)
If def <= 0 Or Val(DGV(2, DGV.Rows(i).Index).Value) <= Val(DGV(8, DGV.Rows(i).Index).Value) Then
DGV(3, DGV.Rows(i).Index).Value = Val(DGV(2, DGV.Rows(i).Index).Value)
DGV(7, DGV.Rows(i).Index).Value = Val(DGV(3, DGV.Rows(i).Index).Value) * Val(DGV(4, DGV.Rows(i).Index).Value)
Continue For
End If
' أذا كان الخصم أقل من اجمالى الصنف
If dis < def * Val(DGV(4, DGV.Rows(i).Index).Value) Then
DGV(3, DGV.Rows(i).Index).Value = Val(DGV(2, DGV.Rows(i).Index).Value) - (dis / Val(DGV(4, DGV.Rows(i).Index).Value))
DGV(7, DGV.Rows(i).Index).Value = Val(DGV(3, DGV.Rows(i).Index).Value) * Val(DGV(4, DGV.Rows(i).Index).Value)
DGV.Rows(i).DefaultCellStyle.BackColor = Color.Red
dis = dis - (def * Val(DGV(4, DGV.Rows(i).Index).Value))
Exit For
End If
If def < dis * Val(DGV(4, DGV.Rows(i).Index).Value) And Val(DGV(2, DGV.Rows(i).Index).Value) > Val(DGV(8, DGV.Rows(i).Index).Value) Then
DGV(3, DGV.Rows(i).Index).Value = Val(DGV(2, DGV.Rows(i).Index).Value) - def
DGV(7, DGV.Rows(i).Index).Value = Val(DGV(3, DGV.Rows(i).Index).Value) * Val(DGV(4, DGV.Rows(i).Index).Value)
DGV.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
Else
DGV(3, DGV.Rows(i).Index).Value = Val(DGV(2, DGV.Rows(i).Index).Value) - dis
DGV(7, DGV.Rows(i).Index).Value = Val(DGV(3, DGV.Rows(i).Index).Value) * Val(DGV(4, DGV.Rows(i).Index).Value)
DGV.Rows(i).DefaultCellStyle.BackColor = Color.Plum
End If
dis = dis - (def * Val(DGV(4, DGV.Rows(i).Index).Value))
If dis <= 0 Then
Exit For
End If
Next
For i As Integer = 0 To DGV.Rows.Count - 1
If Val(DGV(3, DGV.Rows(i).Index).Value) = Nothing Then
DGV(3, DGV.Rows(i).Index).Value = DGV(2, DGV.Rows(i).Index).Value
DGV(7, DGV.Rows(i).Index).Value = Val(DGV(3, DGV.Rows(i).Index).Value) * Val(DGV(4, DGV.Rows(i).Index).Value)
End If
Next
'00000000000000000000000000000000000000000000000
Dim s As Double
For i As Integer = 0 To DGV.Rows.Count - 1
s = s + Val(DGV(7, DGV.Rows(i).Index).Value)
TextBox1.Text = s
Next
قيمة الخصم : 44 جنيه
قبل الخصم
بعد الخصم
للاستفسار
https://goo.gl/Kbu4Mc