我正在创建一个 POS系统,在小计页面上我有各种标签,如'现金','卡','凭证'等。
比如说客户总数达到20英镑,他们想用现金支付10英镑,而另外10英镑用他们的卡支付,我有问题让标签按照他们应该的总计。
'总投标'标签显示0.000,即使它应该说£20.00并且余额和更改标签总是显示0.00,即使他们应该说其他。我知道这是非常基本的,但我现在已经尝试了很多年,而且我无处可去。
我也试过从数据库中调用值,但也没有喜欢。谢谢。
(我只包含一个付款按钮点击事件,因为它们都是相同的,除了标签名称更改,例如lblcash.text会在卡片点击事件中说lblcard.text。)
Private Sub btnCash_Click(sender As Object, e As EventArgs) Handles btnCash.Click
'Payment methods...........??
'2 cash entries
'cash and card
'gift voucher and cash
'gift voucher and card
If txtCash.Text = "" Then
MessageBox.Show("Please enter amount")
ElseIf txtCash.Text >= "0.00" Then
lblCash.Text = txtCash.Text
lblCash.Text = FormatCurrency(lblCash.Text, 2)
lblTotTend.Text = (lblCash.Text) + (lblCredit.Text) + (lblVoucher.Text) + (lblOther.Text)
lblTotTend.Text = FormatCurrency(lblTotTend.Text, 2)
'DISPLAYING AS £0.00
lblBALANCE.Text = (lblTOTALDUE.Text) - (lblTotTend.Text)
lblBALANCE.Text = FormatCurrency(lblBALANCE.Text, 2)
If lblBALANCE.Text < "0.00" Then
lblBALANCE.Text = "£0.00"
End If
lblChange.Text = (lblTotTend.Text) - (lblTOTALDUE.Text)
lblChange.Text = FormatCurrency(lblChange.Text, 2)
If lblChange.Text <= "£0.00" Then
lblChange.Text = "£0.00"
End If
txtCash.Text = ""
SqlStr = "UPDATE Subtotal SET CASH = '" & lblCash.Text & "'"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteScalar
SqlStr = "UPDATE Subtotal SET CHANGE = '" & lblChange.Text & "'"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteScalar
SqlStr = "UPDATE Subtotal SET BalanceRemain = '" & lblBALANCE.Text & "'"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteScalar
SqlStr = "UPDATE Subtotal SET TotalTendered = '" & lblTotTend.Text & "'"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteScalar
End If
SqlStr = "INSERT INTO SalesLog(ReceiptID) SELECT Id FROM Subtotal"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteNonQuery
SqlStr = "INSERT INTO TransactionLog(ReceiptID) SELECT Id FROM Subtotal"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
DataP = CMD.ExecuteNonQuery
' Added this statement to try solve problem with totaltendered label
SqlStr = "SELECT SUM(TotalTendered) FROM Subtotal"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
lblTotTend.Text = CMD.ExecuteScalar
lblTotTend.Text = FormatCurrency(lblTotTend.Text, 2)
'UPDATES THE PRICE LABEL TEXTBOX WITH THE LATEST PRICE TOTAL WITHIN THE ACTIVE TABLE!!
SqlStr = Nothing
SqlStr = "SELECT SUM(Price) FROM Active"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
lblTOTALDUE.Text = CMD.ExecuteScalar
' lblTOTALDUE.Text = FormatCurrency(lblTOTALDUE.Text, 2)
If lblBALANCE.Text = "£0.00" Then
Reset()
Application.DoEvents()
'TILL DRAWER OPEN
Threading.Thread.Sleep(5000)
Me.Close()
Login.Show()
End If
End Sub
答案 0 :(得分:0)
好的......你正在尝试对字符串进行数学运算.. If lblChange.Text <= "£0.00" Then
将无法按照您的预期运作。
我可以建议你的'价值'标签中没有货币符号,但是将它们放在一个单独的标签中,从长远来看这将有所帮助。如果您的应用程序走向国际化......或者我们采用欧元......你永远不会知道:)会发生什么?
使用货币符号,您需要做的就是将“价值”标签转换为双打,例如CDbl(lblChange.Text)
- 确保它们首先不是空白。