?? frmbooksale.frm
字號:
VERSION 5.00
Begin VB.Form frmBookSale
Caption = "圖書銷售"
ClientHeight = 4545
ClientLeft = 60
ClientTop = 450
ClientWidth = 6030
LinkTopic = "Form1"
ScaleHeight = 4545
ScaleWidth = 6030
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame3
Caption = "付款信息"
Height = 3135
Left = 3600
TabIndex = 14
Top = 1320
Width = 2415
Begin VB.CommandButton cmdAll
Caption = "結帳"
Height = 495
Left = 1320
TabIndex = 24
Top = 2400
Width = 855
End
Begin VB.CommandButton cmdOK
Caption = "計算"
Height = 495
Left = 240
TabIndex = 23
Top = 2400
Width = 855
End
Begin VB.TextBox txtrepay
Height = 270
Left = 960
Locked = -1 'True
TabIndex = 22
Top = 1680
Width = 1335
End
Begin VB.TextBox txtpay
Height = 270
Left = 960
TabIndex = 20
Top = 1200
Width = 1335
End
Begin VB.TextBox txtsell
Height = 270
Left = 960
Locked = -1 'True
TabIndex = 18
Top = 720
Width = 1335
End
Begin VB.TextBox txtnumber
Height = 270
Left = 960
TabIndex = 16
Text = "1"
Top = 360
Width = 1335
End
Begin VB.Label Label10
Caption = "應 找 還:"
Height = 255
Left = 120
TabIndex = 21
Top = 1680
Width = 855
End
Begin VB.Label Label9
Caption = "客戶付款:"
Height = 255
Left = 120
TabIndex = 19
Top = 1200
Width = 855
End
Begin VB.Label Label8
Caption = "應 付 款:"
Height = 255
Left = 120
TabIndex = 17
Top = 720
Width = 855
End
Begin VB.Label Label7
Caption = "書 數 量:"
Height = 255
Left = 120
TabIndex = 15
Top = 360
Width = 975
End
End
Begin VB.Frame Frame2
Caption = "書籍信息"
Height = 3135
Left = 120
TabIndex = 3
Top = 1320
Width = 3375
Begin VB.TextBox txtprice
Height = 270
Left = 840
Locked = -1 'True
TabIndex = 13
Top = 2040
Width = 1455
End
Begin VB.TextBox txtdiscount
Height = 270
Left = 840
Locked = -1 'True
TabIndex = 11
Top = 1680
Width = 1455
End
Begin VB.TextBox txtsale
Height = 270
Left = 840
Locked = -1 'True
TabIndex = 9
Top = 1320
Width = 1455
End
Begin VB.TextBox txtbookname
Height = 270
Left = 840
Locked = -1 'True
TabIndex = 7
Top = 720
Width = 1935
End
Begin VB.TextBox txtbookno
Height = 270
Left = 840
Locked = -1 'True
TabIndex = 5
Top = 360
Width = 1935
End
Begin VB.Label Label6
Caption = "出售價:"
Height = 255
Left = 120
TabIndex = 12
Top = 2040
Width = 735
End
Begin VB.Label Label5
Caption = "打 折:"
Height = 255
Left = 120
TabIndex = 10
Top = 1680
Width = 735
End
Begin VB.Label Label4
Caption = "單 價:"
Height = 255
Left = 120
TabIndex = 8
Top = 1320
Width = 735
End
Begin VB.Label Label3
Caption = "書 名:"
Height = 255
Left = 120
TabIndex = 6
Top = 720
Width = 735
End
Begin VB.Label Label2
Caption = "書 號:"
Height = 255
Left = 120
TabIndex = 4
Top = 360
Width = 735
End
End
Begin VB.Frame Frame1
Caption = "請輸入書號"
Height = 1095
Left = 120
TabIndex = 0
Top = 120
Width = 5775
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋體"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 360
TabIndex = 1
Top = 240
Width = 4095
End
Begin VB.Label Label1
Caption = "按回車"
BeginProperty Font
Name = "新宋體"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4680
TabIndex = 2
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "frmBookSale"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Money As Double
Private Sub cmdAll_Click()
txtrepay.Text = (Val(txtpay.Text) - Money) & "元" '應還金額
If Val(txtrepay.Text) < 0 Then '如果客戶所付錢不夠
MsgBox "客戶所付的金額不夠!請提醒對方補錢"
Exit Sub
End If
If rs.State <> 0 Then '如果記錄集不是關閉
rs.Close
End If
cmdAll.Enabled = False '結帳按鈕不可用
Money = 0
Text1.Text = ""
End Sub
Private Sub cmdOK_Click()
If rs("Quantity").Value < Val(txtnumber.Text) Then '如果庫存數量不夠
MsgBox "rs('BookName').Value & ", " 書的庫存數量不夠!", vbOKOnly, "警告"
Exit Sub
End If
txtsell.Text = Val(txtprice.Text) * Val(txtnumber.Text) & "元"
Money = Money + Val(txtprice.Text) * Val(txtnumber.Text)
txtpay.Text = ""
txtrepay.Text = ""
cmdOK.Enabled = False '計算按鈕不可用
cmdAll.Enabled = True '結帳按鈕可用
con.Execute "update BookRecord set Quantity=Quantity - " & Val(txtnumber.Text) _
& " where BookNo='" & txtbookno.Text & "'"
'在bookSale表中添加記錄
' con.Execute "insert into BookSale (Sn,Account,SaleDate,SumMoney) values('" & "111" & "'," & Date & "," & Text1.Text & "," & Val(txtsale.Text) * Val(txtnumber.Text) & ")"
'在salesdetail表中添加記錄
' con.Execute "insert into SalesDetail" _
' & "(Sn,Account,BookNo,BookName,SalePrice,Quantity,Discount)" _
' & "values('" & "111" & "','" & username & "','" & txtbookno.Text _
' & "','" & txtbookname.Text & "'," & Val(txtprice.Text) & "," _
' & Val(txtnumber.Text) & "," & Val(txtdiscount.Text) & ")"
' con.Execute "insert into SalesDetail values('" & strnum & "','" _
' & username & "','" & txtsale(0).Text & "','" & txtsale(1).Text & "'," & Val(txtsale(4).Text) & "," _
' & Val(txtsale(5).Text) & "," & Val(txtsale(3).Text) & ")"
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=圖書銷售系統;"
Set rs = New ADODB.Recordset
cmdOK.Enabled = False '計算按鈕不可用
cmdAll.Enabled = False '結帳按鈕不可用
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
' If rs.State <> 0 Then '如果記錄集不是關閉
' rs.Close
' End If
If KeyAscii = 13 Then '如果是按下回車鍵
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=圖書銷售系統;"
Set rs = New ADODB.Recordset
rs.Open "select BookNo,BookName,SalesPrice,Discount,Quantity,(SalesPrice * Discount*0.1)as price from BookRecord where BookNo='" _
& Text1.Text & "'", con
'填充數據到文本框
If rs.EOF = True Then '如果沒有該書
MsgBox "沒有該書!"
Exit Sub
End If
' 填充表字段的值到各文本框
txtbookno.Text = rs("BookNo").Value
txtbookname.Text = rs("BookName").Value
txtsale.Text = rs("SalesPrice").Value
txtdiscount.Text = rs("Discount").Value
txtprice.Text = rs("price").Value
cmdOK.Enabled = True '計算按鈕可用
cmdAll.Enabled = False '結帳按鈕不可用
End If
Exit Sub
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -