📄 main_jygl_hs.frm
字号:
BackStyle = 0 'Transparent
Caption = "还回品种: 还回数量: 还回金额: 元"
ForeColor = &H00800000&
Height = 315
Left = 75
TabIndex = 8
Top = 285
Width = 5625
End
End
Begin VB.Frame Frame5
Height = 645
Left = 5715
TabIndex = 9
Top = 4680
Width = 5325
Begin VB.CommandButton CmdReg
BackColor = &H00FF8080&
Caption = "登记"
Height = 390
Left = 240
Picture = "main_jygl_hs.frx":0CDF
TabIndex = 13
Top = 165
Width = 1215
End
Begin VB.CommandButton CmdSave
BackColor = &H00C0C0C0&
Caption = "保存"
Enabled = 0 'False
Height = 390
Left = 1455
Picture = "main_jygl_hs.frx":1EBD
TabIndex = 12
Top = 165
Width = 1215
End
Begin VB.CommandButton CmdCancel
BackColor = &H00FF8080&
Caption = "取消"
Enabled = 0 'False
Height = 390
Left = 2670
Picture = "main_jygl_hs.frx":309B
TabIndex = 11
Top = 165
Width = 1215
End
Begin VB.CommandButton CmdEnd
BackColor = &H00FF8080&
Caption = "退出"
Height = 390
Left = 3885
Picture = "main_jygl_hs.frx":4279
TabIndex = 10
Top = 165
Width = 1215
End
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "图 书 归 还 登 记"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 285
Index = 1
Left = 4605
TabIndex = 5
Top = 90
Width = 2655
End
End
Attribute VB_Name = "main_jygl_hs"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim s, Y, i '声明变量
'声明数据集对象
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
Dim rs4 As New ADODB.Recordset
Dim lsph As Integer '声明一个整型变量
Private Sub Form_Load()
'自动识别路径
Adodc1.ConnectionString = "DSN=NBooks"
Adodc1.RecordSource = "select * from jsb"
Adodc1.Refresh
Adodc2.ConnectionString = "DSN=NBooks"
Adodc2.RecordSource = "select * from hsb"
Adodc2.Refresh
Adodc3.ConnectionString = "DSN=NBooks"
Adodc3.RecordSource = "select * from reads"
Adodc3.Refresh
Adodc4.ConnectionString = "DSN=NBooks"
Adodc4.RecordSource = "select * from reads"
Adodc4.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Visible = False
'定义MS1表格的行数、列数
MS1.Rows = 102
MS1.Cols = 10
'定义MS1表格的列宽和表头信息
s = Array("300", "990", "3000", "800", "1200", "800", "600", "1000", "1200", "800")
Y = Array("xh", "条形码", "书名", "作者", "出版社", "单价", "数量", "金额", "图书类别", "备注")
For i = 0 To 9
MS1.ColWidth(i) = s(i)
MS1.TextMatrix(0, i) = Y(i)
Next i
'定义MS1表格的行号
For i = 1 To 101
MS1.TextMatrix(i, 0) = i
Next i
rq.Caption = Date '设置还书日期
DataCombo1.Enabled = False
Tjsr.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True
End Sub
Private Sub DataCombo1_Change()
Adodc3.RecordSource = "select * from reads where 书证号='" + DataCombo1.text + "'"
Adodc3.Refresh
If Adodc3.Recordset.RecordCount > 0 Then
hsr.Caption = Adodc3.Recordset.Fields("姓名")
Adodc1.RecordSource = "select * from jsb where 书证号='" + DataCombo1.text + "'and 是否归还='否'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
DataGrid1.Visible = True
Text1.text = Adodc1.Recordset.Fields("条形码")
Else
MsgBox "该读者没有借书或所借图书已经还清", , "图书综合管理系统"
DataGrid1.Visible = False
End If
End If
End Sub
Private Sub datacombo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Tjsr.SetFocus '按回车键Tjsr获得焦点
End Sub
Private Sub Tjsr_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then '按回车键
Text1.Visible = True
Text1.Enabled = True
'到达第1行,第1列
MS1.Row = 1
MS1.Col = 1
Text1.SetFocus
End If
End Sub
Private Sub MS1_Click()
If MS1.Row >= 1 And MS1.TextMatrix(MS1.Row - 1, 2) <> "" Then '在MS1表格第1行或大于第1行时
Text1.Visible = True 'text1可见
Text1.Enabled = True
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)
'Len 函数返回 Long,其中包含字符串内字符的数目,或是存储一变量所需的字节数。
End If
End Sub
Private Sub MS1_RowColChange() '格式化金额
For i = 1 To 100
If MS1.TextMatrix(i, 1) <> "" Then
MS1.TextMatrix(i, 5) = Format(MS1.TextMatrix(i, 5), "#0.00") 'Format 函数返回 Variant (String),其中含有一个表达式,它是根据格式表达式中的指令来格式化的。
MS1.TextMatrix(MS1.Row, 7) = Val(MS1.TextMatrix(MS1.Row, 6)) * Val(MS1.TextMatrix(MS1.Row, 5))
MS1.TextMatrix(i, 7) = Format(MS1.TextMatrix(i, 7), "#0.00")
End If
Next i
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then ' 按回车键'
If MS1.Col = 1 Then
With Adodc1.Recordset
If .RecordCount > 0 Then '当记录大于零时
'赋值给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, 8) = .Fields("图书类别")
If .Fields("借出数量") <> "" Then MS1.TextMatrix(MS1.Row, 6) = "1"
' MS1.Col = 9
' Text1.SetFocus
CmdSave.SetFocus
End If
End With
End If
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
If KeyCode = vbKeyUp Then '按KeyUp键
If MS1.Row > 1 Then MS1.Row = MS1.Row - 1
End If
If KeyCode = vbKeyDown And (MS1.TextMatrix(MS1.Row, 2)) <> "" Then '按KeyDown键
If MS1.Row < 99 Then MS1.Row = MS1.Row + 1
End If
If KeyCode = vbKeyLeft Then '按KeyLeft键
If Text1.text <> "" Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.text)
End If
If MS1.Col - 8 <= 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 '按KeyRight键
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
End Sub
Private Sub Text1_Change()
MS1.text = Text1.text '赋值给MS1.text
If MS1.Col = 5 Then MS1.TextMatrix(MS1.Row, 7) = Val(MS1.TextMatrix(MS1.Row, 6)) * Val(MS1.TextMatrix(MS1.Row, 5))
If MS1.Col = 6 Then MS1.TextMatrix(MS1.Row, 7) = Val(MS1.TextMatrix(MS1.Row, 6)) * Val(MS1.TextMatrix(MS1.Row, 5))
Dim a, B As Single
For i = 1 To 101
a = Val(MS1.TextMatrix(i, 7)) + a
B = Val(MS1.TextMatrix(i, 6)) + B
If MS1.TextMatrix(i, 1) <> "" And MS1.TextMatrix(i, 6) <> "" Then pz.Caption = i
Next i
hjje.Caption = a
hjsl.Caption = B '计算合计金额,合计数量
End Sub
Private Sub CmdReg_Click() '登记
DataCombo1.Enabled = True
Tjsr.Enabled = True
'查询所有借书数据,并按票号排序
Adodc2.RecordSource = "select * from hsb 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
'Trim 函数返回 Variant (String),其中包含指定字符串的拷贝,没有前导和尾随空白。
PH.Caption = Date & "hs" & Format(lsph, "0000")
End If
Else
PH.Caption = Date & "hs" & "0001"
End If
'设置Text1有效
Text1.Enabled = True
'确定文本框在MS1表格中的位置
Text1.Width = MS1.CellWidth
Text1.Height = MS1.CellHeight
Text1.Left = MS1.CellLeft + MS1.Left
Text1.Top = MS1.CellTop + MS1.Top
MS1.Enabled = True
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
With MS1
'查找借阅图书信息
Set rs3 = New ADODB.Recordset
rs3.Open "select * from jsb where 条形码='" + MS1.TextMatrix(i, 1) + "'and 是否归还='否'", Cnn, adOpenKeyset, adLockOptimistic
If rs3.RecordCount > 0 Then
If Val(rs3.Fields("借出数量").Value) - .TextMatrix(i, 6) > 0 Then
MsgBox "请将所借图书一并归还!", , "图书综合管理系统"
rs3.Close
Exit Sub
End If
'更新"jsb"表中的"还书日期"、"还书经手人"及"是否归还"
Cnn.Execute "update jsb set 还书日期='" & rq.Caption & "',还书经手人='" & Tjsr.text & "',是否归还='是'where 条形码='" + MS1.TextMatrix(i, 1) + "'and 是否归还='否'"
Dim s As Integer
s = Val(MS1.TextMatrix(i, 6)) + s
Set rs4 = New ADODB.Recordset
rs4.Open "select * from reads where 书证号='" + DataCombo1.text + "'", Cnn, adOpenKeyset, adLockOptimistic
If rs4.RecordCount > 0 Then
'更新"kcb"表中的"库存"及"库存金额"
Cnn.Execute "update reads set 已借书数='" & Val(rs4.Fields("已借书数")) - s & "'where 书证号='" + DataCombo1.text + "'"
Else
MsgBox "此读者不存在!", , "图书综合管理系统"
rs3.Close
rs4.Close
Exit Sub
End If
rs4.Close
Else
MsgBox "您没有借阅此图书!", , "图书综合管理系统"
Exit Sub
End If
'查找库存图书信息
Set rs2 = New ADODB.Recordset
rs2.Open "select * from kcb where 条形码='" + MS1.TextMatrix(i, 1) + "'", Cnn, adOpenKeyset, adLockOptimistic
If rs2.RecordCount > 0 Then
'更新"kcb"表中的"库存"及"库存金额"
Cnn.Execute "update kcb set 现存数量='" & Val(rs2.Fields("现存数量")) + Val(MS1.TextMatrix(i, 6)) & "'where 条形码='" + MS1.TextMatrix(i, 1) + "'"
' 'Val 函数返回包含于字符串内的数字,字符串中是一个适当类型的数值。
Else
MsgBox "库存无此图书,无法归还!", , "图书综合管理系统"
Exit Sub
End If
rs3.Close '关闭对象
rs2.Close
'添加还书信息到"hsb"表中
Cnn.Execute "insert into hsb(条形码,书名,作者,出版社,单价,还回数量,金额,图书类别,备注,书证号,还书人," & _
"还书经手人,还书日期,票号,操作员) values('" & .TextMatrix(i, 1) & "','" & .TextMatrix(i, 2) & _
"','" & .TextMatrix(i, 3) & "','" & .TextMatrix(i, 4) & "','" & .TextMatrix(i, 5) & "','" & _
.TextMatrix(i, 6) & "','" & .TextMatrix(i, 7) & "','" & .TextMatrix(i, 8) & "','" & .TextMatrix(i, 9) & _
" ','" & Trim(DataCombo1.text) & "','" & hsr.Caption & "','" & Tjsr.text & "','" & rq.Caption & _
"','" & PH.Caption & "','" & frm_main.St1.Panels(3).text & "')"
End With
End If
Next i
'清空数据
For i = 1 To 100
For j = 1 To 9
MS1.TextMatrix(i, j) = ""
Next j
Next i
'清空控件
Tjsr.text = ""
pz.Caption = ""
hjsl.Caption = ""
hjje.Caption = ""
Text1.Visible = False '设置控件不可见
MS1.Enabled = False
CmdSave.Enabled = False
CmdReg.Enabled = True
CmdCancel.Enabled = False
DataGrid1.Visible = False
End Sub
Private Sub CmdCancel_Click() '取消操作
Tjsr.text = ""
pz.Caption = ""
hjsl.Caption = ""
hjje.Caption = ""
For i = 1 To 100
For j = 1 To 9
MS1.TextMatrix(i, j) = ""
Next j
Next i
'设置控件状态
Text1.Enabled = False
MS1.Enabled = False
CmdSave.Enabled = False
CmdCancel.Enabled = False
CmdReg.Enabled = True
CmdReg.SetFocus
DataGrid1.Visible = False
End Sub
Private Sub CmdEnd_Click() '退出
frm_main.Enabled = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -