⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmbooksmanager.frm

📁 本人用VB 6.0和ACCESS编写的图书管理系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:
            TabIndex        =   28
            Top             =   975
            Width           =   630
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            Caption         =   "图书编号:"
            Height          =   180
            Left            =   360
            TabIndex        =   27
            Top             =   405
            Width           =   810
         End
         Begin VB.Label Label15 
            AutoSize        =   -1  'True
            Caption         =   "借出次数:"
            Height          =   180
            Left            =   9120
            TabIndex        =   26
            Top             =   2685
            Width           =   810
         End
         Begin VB.Label Label14 
            AutoSize        =   -1  'True
            Caption         =   "图书价格:"
            Height          =   180
            Left            =   9120
            TabIndex        =   25
            Top             =   2115
            Width           =   810
         End
         Begin VB.Label Label13 
            AutoSize        =   -1  'True
            Caption         =   "入馆时间:"
            Height          =   180
            Left            =   9120
            TabIndex        =   24
            Top             =   1545
            Width           =   810
         End
         Begin VB.Label Label12 
            AutoSize        =   -1  'True
            Caption         =   "现存数量:"
            Height          =   180
            Left            =   9120
            TabIndex        =   23
            Top             =   975
            Width           =   810
         End
         Begin VB.Label Label11 
            AutoSize        =   -1  'True
            Caption         =   "图书总数:"
            Height          =   180
            Left            =   9120
            TabIndex        =   22
            Top             =   405
            Width           =   810
         End
         Begin VB.Label Label10 
            AutoSize        =   -1  'True
            Caption         =   "出版时间:"
            Height          =   180
            Left            =   4440
            TabIndex        =   21
            Top             =   2685
            Width           =   810
         End
         Begin VB.Label Label9 
            AutoSize        =   -1  'True
            Caption         =   "页数:"
            Height          =   180
            Left            =   4440
            TabIndex        =   20
            Top             =   2115
            Width           =   450
         End
         Begin VB.Label Label8 
            AutoSize        =   -1  'True
            Caption         =   "网址:"
            Height          =   180
            Left            =   4440
            TabIndex        =   19
            Top             =   975
            Width           =   450
         End
         Begin VB.Label Label7 
            AutoSize        =   -1  'True
            Caption         =   "图书种类:"
            Height          =   180
            Left            =   4440
            TabIndex        =   18
            Top             =   1545
            Width           =   810
         End
         Begin VB.Label Label6 
            AutoSize        =   -1  'True
            Caption         =   "出版社:"
            Height          =   180
            Left            =   4440
            TabIndex        =   17
            Top             =   405
            Width           =   630
         End
      End
   End
End
Attribute VB_Name = "frmBooksManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim intIndex As Long            '某类别的图书总数递增号

Private Sub cmdAdd_Click()
    On Error GoTo AddErr
    If BookState <> 1 Then cmdEdit.Enabled = Not cmdEdit.Enabled
    'cmdDelete.Enabled = Not cmdDelete.Enabled
    cmdUpdate.Enabled = Not cmdUpdate.Enabled
    cmdRefresh.Enabled = Not cmdRefresh.Enabled
    If Left(cmdAdd.Caption, 2) = "新增" Then
        cmdAdd.Caption = "确认(&O)"
        cmdClose.Caption = "放弃(&C)"
        cmdGenerate.Enabled = True
        DBcomBookSort.Enabled = True
        'Data1.Recordset.MoveLast
        Data1.Recordset.AddNew
        txtBarCode.SetFocus
    Else
        '输入数据有效性验证
        DTComingDate.Value = FormatDateTime(Now, vbShortDate)
        If txtNowTotal > txtBookTotal Then
            MsgBox "现存数量大于图书总数!", vbOKOnly
            cmdClose_Click
            Exit Sub
        End If
        txtNowTotal = txtBookTotal
        cmdAdd.Caption = "新增(&A)"
        cmdClose.Caption = "关闭(&C)"
        cmdGenerate.Enabled = False
        DBcomBookSort.Enabled = False
        '更新数据控件
        Data1.Recordset.Update
        Data1.Recordset.MoveLast
    End If
    Exit Sub
AddErr:
    MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()
    On Error GoTo CloseErr
    If Left(cmdClose.Caption, 2) = "放弃" Then
        cmdClose.Caption = "关闭(&C)"
        cmdGenerate.Enabled = False
        DBcomBookSort.Enabled = False
        If BookState <> 2 Then
            cmdAdd.Caption = "新增(&A)"
            cmdAdd.Enabled = True
        End If
        If BookState <> 1 Then
            cmdEdit.Caption = "修改(&E)"
            cmdEdit.Enabled = True
        End If
        'cmdDelete.Enabled = True
        cmdUpdate.Enabled = True
        cmdRefresh.Enabled = True
        Data1.UpdateControls
        If Not (Data1.Recordset.BOF And Data1.Recordset.EOF) Then Data1.Recordset.MoveLast  '记录不为空,则移到最后
    Else
        Unload Me
    End If
    Exit Sub
CloseErr:
    MsgBox Err.Description
End Sub

Private Sub cmdDelete_Click()
    On Error GoTo DeleteErr
    With Data1.Recordset
        .Delete
        .MoveNext
        If .EOF Then .MoveLast
    End With
    Exit Sub
DeleteErr:
    MsgBox Err.Description
End Sub

Private Sub cmdEdit_Click()
    On Error GoTo EditErr
    If BookState <> 2 Then cmdAdd.Enabled = Not cmdAdd.Enabled
    'cmdDelete.Enabled = Not cmdDelete.Enabled
    cmdUpdate.Enabled = Not cmdUpdate.Enabled
    cmdRefresh.Enabled = Not cmdRefresh.Enabled
    If Left(cmdEdit.Caption, 2) = "修改" Then
        cmdEdit.Caption = "确认(&O)"
        cmdClose.Caption = "放弃(&C)"
        Data1.Recordset.Edit
        txtBarCode.SetFocus
    Else
        '输入数据有效性验证
        If txtNowTotal > txtBookTotal Then
            MsgBox "现存数量大于图书总数!", vbOKOnly
            cmdClose_Click
            Exit Sub
        End If
        txtNowTotal = txtBookTotal
        cmdEdit.Caption = "修改(&E)"
        cmdClose.Caption = "关闭(&C)"
        '更新数据控件
        Data1.Recordset.Update
    End If
    Exit Sub
EditErr:
    MsgBox Err.Description
End Sub

Private Sub cmdFirst_Click()
    If Not Data1.Recordset.BOF Then Data1.Recordset.MoveFirst
End Sub

Private Sub cmdGenerate_Click()
    On Error GoTo GeneErr
    Dim ws As Workspace, db As Database, rs As Recordset
    Dim strAppName As String, strSQL As String
    strAppName = App.Path & "\图书库.mdb"
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(strAppName, False, True)
    '找到该类别的类别简称号
    Dim strBookSort As String, strBookShort As String
    strBookSort = DBcomBookSort.Text
    If strBookSort = "" Or Asc(strBookSort) = 32 Then
        db.Close
        'ws.Close
        Set db = Nothing
        'Set ws = Nothing
        GoTo GeneErr
    End If
    strSQL = "select 类别简称 from 图书类别表 where 图书类别='" & strBookSort & "'"
    Set rs = db.OpenRecordset(strSQL)
    strBookShort = rs.Fields("类别简称")
    rs.Close
    Set rs = Nothing
    '找到该类别的图书总数,并将新增的图书总数+1
    Dim intCount As Long, strIndex As String
    strSQL = "select 图书编号 from 图书表 where 图书种类='" & strBookSort & "'"
    Set rs = db.OpenRecordset(strSQL)
    If rs.RecordCount = 0 Then
        intCount = 0
    Else
        rs.MoveLast
'        strIndex = Trim(rs.Fields("图书编号"))
'        intCount = DivideBookIndex(strIndex)
        intCount = rs.RecordCount
    End If
    intIndex = intCount: intIndex = intIndex + 1
    '生成图书编号
    txtNo.Text = strBookShort & BookIndex(intIndex)
    rs.Close
    db.Close
    'ws.Close
    Set rs = Nothing
    Set db = Nothing
    'Set ws = Nothing
    '总结:由于用对象变量DAO打开数据库和用Data控件打开数据库用的是同一工作区,所以不能关闭工作区。
    DBcomBookSort.Enabled = False
    cmdGenerate.Enabled = False
    Exit Sub
GeneErr:
    MsgBox Err.Description
End Sub

Private Sub cmdLast_Click()
    If Not Data1.Recordset.EOF Then Data1.Recordset.MoveLast
End Sub

Private Sub cmdNext_Click()
    If Data1.Recordset.BOF And Data1.Recordset.EOF Then Exit Sub        '如果记录为空,则退出
    Data1.Recordset.MoveNext
    If Data1.Recordset.EOF Then Data1.Recordset.MoveLast
End Sub

Private Sub cmdPrevious_Click()
    If Data1.Recordset.BOF And Data1.Recordset.EOF Then Exit Sub        '如果记录为空,则退出
    Data1.Recordset.MovePrevious
    If Data1.Recordset.BOF Then Data1.Recordset.MoveFirst
End Sub

Private Sub cmdRefresh_Click()
    '只有多用户应用程序需要
    On Error GoTo RefreshErr
    Data1.Refresh
    Exit Sub
RefreshErr:
    MsgBox Err.Description
End Sub

Private Sub cmdUpdate_Click()
    On Error GoTo UpdateErr
    Data1.UpdateRecord
    Exit Sub
UpdateErr:
    MsgBox Err.Description
End Sub

Private Sub Data1_Reposition()
    Data1.Caption = "图书记录:" & Data1.Recordset.AbsolutePosition + 1
End Sub

Private Sub Form_Activate()
    txtBarCode.SetFocus
End Sub

Private Sub Form_Load()
    OFFCAT.Play "wave"
    If BookState = 0 Then
        Me.Caption = "图书管理"
        SSTab1.Caption = "图书管理"
    ElseIf BookState = 1 Then
        Me.Caption = "新书入库"
        SSTab1.Caption = "新书入库"
        cmdEdit.Enabled = False
    ElseIf BookState = 2 Then
        Me.Caption = "图书资料修改"
        SSTab1.Caption = "图书资料修改"
        cmdAdd.Enabled = False
    End If
    '打开图书库
    Dim strAppName As String, strSQL As String
    strAppName = App.Path & "\图书库.mdb"
    strSQL = "select 图书编号,条形码,ISBN,图书名称,作者,出版社,网址,图书种类,页数,出版时间,图书总数,现存数量,入馆时间,图书价格,借出次数 from 图书表"
    Data1.DatabaseName = strAppName
    Data1.RecordSource = strSQL
    strSQL = "select * from  图书类别表"
    Data2.DatabaseName = strAppName
    Data2.RecordSource = strSQL
    '给字段赋属性值
    txtNo.DataField = "图书编号": txtBarCode.DataField = "条形码": txtISBN.DataField = "ISBN"
    txtBookName.DataField = "图书名称": txtAuthor.DataField = "作者": txtPubHouse.DataField = "出版社"
    txtURL.DataField = "网址"
    DBcomBookSort.DataField = "图书种类": DBcomBookSort.BoundColumn = "图书类别": DBcomBookSort.ListField = "图书类别"
    txtPageNo.DataField = "页数": DTPubDate.DataField = "出版时间": txtBookTotal.DataField = "图书总数"
    txtNowTotal.DataField = "现存数量": DTComingDate.DataField = "入馆时间": txtBookPrice.DataField = "图书价格"
    txtBorrowTimes.DataField = "借出次数"
End Sub

Private Sub Form_Resize()
    SSTab1.Left = (Me.Width - SSTab1.Width) / 2
    Frame1.Left = (SSTab1.Width - Frame1.Width) / 2
End Sub

Private Function BookIndex(Index As Long) As String             '将数字变为6位数的字符串
    Dim i, count As Integer
    BookIndex = Trim(Str(Index))
    count = Len(BookIndex)
    For i = 1 To 6 - count
        BookIndex = "0" & BookIndex
    Next i
End Function

Private Function DivideBookIndex(strIndex As String) As Long    '将图书编号分解为数字
    Dim strNo As String
    strNo = Mid(strIndex, 3)
    DivideBookIndex = Val(strNo)
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -