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

📄 frmbooks.frm

📁 所在类别: 随书资源/T 工业技术/TP 自动化技术、计算机技术/TP31 计算机软件 其他题名: 作者: 夏邦贵, 刘凡馨等编著 出版者: 机械工业出版社 出版年: 2006 I
💻 FRM
📖 第 1 页 / 共 2 页
字号:
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "出版社:"
      Height          =   180
      Left            =   649
      TabIndex        =   2
      Top             =   1664
      Width           =   720
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "作者:"
      Height          =   180
      Left            =   829
      TabIndex        =   1
      Top             =   1184
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "书名:"
      Height          =   180
      Left            =   829
      TabIndex        =   0
      Top             =   704
      Width           =   540
   End
End
Attribute VB_Name = "frmBooks"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isAdding As Boolean             '定义操作状态标志
Dim objBooks As Recordset           '用于保存图书信息数据表记录
Dim objCn As Connection             '用于建立数据库联接

Private Sub cdmLoadPic_Click()
    Dim strFile$, strDst$
    CommonDialog1.Filter = "图片文件(*.gif,*.jpg,*.bmp)|*.gif;*.jpg;*.bmp"
    CommonDialog1.ShowOpen
    strFile = CommonDialog1.FileName
    If strFile <> "" And Len(Dir(strFile)) > 0 And objBooks.AbsolutePosition > 0 Then
        '将选择的图片文件复制到face目录
        strDst = App.Path & "\booksale\face\face" & objBooks.Fields!book_id & ".jpg"
        If strDst <> strFile Then FileCopy strFile, strDst
        Image1.Picture = LoadPicture(strDst)
        objBooks.Fields!book_face = "face" & objBooks.Fields!book_id & ".jpg"
        objBooks.Update
    End If
End Sub

Private Sub cmdDeletePic_Click()
    If Image1.Picture <> 0 Then     '若图像框中显示了图片,则清除记录中的图书封面字段
        Image1.Picture = LoadPicture()
        objBooks.Fields!book_face = Null
        objBooks.Update
    End If
End Sub

Private Sub cmdExit_Click()
    Unload Me               '关闭图书信息管理窗体
End Sub

Private Sub cmdSeek_Click()
    Dim strKey$
    strKey = InputBox("请输入要查询的图书名称包含字符!", "查询图书信息")
    If strKey = "" Then
        MsgBox "输入无效!", vbInformation, "图书信息管理"
    Else
        With objBooks
            If .RecordCount > 0 Then
                .MoveFirst
                .Find "book_name like '*" & strKey & "*'"
                If .EOF Then
                    MsgBox "无书名包含 " & strKey & " 的图书信息记录!", _
                                vbInformation, "图书信息管理"
                Else
                    ShowData    '显示当前记录数据
                End If
            Else
                MsgBox "无图书信息记录!", vbInformation, "图书信息管理"
            End If
        End With
    End If
End Sub

Private Sub Form_Load()
    '建立数据库联接
    Set objCn = New Connection                 '实例化联接对象
    With objCn                                 '建立数据库联接
        .Provider = "SQLOLEDB"
        .ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
                            "Initial Catalog=图书销售"
        .Open
    End With
    '获取图书信息记录
    Set objBooks = New Recordset                 '实例化objBooks对象
    With objBooks
        Set .ActiveConnection = objCn
        .CursorLocation = adUseClient           '指定使用客户端游标
        .CursorType = adOpenStatic              '指定使用静态游标
        .LockType = adLockOptimistic
        .Open "SELECT * FROM 图书信息"        '获取图书信息登录信息
    End With
    '触发按钮单击事件,显示第一个记录
    cmdMove(0).Value = True
End Sub

Private Sub cmdMove_Click(Index As Integer)
    With objBooks
        Select Case Index           '切换当前记录
            Case 0                  '使第一个记录成为当前记录
                If .RecordCount > 0 And Not .BOF Then .MoveFirst
            Case 1                  '使上一个记录成为当前记录
                If .RecordCount > 0 And Not .BOF Then
                    .MovePrevious
                    If .BOF Then .MoveFirst
                End If
            Case 2                  '使下一个记录成为当前记录
                If .RecordCount > 0 And Not .EOF Then
                    .MoveNext
                    If .EOF Then .MoveLast
                End If
            Case 3                  '使最后一个记录成为当前记录
                If .RecordCount > 0 And Not .EOF Then .MoveLast
        End Select
        ShowData
    End With
    If isAdding Then isAdding = False   '改变当前记录则退出当前添加记录状态
End Sub

Private Sub cmdAdd_Click()
    txtNews = "添加新记录"
    txtName = "": txtWriter = "": txtPublish = ""
    txtDate = "": txtPage = "": txtPrice = ""
    txtBrief = ""
    Image1.Picture = LoadPicture()
    isAdding = True
End Sub

Private Sub cmdDelete_Click()
    '根据是否处于添加记录状态执行不同的操作
    If isAdding Then
        '退出添加记录状态,显示当前记录
        isAdding = False
        ShowData            '显示当前记录数据
    Else
        If objBooks.RecordCount > 0 Then
            If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, _
                        "图书信息管理") = vbYes Then
                objBooks.Delete '执行删除当前记录操作
                cmdMove(2).Value = True '显示下一记录数据
            Else
                ShowData
            End If
        End If
    End If
End Sub
Private Sub cmdSave_Click()
    Dim objCopy As New Recordset
    If Trim(txtName) = "" Then
        MsgBox "书名不能为空!", vbCritical, "图书信息管理"
        txtName.SetFocus
        txtName = ""
    ElseIf Trim(txtWriter) = "" Then
        MsgBox "作者不能为空!", vbCritical, "图书信息管理"
        txtWriter.SetFocus
        txtWriter = ""
    ElseIf Trim(txtPublish) = "" Then
        MsgBox "出版社不能为空!", vbCritical, "图书信息管理"
        txtPublish.SetFocus
        txtPublish = ""
    ElseIf Not IsDate(txtDate) Then
        MsgBox "出版日期无效!", vbCritical, "图书信息管理"
        txtDate.SetFocus
    ElseIf Not IsNumeric(Trim(txtPage)) Then
        MsgBox "图书页数无效!", vbCritical, "图书信息管理"
        txtPage.SetFocus
    ElseIf Not IsNumeric(Trim(txtPrice)) Then
        MsgBox "图书单价无效!", vbCritical, "图书信息管理"
        txtPrice.SetFocus
    ElseIf Trim(txtBrief) = "" Then
        MsgBox "内容简介不能为空!", vbCritical, "图书信息管理"
        txtBrief.SetFocus
        txtBrief = ""
    Else
        With objBooks
            '保存或添加记录
            If isAdding Then .AddNew
            .Fields!book_name = Trim(txtName)
            .Fields!book_writer = Trim(txtWriter)
            .Fields!book_press = Trim(txtPublish)
            .Fields!book_pdate = txtDate
            .Fields!book_page = txtPage
            .Fields!book_price = txtPrice
            .Fields!book_brief = Trim(txtBrief)
            .Update
            MsgBox "数据保存成功!", vbInformation, "图书信息管理"
            isAdding = False
            '显示当前记录编号和记录总数
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
        End With
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    objCn.Close                 '关闭数据联接
    Set objCn = Nothing         '释放数据库联接
    Set objBooks = Nothing      '释放记录集对象
End Sub

Private Sub ShowData()
    With objBooks
        If .RecordCount < 1 Then
            txtNews = "记录:无"    '显示无记录提示
            txtName = "": txtWriter = "": txtPublish = ""
            txtDate = "": txtPage = "": txtPrice = ""
            txtBrief = ""
            Image1.Picture = LoadPicture()
        Else
            '显示当前记录数据
            txtName = .Fields!book_name
            txtWriter = .Fields!book_writer
            txtPublish = .Fields!book_press
            txtDate = .Fields!book_pdate
            txtPage = .Fields!book_page
            txtPrice = .Fields!book_price
            txtBrief = .Fields!book_brief
            If Not IsNull(.Fields!book_face) Then
                Image1.Picture = LoadPicture(App.Path & "\booksale\face\" _
                                                        & .Fields!book_face)
            Else
                Image1.Picture = LoadPicture()
            End If
            '显示当前记录编号和记录总数
            txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
        End If
    End With
    Set objStm = Nothing
End Sub

⌨️ 快捷键说明

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