📄 frmbook_check.frm
字号:
VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmbook_check
BorderStyle = 1 'Fixed Single
Caption = "图书登记"
ClientHeight = 6735
ClientLeft = 45
ClientTop = 330
ClientWidth = 10515
Icon = "frmbook_check.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6735
ScaleWidth = 10515
StartUpPosition = 1 '所有者中心
Tag = "check"
Begin VB.Frame Frame1
Height = 6615
Left = 120
TabIndex = 0
Top = 0
Width = 10215
Begin VB.TextBox txt_book
BackColor = &H80000004&
Enabled = 0 'False
ForeColor = &H80000007&
Height = 375
Index = 0
Left = 2280
MaxLength = 10
TabIndex = 11
Text = "txt_book(0"
Top = 1440
Width = 2415
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 375
Index = 1
Left = 6480
MaxLength = 20
TabIndex = 10
Text = "txt_book(1)"
Top = 1440
Width = 2415
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 375
Index = 2
Left = 2280
MaxLength = 10
TabIndex = 9
Text = "txt_book(2"
Top = 2040
Width = 2415
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 375
Index = 4
Left = 2280
MaxLength = 15
TabIndex = 8
Text = "txt_book(4)"
Top = 2640
Width = 2415
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 375
Index = 5
Left = 6480
MaxLength = 10
TabIndex = 7
Text = "txt_book(5"
Top = 2640
Width = 2415
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 375
Index = 6
Left = 2280
MaxLength = 20
TabIndex = 6
Text = "txt_book(6)"
Top = 3240
Width = 6615
End
Begin VB.TextBox txt_book
ForeColor = &H80000007&
Height = 975
Index = 7
Left = 2280
MaxLength = 50
TabIndex = 5
Text = "txt_book(7)"
Top = 3840
Width = 6615
End
Begin VB.TextBox txt_book
Appearance = 0 'Flat
BackColor = &H8000000A&
BorderStyle = 0 'None
Height = 255
Index = 8
Left = 2280
TabIndex = 4
Text = "txt_book(8)"
Top = 5160
Width = 1095
End
Begin VB.CommandButton Cmd_Book_check
Caption = "确认(&O)"
Default = -1 'True
Height = 495
Left = 3000
TabIndex = 3
Top = 5760
Width = 975
End
Begin VB.CommandButton Cmd_BC_exit
Caption = "退出(&E)"
Height = 495
Left = 6000
TabIndex = 2
Top = 5760
Width = 855
End
Begin MSComCtl2.DTPicker DTPicker1
Height = 375
Left = 6480
TabIndex = 1
Top = 2040
Width = 2415
_ExtentX = 4260
_ExtentY = 661
_Version = 393216
CalendarBackColor= 16777215
CalendarForeColor= 12582912
CalendarTitleBackColor= 128
CalendarTitleForeColor= -2147483634
Format = 24444928
CurrentDate = 38318
End
Begin VB.Label Label1
Caption = "图书登记"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00008000&
Height = 615
Left = 4320
TabIndex = 21
Top = 360
Width = 1935
End
Begin VB.Label lbl_book
Caption = "图书编号"
Height = 255
Index = 0
Left = 1080
TabIndex = 20
Top = 1500
Width = 735
End
Begin VB.Label lbl_book
Caption = "图书名称"
Height = 255
Index = 1
Left = 5280
TabIndex = 19
Top = 1500
Width = 735
End
Begin VB.Label lbl_book
Caption = "图书类别"
Height = 255
Index = 2
Left = 1080
TabIndex = 18
Top = 2100
Width = 735
End
Begin VB.Label lbl_book
Caption = "出版日期"
Height = 255
Index = 3
Left = 5280
TabIndex = 17
Top = 2100
Width = 735
End
Begin VB.Label lbl_book
Caption = "图书价格"
Height = 255
Index = 4
Left = 1080
TabIndex = 16
Top = 2700
Width = 735
End
Begin VB.Label lbl_book
Caption = "图书作者"
Height = 255
Index = 5
Left = 5280
TabIndex = 15
Top = 2700
Width = 735
End
Begin VB.Label lbl_book
Caption = "出版社"
Height = 255
Index = 6
Left = 1080
TabIndex = 14
Top = 3300
Width = 735
End
Begin VB.Label lbl_book
Caption = "备注"
Height = 255
Index = 7
Left = 1080
TabIndex = 13
Top = 3900
Width = 735
End
Begin VB.Label lbl_book
Caption = "登记日期"
Height = 255
Index = 8
Left = 1200
TabIndex = 12
Top = 5160
Width = 735
End
Begin VB.Image Image1
Height = 495
Left = 3480
Top = 5040
Width = 5415
End
End
End
Attribute VB_Name = "frmbook_check"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rds_bookid As ADODB.Recordset
Option Explicit
Public Sub renew()
Dim i As Integer
rds_bookid.Open "select max(BOOK_ID) AS maxNUM from 图书信息", myconn, adOpenKeyset, adLockOptimistic, 1
If IsNull(rds_bookid.Fields(0)) Then
txt_book(0).Text = 1
txt_book(0).SelStart = Len(txt_book(0)) + 1
Else
txt_book(0).Text = rds_bookid.Fields(0) + 1
txt_book(0).SelStart = Len(txt_book(0)) + 1
End If
rds_bookid.Close
For i = 1 To 7
If i <> 3 Then txt_book(i) = ""
Next i
DTPicker1.Value = #1/1/1900#
End Sub
Private Sub Form_Activate()
Set rds_bookid = New ADODB.Recordset
If Me.Tag = "check" Then
Call renew
txt_book(8) = Date
End If
End Sub
Private Sub Cmd_Book_check_Click() '确认
Dim i As Integer
'对信息的判断
'Debug.Print "Me.Tag"; Me.Tag '判断状态
For i = 0 To 7
If i <> 3 Then: If i <> 7 And txt_book(i) = "" Then MsgBox "请输入" + lbl_book(i): txt_book(i).SetFocus: Exit Sub
Next i
If DTPicker1.Value >= Date Then MsgBox "出版日期错误": DTPicker1.SetFocus: Exit Sub
'判断《图书价格》是否为数值且小数点后为两位数字
If Not IsNumeric(txt_book(4)) Then MsgBox "图书价格有误,请输入正确的价格": txt_book(4).SetFocus: txt_book(4).SelStart = 0: txt_book(4).SelLength = Len(txt_book(4)): Exit Sub
'InStr(1, txt_book(4), ".") <> 0确认是否包含小数点
'Mid(txt_book(4), 1, InStr(1, txt_book(4), ".") + 2) <>Val(txt_book(4))判断小数点后位数:50/50./50.0/50.00
If InStr(1, txt_book(4), ".") <> 0 And Mid(txt_book(4), 1, InStr(1, txt_book(4), ".") + 2) <> Val(txt_book(4)) Then
MsgBox "图书价格只保留两位小数"
txt_book(4).SetFocus
txt_book(4).SelStart = 0
txt_book(4).SelLength = Len(txt_book(4))
Exit Sub
End If
With rds_book
If Me.Tag = "check" Then
If .State = adStateOpen Then .Close
.Open "图书信息", myconn, adOpenKeyset, adLockPessimistic, adCmdTable
.AddNew
.Update "BOOK_ID", txt_book(0)
ElseIf Me.Tag = "modify" Then
If .State = adStateOpen Then .Close 'Or Left(.Source, 34) <> "select * from 图书信息 where BOOK_ID='" Then
.Open "select * from 图书信息 where BOOK_ID='" + txt_book(0) + "'", myconn, adOpenKeyset, adLockPessimistic, adCmdText
'End If
End If
.Update "BOOK_NAME", txt_book(1)
.Update "BOOK_SORT", txt_book(2)
.Update "BOOK_DATE", DTPicker1.Value
.Update "BOOK_PRICE", Round(txt_book(4), 2)
.Update "BOOK_WRITER", txt_book(5)
.Update "BOOK_CONCERN", txt_book(6)
.Update "BOOK_REMARK", txt_book(7)
.Update "BOOK_CHECK_DATE", CDate(txt_book(8))
.Close
End With
If Me.Tag = "check" Then
Call renew
MsgBox "添加成功"
ElseIf Me.Tag = "modify" Then
Unload Me
End If
End Sub
Private Sub Cmd_BC_exit_Click()
Unload Me
End Sub
Private Sub txt_book_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then Call Cmd_Book_check_Click
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -