السلام عليكم ورحمة الله
هذه دالة QuantityDiscount لإجراء الخصم من المستودعات ترسل لها رقم الصنف الكمية المطلوبة، إن شاء الله يكون تمام
PHP كود :
Dim connString As String = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = Database1.accdb;"
Dim conn As New OleDbConnection(connString)
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
QuantityDiscount(Val(Me.TextBox1.Text), Val(Me.TextBox2.Text))
End Sub
' خصم الكمية المطلوبة من المستودعات '
Public Function QuantityDiscount(nump As Integer, qty As Integer) As Boolean
' التأكد من صحة الأرقام المدخلة '
If (nump <= 0) Or (qty <= 0) Then Exit Function
'----------------------------------------'
Using con As New OleDbConnection(connString)
con.Open()
'---------- التأكد من توفر الكمية المطلوبة ----------'
Using comm As New OleDbCommand(" SELECT [nowp] FROM [products] WHERE [nump] = @nump ", con)
comm.Parameters.AddWithValue("@nump", nump)
If comm.ExecuteScalar < qty Then
MsgBox("الكمية المطلوبة غير متوفرة في المستودعات", _
MsgBoxStyle.Critical + MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.MsgBoxRight)
Return False
End If
End Using
'---------- خصم الكمية المطلوبة من المستودعات ----------'
Dim result As Integer
Using comm As New OleDbCommand(" UPDATE [products] SET [nowp] = [nowp] - @qty ", con)
comm.Parameters.AddWithValue("@qty", qty)
result = comm.ExecuteNonQuery()
End Using
'---------- التأكد من نتيجة عملية الخصم ----------'
If result > 0 Then
MsgBox("تم خصم الكمية المطلوبة من المستودعات", _
MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.MsgBoxRight)
Return True
End If
con.Close()
End Using
End Function

