📄 frmxiaoshou.frm
字号:
VERSION 5.00
Begin VB.Form frmXS
BorderStyle = 1 'Fixed Single
Caption = "销售"
ClientHeight = 5085
ClientLeft = 45
ClientTop = 330
ClientWidth = 7680
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 5085
ScaleWidth = 7680
Begin VB.CommandButton Command2
Caption = "关闭"
Height = 375
Left = 5400
TabIndex = 7
Top = 4560
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "销售"
Height = 375
Left = 1080
TabIndex = 6
Top = 4560
Width = 1215
End
Begin VB.Frame Frame2
Caption = "结帐"
Height = 1215
Left = 360
TabIndex = 13
Top = 3000
Width = 6975
Begin VB.Label lblJZ
BeginProperty DataFormat
Type = 1
Format = """¥""#,##0.00"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 2
EndProperty
Height = 255
Index = 5
Left = 5280
TabIndex = 19
Top = 600
Width = 735
End
Begin VB.Label lblJZ
Caption = "金额:"
Height = 255
Index = 4
Left = 4800
TabIndex = 18
Top = 600
Width = 735
End
Begin VB.Label lblJZ
BeginProperty DataFormat
Type = 1
Format = """¥""#,##0.00"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 2
EndProperty
Height = 255
Index = 3
Left = 3240
TabIndex = 17
Top = 600
Width = 735
End
Begin VB.Label lblJZ
Caption = "单价:"
Height = 255
Index = 2
Left = 2640
TabIndex = 16
Top = 600
Width = 735
End
Begin VB.Label lblJZ
Height = 255
Index = 1
Left = 1440
TabIndex = 15
Top = 600
Width = 735
End
Begin VB.Label lblJZ
Caption = "商品名称:"
Height = 255
Index = 0
Left = 360
TabIndex = 14
Top = 600
Width = 975
End
End
Begin VB.Frame Frame1
Caption = "输入销售信息"
Height = 2055
Left = 360
TabIndex = 8
Top = 720
Width = 6975
Begin VB.TextBox txtPrice
Height = 375
Left = 3120
TabIndex = 4
Top = 1200
Width = 1335
End
Begin VB.ComboBox cboType
Height = 300
Left = 4920
Style = 2 'Dropdown List
TabIndex = 2
Top = 480
Width = 1455
End
Begin VB.ComboBox cboCode
Height = 300
Left = 1200
Style = 2 'Dropdown List
TabIndex = 1
Top = 360
Width = 1455
End
Begin VB.TextBox txtOutdate
DataField = "outdate"
BeginProperty DataFormat
Type = 1
Format = "yyyy-M-d"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 3
EndProperty
DataSource = "Adodc1"
Height = 375
Left = 5400
TabIndex = 5
Top = 1200
Width = 1215
End
Begin VB.TextBox txtCount
DataField = "count"
Height = 375
Left = 1440
TabIndex = 3
Top = 1200
Width = 855
End
Begin VB.Label Label6
Caption = "单价:"
Height = 375
Left = 2520
TabIndex = 20
Top = 1200
Width = 735
End
Begin VB.Label Label5
Caption = "销售日期:"
Height = 375
Left = 4560
TabIndex = 12
Top = 1200
Width = 975
End
Begin VB.Label Label4
Caption = "销售数量:"
Height = 375
Left = 360
TabIndex = 11
Top = 1200
Width = 1095
End
Begin VB.Label Label3
Caption = "类型(批发/零售):"
Height = 375
Left = 3000
TabIndex = 10
Top = 480
Width = 1935
End
Begin VB.Label Label2
Caption = "商品代码:"
Height = 375
Left = 240
TabIndex = 9
Top = 480
Width = 975
End
End
Begin VB.Label Label1
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "商品销售信息"
BeginProperty Font
Name = "新宋体"
Size = 21.75
Charset = 134
Weight = 700
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 495
Left = 1320
TabIndex = 0
Top = 120
Width = 5175
End
End
Attribute VB_Name = "frmXS"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim DBkc As Database '声明数据库变量,
Dim RSkc As Recordset '声明一个记录集, 用来打开库存表
Dim db As Database
Dim rs As Recordset
Dim Sql As String
Dim SQL2 As String '声明SQL2
Dim Sname As String
Dim addCode As String
Private Sub cboCode_Click()
Sname = cboCode.Text
Sql = "select * from 库存表 where name='" & Sname & "'"
Set RSkc = DBkc.OpenRecordset(Sql)
lblJZ(1).Caption = RSkc.Fields("name")
addCode = RSkc.Fields("code")
cboType.Enabled = True
End Sub
Private Sub cboType_Click()
txtCount.Enabled = True
End Sub
Private Sub Command1_Click()
'打开销售表
Set db = OpenDatabase(App.Path & "\db1.mdb")
Set rs = db.OpenRecordset("销售表")
'添加销售记录
rs.AddNew
rs.Fields("code") = addCode
rs.Fields("count") = Val(txtCount.Text)
rs.Fields("type") = cboType.Text
rs.Fields("outdate") = txtOutdate.Text
rs.Fields("price") = Val(txtPrice.Text)
rs.Update
'修改库存表中的相关记录
Sname = addCode
SQL2 = "select * from 库存表 where code='" & Sname & "'"
Set DBkc = OpenDatabase(App.Path & "\db1.mdb")
Set RSkc = DBkc.OpenRecordset(SQL2)
RSkc.Edit
'Val(string)返回包含于字符串内的数字,字符串中是一个适当类型的数值。
RSkc.Fields("number") = Val(RSkc.Fields("number")) - Val(txtCount.Text)
RSkc.Update
txtCount = ""
txtPrice = ""
cboCode.SetFocus
Command1.Enabled = False
cboType.Enabled = False
txtCount.Enabled = False
txtPrice.Enabled = False
txtOutdate.Enabled = False
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
'打开数据库
Dim DBName As String
DBName = App.Path & "\db1.mdb"
Set DBkc = OpenDatabase(DBName)
'打开表
Set RSkc = DBkc.OpenRecordset("库存表")
'移到第一条记录
RSkc.MoveFirst
'将库存表的code字段的值添加到cbocode中
Do While Not RSkc.EOF
cboCode.AddItem RSkc.Fields("name").Value
RSkc.MoveNext
Loop
cboType.AddItem "批发"
cboType.AddItem "零售"
Command1.Enabled = False
txtOutdate = Date
cboType.Enabled = False
txtCount.Enabled = False
txtPrice.Enabled = False
txtOutdate.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
DBkc.Close
End Sub
Private Sub txtCount_Click()
txtPrice.Enabled = True
End Sub
Private Sub txtCount_Validate(Cancel As Boolean)
Cancel = True
If txtCount.Text = "" Then
MsgBox "请正确输入数量"
ElseIf Val(txtCount) < 0 Then MsgBox "数量不能小于零"
ElseIf Val(txtCount) > RSkc.Fields("number").Value Then MsgBox "该种商品库存" & RSkc.Fields("number").Value & ",不足!"
Else
Cancel = False
End If
End Sub
Private Sub txtPrice_Click()
Command1.Enabled = True
End Sub
Private Sub txtPrice_LostFocus()
If txtPrice.Text = "" Then
MsgBox "请正确输入价格"
txtPrice.SetFocus
ElseIf Val(txtPrice) < 0 Then MsgBox "价格不能小于零"
ElseIf Val(txtPrice) < RSkc.Fields("rate") Then MsgBox "销售价格不可以低于进货价格"
txtPrice.SetFocus
Else
Command1.Enabled = True
lblJZ(3) = txtPrice
lblJZ(5) = txtCount * txtPrice
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -