计算错误vb.net文本框

时间:2017-03-27 11:27:15

标签: vb.net

我正在使用库存系统,交易表格我主要有2个文本框,第1个是从数据库可用的数量,其他文本框是来自用户添加数量的avqty。

当用户添加qty avaqty文本框时自动更改为 (avaqty) - (avqty)但作为一个例子10-10结果进来-1

我的代码是:

Public Class transaction
Dim objcon As New connectionclass

Dim qty As String
Public Function getqty() As String
    If itemid.Text = "" Then
    Else
        Try
            objcon.myconnection.Open()
            Dim getqty1 As New OleDbCommand("select balance from avaqty where item_id=" & itemid.Text & "", objcon.myconnection)
            Dim reader As OleDbDataReader = getqty1.ExecuteReader
            While reader.Read
                qty = reader("balance")
            End While
            objcon.myconnection.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End If
    Return qty
End Function
Private Sub itemid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles itemid.KeyPress
    If Asc(e.KeyChar) = 13 Then
        objcon.myconnection.Open()
        Try

            Dim getdata As New OleDbCommand("select*from itemtbl where item_id=" & itemid.Text & "", objcon.myconnection)
            Dim reader As OleDbDataReader = getdata.ExecuteReader
            While reader.Read

                itemdesc.Text = reader("item_des").ToString
                yom.Text = reader("unit_of_mesure").ToString
                cost.Text = reader("item_cost").ToString

            End While

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        objcon.myconnection.Close()
    End If
    If getqty() = 0 Then
        avaqty.Text = 0
    Else
        avaqty.Text = getqty()
    End If
End Sub



Private Sub initem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles initem.CheckedChanged
    dataview.DataSource = GETDATA()
End Sub

Private Sub outitem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles outitem.CheckedChanged
    dataview.DataSource = GETDATA2()
End Sub

Private Sub avqty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles avqty.TextChanged
    Try
        If avqty.Text = "" Then
            avaqty.Text = getqty()
        Else

            avaqty.Text = CDbl(avaqty.Text - avqty.Text)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Private Sub avaqty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles avaqty.TextChanged
    If avaqty.Text < 0 Then
        MsgBox("not inough qty")
        avqty.Clear()
    End If
End Sub
End Class

0 个答案:

没有答案