📄 frmbook1.frm
字号:
VERSION 5.00
Begin VB.Form frmbook1
Caption = "图书信息"
ClientHeight = 5745
ClientLeft = 60
ClientTop = 420
ClientWidth = 9120
LinkTopic = "Form1"
ScaleHeight = 5745
ScaleWidth = 9120
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdExit
Caption = "返 回(&X)"
Height = 615
Left = 4560
TabIndex = 16
Top = 3480
Width = 2175
End
Begin VB.CommandButton cmd
Caption = "保 存(&S)"
Height = 615
Left = 1680
TabIndex = 15
Top = 3480
Width = 2175
End
Begin VB.Frame Frame1
Caption = "书籍信息"
Height = 2895
Left = 240
TabIndex = 0
Top = 240
Width = 8655
Begin VB.TextBox txtItem
Height = 375
Index = 5
Left = 840
TabIndex = 14
Top = 2040
Width = 2775
End
Begin VB.TextBox txtItem
Height = 375
Index = 4
Left = 5040
TabIndex = 13
Top = 1200
Width = 2775
End
Begin VB.TextBox txtItem
Height = 375
Index = 3
Left = 840
TabIndex = 12
Top = 1320
Width = 2775
End
Begin VB.TextBox txtItem
Height = 375
Index = 2
Left = 5040
TabIndex = 11
Top = 720
Width = 2775
End
Begin VB.TextBox txtItem
Height = 375
Index = 1
Left = 840
TabIndex = 10
Top = 720
Width = 2775
End
Begin VB.TextBox txtItem
Height = 375
Index = 0
Left = 5040
TabIndex = 9
Top = 240
Width = 2775
End
Begin VB.ComboBox Combo1
Height = 300
Left = 840
TabIndex = 8
Top = 240
Width = 2775
End
Begin VB.Label Label2
Caption = "库存数"
Height = 495
Index = 6
Left = 120
TabIndex = 7
Top = 2160
Width = 975
End
Begin VB.Label Label2
Caption = "复本数"
Height = 495
Index = 5
Left = 4080
TabIndex = 6
Top = 1320
Width = 975
End
Begin VB.Label Label2
Caption = "价 格"
Height = 495
Index = 4
Left = 120
TabIndex = 5
Top = 1440
Width = 975
End
Begin VB.Label Label2
Caption = "出版社"
Height = 495
Index = 3
Left = 4080
TabIndex = 4
Top = 720
Width = 975
End
Begin VB.Label Label2
Caption = "作 者"
Height = 495
Index = 2
Left = 120
TabIndex = 3
Top = 840
Width = 975
End
Begin VB.Label Label2
Caption = "书 名"
Height = 495
Index = 1
Left = 4080
TabIndex = 2
Top = 240
Width = 975
End
Begin VB.Label Label2
Caption = " ISBN"
Height = 495
Index = 0
Left = 120
TabIndex = 1
Top = 240
Width = 975
End
End
End
Attribute VB_Name = "frmBook1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public isbn As String
Private Sub cmd_Click()
Dim icount As Integer
Dim smeg As String
Dim mrcc As ADODB.Recordset
Dim msgtext As String
Dim shum, zuozh, cbsh As String
Dim isbn1 As String
Dim jiag As Double
Dim fbl, kcl As Integer
Dim cnn As ADODB.Connection
Dim cmddele As New ADODB.Command
Select Case bflagadd
Case 1
If Trim(Combo1.Text & "") = "" Then
smeg = "图书的ISBN编号"
End If
For icount = 0 To 5
If Trim(txtItem(icount) & "") = "" Then
Select Case icount
Case 0
smeg = "书名"
Case 1
smeg = "作者"
Case 2
smeg = "出版社"
Case 3
smeg = "价格"
Case 4
smeg = "复本数"
Case 5
smeg = "库存数"
End Select
smeg = smeg & "不能为空!"
MsgBox smeg, vbOKOnly + vbExclamation, "警告"
txtItem(icount).SetFocus
Exit Sub
End If
Next icount
isbn = Combo1.Text
Combo1.AddItem Trim(isbn)
shum = txtItem(0).Text
zuozh = txtItem(1).Text
cbsh = txtItem(2).Text
jiag = CDbl(txtItem(3).Text)
fbl = CInt(txtItem(4).Text)
kcl = CInt(txtItem(5).Text)
txtsql = "select * from book where isbn= '" & Trim(Combo1.Text) & " ' "
Set mrcc = ExecuteSQL(txtsql, msgtext)
If mrcc.EOF = False Then
MsgBox "此书的ISBN编号已存在!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
mrcc.Close
Else
Set cnn = New ADODB.Connection
cnn.Open ConnectString
cnn.Execute "exec book_insert '" & isbn & "','" & shum & "','" & zuozh & "','" & cbsh & "'," & jiag & "," & fbl & "," & kcl
cnn.Close
MsgBox "数据已保存!", vbOKOnly + vbExclamation, "提示"
Combo1.Text = ""
For icount = 0 To 5
txtItem(icount).Text = ""
Next icount
End If
Case 2
isbn1 = Combo1.Text
If Trim(isbn) <> Trim(isbn1) Then
MsgBox "书籍的ISBN不能修改", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
shum = txtItem(0).Text
zuozh = txtItem(1).Text
cbsh = txtItem(2).Text
jiag = CDbl(txtItem(3).Text)
fbl = CInt(txtItem(4).Text)
kcl = CInt(txtItem(5).Text)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
cnn.Execute "exec book_update '" & isbn & "','" & shum & "','" & zuozh & "','" & cbsh & "'," & jiag & "," & fbl & "," & kcl
cnn.Close
MsgBox "数据已更新!", vbOKOnly + vbExclamation, "提示"
Case 3
Set cnn = New ADODB.Connection
cnn.Open ConnectString
Set cmddele.ActiveConnection = cnn
cmddele.CommandText = "book_delete"
cmddele.CommandType = adCmdStoredProc
cmddele.Parameters.Append cmddele.CreateParameter("ISBN", adChar, adParamInput, 16, isbn)
cmddele.Parameters.Append cmddele.CreateParameter("flag", adInteger, adParamOutput)
cmddele.Execute
If cmddele("flag") = 0 Then
MsgBox "记录已被删除!", vbOKOnly + vbExclamation, "提示"
For icount = 0 To Combo1.ListCount - 1
If Combo1.List(icount) = Combo1.Text And Combo1.Text <> "" Then
Combo1.RemoveItem icount
Combo1.Text = ""
End If
Next icount
For icount = 0 To 5
txtItem(icount).Text = ""
Next icount
Else
MsgBox "记录不能删除,有书未还!", vbOKOnly + vbExclamation, "提示"
End If
cnn.Close
End Select
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Combo1_Click()
Dim strtext, msgtext As String
If (bflagadd = 2 Or bflagadd = 3 Or bflagadd = 4) Then
strtext = Combo1.Text
isbn = Combo1.Text
txtsql = "select*from book where ISBN ='" & strtext & " '"
Set mrc = ExecuteSQL(txtsql, msgtext)
If Not mrc.EOF Then
txtItem(0).Text = mrc.Fields(1)
txtItem(1).Text = mrc.Fields(2)
txtItem(2).Text = mrc.Fields(3)
txtItem(3).Text = CDbl(mrc.Fields(4))
txtItem(4).Text = CInt(mrc.Fields(5))
txtItem(5).Text = CInt(mrc.Fields(6))
End If
mrc.Close
End If
Combo1.SetFocus
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim msgtext As String
If KeyAscii = 13 And bflagadd = 1 Then '添加书籍操作
txtsql = "select*from book where isbn='" & Trim(Combo1.Text) & "'"
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.EOF = False Then
MsgBox "此ISBN已存在!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
mrc.Close
Else
txtItem(0).SetFocus
End If
End If
End Sub
Private Sub Form_Activate()
Dim msgtext As String
Dim ftag As Integer
txtsql = "select * from book"
Set mrc = ExecuteSQL(txtsql, msgtext)
ftag = 0
Do While Not mrc.EOF
Combo1.AddItem Trim(mrc.Fields(0))
If (bflagadd = 2 Or bflagadd = 3 Or bflagadd = 4) And ftag = 0 Then
ftag = 1 '当ftag=0时显示第一条记录信息
Combo1.Text = mrc.Fields(0)
isbn = Combo1.Text
txtItem(0).Text = mrc.Fields(1)
txtItem(1).Text = mrc.Fields(2)
txtItem(2).Text = mrc.Fields(3)
txtItem(3).Text = CDbl(mrc.Fields(4))
txtItem(4).Text = CInt(mrc.Fields(5))
txtItem(5).Text = CInt(mrc.Fields(6))
End If
mrc.MoveNext
Loop
mrc.Close
Combo1.SetFocus
End Sub
Private Sub Form_Load()
Select Case bflagadd
Case 1
Me.Caption = Me.Caption & "添加"
cmd.Visible = True
cmd.Enabled = True
cmd.Caption = "保存(&S)"
Case 2
Me.Caption = Me.Caption & "修改"
cmd.Visible = True
cmd.Enabled = True
cmd.Caption = "更新(&U)"
Case 3
Me.Caption = Me.Caption & "删除"
cmd.Visible = True
cmd.Enabled = True
cmd.Caption = "删除(&D)"
Case 4
Me.Caption = Me.Caption & "查询"
cmd.Visible = False
cmd.Enabled = False
End Select
End Sub
Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
Select Case Index
Case 0
If KeyCode = 13 Then
txtItem(1).SetFocus
End If
Case 1
If KeyCode = 13 Then
txtItem(2).SetFocus
End If
Case 2
If KeyCode = 13 Then
txtItem(3).SetFocus
End If
Case 3
If KeyCode = 13 Then
txtItem(4).SetFocus
End If
Case 4
If KeyCode = 13 Then
txtItem(5).SetFocus
End If
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -