hi all,
I have a form where user enters productID and price and it will sum the total in a textbox txtTotal.text, then the user will select type of payments (cash, master, visa, ..etc) and will input tendered amount in txtTendered.text and the Balance amount will show in a textbox txtBalance.text. Now if the total amount is 45.99 and the user enters 50.00 in txtTendered.text then txtBlance will show 4.01 (thats easy), if user decides to pay 5.00 cash and 5 visa, 5 master, ...etc what is the most effecient way to calculate this? i mean i am using public variables and its getting crazy. when there txtBalance.text = 0 (no outstanding amount) then the sale form should be closed and the main form will appear.
I am using MSDE. should i just create a datatable to load values everytime the user enters amount? would it slow down the process this way? if multiuser were to be used?
i am using the following code:
then i am calling it in the following procedure:
I just feel there is a better way of accomplishing this.
if anyone knows how to do this, please let me know. thank you
I have a form where user enters productID and price and it will sum the total in a textbox txtTotal.text, then the user will select type of payments (cash, master, visa, ..etc) and will input tendered amount in txtTendered.text and the Balance amount will show in a textbox txtBalance.text. Now if the total amount is 45.99 and the user enters 50.00 in txtTendered.text then txtBlance will show 4.01 (thats easy), if user decides to pay 5.00 cash and 5 visa, 5 master, ...etc what is the most effecient way to calculate this? i mean i am using public variables and its getting crazy. when there txtBalance.text = 0 (no outstanding amount) then the sale form should be closed and the main form will appear.
I am using MSDE. should i just create a datatable to load values everytime the user enters amount? would it slow down the process this way? if multiuser were to be used?
i am using the following code:
VB.NET:
Private Function updatePayment(ByVal myTotal As Double) As Boolean
' This sub updates payment amount entered by the user Dim dTotal As Double
dTotal = CType(txtTotal.Text, Double)
' Check if user payment is more or less than the total
If (myTotal >= dTotal) Then
' Show balance due to customer
txtBalance.Text = returnBalanceDue(dTotal, CType(txtTendered.Text, Double)) ' basically it just subtract!
' Finaliaze sale and update DataSet
...
frmMain.lblChangeBack.Text = txtBalance.Text
Return True
Else
Return False
End If
End Function
then i am calling it in the following procedure:
VB.NET:
Private Sub txtTendered_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTendered.KeyPress
If (updatePaymentAmount(CType(txtTendered.Text, Double))) Then
' No outstanding balance
' Update change back label
Me.Close()
Me.Dispose()
Else
' There is an outstanding balance
' Send focus back to type of payment to select another type
objSalesBalance.GetBalance = CType(txtTendered.Text, Double) ' public property check below
ctrBalance = objSalesBalance.GetBalance
txtPaymentType.Text = ""
txtTendered.Text = ""
txtPaymentType.Focus()
txtBalance.Text = returnBalanceDue(CType(txtTotal.Text, Double), ctrBalance)
End If
End Sub
VB.NET:
Public Class TransactionClass
Public salesTotal As Double ' Stores sales balance
Public Property GetBalance() As Double
Get
Return salesTotal
End Get
Set(ByVal value As Double)
salesTotal = salesTotal + value
End Set
End Property
End Class
I just feel there is a better way of accomplishing this.
if anyone knows how to do this, please let me know. thank you