📄 frmupdateemployee.frm
字号:
VERSION 5.00
Begin VB.Form frmUpdateEmployee
Caption = "修改删除员工信息"
ClientHeight = 3930
ClientLeft = 60
ClientTop = 345
ClientWidth = 5790
LinkTopic = "Form1"
ScaleHeight = 3930
ScaleWidth = 5790
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3720
TabIndex = 18
Top = 3360
Width = 1215
End
Begin VB.CommandButton cmdDelete
Caption = "删除(&D)"
Height = 375
Left = 2160
TabIndex = 17
Top = 3360
Width = 1215
End
Begin VB.CommandButton cmdModify
Caption = "修改(&M)"
Height = 375
Left = 600
TabIndex = 16
Top = 3360
Width = 1215
End
Begin VB.Frame Frame2
Caption = "选择"
Height = 975
Left = 120
TabIndex = 13
Top = 120
Width = 5535
Begin VB.ComboBox cboNo
Height = 315
Left = 1560
TabIndex = 15
Top = 360
Width = 2175
End
Begin VB.Label Label7
Caption = "选择员工编号:"
Height = 255
Left = 240
TabIndex = 14
Top = 360
Width = 1455
End
End
Begin VB.Frame Frame1
Caption = "员工信息"
Height = 1935
Left = 120
TabIndex = 0
Top = 1200
Width = 5535
Begin VB.TextBox txtNo
Enabled = 0 'False
Height = 285
Left = 1200
TabIndex = 6
Text = " "
Top = 360
Width = 1335
End
Begin VB.TextBox txtName
Height = 285
Left = 3720
TabIndex = 5
Top = 360
Width = 1695
End
Begin VB.ComboBox cboSex
Height = 315
Left = 1200
TabIndex = 4
Top = 840
Width = 1215
End
Begin VB.TextBox txtBirthDate
Height = 285
Left = 3720
TabIndex = 3
Top = 840
Width = 1695
End
Begin VB.TextBox txtDepart
Height = 285
Left = 1200
TabIndex = 2
Top = 1320
Width = 1335
End
Begin VB.TextBox txtTitle
Height = 285
Left = 3720
TabIndex = 1
Top = 1320
Width = 1695
End
Begin VB.Label Label1
Caption = "员工编号:"
Height = 255
Left = 240
TabIndex = 12
Top = 360
Width = 1095
End
Begin VB.Label Label2
Caption = "员工姓名:"
Height = 255
Left = 2760
TabIndex = 11
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "性 别:"
Height = 255
Left = 240
TabIndex = 10
Top = 840
Width = 975
End
Begin VB.Label Label4
Caption = "出生日期:"
Height = 255
Left = 2760
TabIndex = 9
Top = 840
Width = 975
End
Begin VB.Label Label5
Caption = "所属部门:"
Height = 255
Left = 240
TabIndex = 8
Top = 1320
Width = 975
End
Begin VB.Label Label6
Caption = "职 务:"
Height = 255
Left = 2760
TabIndex = 7
Top = 1320
Width = 975
End
End
End
Attribute VB_Name = "frmUpdateEmployee"
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 cboNo_Click()
getEmployeeInfo cboNo.Text
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
Dim conn As ADODB.Connection
'组合得到完成数据删除的SQL语句
sqlStr = "delete from employee where" _
& " [employeeNo]='" & Trim(txtNo.Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "成功删除数据!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub cmdModify_Click()
Dim conn As ADODB.Connection
'组合得到完成数据修改的SQL语句
sqlStr = "update employee set [employeeName]='" & txtName.Text _
& "',[sex]='" & cboSex.Text _
& "',[birthdate]=#" & txtBirthDate.Text _
& "#,[department]='" & txtDepart.Text _
& "',[title]='" & txtTitle.Text _
& "' where [employeeNo]='" & Trim(txtNo.Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "成功修改数据!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub Form_Load()
initForm
End Sub
Sub initEmployeeNo()
'在组合列表框中列出所有员工编号
Dim rstEmployeeNo As ADODB.Recordset
'从员工信息表中读取所有员工编号并添加到组合列表框中
sqlStr = "select employeeNo from employee"
Set rstEmployeeNo = ExecuteSQL(sqlStr, msgText)
cboNo.Clear
If Not rstEmployeeNo.EOF Then
Do While Not rstEmployeeNo.EOF
cboNo.AddItem Trim(rstEmployeeNo.Fields(0))
rstEmployeeNo.MoveNext
Loop
cboNo.ListIndex = 0
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstEmployeeNo.Close
End Sub
Sub getEmployeeInfo(no As String)
Dim rstEmployee As ADODB.Recordset
'从员工信息表中读取员工信息
sqlStr = "select * from employee where" _
& " employeeNo='" & no & "'"
Set rstEmployee = ExecuteSQL(sqlStr, msgText)
If Not rstEmployee.EOF Then
txtNo.Text = Trim(rstEmployee.Fields("employeeNo"))
txtName.Text = Trim(rstEmployee.Fields("employeeName"))
cboSex.Text = Trim(rstEmployee.Fields("sex"))
txtBirthDate.Text = Trim(rstEmployee.Fields("birthDate"))
txtDepart.Text = Trim(rstEmployee.Fields("department"))
txtTitle.Text = Trim(rstEmployee.Fields("title"))
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstEmployee.Close
End Sub
Sub initForm()
txtNo = ""
txtName = ""
txtBirthDate = ""
txtDepart = ""
txtTitle = ""
cboSex.Clear
cboSex.AddItem "男"
cboSex.AddItem "女"
initEmployeeNo
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -