?? frmmodifyemployee.frm
字號:
VERSION 5.00
Begin VB.Form frmModifyEmployee
Caption = "刪改員工信息"
ClientHeight = 4290
ClientLeft = 60
ClientTop = 345
ClientWidth = 6840
LinkTopic = "Form1"
ScaleHeight = 4290
ScaleWidth = 6840
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 4200
TabIndex = 26
Top = 3720
Width = 1095
End
Begin VB.CommandButton cmdDelete
Caption = "刪除(&D)"
Height = 375
Left = 2640
TabIndex = 25
Top = 3720
Width = 1215
End
Begin VB.CommandButton cmdUpdate
Caption = "修改(&U)"
Height = 375
Left = 1080
TabIndex = 24
Top = 3720
Width = 1215
End
Begin VB.Frame Frame1
Caption = "基本信息"
Height = 2295
Index = 1
Left = 120
TabIndex = 3
Top = 1200
Width = 6615
Begin VB.TextBox txtEName
Enabled = 0 'False
Height = 285
Left = 840
TabIndex = 13
Text = "Text1"
Top = 360
Width = 1935
End
Begin VB.TextBox txtENo
Enabled = 0 'False
Height = 285
Left = 4320
TabIndex = 12
Text = "Text2"
Top = 360
Width = 2055
End
Begin VB.ComboBox cboDept
Height = 315
Left = 840
TabIndex = 11
Text = "Combo1"
Top = 720
Width = 1935
End
Begin VB.TextBox txtBirth
Enabled = 0 'False
Height = 285
Left = 4320
TabIndex = 10
Text = "Text3"
Top = 720
Width = 2055
End
Begin VB.ComboBox cboSex
Enabled = 0 'False
Height = 315
Left = 840
TabIndex = 9
Text = "Combo2"
Top = 1080
Width = 1935
End
Begin VB.TextBox txtBirthPlace
Enabled = 0 'False
Height = 285
Left = 4320
TabIndex = 8
Text = "Text4"
Top = 1080
Width = 2055
End
Begin VB.ComboBox cboDegree
Height = 315
Left = 840
TabIndex = 7
Text = "Combo3"
Top = 1440
Width = 1935
End
Begin VB.TextBox txtMajor
Height = 285
Left = 4320
TabIndex = 6
Text = "Text5"
Top = 1440
Width = 2055
End
Begin VB.TextBox txtTitle
Height = 285
Left = 840
TabIndex = 5
Text = "Text6"
Top = 1800
Width = 1935
End
Begin VB.TextBox txtdateIn
Enabled = 0 'False
Height = 285
Left = 4320
TabIndex = 4
Text = "Text7"
Top = 1800
Width = 2055
End
Begin VB.Label Label1
Caption = "姓名:"
Height = 255
Index = 1
Left = 240
TabIndex = 23
Top = 360
Width = 735
End
Begin VB.Label Label2
Caption = "員 工 號:"
Height = 255
Left = 3360
TabIndex = 22
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "部門:"
Height = 255
Left = 240
TabIndex = 21
Top = 720
Width = 615
End
Begin VB.Label Label4
Caption = "出生日期:"
Height = 255
Left = 3360
TabIndex = 20
Top = 720
Width = 1095
End
Begin VB.Label Label5
Caption = "性別:"
Height = 255
Left = 240
TabIndex = 19
Top = 1080
Width = 615
End
Begin VB.Label Label6
Caption = "籍 貫:"
Height = 255
Left = 3360
TabIndex = 18
Top = 1080
Width = 975
End
Begin VB.Label Label7
Caption = "學歷:"
Height = 255
Left = 240
TabIndex = 17
Top = 1440
Width = 615
End
Begin VB.Label Label8
Caption = "專 業:"
Height = 255
Left = 3360
TabIndex = 16
Top = 1440
Width = 975
End
Begin VB.Label Label9
Caption = "入職時間:"
Height = 255
Left = 3360
TabIndex = 15
Top = 1800
Width = 975
End
Begin VB.Label Label10
Caption = "職稱:"
Height = 255
Left = 240
TabIndex = 14
Top = 1800
Width = 615
End
End
Begin VB.Frame Frame1
Caption = "查詢"
Height = 975
Index = 0
Left = 120
TabIndex = 0
Top = 120
Width = 6615
Begin VB.ComboBox cboNo
Height = 315
Left = 1440
TabIndex = 2
Top = 360
Width = 2535
End
Begin VB.Label Label1
Caption = "員工編號:"
Height = 375
Index = 0
Left = 480
TabIndex = 1
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "frmModifyEmployee"
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
sqlStr = "delete from employeeBasic where employeeNo='" & txtENo.Text & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "成功刪除數據!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub cmdUpdate_Click()
Dim conn As ADODB.Connection
sqlStr = "Update employeeBasic set name='" & txtEName.Text _
& "',department='" & cboDept.Text & "',degree='" _
& cboDegree.Text & "',major='" & txtMajor.Text _
& "',title='" & txtTitle.Text _
& "' where employeeNo='" & txtENo.Text & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "成功修改數據!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub Form_Load()
initForm
End Sub
Sub initDept()
Dim rstDept As ADODB.Recordset
'從數據庫中讀取所有部門名稱并添加到組合列表框中
'方便錄入時進行選擇
sqlStr = "select departName from department"
Set rstDept = ExecuteSQL(sqlStr, msgText)
cboDept.Clear
If Not rstDept.EOF Then
Do While Not rstDept.EOF
cboDept.AddItem Trim(rstDept.Fields(0))
rstDept.MoveNext
Loop
Else
MsgBox "沒有部門信息,請添加部門!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstDept.Close
End Sub
Sub initForm()
txtEName = ""
txtENo = ""
txtBirth = ""
txtBirthPlace = ""
txtMajor = ""
txtTitle = ""
txtdateIn = ""
cboSex.Clear
cboSex.AddItem "男"
cboSex.AddItem "女"
cboDegree.Clear
cboDegree.AddItem "高中"
cboDegree.AddItem "專科"
cboDegree.AddItem "本科"
cboDegree.AddItem "碩士研究生"
cboDegree.AddItem "博士研究生"
initDept
initEmployeeNo
End Sub
Sub initEmployeeNo()
Dim rstEmployeeNo As ADODB.Recordset
'從數據庫中讀取所有員工編號并添加到組合列表框中
sqlStr = "select employeeNo from employeeBasic"
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 EmployeeBasic where employeeNo='" & no & "'"
Set rstEmployee = ExecuteSQL(sqlStr, msgText)
If Not rstEmployee.EOF Then
txtEName.Text = Trim(rstEmployee.Fields("name"))
txtENo.Text = Trim(rstEmployee.Fields("employeeNo"))
cboDept.Text = Trim(rstEmployee.Fields("department"))
cboSex.Text = Trim(rstEmployee.Fields("sex"))
cboDegree.Text = Trim(rstEmployee.Fields("degree"))
txtBirth.Text = Trim(rstEmployee.Fields("birthdate"))
txtBirthPlace.Text = rstEmployee.Fields("birthplace")
txtMajor.Text = rstEmployee.Fields("major")
txtTitle.Text = rstEmployee.Fields("title")
txtdateIn.Text = rstEmployee.Fields("dateStart")
Else
MsgBox "沒找到符合條件的數據!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstEmployee.Close
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -