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

📄 frmadddisk.frm

📁 数据库课程设计
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmAddDisk 
   Caption         =   "添加影碟"
   ClientHeight    =   4425
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6495
   LinkTopic       =   "Form1"
   ScaleHeight     =   4425
   ScaleWidth      =   6495
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdCancel 
      Caption         =   "返回(&C)"
      Height          =   375
      Left            =   3360
      TabIndex        =   15
      Top             =   3840
      Width           =   1215
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "添加(&A)"
      Height          =   375
      Left            =   1560
      TabIndex        =   14
      Top             =   3840
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "影碟信息"
      Height          =   3495
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6255
      Begin VB.ComboBox cboType 
         Height          =   315
         Left            =   960
         TabIndex        =   17
         Text            =   "Combo1"
         Top             =   1200
         Width           =   2055
      End
      Begin VB.TextBox txtItem 
         Height          =   645
         Index           =   5
         Left            =   960
         MultiLine       =   -1  'True
         TabIndex        =   13
         Text            =   "frmAddDisk.frx":0000
         Top             =   2640
         Width           =   5055
      End
      Begin VB.TextBox txtItem 
         Height          =   855
         Index           =   4
         Left            =   960
         MultiLine       =   -1  'True
         TabIndex        =   11
         Text            =   "frmAddDisk.frx":0006
         Top             =   1680
         Width           =   5055
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   3
         Left            =   4200
         TabIndex        =   7
         Text            =   "Text4"
         Top             =   840
         Width           =   1815
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   2
         Left            =   960
         TabIndex        =   5
         Text            =   "Text3"
         Top             =   810
         Width           =   1215
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   1
         Left            =   4200
         TabIndex        =   4
         Text            =   "Text1"
         Top             =   360
         Width           =   1815
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   0
         Left            =   960
         TabIndex        =   2
         Text            =   "Text2"
         Top             =   360
         Width           =   2055
      End
      Begin VB.Label Label8 
         Caption         =   "类别:"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   1200
         Width           =   615
      End
      Begin VB.Label Label7 
         Caption         =   "备注:"
         Height          =   255
         Left            =   360
         TabIndex        =   12
         Top             =   2640
         Width           =   615
      End
      Begin VB.Label Label6 
         Caption         =   "简介:"
         Height          =   255
         Left            =   360
         TabIndex        =   10
         Top             =   1680
         Width           =   615
      End
      Begin VB.Label Label5 
         Caption         =   "(元/天)"
         Height          =   255
         Left            =   2160
         TabIndex        =   9
         Top             =   840
         Width           =   855
      End
      Begin VB.Label Label4 
         Caption         =   "数        量:"
         Height          =   255
         Left            =   3240
         TabIndex        =   8
         Top             =   840
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "租金:"
         Height          =   255
         Left            =   360
         TabIndex        =   6
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "购买日期:"
         Height          =   375
         Left            =   3240
         TabIndex        =   3
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "名称:"
         Height          =   255
         Left            =   360
         TabIndex        =   1
         Top             =   360
         Width           =   615
      End
   End
End
Attribute VB_Name = "frmAddDisk"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public sqlStr As String
Public msgText As String

Private Sub cmdAdd_Click()
 Dim rstDisk As ADODB.Recordset
 Dim i As Integer
  
 For i = 0 To 3
    If txtItem(i).Text = "" Then
    
       MsgBox "请将信息填写完整", vbOKOnly + vbExclamation, "警告"
 
       Exit Sub
    
    End If
 Next i

 '添加新记录
 sqlStr = "select * from disks"
 Set rstDisk = ExecuteSQL(sqlStr, msgText)
 rstDisk.AddNew
 rstDisk.Fields("diskName") = txtItem(0).Text
 rstDisk.Fields("buyDate") = txtItem(1).Text
 rstDisk.Fields("payForRent") = txtItem(2).Text
 rstDisk.Fields("stock") = txtItem(3).Text
 rstDisk.Fields("total") = txtItem(3).Text
 rstDisk.Fields("description") = txtItem(4).Text
 rstDisk.Fields("memo") = txtItem(5).Text
 rstDisk.Fields("category") = cboType.Text
 rstDisk.Update
 rstDisk.Close
     
 MsgBox "影碟信息添加完成!", vbOKOnly + vbExclamation, "警告"
 
 initTextBox

End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub Form_Load()

'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2

initTextBox
initCategories
End Sub

Sub initTextBox()
Dim i As Integer

'将文本框清空
For i = 0 To 5
   txtItem(i).Text = ""
Next i
End Sub

Sub initCategories()
'方法的作用:将类别表中的类别名称显示到列表框中

Dim rstCategory As ADODB.Recordset

    '从数据库中读取所有类别并添加到组合列表框中
    sqlStr = "select name from categories"
    Set rstCategory = ExecuteSQL(sqlStr, msgText)
    cboType.Clear
    
    If Not rstCategory.EOF Then
        
            Do While Not rstCategory.EOF
                cboType.AddItem Trim(rstCategory.Fields(0))
                rstCategory.MoveNext
            Loop
            cboType.ListIndex = 0
        
    Else
        MsgBox "没有类别信息,请添加!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstCategory.Close

End Sub

⌨️ 快捷键说明

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