📄 main_rcyw_tsrk.frm
字号:
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, 6) <> "" 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, 9) = Format(MS1.TextMatrix(i, 9), "#0.00")
MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
MS1.TextMatrix(i, 11) = Format(MS1.TextMatrix(i, 11), "#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, 7) = .Fields("图书类别")
If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 8) = .Fields("存放位置")
If .Fields("单价") <> "" Then MS1.TextMatrix(MS1.Row, 9) = .Fields("单价")
'Text1.text = MS1.text
Text1.SetFocus
MS1.Col = 6
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, 7) = .Fields("图书类别")
If .Fields("存放位置") <> "" Then MS1.TextMatrix(MS1.Row, 8) = .Fields("存放位置")
If .Fields("单价") <> "" Then MS1.TextMatrix(MS1.Row, 9) = .Fields("单价")
'Text1.text = MS1.text
MS1.Col = 6
Text1.SetFocus
End With
End If
Grid1.Visible = False
If MS1.Col = 6 Then MS1.Col = 9
If MS1.Col = 10 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
Else
If MS1.Col = 10 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 - 10 <= 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"
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 + "'+'%'"
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 = 9 Then MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
If MS1.Col = 10 Then MS1.TextMatrix(MS1.Row, 11) = Val(MS1.TextMatrix(MS1.Row, 9)) * Val(MS1.TextMatrix(MS1.Row, 10))
If MS1.Col = 7 Then
Text1.Visible = False
Combo1.Visible = True
Combo1.Width = MS1.CellWidth
Combo1.Left = MS1.CellLeft + MS1.Left
Combo1.Top = MS1.CellTop + MS1.Top
Combo1.SetFocus
End If
Dim a, B As Single
For i = 1 To 101
a = Val(MS1.TextMatrix(i, 11)) + a
B = Val(MS1.TextMatrix(i, 10)) + B
If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 10) <> "" Then pz.Caption = i
Next i
'计算合计金额,合计数量
hjje.Caption = a '计算合计金额
hjsl.Caption = B '计算合计数量
End Sub
Private Sub CmdReg_Click()
'查询所有入库数据,并按票号排序
Adodc2.RecordSource = "select * from rkb 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 & "rk" & Format(lsph, "0000")
End If
Else
PH.Caption = Date & "rk" & "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 rkb", Cnn, adOpenKeyset, adLockOptimistic
'添加入库商品信息到"rkb"表中
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 MS1.TextMatrix(i, 11) <> "" Then rs1.Fields("金额") = MS1.TextMatrix(i, 11)
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.AddNew
If MS1.TextMatrix(i, 1) <> "" Then rs2.Fields("书号") = MS1.TextMatrix(i, 1)
If MS1.TextMatrix(i, 2) <> "" Then rs2.Fields("条形码") = MS1.TextMatrix(i, 2)
If MS1.TextMatrix(i, 3) <> "" Then rs2.Fields("书名") = MS1.TextMatrix(i, 3)
If MS1.TextMatrix(i, 4) <> "" Then rs2.Fields("作者") = MS1.TextMatrix(i, 4)
If MS1.TextMatrix(i, 5) <> "" Then rs2.Fields("出版社") = MS1.TextMatrix(i, 5)
If MS1.TextMatrix(i, 7) <> "" Then rs2.Fields("图书类别") = MS1.TextMatrix(i, 7)
If MS1.TextMatrix(i, 8) <> "" Then rs2.Fields("存放位置") = MS1.TextMatrix(i, 8)
If MS1.TextMatrix(i, 9) <> "" Then rs2.Fields("单价") = MS1.TextMatrix(i, 9)
If MS1.TextMatrix(i, 10) <> "" Then rs2.Fields("现存数量") = MS1.TextMatrix(i, 10)
If MS1.TextMatrix(i, 10) <> "" Then rs2.Fields("图书总数") = MS1.TextMatrix(i, 10)
If MS1.TextMatrix(i, 11) <> "" Then rs2.Fields("金额") = MS1.TextMatrix(i, 11)
rs2.Fields("借出次数") = 0
rs2.Update '更新表
Else
'更新"kcb"表中的"库存"及"库存金额"
Adodc1.Recordset.Fields("现存数量") = Val(MS1.TextMatrix(i, 10)) + Val(Adodc1.Recordset.Fields("现存数量"))
Adodc1.Recordset.Fields("图书总数") = Val(MS1.TextMatrix(i, 10)) + Val(Adodc1.Recordset.Fields("图书总数"))
Adodc1.Recordset.Fields("金额") = Val(Adodc1.Recordset.Fields("图书总数")) * Val(Adodc1.Recordset.Fields("单价"))
Adodc1.Recordset.Update
End If
End If
Next i
Set rs3 = New ADODB.Recordset
rs3.Open "select * from rkph", Cnn, adOpenKeyset, adLockOptimistic
rs3.AddNew
rs3.Fields("票号") = PH.Caption
rs3.Fields("入库品种") = pz.Caption
rs3.Fields("入库数量") = hjsl.Caption
rs3.Fields("合计金额") = hjje.Caption
rs3.Fields("经手人") = jsr.text
rs3.Fields("操作员") = frm_main.St1.Panels(3).text
rs3.Fields("日期") = rq.Caption
rs3.Update
rs1.Close
rs2.Close
rs3.Close
'清空数据
For i = 1 To 101
For j = 1 To 11
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 11
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 + -