Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
MsgBox(e.KeyCode)
End Sub
Date :
2011-12-22 17:17:09
By :
webmaster
No. 2
Guest
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
'btnadd = AcceptButton()
'แก้ไข aceptbutton = enter
code = txtcode.Text
Dim name As String
Dim price_sale As Double
Dim amount As Integer
Dim sqlsale As String
Dim sqlmedicine As String
Dim profit As Double
If txtcode.Text = "" Then
MessageBox.Show("กรุณากรอกบาร์โค้ด", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
sqlmedicine = "select med_code,med_name,med_price_sale,med_amount,med_profit from medicine where med_code='" + code + "'"
Dim ds As New DataSet
ds = con.getdata(sqlmedicine)
Dim i As Integer = ds.Tables("table").Rows.Count
If i > 0 Then
name = ds.Tables("table").Rows(0)("med_name").ToString()
price_sale = ds.Tables("table").Rows(0)("med_price_sale").ToString()
amount = ds.Tables("table").Rows(0)("med_amount").ToString()
profit = ds.Tables("table").Rows(0)("med_profit").ToString()
If amount <= 0 Then
MessageBox.Show("ยาหมดแล้ว", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
sqlsale = "select med_code,med_name,med_price_sale,sale_amount from sale where med_code='" + code + "'"
Dim ds2 As New DataSet
ds2 = con.getdata(sqlsale)
Dim num As Integer = ds2.Tables("table").Rows.Count
If (num > 0) Then
Dim amount_sale As Integer
Dim sale_date As String = DateTime.Now.ToString()
amount_sale = ds2.Tables("table").Rows(0)("sale_amount").ToString()
Dim price As Double = Convert.ToDouble(ds2.Tables("table").Rows(0)("med_price_sale").ToString)
amount_sale = amount_sale + 1
Dim total As Double = amount_sale * price
Dim totalp As Double = amount_sale * profit
Dim sqlup As String = "update sale set sale_amount=" + amount_sale.ToString() + ",sale_total=" + total.ToString() + ",med_profit=" + totalp.ToString() + " where med_code='" + code + "'"
Dim ds3 As New DataSet
ds3 = con.getdata(sqlup)
Else
Dim sale_date As String = DateTime.Now.ToString()
Dim sqlin As String = "insert into sale(med_code,med_name,med_price_sale,sale_amount,sale_date,sale_total,med_profit) values ('" + code + "','" + name + "'," + price_sale.ToString() + ",1,'" + sale_date + "'," + price_sale.ToString() + "," + profit.ToString() + ")"
Dim ds3 As New DataSet
ds3 = con.getdata(sqlin)
End If
showdata()
End If
Else
MessageBox.Show("รหัสยาไม่ถูกต้อง", "ERRROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
End Sub
กำหนด Properties ของ Form ตรง KeyPreview ให้เป็น True ก่อนนะครับ
แล้วก็จาก code ของ พี่ mr.win
Code (VB.NET)
Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Enter Then
call btnadd_Click(nothing,nothing)
End If
End Sub