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

📄 frmupdateproduct.frm

📁 数据库课程设计
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmUpdateProduct 
   Caption         =   "产品修改删除"
   ClientHeight    =   3960
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6765
   LinkTopic       =   "Form1"
   ScaleHeight     =   3960
   ScaleWidth      =   6765
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdCancel 
      Caption         =   "返回(&C)"
      Height          =   375
      Left            =   4200
      TabIndex        =   21
      Top             =   3360
      Width           =   1215
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "删除(&D)"
      Height          =   375
      Left            =   2760
      TabIndex        =   20
      Top             =   3360
      Width           =   1215
   End
   Begin VB.CommandButton cmdUpdate 
      Caption         =   "修改(&U)"
      Height          =   375
      Left            =   1320
      TabIndex        =   19
      Top             =   3360
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "产品信息"
      Height          =   1935
      Index           =   1
      Left            =   120
      TabIndex        =   6
      Top             =   1200
      Width           =   6495
      Begin VB.TextBox txtProduct 
         Enabled         =   0   'False
         Height          =   285
         Index           =   5
         Left            =   4440
         TabIndex        =   23
         Top             =   1440
         Width           =   1215
      End
      Begin VB.TextBox txtProduct 
         Enabled         =   0   'False
         Height          =   285
         Index           =   0
         Left            =   1440
         TabIndex        =   11
         Top             =   480
         Width           =   1815
      End
      Begin VB.TextBox txtProduct 
         Height          =   285
         Index           =   2
         Left            =   1440
         TabIndex        =   10
         Top             =   960
         Width           =   1215
      End
      Begin VB.TextBox txtProduct 
         Height          =   285
         Index           =   3
         Left            =   4440
         TabIndex        =   9
         Top             =   960
         Width           =   1215
      End
      Begin VB.TextBox txtProduct 
         Height          =   285
         Index           =   4
         Left            =   1440
         TabIndex        =   8
         Top             =   1440
         Width           =   1215
      End
      Begin VB.TextBox txtProduct 
         Enabled         =   0   'False
         Height          =   285
         Index           =   1
         Left            =   4440
         TabIndex        =   7
         Top             =   480
         Width           =   1695
      End
      Begin VB.Label Label7 
         Caption         =   "已售数量:"
         Height          =   255
         Left            =   3480
         TabIndex        =   22
         Top             =   1440
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "产品名称:"
         Height          =   375
         Index           =   1
         Left            =   480
         TabIndex        =   18
         Top             =   480
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "产品价格:"
         Height          =   375
         Index           =   1
         Left            =   480
         TabIndex        =   17
         Top             =   960
         Width           =   1095
      End
      Begin VB.Label Label3 
         Caption         =   "产品成本:"
         Height          =   255
         Left            =   3480
         TabIndex        =   16
         Top             =   960
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "产品数量:"
         Height          =   375
         Left            =   480
         TabIndex        =   15
         Top             =   1440
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "(元)"
         Height          =   255
         Index           =   0
         Left            =   2760
         TabIndex        =   14
         Top             =   960
         Width           =   375
      End
      Begin VB.Label Label5 
         Caption         =   "(元)"
         Height          =   255
         Index           =   1
         Left            =   5760
         TabIndex        =   13
         Top             =   960
         Width           =   375
      End
      Begin VB.Label Label6 
         Caption         =   "产品编号:"
         Height          =   255
         Left            =   3480
         TabIndex        =   12
         Top             =   480
         Width           =   975
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "查询"
      Height          =   975
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6495
      Begin VB.CommandButton cmdQuery 
         Caption         =   "查询(&Q)"
         Height          =   375
         Left            =   5160
         TabIndex        =   5
         Top             =   360
         Width           =   1095
      End
      Begin VB.ComboBox cboNo 
         Height          =   315
         Left            =   3600
         TabIndex        =   4
         Top             =   360
         Width           =   1335
      End
      Begin VB.ComboBox cboName 
         Height          =   315
         Left            =   1080
         TabIndex        =   2
         Top             =   360
         Width           =   1455
      End
      Begin VB.Label Label2 
         Caption         =   "产品编号:"
         Height          =   255
         Index           =   0
         Left            =   2640
         TabIndex        =   3
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "产品名称:"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   360
         Width           =   975
      End
   End
End
Attribute VB_Name = "frmUpdateProduct"
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 cboName_Click()
getProductID cboName.Text
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdDelete_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据删除的SQL语句
   sqlStr = "delete from products where productID='" _
          & Trim(txtProduct(1).Text) & "'"
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功删除数据!!"
   initProducts
   initTextBox
exitSub:
   
   conn.Close

End Sub

Private Sub cmdQuery_Click()
getProductInfo cboNo.Text
End Sub

Private Sub cmdUpdate_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据修改的SQL语句
   sqlStr = "update products set price=" & txtProduct(2).Text _
          & ",cost=" & txtProduct(3).Text _
          & ",stored=" & txtProduct(4).Text _
          & " where productID='" & Trim(txtProduct(1).Text) & "'"
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功修改数据!!"
   initProducts
   initTextBox
exitSub:
   
   conn.Close

End Sub

Private Sub Form_Load()
initProducts
initTextBox
End Sub

Sub initProducts()

Dim rstProduct As ADODB.Recordset

    '从数据库中读取所有产品名称
    sqlStr = "select DISTINCT productName from products"
    Set rstProduct = ExecuteSQL(sqlStr, msgText)
    cboName.Clear
    
    If Not rstProduct.EOF Then
        Do While Not rstProduct.EOF
            cboName.AddItem Trim(rstProduct.Fields(0))
            rstProduct.MoveNext
        Loop
        cboName.ListIndex = 0
    Else
        MsgBox "没有产品信息,请添加!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstProduct.Close

End Sub

Sub getProductID(productName As String)
Dim rstProductID As ADODB.Recordset

    '从数据库中读取指定产品名称的产品ID
    sqlStr = "select productID from products" _
           & " where productName='" & productName & "'"
    Set rstProductID = ExecuteSQL(sqlStr, msgText)
    cboNo.Clear
    
    If Not rstProductID.EOF Then
        Do While Not rstProductID.EOF
            cboNo.AddItem Trim(rstProductID.Fields(0))
            rstProductID.MoveNext
        Loop
        cboNo.ListIndex = 0
    Else
        MsgBox "没有相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstProductID.Close

End Sub

Sub getProductInfo(id As String)
Dim rstProduct As ADODB.Recordset

    '从数据库中读取产品信息
    sqlStr = "select * from products" _
           & " where productID='" & id & "'"
    Set rstProduct = ExecuteSQL(sqlStr, msgText)
    
    If Not rstProduct.EOF Then
            txtProduct(0).Text = Trim(rstProduct.Fields("productName"))
            txtProduct(1).Text = Trim(rstProduct.Fields("productID"))
            txtProduct(2).Text = Trim(rstProduct.Fields("price"))
            txtProduct(3).Text = Trim(rstProduct.Fields("cost"))
            txtProduct(4).Text = Trim(rstProduct.Fields("stored"))
            txtProduct(5).Text = Trim(rstProduct.Fields("saled"))
    Else
        MsgBox "没有找到相关产品信息!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstProduct.Close

End Sub

Sub initTextBox()
Dim i As Integer
For i = 0 To 5
   txtProduct(i).Text = ""
Next i

End Sub

⌨️ 快捷键说明

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