📄 main_rcyw_tsxs.frm
字号:
End If
If KeyCode = vbKeyEscape Then '按ESC键
Grid1.Visible = False 'grid1不可见
Text1.SetFocus 'text1获得焦点
End If
End Sub
Private Sub jsr_GotFocus()
jsr.BackColor = &HFFFF00
End Sub
Private Sub jsr_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then '按回车键
Text1.Visible = True
'到达第1行,第1列
MS1.Row = 1
MS1.Col = 1
Text1.SetFocus
End If
End Sub
Private Sub jsr_LostFocus()
jsr.BackColor = &HFFFFFF
End Sub
Private Sub MS1_Click()
If MS1.Row >= 1 And MS1.TextMatrix(MS1.Row - 1, 9) <> "" Then '在MS1表格第1行或大于第1行时
Text1.Visible = True 'text1可见
Text1.SetFocus
End If
End Sub
Private Sub MS1_entercell()
Dim X, Y, p As String
If MS1.CellWidth <= 0 Or MS1.CellHeight <= 0 Then Exit Sub
X = MS1.TextMatrix(MS1.FixedRows, MS1.Col)
Y = MS1.TextMatrix(MS1.Row, 0)
If Y <> "" Then
If MS1.Col - MS1.LeftCol <= 3 Then MS1.LeftCol = MS1.LeftCol + 1
If MS1.CellWidth > 0 And MS1.CellHeight > 0 Then
Text1.Width = MS1.CellWidth
Text1.Height = MS1.CellHeight
Text1.Left = MS1.CellLeft + MS1.Left
Text1.Top = MS1.CellTop + MS1.Top
End If
X = MS1.TextMatrix(MS1.FixedRows, MS1.Col)
Y = MS1.TextMatrix(MS1.Row, 0)
p = MS1.TextMatrix(MS1.Row, MS1.Col)
Text1.text = MS1.text
Text1.SelStart = 0
Text1.SelLength = Len(Text1.text)
End If
End Sub
Private Sub MS1_RowColChange() '格式化金额
For i = 1 To 100
If MS1.TextMatrix(i, 1) <> "" Then
MS1.TextMatrix(i, 8) = Format(MS1.TextMatrix(i, 8), "#0.00")
MS1.TextMatrix(MS1.Row, 10) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 8))
MS1.TextMatrix(i, 10) = Format(MS1.TextMatrix(i, 10), "#0.00")
End If
Next i
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Text1.text = MS1.text
Adodc3.RecordSource = "select * from kcb where 条形码='" + MS1.TextMatrix(MS1.Row, 2) + "'"
Adodc3.Refresh
If Adodc3.Recordset.RecordCount > 0 Then '当记录大于零时
If MS1.Col = 2 Then
With Adodc3.Recordset
'赋值给MS1表格
If .Fields("书号") <> "" Then MS1.TextMatrix(MS1.Row, 1) = .Fields("书号")
If .Fields("条形码") <> "" Then MS1.TextMatrix(MS1.Row, 2) = .Fields("条形码")
If .Fields("书名") <> "" Then MS1.TextMatrix(MS1.Row, 3) = .Fields("书名")
If .Fields("作者") <> "" Then MS1.TextMatrix(MS1.Row, 4) = .Fields("作者")
If .Fields("出版社") <> "" Then MS1.TextMatrix(MS1.Row, 5) = .Fields("出版社")
If .Fields("图书类别") <> "" Then MS1.TextMatrix(MS1.Row, 6) = .Fields("图书类别")
If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 7) = .Fields("存放位置")
MS1.Col = 7
Text1.SetFocus
End With
End If
End If
If Adodc1.Recordset.RecordCount > 0 Then '当记录大于零时
If MS1.Col = 1 Then
With Adodc1.Recordset
'赋值给MS1表格
If .Fields("书号") <> "" Then MS1.TextMatrix(MS1.Row, 1) = .Fields("书号")
If .Fields("条形码") <> "" Then MS1.TextMatrix(MS1.Row, 2) = .Fields("条形码")
If .Fields("书名") <> "" Then MS1.TextMatrix(MS1.Row, 3) = .Fields("书名")
If .Fields("作者") <> "" Then MS1.TextMatrix(MS1.Row, 4) = .Fields("作者")
If .Fields("出版社") <> "" Then MS1.TextMatrix(MS1.Row, 5) = .Fields("出版社")
If .Fields("图书类别") <> "" Then MS1.TextMatrix(MS1.Row, 6) = .Fields("图书类别")
If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 7) = .Fields("存放位置")
MS1.Col = 7
Text1.SetFocus
End With
End If
Grid1.Visible = False
If MS1.Col = 9 Then
MS1.Row = MS1.Row + 1
MS1.Col = 1
Else
If MS1.Col + 1 <= MS1.Cols - 1 Then
MS1.Col = MS1.Col + 1
Else
If MS1.Row + 1 <= MS1.Rows - 1 Then
MS1.Row = MS1.Row + 1
MS1.Col = 1
End If
End If
End If
End If
End If
If KeyCode = vbKeyUp Then
If MS1.Row > 1 Then MS1.Row = MS1.Row - 1
End If
If KeyCode = vbKeyDown And (MS1.TextMatrix(MS1.Row, 1)) <> "" Then
If MS1.Row < 99 Then MS1.Row = MS1.Row + 1
End If
If KeyCode = vbKeyLeft Then
If Text1.text <> "" Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.text)
End If
If MS1.Col - 9 <= MS1.Cols + 1 Then
MS1.Col = MS1.Col - 1
If MS1.Col = 0 Then MS1.Col = 1
Else
If MS1.Row + 1 <= MS1.Row - 1 Then
MS1.Row = MS1.Row + 1
MS1.Col = 1
End If
End If
End If
If KeyCode = vbKeyRight Then
If Text1.text <> "" Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.text)
End If
If MS1.Col + 1 <= MS1.Cols - 1 Then
MS1.Col = MS1.Col + 1
Else
If MS1.Row + 1 <= MS1.Rows - 1 Then
MS1.Row = MS1.Row + 1
MS1.Col = 1
End If
End If
End If
If KeyCode = vbKeyPageDown And MS1.Col = 1 Then
Adodc1.RecordSource = "select * from kcb order by 书号"
Adodc1.Refresh
Grid1.Visible = True
Grid1.SetFocus
End If
End Sub
Private Sub Text1_Change()
MS1.text = Text1.text '赋值给MS1.text
If MS1.Col = 1 Then
'按书号查询库存图书信息
Adodc1.RecordSource = "select * from kcb where 书号 like +'" + Text1.text + "'+'%'order by val(书号)"
Adodc1.Refresh
If Text1.text = "" Then '当text1.text为空时
Grid1.Visible = False 'grid1不可见
Else
If Adodc1.Recordset.RecordCount > 0 Then '当记录大于零时
Grid1.Visible = True 'grid1可见
Text1.Visible = True
Text1.SetFocus
Else
Grid1.Visible = False
End If
End If
End If
If MS1.Col = 8 Then MS1.TextMatrix(MS1.Row, 10) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 8))
If MS1.Col = 9 Then MS1.TextMatrix(MS1.Row, 10) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 8))
Dim a, B As Single
For i = 1 To 101
a = Val(MS1.TextMatrix(i, 10)) + a
B = Val(MS1.TextMatrix(i, 9)) + B
If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 9) <> "" Then pz.Caption = i
Next i
hjje.Caption = a '计算合计金额
hjsl.Caption = B '计算合计数量
If Combo1.text = "" Then
zhje.Caption = a '计算折后金额
Else
zhje.Caption = Val(hjje.Caption) * (Left(Combo1.text, 1) / 10) '计算折后金额
End If
End Sub
Private Sub Combo1_Click()
zhje.Caption = Val(hjje.Caption) * (Left(Combo1.text, 1) / 10) '计算折后金额
End Sub
Private Sub CmdReg_Click()
'查询所有销售数据,并按票号排序
Adodc2.RecordSource = "select * from xsb order by 票号"
Adodc2.Refresh
'创建销售票号
If Adodc2.Recordset.RecordCount > 0 Then
If Not Adodc2.Recordset.EOF Then Adodc2.Recordset.MoveLast
If Adodc2.Recordset.Fields("票号") <> "" Then
lsph = Right(Trim(Adodc2.Recordset.Fields("票号")), 4) + 1
PH.Caption = Date & "xs" & Format(lsph, "0000")
End If
Else
PH.Caption = Date & "xs" & "0001"
End If
'设置jsr有效
jsr.Enabled = True
'jsr获得焦点
jsr.SetFocus
Text1.Enabled = True
MS1.Enabled = True
'确定文本框在MS1表格中的位置
Text1.Width = MS1.CellWidth
Text1.Height = MS1.CellHeight
Text1.Left = MS1.CellLeft + MS1.Left
Text1.Top = MS1.CellTop + MS1.Top
CmdSave.Enabled = True
CmdCancel.Enabled = True
CmdReg.Enabled = False
End Sub
Private Sub CmdSave_Click()
For i = 1 To 101
If MS1.TextMatrix(i, 1) <> "" Then
Set rs1 = New ADODB.Recordset
rs1.Open "select * from xsb", Cnn, adOpenKeyset, adLockOptimistic
'添加销售图书信息到"xsb"表中
rs1.AddNew
If MS1.TextMatrix(i, 1) <> "" Then rs1.Fields("书号") = MS1.TextMatrix(i, 1)
If MS1.TextMatrix(i, 2) <> "" Then rs1.Fields("条形码") = MS1.TextMatrix(i, 2)
If MS1.TextMatrix(i, 3) <> "" Then rs1.Fields("书名") = MS1.TextMatrix(i, 3)
If MS1.TextMatrix(i, 4) <> "" Then rs1.Fields("作者") = MS1.TextMatrix(i, 4)
If MS1.TextMatrix(i, 5) <> "" Then rs1.Fields("出版社") = MS1.TextMatrix(i, 5)
If MS1.TextMatrix(i, 6) <> "" Then rs1.Fields("图书类别") = MS1.TextMatrix(i, 6)
If MS1.TextMatrix(i, 7) <> "" Then rs1.Fields("存放位置") = MS1.TextMatrix(i, 7)
If MS1.TextMatrix(i, 8) <> "" Then rs1.Fields("单价") = MS1.TextMatrix(i, 8)
If MS1.TextMatrix(i, 9) <> "" Then rs1.Fields("销售数量") = MS1.TextMatrix(i, 9)
If MS1.TextMatrix(i, 10) <> "" Then rs1.Fields("金额") = MS1.TextMatrix(i, 10)
If jsr.text <> "" Then rs1.Fields("经手人") = jsr.text
If PH.Caption <> "" Then rs1.Fields("票号") = PH.Caption
If jsr.text <> "" Then rs1.Fields("操作员") = frm_main.St1.Panels(3).text
If rq.Caption <> "" Then rs1.Fields("日期") = rq.Caption
rs1.Update '更新表
'查找库存图书信息
Set rs2 = New ADODB.Recordset
rs2.Open "select * from kcb where 书号='" + MS1.TextMatrix(i, 1) + "'", Cnn, adOpenKeyset, adLockOptimistic
If rs2.RecordCount > 0 Then
'更新"kcb"表中的"现存数量"及"金额"
rs2.Fields("现存数量") = Val(rs2.Fields("现存数量")) - Val(MS1.TextMatrix(i, 9))
rs2.Fields("金额") = Val(rs2.Fields("现存数量")) * Val(Adodc1.Recordset.Fields("单价"))
rs2.Update
Else
MsgBox ("库存中无此图书,不能进行销售!")
Exit Sub
End If
End If
Next i
rs1.Close
rs2.Close
Set rs3 = New ADODB.Recordset
rs3.Open "select * from xsph", Cnn, adOpenKeyset, adLockOptimistic
rs3.AddNew
If PH.Caption <> "" Then rs3.Fields("票号") = PH.Caption
If pz.Caption <> "" Then rs3.Fields("销售品种") = Val(pz.Caption)
If hjsl.Caption <> "" Then rs3.Fields("销售数量") = Val(hjsl.Caption)
If hjje.Caption <> "" Then rs3.Fields("合计金额") = Val(hjje.Caption)
If Combo1.text <> "" Then rs3.Fields("折扣") = Combo1.text
If zhje.Caption <> "" Then rs3.Fields("折后金额") = Val(zhje.Caption)
If jsr.text <> "" Then rs3.Fields("经手人") = jsr.text
If jsr.text <> "" Then rs3.Fields("操作员") = frm_main.St1.Panels(3).text
If rq.Caption <> "" Then rs3.Fields("日期") = rq.Caption
rs3.Update
rs3.Close
'清空数据
For i = 1 To 101
For j = 1 To 10
MS1.TextMatrix(i, j) = ""
Next j
Next i
jsr.text = ""
pz.Caption = ""
hjsl.Caption = ""
hjje.Caption = ""
Text1.Visible = False
MS1.Enabled = False
CmdSave.Enabled = False
CmdReg.Enabled = True
CmdCancel.Enabled = False
End Sub
Private Sub CmdCancel_Click() '取消操作
jsr.text = ""
pz.Caption = ""
hjsl.Caption = ""
hjje.Caption = ""
For i = 1 To 100
For j = 1 To 10
MS1.TextMatrix(i, j) = ""
Next j
Next i
jsr.Enabled = False
Text1.Enabled = False
MS1.Enabled = False
CmdSave.Enabled = False
CmdCancel.Enabled = False
CmdReg.Enabled = True
CmdReg.SetFocus
End Sub
Private Sub CmdEnd_Click()
frm_main.Enabled = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -