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

📄 frmmodifyclient.frm

📁 数据库课程设计
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmModifyClient 
   Caption         =   "客户删改"
   ClientHeight    =   5265
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5775
   LinkTopic       =   "Form1"
   ScaleHeight     =   5265
   ScaleWidth      =   5775
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "客户信息"
      Height          =   3375
      Left            =   120
      TabIndex        =   6
      Top             =   1080
      Width           =   5535
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   0
         Left            =   1200
         TabIndex        =   13
         Top             =   360
         Width           =   1215
      End
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   2
         Left            =   1200
         TabIndex        =   12
         Top             =   840
         Width           =   1215
      End
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   1
         Left            =   3600
         TabIndex        =   11
         Top             =   330
         Width           =   1695
      End
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   3
         Left            =   3600
         TabIndex        =   10
         Top             =   840
         Width           =   1695
      End
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   5
         Left            =   1200
         TabIndex        =   9
         Top             =   1800
         Width           =   4095
      End
      Begin VB.TextBox txtInfo 
         Height          =   855
         Index           =   6
         Left            =   1200
         TabIndex        =   8
         Top             =   2280
         Width           =   4095
      End
      Begin VB.TextBox txtInfo 
         Height          =   285
         Index           =   4
         Left            =   1200
         TabIndex        =   7
         Top             =   1320
         Width           =   4095
      End
      Begin VB.Label Label1 
         Caption         =   "客户名称:"
         Height          =   255
         Left            =   240
         TabIndex        =   20
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "联  系  人:"
         Height          =   375
         Left            =   240
         TabIndex        =   19
         Top             =   840
         Width           =   1095
      End
      Begin VB.Label Label3 
         Caption         =   "电话号码:"
         Height          =   255
         Left            =   2640
         TabIndex        =   18
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "电子邮件:"
         Height          =   255
         Left            =   2640
         TabIndex        =   17
         Top             =   840
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "通信地址:"
         Height          =   255
         Left            =   240
         TabIndex        =   16
         Top             =   1800
         Width           =   975
      End
      Begin VB.Label Label6 
         Caption         =   "备        注:"
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   2280
         Width           =   975
      End
      Begin VB.Label Label7 
         Caption         =   "产品范围:"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   14
         Top             =   1320
         Width           =   975
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "返回(&C)"
      Height          =   375
      Left            =   3720
      TabIndex        =   5
      Top             =   4680
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "删除(&D)"
      Height          =   375
      Left            =   2400
      TabIndex        =   4
      Top             =   4680
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "修改(&U)"
      Height          =   375
      Left            =   1080
      TabIndex        =   3
      Top             =   4680
      Width           =   1095
   End
   Begin VB.Frame Frame2 
      Caption         =   "选择客户"
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5535
      Begin VB.ComboBox cboClientName 
         Height          =   315
         Left            =   1200
         TabIndex        =   2
         Top             =   360
         Width           =   3015
      End
      Begin VB.Label Label7 
         Caption         =   "客户名称:"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   360
         Width           =   975
      End
   End
End
Attribute VB_Name = "frmModifyClient"
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 cboClientName_Click()
getClientInfo cboClientName.Text
End Sub

Private Sub Command1_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据修改的SQL语句
   sqlStr = "update client set [email]='" & txtInfo(3).Text _
          & "',[telno]='" & txtInfo(1).Text _
          & "',[contact]='" & txtInfo(2).Text _
          & "',[products]='" & txtInfo(4).Text _
          & "',[address]='" & txtInfo(5).Text _
          & "',[memo]='" & txtInfo(6).Text _
          & "' where [clientName]='" & Trim(txtInfo(0).Text) & "'"
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功修改数据!!"
   
   initClients
   
exitSub:
   
   conn.Close

End Sub

Private Sub Command2_Click()
   Dim conn As ADODB.Connection
   
   '组合得到完成数据删除的SQL语句
   sqlStr = "delete from client where [clientName]='" _
            & Trim(txtInfo(0).Text) & "'"
   On Error GoTo exitSub
   Set conn = New ADODB.Connection
   conn.Open connStr
   
   '执行SQL语句
   conn.Execute sqlStr
   MsgBox "成功删除数据!!"
   
   initClients
   
exitSub:
   
   conn.Close

End Sub

Private Sub Command3_Click()
Unload Me

End Sub

Private Sub Form_Load()
initClients
End Sub

Sub initClients()

Dim rstClient As ADODB.Recordset

    '从数据库中读取所有客户名称
    sqlStr = "select clientName from client"
    Set rstClient = ExecuteSQL(sqlStr, msgText)
    cboClientName.Clear
    
    If Not rstClient.EOF Then
        Do While Not rstClient.EOF
            cboClientName.AddItem Trim(rstClient.Fields(0))
            rstClient.MoveNext
        Loop
        cboClientName.ListIndex = 0
    Else
        MsgBox "没有类别信息,请添加!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstClient.Close

End Sub

Sub getClientInfo(clientName As String)
Dim rstClient As ADODB.Recordset

    '根据客户名称从数据库中查询客户信息
    sqlStr = "select * from client where clientName='" _
           & clientName & "'"
           
    Set rstClient = ExecuteSQL(sqlStr, msgText)
  
    If Not rstClient.EOF Then
            txtInfo(0).Text = Trim(rstClient.Fields("clientName"))
            txtInfo(1).Text = Trim(rstClient.Fields("telno"))
            txtInfo(2).Text = Trim(rstClient.Fields("contact"))
            txtInfo(3).Text = Trim(rstClient.Fields("email"))
            txtInfo(4).Text = Trim(rstClient.Fields("products"))
            txtInfo(5).Text = Trim(rstClient.Fields("address"))
            txtInfo(6).Text = Trim(rstClient.Fields("memo"))
            
    Else
        MsgBox "没有找到客户信息!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstClient.Close


End Sub

⌨️ 快捷键说明

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