我的表单上有4个文本框和一个标签,4个文本框代表4种付款方式(现金,卡,银行转帐和其他付款方式)。 在我的标签中,我有汇总值,当我向收据中添加新项目时,该值会增加。
文本框名称为:cashTbox
cardTbox
bankTbox
otherTbox
标签名称为:summaryLbl
默认情况下,cashTextbox.text等于summ.content,并且每次我向数据库添加项目时,我都会递增summaryLbl
+ itemPrice
(数据库中的商品价格)。
我尝试过创建一个函数,该函数将允许我从cashTbox
减去其他付款类型,而又不允许cashTbox
变为负值。
我的代码如下:
Private Sub cashTbox_LostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs) Handles cashTbox.LostKeyboardFocus
If sender.IsFocused = True And sender.text.length > 0 Then
If calculateP(sender) = True Then
End If
End If
End Sub
Dim sumP as decimal = summaryLbl.content
Dim cashP as decimal = cashTbox.text
Dim cardP as decimal = cardTbox.text
Dim bankP as decimal = bankTbox.text
Dim otherP as decimal = otherTbox.text
Public Function calculateP(ByVal s As Object)
Try
If String.IsNullOrEmpty(s.text) Then
s.text = "0,00"
Else
s.text = Decimal.Parse(s.text)
End If
If s Is cashTbox Then
ElseIf s Is cardTbox Then
cardP = s.text
cashTbox.Text = sumP - (cardP + bankP + otherP )
ElseIf s Is bankTbox Then
bankP = s.text
cashTbox.Text = sumP - (cardP + bankP + otherP )
ElseIf s Is otherTbox Then
otherP = s.text
cashTbox.Text = sumP - (cardP + bankP + otherP )
End If
cashTbox.Text = sumP - (cardP + bankP + otherP )
Catch ex As Exception
End Try
setValues()
Return True
End Function
Public Function setValues()
summaryLbl.content = sumP
cashTbox.text = cashP
cardTbox.text = cardP
bankTbox.text = bankP
otherTbox.text = otherP
End Function