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

📄 frmupdatedisk.frm

📁 数据库课程设计
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmUpdateDisk 
   Caption         =   "影碟信息-修改删除"
   ClientHeight    =   4815
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7455
   LinkTopic       =   "Form1"
   ScaleHeight     =   4815
   ScaleWidth      =   7455
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "影碟信息"
      Height          =   3495
      Index           =   1
      Left            =   120
      TabIndex        =   6
      Top             =   1200
      Width           =   7215
      Begin VB.TextBox txtItem 
         Enabled         =   0   'False
         Height          =   285
         Index           =   6
         Left            =   4680
         TabIndex        =   23
         Text            =   "Text1"
         Top             =   1200
         Width           =   2295
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   0
         Left            =   960
         TabIndex        =   13
         Text            =   "Text2"
         Top             =   360
         Width           =   2415
      End
      Begin VB.TextBox txtItem 
         Enabled         =   0   'False
         Height          =   285
         Index           =   1
         Left            =   4680
         TabIndex        =   12
         Text            =   "                 "
         Top             =   360
         Width           =   2295
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   2
         Left            =   960
         TabIndex        =   11
         Text            =   "Text3"
         Top             =   810
         Width           =   1575
      End
      Begin VB.TextBox txtItem 
         Height          =   285
         Index           =   3
         Left            =   4680
         TabIndex        =   10
         Text            =   "Text4"
         Top             =   840
         Width           =   2295
      End
      Begin VB.TextBox txtItem 
         Height          =   855
         Index           =   4
         Left            =   960
         MultiLine       =   -1  'True
         TabIndex        =   9
         Text            =   "frmUpdateDisk.frx":0000
         Top             =   1680
         Width           =   6015
      End
      Begin VB.TextBox txtItem 
         Height          =   645
         Index           =   5
         Left            =   960
         MultiLine       =   -1  'True
         TabIndex        =   8
         Text            =   "frmUpdateDisk.frx":0006
         Top             =   2640
         Width           =   6015
      End
      Begin VB.ComboBox cboType 
         Height          =   315
         Left            =   960
         TabIndex        =   7
         Text            =   "Combo1"
         Top             =   1200
         Width           =   2415
      End
      Begin VB.Label Label9 
         Caption         =   "库  存  量:"
         Height          =   255
         Left            =   3720
         TabIndex        =   22
         Top             =   1200
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "名称:"
         Height          =   255
         Left            =   360
         TabIndex        =   21
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "购买日期:"
         Height          =   255
         Index           =   1
         Left            =   3720
         TabIndex        =   20
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "租金:"
         Height          =   255
         Left            =   360
         TabIndex        =   19
         Top             =   840
         Width           =   615
      End
      Begin VB.Label Label4 
         Caption         =   "总  数  量:"
         Height          =   255
         Left            =   3720
         TabIndex        =   18
         Top             =   840
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "(元/天)"
         Height          =   255
         Left            =   2520
         TabIndex        =   17
         Top             =   840
         Width           =   855
      End
      Begin VB.Label Label6 
         Caption         =   "简介:"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   1680
         Width           =   615
      End
      Begin VB.Label Label7 
         Caption         =   "备注:"
         Height          =   255
         Left            =   360
         TabIndex        =   15
         Top             =   2640
         Width           =   615
      End
      Begin VB.Label Label8 
         Caption         =   "类别:"
         Height          =   255
         Left            =   360
         TabIndex        =   14
         Top             =   1200
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "选择"
      Height          =   975
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7215
      Begin VB.ComboBox cboDisks 
         Height          =   315
         Left            =   1200
         TabIndex        =   5
         Text            =   "Combo1"
         Top             =   360
         Width           =   1335
      End
      Begin VB.CommandButton cmdCancel 
         Caption         =   "返回(&C)"
         Height          =   375
         Left            =   5760
         TabIndex        =   4
         Top             =   360
         Width           =   1095
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "删除(&D)"
         Height          =   375
         Left            =   4320
         TabIndex        =   3
         Top             =   360
         Width           =   1095
      End
      Begin VB.CommandButton cmdModify 
         Caption         =   "修改(&M)"
         Height          =   375
         Left            =   2880
         TabIndex        =   2
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "影碟编号:"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   360
         Width           =   975
      End
   End
End
Attribute VB_Name = "frmUpdateDisk"
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 cboDisks_Click()
getDiskInfo
End Sub


Private Sub cmdCancel_Click()
Unload Me

End Sub

Private Sub cmdDelete_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据修改的SQL语句
   sqlStr = "delete from disks where [no]=" & Trim(cboDisks.Text)
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功删除数据!!"
   
   initDiskNo
   
exitSub:
   
   conn.Close

End Sub

Private Sub cmdModify_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据修改的SQL语句
   sqlStr = "update disks set diskName='" & txtItem(0).Text _
          & "',[description]='" & txtItem(4).Text _
          & "',payForRent=" & txtItem(2).Text _
          & ",stock=" & txtItem(6).Text _
          & ",total=" & txtItem(3).Text _
          & ",[memo]='" & txtItem(5).Text _
          & "',category='" & cboType.Text _
          & "' where [no]=" & Trim(cboDisks.Text)
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功修改数据!!"
   
   initDiskNo
   
exitSub:
   
   conn.Close

End Sub

Private Sub Form_Load()

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

initTextBox
initCategories
initDiskNo
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

Sub initDiskNo()
Dim rstDisks As ADODB.Recordset

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

End Sub

Sub getDiskInfo()
Dim rstDisk As ADODB.Recordset

    '从数据库中查找符合条件的影碟信息
    sqlStr = "select * from disks where [no]=" & cboDisks.Text
    Set rstDisk = ExecuteSQL(sqlStr, msgText)
    
    If Not rstDisk.EOF Then
        txtItem(0).Text = rstDisk.Fields("diskName")
        txtItem(1).Text = rstDisk.Fields("buyDate")
        txtItem(2).Text = rstDisk.Fields("payForRent")
        txtItem(3).Text = rstDisk.Fields("total")
        txtItem(4).Text = rstDisk.Fields("description")
        txtItem(5).Text = rstDisk.Fields("memo")
        txtItem(6).Text = rstDisk.Fields("stock")
       cboType.Text = rstDisk.Fields("category")
        
    Else
        MsgBox "没有找到符合条件的数据记录!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstDisk.Close

End Sub

⌨️ 快捷键说明

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